internal override Geometry TransformBy(ICoordinateSystemEntity csEntity) { SubDivisionMesh mesh = base.TransformBy(csEntity) as SubDivisionMesh; mesh.SubDivisionLevel = this.SubDivisionLevel; return(mesh); }
protected override Geometry Translate(Vector offset) { SubDivisionMesh mesh = base.Translate(offset) as SubDivisionMesh; if (null != mesh) { mesh.SubDivisionLevel = SubDivisionLevel; } return(mesh); }
public IContextData[] ImportData(Dictionary <string, object> connectionParameters) { List <Geometry> geometryList = new List <Geometry>(); Geometry[] geometry = null; foreach (var param in connectionParameters) { switch (param.Key) { case "OBJ": geometry = SubDivisionMesh.ImportFromOBJ(Convert.ToString(param.Value)); break; case "SAT": geometry = Geometry.ImportFromSAT(Convert.ToString(param.Value)); break; default: if (param.Value.GetType().IsArray) { Array data = param.Value as Array; geometry = GeometryDataSerializer.CreateGeometryFromData(param.Key, data); } break; } if (null != geometry && geometry.Length > 0) { geometryList.AddRange(geometry); } } int nItems = geometryList.Count; if (nItems == 0) { return(null); } IContextData[] contextData = new IContextData[nItems]; for (int i = 0; i < nItems; ++i) { contextData[i] = new GeometryData("ImportData", geometryList[i], this); } return(contextData); }
/// <summary> /// Creates a SubDivisionMesh from Solid or Surface geometry by faceting /// the faces of Solid or Surface. /// </summary> /// <param name="context">Input geometry, Solid or Surface.</param> /// <param name="maxEdgeLength">Maximum allowed edge length /// to define coarseness of the mesh.</param> /// <returns>SubDivisionMesh</returns> public static SubDivisionMesh FromGeometry(Geometry context, double maxEdgeLength) { string kMethodName = "SubDivisionMesh.FromGeometry"; if (null == context) { throw new System.ArgumentNullException("context"); } ISubDMeshEntity entity = HostFactory.Factory.SubDMeshFromGeometry(context.GeomEntity, maxEdgeLength); if (null == entity) { throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); } SubDivisionMesh mesh = new SubDivisionMesh(entity, true); mesh.Context = context; mesh.SubDivisionLevel = 0; return(mesh); }
/// <summary> /// Constructs a subdivision mesh by vertex shading, given an input /// array of vertex points and an input array of faces defined by a set /// of numbers, which are the indices of the vertices in the 'vertices' /// array making up the face. /// </summary> /// <param name="vertices">Input array of vertex points</param> /// <param name="faceIndices">Input array of faces indices for each /// vertex </param> /// <param name="vertexNormals">Input array of vertex normals</param> /// <param name="vertexColors">Input array of color assigned to each /// vertex </param> /// <param name="subDivisionLevel">Initial smoothness level, subDivisionLevel must /// have a value greater than or equal to 0 and less than 5.</param> /// <returns>SubDivisionMesh</returns> public static SubDivisionMesh ByVerticesFaceIndices(Point[] vertices, int[][] faceIndices, Vector[] vertexNormals, Color[] vertexColors, int subDivisionLevel) { string kMethodName = "SubDivisionMesh.ByVerticesFaceIndices"; if (subDivisionLevel < 0 || subDivisionLevel >= 5) { throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "subDivisionLevel", kMethodName)); } IPointEntity[] points = vertices.ConvertAll(GeometryExtension.ToEntity <Point, IPointEntity>); if (points.Length < 3 || points.ArePointsColinear()) { throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "vertices", kMethodName)); } ISubDMeshEntity entity = HostFactory.Factory.SubDMeshByVerticesFaceIndices(points, faceIndices, subDivisionLevel); if (null == entity) { throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); } SubDivisionMesh mesh = new SubDivisionMesh(entity, true); try { if (null != vertexNormals && vertexNormals.Length > 0) { if (vertexNormals.Length != entity.GetNumVertices()) { throw new System.ArgumentException(string.Format(Properties.Resources.NotEqual, "size of vertexNormals", "number of vertices"), "vertexNormals"); } if (!entity.UpdateSubDMeshNormals(vertexNormals.ConvertAll((Vector v) => v.IVector))) { throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); } } if (null != vertexColors && vertexColors.Length > 0) { if (subDivisionLevel > 0) { throw new System.InvalidOperationException(Properties.Resources.VertexColorNotSupported); } if (vertexColors.Length != entity.GetNumVertices()) { throw new System.ArgumentException(string.Format(Properties.Resources.NotEqual, "size of vertexColors", "number of vertices"), "vertexColors"); } if (!entity.UpdateSubDMeshColors(vertexColors.ConvertAll((Color c) => c.IColor))) { throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); } } } catch (System.Exception ex) { mesh.Dispose(); throw ex; } mesh.SubDivisionLevel = subDivisionLevel; return(mesh); }