private void GenerateGeometry(IntPtr model, IFCItem item) { while (item != null) { // Generate WireFrames Geometry IfcEngine.Setting setting = IfcEngine.Setting.Default; IfcEngine.Mask mask = IfcEngine.Mask.Default; mask |= IfcEngine.Mask.DoublePrecision; // PRECISION (32/64 bit) mask |= IfcEngine.Mask.UseIndex64; // INDEX ARRAY (32/64 bit) mask |= IfcEngine.Mask.GenNormals; // NORMALS mask |= IfcEngine.Mask.GenTriangles; // TRIANGLES mask |= IfcEngine.Mask.GenWireFrame; // WIREFRAME setting |= IfcEngine.Setting.GenWireframe; // WIREFRAME ON ModelManager.Instance.IFCEngine.SetFormat(model, setting, mask); GenerateWireFrameGeometry(model, item); setting = IfcEngine.Setting.Default; setting |= IfcEngine.Setting.GenNormals; // NORMALS ON setting |= IfcEngine.Setting.GenTriangles; // TRIANGLES ON ModelManager.Instance.IFCEngine.SetFormat(model, setting, mask); GenerateFacesGeometry(model, item); ModelManager.Instance.IFCEngine.CleanMemory(model); GenerateGeometry(model, item.child); item = item.next; } }
private void FillMeshByIfcColor(IFCItem item) { if (item.Mesh3d != null) { if (item.ifcTreeItem.ifcColor != null) { var ifcColor = item.ifcTreeItem.ifcColor; var color = System.Windows.Media.Color.FromArgb( (byte)(255 - ifcColor.A * 255), (byte)(ifcColor.R * 255), (byte)(ifcColor.G * 255), (byte)(ifcColor.B * 255)); item.Mesh3d.Material = new PhongMaterial() { AmbientColor = System.Windows.Media.Colors.Black.ToColor4(), DiffuseColor = System.Windows.Media.Colors.Black.ToColor4(), EmissiveColor = color.ToColor4(), ReflectiveColor = System.Windows.Media.Colors.Black.ToColor4(), SpecularColor = color.ToColor4() }; } else { item.Mesh3d.Material = PhongMaterials.Bronze; } } }
public void BuildTree(IntPtr model, IFCItem item) { var treeData = new IFCTreeData(this.ifcEngine, model, item, this.treeViewControl); treeData.BuildTree(); this.ModelName = treeData.ModelName; }
private void GenerateWireFrameGeometry(IntPtr model, IFCItem item) { if (item.ifcID != IntPtr.Zero) { IntPtr noVertices = IntPtr.Zero; IntPtr noIndices = IntPtr.Zero; ModelManager.Instance.IFCEngine.InitializeModellingInstance(model, ref noVertices, ref noIndices, 0, item.ifcID); if (noVertices != IntPtr.Zero && noIndices != IntPtr.Zero) { item.noVerticesForWireFrame = noVertices.ToInt32(); item.verticesForWireFrame = new float[3 * noVertices.ToInt32()]; item.indicesForWireFrame = new int[noIndices.ToInt32()]; ModelManager.Instance.IFCEngine.FinalizeModelling(model, item.verticesForWireFrame, item.indicesForWireFrame, IntPtr.Zero); item.noPrimitivesForWireFrame = 0; item.indicesForWireFrameLineParts = new int[2 * noIndices.ToInt32()]; int faceCount = ModelManager.Instance.IFCEngine.GetConceptualFaceCount(item.ifcID).ToInt32(); for (int i = 0; i < faceCount; i++) { IntPtr startIndexFacesPolygons = IntPtr.Zero, noIndicesFacesPolygons = IntPtr.Zero, indexTriangles = IntPtr.Zero, indexLines = IntPtr.Zero, indexPoints = IntPtr.Zero, indexConceptualFacePolygon = IntPtr.Zero; ModelManager.Instance.IFCEngine.GetConceptualFaceEx(item.ifcID, new IntPtr(i), ref indexTriangles, ref indexTriangles, ref indexLines, ref indexLines, ref indexPoints, ref indexPoints, ref startIndexFacesPolygons, ref noIndicesFacesPolygons, ref indexConceptualFacePolygon, ref indexConceptualFacePolygon); int j = 0, lastItem = -1; while (j < noIndicesFacesPolygons.ToInt32()) { if (lastItem >= 0 && item.indicesForWireFrame[startIndexFacesPolygons.ToInt32() + j] >= 0) { item.indicesForWireFrameLineParts[2 * item.noPrimitivesForWireFrame] = lastItem; item.indicesForWireFrameLineParts[2 * item.noPrimitivesForWireFrame + 1] = item.indicesForWireFrame[startIndexFacesPolygons.ToInt32() + j]; item.noPrimitivesForWireFrame++; } lastItem = item.indicesForWireFrame[startIndexFacesPolygons.ToInt32() + j]; j++; } } } } }
/// <summary> /// 以json的格式输出到txt文件中 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 显示ifc信息ToolStripMenuItem_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); Dictionary <string, IFCItem> ifc = parser.getIFCDict(); Dictionary <string, string> attributes; sb.Append("{\n"); int instanceCount = 0; if (ifc != null) { foreach (string guid in ifc.Keys) { sb.Append(" \"" + guid + "\": {\n"); IFCItem instance = ifc[guid]; attributes = instance.getAttributes(); int attributesCount = 0; foreach (string field in attributes.Keys) { string value = attributes[field]; if (value != null) { value = value.Trim().Replace('\\', '/').Replace('\n', ' '); } sb.Append(" \"" + field + "\": \"" + value + "\""); if (attributesCount < attributes.Count - 1) { sb.Append(","); } sb.Append("\n"); attributesCount++; } sb.Append(" }"); if (instanceCount < ifc.Count - 1) { sb.Append(","); } sb.Append("\n"); instanceCount++; } } sb.Append(" }"); SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "文本文档|*.txt|json文件|*.json"; if (dialog.ShowDialog() == DialogResult.OK) { StreamWriter sw = new StreamWriter(dialog.FileName); sw.Write(sb.ToString()); sw.Close(); MessageBox.Show("输入完成"); } }
private void RecursiveGettingItem(ref IFCItem item, string attribute) { if (item == null) { item = new IFCItem(); CreateItem(item, attribute); } else { RecursiveGettingItem(ref item.next, attribute); } }
private void CreateSubItem(IFCItem item, string attribute) { for (int i = 0; i < NumberIfcObjectInstance.ToInt32(); i++) { IntPtr ifcObject = IntPtr.Zero; ModelManager.Instance.IFCEngine.GetAggregationElement(this.IfcObjectInstances, i, IfcEngine.SdaiType.Instance, out ifcObject); var GlobalId = GettingAttribute(ifcObject, "GlobalId"); var Name = GettingAttribute(ifcObject, "Name"); var Description = GettingAttribute(ifcObject, "Description"); IFCItem subItem = new IFCItem(); subItem.CreateItem(item, ifcObject, attribute, GlobalId, Name, Description); } }
private void GenerateFacesGeometry(IntPtr model, IFCItem item) { if (item.ifcID != IntPtr.Zero) { IntPtr noVertices = IntPtr.Zero, noIndices = IntPtr.Zero; ModelManager.Instance.IFCEngine.InitializeModellingInstance(model, ref noVertices, ref noIndices, 0, item.ifcID); if (noVertices != IntPtr.Zero && noIndices != IntPtr.Zero) { item.noVerticesForFaces = noVertices.ToInt32(); item.noPrimitivesForFaces = noIndices.ToInt32() / 3; item.verticesForFaces = new float[6 * noVertices.ToInt32()]; item.indicesForFaces = new int[noIndices.ToInt32()]; float[] pVertices = new float[noVertices.ToInt32() * 6]; ModelManager.Instance.IFCEngine.FinalizeModelling(model, pVertices, item.indicesForFaces, IntPtr.Zero); int i = 0; while (i < noVertices.ToInt32()) { item.verticesForFaces[6 * i + 0] = pVertices[6 * i + 0]; item.verticesForFaces[6 * i + 1] = pVertices[6 * i + 1]; item.verticesForFaces[6 * i + 2] = pVertices[6 * i + 2]; item.verticesForFaces[6 * i + 3] = pVertices[6 * i + 3]; item.verticesForFaces[6 * i + 4] = pVertices[6 * i + 4]; item.verticesForFaces[6 * i + 5] = pVertices[6 * i + 5]; for (int j = 0; j < 3; j++) { ModelManager.Instance.MinCorner[j] = Math.Min(ModelManager.Instance.MinCorner[j], pVertices[6 * i + j]); ModelManager.Instance.MaxCorner[j] = Math.Max(ModelManager.Instance.MaxCorner[j], pVertices[6 * i + j]); } i++; } } } }
private void FillMeshByRandomIfcColor(IFCItem item) { if (item.Mesh3d != null) { Random rand = new Random(); byte[] colorValue = new byte[4]; rand.NextBytes(colorValue); var color = System.Windows.Media.Color.FromArgb( (byte)(255 - colorValue[0] * 255), (byte)(colorValue[1] * 255), (byte)(colorValue[2] * 255), (byte)(colorValue[3] * 255)); item.Mesh3d.Material = new PhongMaterial() { AmbientColor = System.Windows.Media.Colors.Black.ToColor4(), DiffuseColor = System.Windows.Media.Colors.Black.ToColor4(), EmissiveColor = color.ToColor4(), ReflectiveColor = System.Windows.Media.Colors.Black.ToColor4(), SpecularColor = color.ToColor4() }; } }
private static void Draw(IFCItem element, ref List <IfcMeshGeometryModel3D> modelList, string[] filter) { while (element != null) { if (element.child != null) { Draw(element.child, ref modelList, filter); } if (!(element.noPrimitivesForFaces > 0)) { element = element.next; continue; } if (filter != null) { var index = Array.FindIndex(filter, x => x.Equals(element.name, StringComparison.InvariantCultureIgnoreCase)); if (filter.Any() && index == -1) { element = element.next; continue; } } MeshGeometry3D geometry = new MeshGeometry3D() { Positions = new Vector3Collection(), Normals = new Vector3Collection(), Indices = new IntCollection(), TextureCoordinates = new Vector2Collection() }; var positions = new Vector3Collection(); var normals = new Vector3Collection(); //ToDo: Depending on if the model is modelled in meter or millimeter this divident has to be changed var divident = 1000; for (int i = 0; i < element.noVerticesForFaces; i++) { var offset = i * 6; positions.Add(new SharpDX.Vector3( element.verticesForFaces[offset + 0] / divident, element.verticesForFaces[offset + 2] / divident, -element.verticesForFaces[offset + 1] / divident )); normals.Add(new SharpDX.Vector3( element.verticesForFaces[offset + 3], element.verticesForFaces[offset + 5], -element.verticesForFaces[offset + 4] )); } for (int i = 0; i < element.indicesForFaces.Length; i++) { geometry.Indices.Add(i); geometry.Positions.Add(positions[(int)element.indicesForFaces[i]]); geometry.Normals.Add(normals[(int)element.indicesForFaces[i]]); //just needs to be filled with something geometry.TextureCoordinates.Add(new Vector2(0, 0)); } modelList.Add(new IfcMeshGeometryModel3D() { Geometry = geometry, IfcName = element.name, IfcGlobalId = element.globalID }); element = element.next; } }
public static void Draw(IFCItem element, ref List<IfcMeshGeometryModel3D> modelList) { while (element != null) { if (element.child != null) { Draw(element.child, ref modelList); } if (!(element.noPrimitivesForFaces > 0)) { element = element.next; continue; } MeshGeometry3D geometry = new MeshGeometry3D() { Positions = new Vector3Collection(), Normals = new Vector3Collection(), Indices = new IntCollection(), TextureCoordinates = new Vector2Collection() }; var positions = new Vector3Collection(); var normals = new Vector3Collection(); //ToDo: Depending on if the model is modelled in meter or millimeter this divident has to be changed var divident = 1000; for (int i = 0; i < element.noVerticesForFaces; i++) { var offset = i * 6; positions.Add(new SharpDX.Vector3( element.verticesForFaces[offset + 0] / divident, element.verticesForFaces[offset + 2] / divident, -element.verticesForFaces[offset + 1] / divident )); normals.Add(new SharpDX.Vector3( element.verticesForFaces[offset + 3], element.verticesForFaces[offset + 5], -element.verticesForFaces[offset + 4] )); } for (int i = 0; i < element.indicesForFaces.Length; i++) { geometry.Indices.Add(i); geometry.Positions.Add(positions[(int)element.indicesForFaces[i]]); geometry.Normals.Add(normals[(int)element.indicesForFaces[i]]); //just needs to be filled with something geometry.TextureCoordinates.Add(new Vector2(0,0)); } modelList.Add(new IfcMeshGeometryModel3D() { Geometry = geometry, IfcName = element.name }); element = element.next; } }
public void CreateFaceModelsRecursive(IFCItem item, Vector3 center) { while (item != null) { if (item.ifcID != IntPtr.Zero && item.noVerticesForFaces != 0 && item.noPrimitivesForFaces != 0) { var positions = new Vector3Collection(); var normals = new Vector3Collection(); if (item.verticesForFaces != null) { for (int i = 0; i < item.noVerticesForFaces; i++) { positions.Add(new Vector3( item.verticesForFaces[6 * i + 0] - center.X, item.verticesForFaces[6 * i + 1] - center.Y, item.verticesForFaces[6 * i + 2] - center.Z)); normals.Add(new Vector3(item.verticesForFaces[6 * i + 3], item.verticesForFaces[6 * i + 4], item.verticesForFaces[6 * i + 5])); } } var indices = new IntCollection(); if (item.indicesForFaces != null) { for (int i = 0; i < 3 * item.noPrimitivesForFaces; i++) { indices.Add(item.indicesForFaces[i]); } } var meshGeometry = new MeshGeometry3D(); meshGeometry.Positions = positions; meshGeometry.Normals = normals; meshGeometry.Indices = indices; meshGeometry.TextureCoordinates = null; meshGeometry.Colors = null; meshGeometry.Tangents = null; meshGeometry.BiTangents = null; MeshGeometryModel3D mesh = new MeshGeometryModel3D() { Geometry = meshGeometry }; item.Mesh3d = mesh; meshToIfcItems[mesh] = item; //FillMeshByIfcColor(item); FillMeshByRandomIfcColor(item); mesh.Tag = item.ifcType + ":" + item.ifcID; model.Add(mesh); } CreateFaceModelsRecursive(item.child, center); item = item.next; } }
private void CreateItem(IFCItem item, string attribute) { item.CreateItem(null, IntPtr.Zero, "", attribute, "", ""); CreateSubItem(item, attribute); }
public void CreateWireFrameModelsRecursive(IFCItem item, Vector3 center) { while (item != null) { if (item.ifcID != IntPtr.Zero && item.noVerticesForWireFrame != 0 && item.noPrimitivesForWireFrame != 0) { var geo = new LineGeometry3D() { Positions = new Vector3Collection(), Indices = new IntCollection() }; var points = new Vector3Collection(); if (item.verticesForWireFrame != null) { for (int i = 0; i < item.noVerticesForWireFrame; i++) { points.Add(new Vector3( (item.verticesForWireFrame[3 * i + 0] - center.X), (item.verticesForWireFrame[3 * i + 1] - center.Y), (item.verticesForWireFrame[3 * i + 2] - center.Z))); geo.Positions.Add(new Vector3( (item.verticesForWireFrame[3 * i + 0] - center.X), (item.verticesForWireFrame[3 * i + 1] - center.Y), (item.verticesForWireFrame[3 * i + 2] - center.Z))); } } if (item.indicesForWireFrameLineParts != null) { for (int i = 0; i < item.noPrimitivesForWireFrame; i++) { var idx = item.indicesForWireFrameLineParts[2 * i + 0]; geo.Indices.Add(idx); idx = item.indicesForWireFrameLineParts[2 * i + 1]; geo.Indices.Add(idx); } } else { for (int i = 0, count = points.Count; i < count; i++) { geo.Indices.Add(i); geo.Indices.Add((i + 1) % count); } } LineGeometryModel3D line = new LineGeometryModel3D(); line.Geometry = geo; line.Color = new SharpDX.Color(0, 0, 0); line.Thickness = 0.5; item.Wireframe = line; line.Tag = item.ifcType + ":" + item.ifcID; model.Add(line); } CreateWireFrameModelsRecursive(item.child, center); item = item.next; } }