private Tuple <IList <GeometryObject>, bool> CollectFaces(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { using (BuilderScope bs = shapeEditScope.InitializeBuilder(IFCShapeBuilderType.TessellatedShapeBuilder)) { TessellatedShapeBuilderScope tsBuilderScope = bs as TessellatedShapeBuilderScope; tsBuilderScope.StartCollectingFaceSet(); Outer.CreateShape(shapeEditScope, lcs, scaledLcs, guid); IList <GeometryObject> geomObjs = null; bool canRevertToMesh = tsBuilderScope.CanRevertToMesh(); int numCreatedFaces = tsBuilderScope.CreatedFacesCount; int numExpectedFaces = Outer.Faces.Count; if (numCreatedFaces == numExpectedFaces || (!canRevertToMesh && numCreatedFaces > 0)) { geomObjs = tsBuilderScope.CreateGeometry(guid); if (numCreatedFaces < numExpectedFaces) { Importer.TheLog.LogWarning(Outer.Id, "Processing " + numCreatedFaces + " valid faces out of " + numExpectedFaces + " total.", false); } } return(Tuple.Create(geomObjs, canRevertToMesh)); } }
/// <summary> /// Return geometry for a particular representation item. /// </summary> /// <param name="shapeEditScope">The shape edit scope.</param> /// <param name="lcs">Local coordinate system for the geometry, without scale.</param> /// <param name="scaledLcs">Local coordinate system for the geometry, including scale, potentially non-uniform.</param> /// <param name="guid">The guid of an element for which represntation is being created.</param> /// <returns>The created geometry.</returns> protected override IList <GeometryObject> CreateGeometryInternal( IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { if (Outer == null || Outer.Faces.Count == 0) { return(null); } IList <GeometryObject> geomObjs = null; bool canRevertToMesh = false; using (BuilderScope bs = shapeEditScope.InitializeBuilder(IFCShapeBuilderType.TessellatedShapeBuilder)) { TessellatedShapeBuilderScope tsBuilderScope = bs as TessellatedShapeBuilderScope; tsBuilderScope.StartCollectingFaceSet(); Outer.CreateShape(shapeEditScope, lcs, scaledLcs, guid); if (tsBuilderScope.CreatedFacesCount == Outer.Faces.Count) { geomObjs = tsBuilderScope.CreateGeometry(guid); } canRevertToMesh = tsBuilderScope.CanRevertToMesh(); } if (geomObjs == null || geomObjs.Count == 0) { if (canRevertToMesh) { using (IFCImportShapeEditScope.BuildPreferenceSetter setter = new IFCImportShapeEditScope.BuildPreferenceSetter(shapeEditScope, IFCImportShapeEditScope.BuildPreferenceType.AnyMesh)) { using (BuilderScope newBuilderScope = shapeEditScope.InitializeBuilder(IFCShapeBuilderType.TessellatedShapeBuilder)) { TessellatedShapeBuilderScope newTsBuilderScope = newBuilderScope as TessellatedShapeBuilderScope; // Let's see if we can loosen the requirements a bit, and try again. newTsBuilderScope.StartCollectingFaceSet(); Outer.CreateShape(shapeEditScope, lcs, scaledLcs, guid); // This needs to be in scope so that we keep the mesh tolerance for vertices. if (newTsBuilderScope.CreatedFacesCount != 0) { if (newTsBuilderScope.CreatedFacesCount != Outer.Faces.Count) { Importer.TheLog.LogWarning (Outer.Id, "Processing " + newTsBuilderScope.CreatedFacesCount + " valid faces out of " + Outer.Faces.Count + " total.", false); } geomObjs = newTsBuilderScope.CreateGeometry(guid); } } } } } if (geomObjs == null || geomObjs.Count == 0) { // Couldn't use fallback, or fallback didn't work. Importer.TheLog.LogWarning(Id, "Couldn't create any geometry.", false); return(null); } return(geomObjs); }
protected override void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { if (CoordIndex == null) { Importer.TheLog.LogError(Id, "Invalid coordinates for this triangulation, ignoring.", false); return; } using (BuilderScope bs = shapeEditScope.InitializeBuilder(IFCShapeBuilderType.TessellatedShapeBuilder)) { base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid); TessellatedShapeBuilderScope tsBuilderScope = bs as TessellatedShapeBuilderScope; tsBuilderScope.StartCollectingFaceSet(); // Create triangle face set from CoordIndex. We do not support the Normals yet at this point foreach (List <int> triIndex in CoordIndex) { // This is a defensive check in an unlikely situation that the index is larger than the data if (triIndex[0] > Coordinates.CoordList.Count || triIndex[1] > Coordinates.CoordList.Count || triIndex[2] > Coordinates.CoordList.Count) { continue; } // This is already triangulated, so no need to attempt triangulation here. tsBuilderScope.StartCollectingFace(GetMaterialElementId(shapeEditScope), false); IList <XYZ> loopVertices = new List <XYZ>(); for (int ii = 0; ii < 3; ++ii) { int actualVIdx = triIndex[ii] - 1; if (PnIndex != null) { actualVIdx = PnIndex[actualVIdx] - 1; } XYZ vv = Coordinates.CoordList[actualVIdx]; loopVertices.Add(vv); } IList <XYZ> transformedVertices = new List <XYZ>(); foreach (XYZ vertex in loopVertices) { transformedVertices.Add(scaledLcs.OfPoint(vertex)); } // Check triangle that is too narrow (2 vertices are within the tolerance IFCGeometryUtil.CheckAnyDistanceVerticesWithinTolerance(Id, shapeEditScope, transformedVertices, out List <XYZ> validVertices); if (validVertices.Count != transformedVertices.Count && tsBuilderScope.CanRevertToMesh()) { tsBuilderScope.RevertToMeshIfPossible(); IFCGeometryUtil.CheckAnyDistanceVerticesWithinTolerance(Id, shapeEditScope, transformedVertices, out validVertices); } // We are going to catch any exceptions if the loop is invalid. // We are going to hope that we can heal the parent object in the TessellatedShapeBuilder. bool bPotentiallyAbortFace = false; int count = validVertices.Count; if (validVertices.Count < 3) { Importer.TheLog.LogComment(Id, "Too few distinct loop vertices (" + count + "), ignoring.", false); bPotentiallyAbortFace = true; } else { if (!tsBuilderScope.AddLoopVertices(Id, validVertices)) { bPotentiallyAbortFace = true; } } tsBuilderScope.StopCollectingFace(!bPotentiallyAbortFace, false); } IList <GeometryObject> createdGeometries = tsBuilderScope.CreateGeometry(guid); if (createdGeometries != null) { foreach (GeometryObject createdGeometry in createdGeometries) { shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, createdGeometry)); } } } }