xBimTeam / XbimGeometry

XbimGeometry contains the CLR interop libraries and the c++ engine used to compute the 3D geometry of models.
https://xbimteam.github.io/
Other
260 stars 132 forks source link

Modifying geometry - update IFC file. #345

Closed DamianOtto closed 3 years ago

DamianOtto commented 3 years ago

Hello, I wanted to update IFC file after modifying its geometry (for specific model). How can I do that?

Steps (or code) to reproduce the issue:

I have two approaches to modify geometry.

1.

using (var model = IfcStore.Open(filePath))
{
    var wall = model.Instances.OfType<IIfcBuildingElement>().Single(x => x.GlobalId == "3cUkl32yn9qRSPvBJVyWy4");
    Xbim3DModelContext context = new Xbim3DModelContext(model);
    context.CreateContext();

    var wallGeometry = instances.Single(x => x.IfcProductLabel == 1 && x.Transformation.IsIdentity == false);   
    XbimMatrix3D transformationMatrix = GetTransformationMatrix(wallGeometry.Transformation);
    wallGeometry.Transformation = transformationMatrix;
    // SAVE MODIFIED GEOMETRY TO IFC FILE?
}

2.

using (var model = IfcStore.Open(filePath))
{
    var wall = model.Instances.OfType<IIfcBuildingElement>().Single(x => x.GlobalId == "3cUkl32yn9qRSPvBJVyWy4");

    Xbim3DModelContext context = new Xbim3DModelContext(model);
    context.CreateContext();

    var wallGeometry = instances.Single(x => x.IfcProductLabel == 1 && x.Transformation.IsIdentity == false);

    XbimShapeGeometry geometry = context.ShapeGeometry(wallGeometry);

    byte[] data = ((IXbimShapeGeometryData)geometry).ShapeData;

    using (var stream = new MemoryStream(data))
    using (var reader = new BinaryReader(stream))
    {
       XbimShapeTriangulation mesh = reader.ReadShapeTriangulation();

       XbimMatrix3D transformationMatrix = GetTransformationMatrix(wallGeometry.Transformation);

       XbimShapeTriangulation modifiedMesh = mesh.Transform(transformationMatrix);
       //HOW TO SAVE THIS GEOMETRY MESHTO IFC FILE?
    }
}

static XbimMatrix3D GetTransformationMatrix(XbimMatrix3D baseTransformationMatrix)
{
    var transformationMatrix = XbimMatrix3D.Identity;

    transformationMatrix.Scale(1.1);

    transformationMatrix.Scale(new XbimVector3D(2d, 1d, 1d));
    transformationMatrix.RotateAroundXAxis(1d);
    transformationMatrix.RotateAroundYAxis(2d);
    transformationMatrix.OffsetX = baseTransformationMatrix.OffsetX;
    transformationMatrix.OffsetY = baseTransformationMatrix.OffsetY;
    transformationMatrix.OffsetZ = baseTransformationMatrix.OffsetZ;

    return transformationMatrix;
}

Minimal file to reproduce the issue:

IFC file with for example wall model.

Expected behavior:

Save modified geometry for specific model i.e. update IFC file.

bekraft commented 3 years ago

Hi,

you can't save the geometry directly back to IFC. It's generated and doesn't affect the IFC. You have to modify the placements (IfcObjectPlacement, search the IFC from bS specs to find it) entities if the IFC model instance. Each IFC product has a placement,

Concerning the final transformation, it depends on the parent scene structure. See XbimPlacementTree and maybe the extensions of IfcPlacementExtensions will help you.

Cheers, Bernold

DamianOtto commented 3 years ago

Hi, except of wexbim file, I'm able to save this geometry to glTF file?

CBenghi commented 3 years ago

See https://github.com/xBimTeam/XbimGltf

On Fri, 21 May 2021 at 08:56, DamianOtto @.***> wrote:

Hi, expect of wexbim file, I'm able to save this geometry to glTF file?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/xBimTeam/XbimGeometry/issues/345#issuecomment-845707222, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJY7MLJ3TUB6LP4EDYBB6TTOX7ZJANCNFSM45IQB7DQ .