public static IndexedGeometry GetIndexedGeometry( this PolyMesh mesh, PolyMesh.GetGeometryOptions options = PolyMesh.GetGeometryOptions.Default, double absoluteEps = 10e-6) { return(mesh.GetIndexedGeometry(mesh.FaceCount.Range(), options, absoluteEps)); }
public static IndexedGeometry GetIndexedGeometry( this PolyMesh mesh, IEnumerable <int> faceIndices, PolyMesh.GetGeometryOptions options = PolyMesh.GetGeometryOptions.Default, double absoluteEps = 10e-6 ) { var faceAttributes = mesh.FaceAttributes.Keys.Where(k => k.IsPositive).ToArray(); var vertexAttributes = mesh.VertexAttributes.Keys.Where(k => k.IsPositive).ToArray(); var faceVertexAttributes = mesh.FaceVertexAttributes.Keys.Where(k => k.IsPositive).ToArray(); var instanceAttributes = mesh.InstanceAttributes.Keys.ToArray(); return(mesh.GetIndexedGeometry(options, absoluteEps, faceIndices, faceAttributes, vertexAttributes, faceVertexAttributes, instanceAttributes)); }
public static IndexedGeometry GetIndexedGeometry( this PolyMesh mesh, PolyMesh.GetGeometryOptions options, double absoluteEps, IEnumerable <int> faceIndices, IEnumerable <Symbol> faceAttributeNames, IEnumerable <Symbol> vertexAttributeNames, IEnumerable <Symbol> faceVertexAttributeNames, IEnumerable <Symbol> instanceAttributeNames) { var faceBackMap = faceIndices.ToArray(); var faceAttributeArray = (from a in faceAttributeNames select PolyMesh.GetIAttribute(a, mesh.FaceAttributes)).WhereNotNull().ToArray(); var vertexAttributeArray = (from a in vertexAttributeNames select PolyMesh.GetIAttribute(a, mesh.VertexAttributes)).WhereNotNull().ToArray(); var faceVertexAttributeArray = (from a in faceVertexAttributeNames select PolyMesh.GetIAttribute(a, mesh.FaceVertexAttributes)).WhereNotNull().ToArray(); var instanceAttributes = new SymbolDict <object>(); foreach (var name in instanceAttributeNames) { instanceAttributes[name] = mesh.InstanceAttributes[name]; } return(mesh.GetIndexedGeometry( options, absoluteEps, faceBackMap, faceAttributeArray, vertexAttributeArray, faceVertexAttributeArray, instanceAttributes )); }
public static IndexedGeometry GetIndexedGeometry( this PolyMesh mesh, PolyMesh.GetGeometryOptions options, double absoluteEps, int[] faceBackMap, PolyMesh.IAttribute[] faceAttributes, PolyMesh.IAttribute[] vertexAttributes, PolyMesh.IAttribute[] faceVertexAttributes, SymbolDict <object> instanceAttributes) { mesh.ComputeVertexBackMaps(faceBackMap, (options & PolyMesh.GetGeometryOptions.Compact) != 0, faceAttributes, vertexAttributes, faceVertexAttributes, out int[] firstIndexArray, out int[] vertexIndexArray, out int[] vBackMap, out int[] vfBackMap, out int[] vfvBackMap); var indexedAttributes = new SymbolDict <Array>(); var vc = vBackMap.Length; if ((options & PolyMesh.GetGeometryOptions.FloatVectorsAndByteColors) != 0) { var fv = (options & PolyMesh.GetGeometryOptions.FloatVectors) != 0; var bc = (options & PolyMesh.GetGeometryOptions.ByteColors) != 0; foreach (var a in faceAttributes) { var array = a.BackMappedConvertedCopy(vfBackMap, vc, fv, bc); if (array != null) { indexedAttributes[a.Name] = array; } } foreach (var a in vertexAttributes) { var array = a.BackMappedConvertedCopy(vBackMap, vc, fv, bc); if (array != null) { indexedAttributes[a.Name] = array; } } foreach (var a in faceVertexAttributes) { var array = a.BackMappedConvertedCopy(vfvBackMap, vc, fv, bc); if (array != null) { indexedAttributes[a.Name] = array; } } } else { foreach (var a in vertexAttributes) { var array = a.BackMappedCopy(vBackMap, vc); if (array != null) { indexedAttributes[a.Name] = array; } } foreach (var a in faceAttributes) { var array = a.BackMappedCopy(vfBackMap, vc); if (array != null) { indexedAttributes[a.Name] = array; } } foreach (var a in faceVertexAttributes) { var array = a.BackMappedCopy(vfvBackMap, vc); if (array != null) { indexedAttributes[a.Name] = array; } } } var triangleIndices = PolyMesh.CreateSimpleTriangleVertexIndexArray( firstIndexArray, vertexIndexArray, faceBackMap.Length, vertexIndexArray.Length, mesh.FaceVertexCountRange); var indexArray = ((options & PolyMesh.GetGeometryOptions.IntIndices) != 0) ? (Array)triangleIndices : (Array)triangleIndices.Map(i => (short)i); return(new IndexedGeometry(indexArray, indexedAttributes, instanceAttributes)); }
/// <summary> /// Splits the mesh on the specified plane in a pair containing the negative /// (element 0) and the positive side (element 1) of the plane. /// Note that the normal vector of the plane need not be normalized. /// </summary> public (PolyMesh, PolyMesh) SplitOnPlane( Plane3d plane, double epsilon, SplitterOptions options) { var heightArray = m_positionArray.Map( m_vertexCount, p => plane.Height(p)); var splitter = new PolygonSplitter( m_firstIndexArray, m_faceCount, m_vertexIndexArray, m_faceVertexCountRange.Max, heightArray, epsilon, options); var result = (default(PolyMesh), default(PolyMesh)); for (int side = 0; side < 2; side++) { var fia = splitter.FirstIndexArray(side); if (fia != null) { if (splitter.IsEqualToInput(side)) { //result[side] = this; switch (side) { case 0: result = (this, result.Item2); break; case 1: result = (result.Item1, this); break; default: throw new IndexOutOfRangeException(); } } else { var pm = new PolyMesh() { FirstIndexArray = fia, VertexIndexArray = splitter.VertexIndexArray(side), InstanceAttributes = InstanceAttributes, FaceAttributes = FaceIAttributes.Select( a => splitter.FaceAttribute(side, a)).ToSymbolDict(), VertexAttributes = VertexIAttributes.Select( a => splitter.VertexAttribute(side, a)).ToSymbolDict(), FaceVertexAttributes = FaceVertexIAttributes.Select( a => splitter.FaceVertexAttribute(side, a)).ToSymbolDict(), }; //result[side] = pm; switch (side) { case 0: result = (pm, result.Item2); break; case 1: result = (result.Item1, pm); break; default: throw new IndexOutOfRangeException(); } } } } return(result); }