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
254 stars 128 forks source link

How to get geometry correctly? #299

Open GVladislavG opened 3 years ago

GVladislavG commented 3 years ago

Hello! I try to get geometry, using this code

   //Получаем XbimShapeInstances для данного IfcElement
   List<XbimShapeInstance> shapeInsts = (from t in m_ShapeInsts // определяем каждый объект из teams как t
                                                 where t.IfcProductLabel == EntLabel //фильтрация по критерию                                                 
                                                 select t).ToList(); // выбираем объект

            if (shapeInsts == null || shapeInsts.Count == 0) return;            

            //Обрабатываем все XbimShapeInstance данного IFCElement
            foreach (var instance in shapeInsts)
            {
                var transfor = instance.Transformation; //Transformation matrix (location point inside)                

                XbimShapeGeometry geometry = 
                m_3DMdlContext.ShapeGeometry(instance);   //Instance geometry
                XbimRect3D box = geometry.BoundingBox; //bounding box you need

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

                //Получим сетку треугольников
                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>;
                    }
                 }
             }

But result is not quite correct. Screen

I suppose I have to use transfor matrix. But I don't know how to do it right. Thanks for the answers.

martin1cerny commented 3 years ago

See the code here.

GVladislavG commented 3 years ago

I applied this code

         var mesh = reader.ReadShapeTriangulation();
         mesh.Transform(transfor);

but result is still the same(

martin1cerny commented 3 years ago
   var mesh = reader.ReadShapeTriangulation();
   mesh =  mesh.Transform(transfor);