xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
485 stars 172 forks source link

[QUESTION] Classes in this library for getting Mesh of entity #506

Closed Blogbotana closed 1 year ago

Blogbotana commented 1 year ago

Hi everyone, can you help me with my problem? I have an IFC file and I need to get bynary data of geometry (Vertices, Triangles, Nornals). Usually I have "Swept Solid" representation.

I tried to use Xbim.Tessellator.XbimTessellator, but it doesn't work with IfcExtrudedAreaSolid. Also I tried to use Xbim.Geometry.Engine.Interop.XbimGeometryEngine but I didn't understand how it works properly. How I can get data of Vertices, Triangles and Normals?

Thank you

GVladislavG commented 1 year ago

Hi, @Blogbotana. You can try and develop this code sample

var m_3DMdlContext = new Xbim3DModelContext(m_model);
                    m_3DMdlContext.MaxThreads = 1;
                    m_3DMdlContext.CreateContext();

var m_ShapeInsts = m_3DMdlContext.ShapeInstances().ToList();
if (shapeInsts == null || shapeInsts.Count == 0)
                shapeInsts = (from inst in m_ShapeInsts
                              where inst.IfcProductLabel == EntLabel select inst).ToList();

foreach (var instance in shapeInsts)
{  
    using (var stream = new MemoryStream(data))
                {
                    using (var reader = new BinaryReader(stream))
                    {
                        var mesh = reader.ReadShapeTriangulation();                        

                        List<XbimFaceTriangulation> faces = mesh.Faces as List<XbimFaceTriangulation>;
                        List<XbimPoint3D> vertices = mesh.Vertices as List<XbimPoint3D>;
                     }
                 }
}
Blogbotana commented 1 year ago

Thank you for your feedback. It was very helpfull. I tried to use it, but this lose part of geometry. What to do this that? Original and Result

martin1cerny commented 1 year ago

You may need to change deflection angle when you create Xbim3DModelContext That defines how smooth curves are tesselated.

Blogbotana commented 1 year ago

@martin1cerny There's no any deflection angle and I didn't find any property or field

Blogbotana commented 1 year ago

I found CustomMeshingBehaviourdelegate, but don't understand how it works

Blogbotana commented 1 year ago

I tried to change deflection, but it didn't help me. May be because this is C profile in representation?

martin1cerny commented 1 year ago

You can change deflection settings using IModel.ModelFactors. DeflectionAngle. Can you share the IFC file?

Blogbotana commented 1 year ago

Yes, sure. I'm trying to work with purlins out22.zip

Blogbotana commented 1 year ago

Could you repeat the same result?

jomijomi commented 1 year ago

I found CustomMeshingBehaviourdelegate, but don't understand how it works

You can use it something like this :

private Xbim3DModelContext.MeshingBehaviourResult MyCustomMeshingBehaviour(int elementId, int typeId, ref double linearDeflection, ref double angularDeflection)
{
    if (typeId == 571) //rebars, don't make them too detailed (i.e. do coarse tessellation)
    {
        linearDeflection *= 10;
        angularDeflection = 1.5;
    }

    return Xbim3DModelContext.MeshingBehaviourResult.Default;
}

IfcStore theModel = IfcStore.Open(theFileName);
var context = new Xbim3DModelContext(theModel);
context.CustomMeshingBehaviour = MyCustomMeshingBehaviour;
context.CreateContext();
jomijomi commented 1 year ago

Ok, now I actually looked at your images also, it's about the fillet radius, right?? Then you should be able to fiddle with the "ModelFactors", specifically "ProfileDefLevelOfDetail". From the comments in the code: "Indicates level of detail for IfcProfileDefinitions, if 0 no fillet radii are applied, no leg slopes area applied, if 1 all details are applied"

/Mikael

jomijomi commented 1 year ago

Just tested, it works, just set

theModel.ModelFactors.ProfileDefLevelOfDetail = 1;

before calling CreateContext() (First image below is with no fillet, the other two with fillet, i.e. ProfileDefLevelOfDetail set to one)

No_fillet Fillet_01 Fillet_02

Blogbotana commented 1 year ago

Thank you very much @jomijomi you helped me a lot image