Exemplo n.º 1
0
        internal CTMESH(GEOM geom)
        {
            if (geom.numberVertices > MAX_VERTICES)
            {
                throw new MeshException("This mesh has too many vertices and cannot be converted to a CAS Tools Mesh!");
            }
            if (geom.numberFaces > MAX_TRIANGLES)
            {
                throw new MeshException("This mesh has too many triangles and cannot be converted to a CAS Tools Mesh!");
            }

            this.vertices = new Vector3[geom.numberVertices];
            for (int i = 0; i < geom.numberVertices; i++)
            {
                this.vertices[i] = new Vector3(geom.getPosition(i));
            }

            faces = new Face[geom.numberFaces];
            for (int i = 0; i < geom.numberFaces; i++)
            {
                int[]       f      = geom.getFaceIndices(i);       //vertex indices
                FacePoint[] points = new FacePoint[3];

                for (int p = 0; p < 3; p++)                 //for each vertex in the face
                {
                    Vector3   pos  = new Vector3(geom.getPosition(f[p]));
                    Vector3   norm = new Vector3(geom.getNormal(f[p]));
                    Vector2[] uv   = new Vector2[geom.numberUVsets];
                    for (int u = 0; u < geom.numberUVsets; u++)
                    {
                        uv[u] = new Vector2(geom.getUV(f[p], u));
                    }
                    points[p] = new FacePoint(f[p], pos, norm, uv);
                }

                faces[i] = new Face(f, points);
            }
        }
Exemplo n.º 2
0
        public OBJ(GEOM geom, List <GEOM.Face[]> layers, List <string> layerNames, int uvSet)
        {
            vertexList = new List <Vertex>();
            normalList = new List <Normal>();
            uvList     = new List <UV>();
            groupList  = new List <Group>();

            int vertOffset = 1;
            int groupNum   = 0;

            if (!geom.hasUVset(uvSet))
            {
                DialogResult res = MessageBox.Show("Input GEOM does not have UV set " + uvSet.ToString() + "! Continue using UV0?", "No UV" + uvSet.ToString(), MessageBoxButtons.OKCancel);
                if (res == DialogResult.Cancel)
                {
                    return;
                }
            }
            for (int i = 0; i < geom.numberVertices; i++)
            {
                vertexList.Add(new Vertex(geom.getPosition(i)));
                normalList.Add(new Normal(geom.getNormal(i)));
                uvList.Add(new UV(geom.getUV(i, uvSet), true));
            }

            for (int l = 0; l < layers.Count; l++)
            {
                string grpName;
                if (layerNames != null)
                {
                    grpName = layerNames[l] + l.ToString();
                }
                else
                {
                    grpName = "Layer" + l.ToString();
                }
                this.groupList.Add(new Group(grpName));
                for (int i = 0; i < layers[l].Length; i++)
                {
                    this.groupList[groupNum].addFace(new Face(new int[] { layers[l][i].facePoint0,
                                                                          layers[l][i].facePoint1, layers[l][i].facePoint2 }, vertOffset));
                }
                groupNum++;
            }
        }