Advertisement
Ajes1337

Untitled

May 31st, 2017
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.90 KB | None | 0 0
  1. private static byte[] ReadIfcFileAjesStyle(string ifcFilename) {
  2.             List<Vector3[]> vecs = new List<Vector3[]>();
  3.             List<int[]> trises = new List<int[]>();
  4.             List<string> types = new List<string>();
  5.             using (var model2 = IfcStore.Open(ifcFilename)) {
  6.                 if (model2.GeometryStore.IsEmpty) {
  7.                     Console.WriteLine("model.GeometryStore.IsEmpty");
  8.                     var context = new Xbim3DModelContext(model2);
  9.                     context.CreateContext();//skal køre for at virke..
  10.                 }
  11.                 XbimModelPositioningCollection modelPositions = new XbimModelPositioningCollection();
  12.                 short userDefinedId = 0;
  13.                 model2.UserDefinedId = userDefinedId;
  14.                 modelPositions.AddModel(model2.ReferencingModel);
  15.                 if (model2.IsFederation) {
  16.                     foreach (IReferencedModel refModel in model2.ReferencedModels) {
  17.                         refModel.Model.UserDefinedId = ++userDefinedId;
  18.                         IfcStore v = refModel.Model as IfcStore;
  19.                         if (v != null)
  20.                             modelPositions.AddModel(v.ReferencingModel);
  21.                     }
  22.                 }
  23.                 XbimRect3D modelBounds = modelPositions.GetEnvelopeInMeters();
  24.                 XbimPoint3D p = modelBounds.Centroid();
  25.                 XbimVector3D modelTranslation = new XbimVector3D(-p.X, -p.Y, -p.Z);
  26.                 double oneMeter = model2.ModelFactors.OneMetre;
  27.                 XbimMatrix3D translation = XbimMatrix3D.CreateTranslation(modelTranslation * oneMeter);
  28.                 XbimMatrix3D scaling = XbimMatrix3D.CreateScale(1 / oneMeter);
  29.                 XbimMatrix3D transform = translation * scaling;
  30.                 WpfMaterial mat = new WpfMaterial();
  31.                 Color SelectionColor = Colors.Blue;
  32.                 mat.CreateMaterial(new XbimColour("Selection", SelectionColor.ScR, SelectionColor.ScG, SelectionColor.ScB, SelectionColor.ScA));
  33.                 Console.WriteLine("model.Instances amount: " + model2.Instances.Count);
  34.                 bool runOnce = false;
  35.                 foreach (IPersistEntity entityThe in model2.Instances) {
  36.                     WpfMeshGeometry3D m = WpfMeshGeometry3D.GetGeometry(entityThe, transform, mat);
  37.                     string nameOfType = entityThe.GetType().ToString();
  38.                     List<Vector3> vecsHere = new List<Vector3>();
  39.                     foreach (Point3D point in m.Mesh.Positions) {
  40.                         vecsHere.Add(new Vector3(point));
  41.                     }
  42.                     vecs.Add(vecsHere.ToArray());
  43.                     trises.Add(m.Mesh.TriangleIndices.ToArray());
  44.                     types.Add(nameOfType);
  45.                 }
  46.             }
  47.             byte[] data = SerializerMeshPack.SerializeMeshPack(vecs, trises, types);
  48.             return data;
  49.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement