// Update is called once per frame public static void GenerateMesh(GameObject go, Material ObjMaterial, Solid mesh) { MeshFilter mf = go.GetComponent<MeshFilter> (); if(mf == null) mf = go.AddComponent<MeshFilter> (); Mesh tmesh = new Mesh(); int mlen = mesh.getVertices().Length; Vector3 [] vertices = new Vector3[mlen]; for(int i=0; i<mlen; i++) { Net3dBool.Point3d p = mesh.getVertices()[i]; vertices[i] = new Vector3((float)p.x, (float)p.y, (float)p.z); } tmesh.vertices = vertices; tmesh.triangles = mesh.getIndices (); int clen = mesh.getColors ().Length; Color [] clrs = new Color[clen]; for (int j=0; j<clen; j++) { Net3dBool.Color3f c = mesh.getColors()[j]; clrs[j] = new Color((float)c.r, (float)c.g, (float)c.b); } tmesh.colors = clrs; tmesh.RecalculateNormals(); mf.mesh = tmesh; MeshRenderer mr = go.GetComponent<MeshRenderer> (); if(mr == null) mr = go.AddComponent<MeshRenderer> (); mr.sharedMaterials = new Material[1]; mr.sharedMaterials[0] = ObjMaterial; mr.sharedMaterial = ObjMaterial; }
//----------------------------------CONSTRUCTOR---------------------------------// /** * Constructs a Object3d object based on a solid file. * * @param solid solid used to construct the Object3d object */ public Object3D(Solid solid) { Vertex v1, v2, v3, vertex; Point3d[] verticesPoints = solid.getVertices(); int[] indices = solid.getIndices(); Color3f[] colors = solid.getColors(); var verticesTemp = new List <Vertex>(); //create vertices vertices = new List <Vertex>(); for (int i = 0; i < verticesPoints.Length; i++) { vertex = addVertex(verticesPoints[i], colors[i], Vertex.UNKNOWN); verticesTemp.Add(vertex); } //create faces faces = new List <Face>(); for (int i = 0; i < indices.Length; i = i + 3) { v1 = verticesTemp[indices[i]]; v2 = verticesTemp[indices[i + 1]]; v3 = verticesTemp[indices[i + 2]]; addFace(v1, v2, v3); } //create bound bound = new Bound(verticesPoints); }
//----------------------------------CONSTRUCTOR---------------------------------// /** * Constructs a Object3d object based on a solid file. * * @param solid solid used to construct the Object3d object */ public Object3D(Solid solid) { Vertex v1, v2, v3, vertex; Point3d[] verticesPoints = solid.getVertices(); int[] indices = solid.getIndices(); Color3f[] colors = solid.getColors(); var verticesTemp = new List <Vertex>(); Dictionary <int, int> revlookup = new Dictionary <int, int> (); for (int d = 0; d < indices.Length; d++) { revlookup [indices [d]] = d; } //create vertices vertices = new List <Vertex>(); for (int i = 0; i < verticesPoints.Length; i++) { Color3f col = new Color3f(1, 1, 1); if (colors.Length > 0) { col = colors[i]; } vertex = addVertex(verticesPoints[i], col, Vertex.UNKNOWN); verticesTemp.Add(vertex); } //create faces faces = new List <Face>(); for (int i = 0; i < indices.Length; i = i + 3) { v1 = verticesTemp[indices[i]]; v2 = verticesTemp[indices[i + 1]]; v3 = verticesTemp[indices[i + 2]]; addFace(v1, v2, v3); } //create bound bound = new Bound(verticesPoints); }
//----------------------------------CONSTRUCTOR---------------------------------// /** * Constructs a Object3d object based on a solid file. * * @param solid solid used to construct the Object3d object */ public Object3D(Solid solid) { Vertex v1, v2, v3, vertex; Point3d[] verticesPoints = solid.getVertices(); int[] indices = solid.getIndices(); Color3f[] colors = solid.getColors(); var verticesTemp = new List<Vertex>(); Dictionary<int,int> revlookup = new Dictionary<int, int> (); for (int d=0; d<indices.Length; d++) revlookup [indices [d]] = d; //create vertices vertices = new List<Vertex>(); for (int i = 0; i < verticesPoints.Length; i++) { Color3f col = new Color3f(1, 1, 1); if(colors.Length > 0) col = colors[i]; vertex = addVertex(verticesPoints[i], col, Vertex.UNKNOWN); verticesTemp.Add(vertex); } //create faces faces = new List<Face>(); for (int i = 0; i < indices.Length; i = i + 3) { v1 = verticesTemp[indices[i]]; v2 = verticesTemp[indices[i + 1]]; v3 = verticesTemp[indices[i + 2]]; addFace(v1, v2, v3); } //create bound bound = new Bound(verticesPoints); }