I am using the Components library from ThatOpen to load an IFC file to my Three.js scene. With DragControls I am able to move stuff around, and I save the moved elements to a Map with the expressIDs as keys and the FragmentsGroups as values. Then with the Web-IFC library I am finding the moved elements and try to update their placement, but the issue is that my code works only for certain elements, and for other elements the axes are being interchanged. For example, I move a door a lot to the left and a bit forward, export to IFC, open the IFC and it is properly placed. But if I move a window a lot to the left and a bit forward, export to IFC, when I open it, it is placed a lot forward and a bit to the left, so the x and z axis are switched...
private changeObjectTransformation(selectionGroup: FRAG.FragmentsGroup, expressIds: Set<number>) {
for (let expressId of expressIds) {
// Get the object from ifc file
const object = this.ifcApi.GetLine(this.modelId, expressId);
const objectPlac = this.ifcApi.GetLine(this.modelId, object.ObjectPlacement.value);
const relativePlac = this.ifcApi.GetLine(this.modelId, objectPlac.RelativePlacement.value);
const axis = this.ifcApi.GetLine(this.modelId, relativePlac.Axis.value);
const refDir = this.ifcApi.GetLine(this.modelId, relativePlac.RefDirection.value);
const location = this.ifcApi.GetLine(this.modelId, relativePlac.Location.value);
const position = selectionGroup.position;
// Create a new placement
const point = this.ifcApi.CreateIfcEntity(this.modelId, WEBIFC.IFCCARTESIANPOINT, [
position.x,
position.z,
position.y
]);
// Create axis2placement3d
const axis2placement3d = this.ifcApi.CreateIfcEntity(this.modelId, WEBIFC.IFCAXIS2PLACEMENT3D,
point,
axis,
refDir
);
// Create new local placement
const localPlacement = this.ifcApi.CreateIfcEntity(this.modelId, WEBIFC.IFCLOCALPLACEMENT,
objectPlac.PlacementRelTo, // RelativeTo (keeping the original reference)
axis2placement3d // RelativePlacement
);
// Update the object's placement
object.ObjectPlacement = localPlacement;
// Write the modified object back to the model
this.ifcApi.WriteLine(this.modelId, object);
}
}