示例#1
0
        private void loadModel(string fileName)
        {
            treeView1.Nodes.Clear();
            m = new WavefrontOBJ();
            m.loadObjModel(fileName);

            TreeNode nodeObjects = new TreeNode("Objects (" + m.getNumObjects() + ")");

            for (int i = 0; i < m.getNumObjects(); i++)
            {
                ObjObject o          = m.getObject(i);
                TreeNode  nodeObject = new TreeNode("Object " + i + " - \"" + o.getName() + "\"");
                // object name
                TreeNode nodeObjectName      = new TreeNode("Name");
                TreeNode nodeObjectNameValue = new TreeNode(o.getName());
                nodeObjectNameValue.Tag = o;
                nodeObjectName.Nodes.Add(nodeObjectNameValue);
                nodeObject.Nodes.Add(nodeObjectName);
                // first face
                TreeNode nodeObjectFirstFace      = new TreeNode("First face");
                TreeNode nodeObjectFirstFaceValue = new TreeNode(o.getFirstFace().ToString());
                nodeObjectFirstFace.Nodes.Add(nodeObjectFirstFaceValue);
                nodeObject.Nodes.Add(nodeObjectFirstFace);
                // face count
                TreeNode nodeObjectNumFaces      = new TreeNode("Faces count");
                TreeNode nodeObjectNumFacesValue = new TreeNode(o.getNumFaces().ToString());
                nodeObjectNumFaces.Nodes.Add(nodeObjectNumFacesValue);
                nodeObject.Nodes.Add(nodeObjectNumFaces);

                nodeObjects.Nodes.Add(nodeObject);
            }
            treeView1.Nodes.Add(nodeObjects);
            TreeNode nodeGroups = new TreeNode("Groups (" + m.getNumGroups() + ")");

            for (int i = 0; i < m.getNumGroups(); i++)
            {
                ObjGroup o         = m.getGroup(i);
                TreeNode nodeGroup = new TreeNode("Group " + i + " - \"" + o.getName() + "\"");
                // object name
                TreeNode nodeGroupName      = new TreeNode("Name");
                TreeNode nodeGroupNameValue = new TreeNode(o.getName());
                nodeGroupNameValue.Tag = o;
                nodeGroupName.Nodes.Add(nodeGroupNameValue);
                nodeGroup.Nodes.Add(nodeGroupName);
                // first face
                TreeNode nodeGroupFirstFace      = new TreeNode("First face");
                TreeNode nodeGroupFirstFaceValue = new TreeNode(o.getFirstFace().ToString());
                nodeGroupFirstFace.Nodes.Add(nodeGroupFirstFaceValue);
                nodeGroup.Nodes.Add(nodeGroupFirstFace);
                // face count
                TreeNode nodeGroupNumFaces      = new TreeNode("Faces count");
                TreeNode nodeGroupNumFacesValue = new TreeNode(o.getNumFaces().ToString());
                nodeGroupNumFaces.Nodes.Add(nodeGroupNumFacesValue);
                nodeGroup.Nodes.Add(nodeGroupNumFaces);

                nodeGroups.Nodes.Add(nodeGroup);
            }
            treeView1.Nodes.Add(nodeGroups);
            TreeNode nodeFaces = new TreeNode("Faces (" + m.getNumFaces() + ")");

            for (int i = 0; i < m.getNumFaces(); i++)
            {
                ObjFace  f        = m.getFace(i);
                TreeNode nodeFace = new TreeNode("Face " + i);
                // number of vertices

                /*TreeNode nodeFaceNumFaceVerts = new TreeNode("FaceVerts count");
                 * TreeNode nodeFaceNumFaceVertsValue = new TreeNode(f.getNumVerts().ToString());
                 * nodeFaceNumFaceVerts.Nodes.Add(nodeFaceNumFaceVertsValue);
                 * nodeFace.Nodes.Add(nodeFaceNumFaceVerts);*/
                // vertices
                TreeNode nodeFaceFaceVerts = new TreeNode("FaceVerts (" + f.getNumVerts() + ")");
                for (int j = 0; j < f.getNumVerts(); j++)
                {
                    TreeNode nodeFaceFaceVert = new TreeNode("FaceVert " + j + " (abs " + (j + f.getFirstVert()) + ")");
                    nodeFaceFaceVerts.Nodes.Add(nodeFaceFaceVert);
                }
                nodeFace.Nodes.Add(nodeFaceFaceVerts);

                nodeFaces.Nodes.Add(nodeFace);
            }
            treeView1.Nodes.Add(nodeFaces);
            TreeNode nodePositions = new TreeNode("XYZs (" + m.getNumXYZs() + ")");

            for (int i = 0; i < m.getNumXYZs(); i++)
            {
                TreeNode nodePosition      = new TreeNode("XYZ " + i);
                TreeNode nodePositionValue = new TreeNode(m.getXYZ(i).ToString());
                nodePosition.Nodes.Add(nodePositionValue);
                nodePositions.Nodes.Add(nodePosition);
            }
            treeView1.Nodes.Add(nodePositions);
            if (m.getNumTexCoords() > 0)
            {
                TreeNode nodeTexCoords = new TreeNode("TexCoords (" + m.getNumTexCoords() + ")");
                for (int i = 0; i < m.getNumTexCoords(); i++)
                {
                    TreeNode nodeTexCoord      = new TreeNode("TexCoord " + i);
                    TreeNode nodeTexCoordValue = new TreeNode(m.getTexCoord(i).ToString());
                    nodeTexCoord.Nodes.Add(nodeTexCoordValue);
                    nodeTexCoords.Nodes.Add(nodeTexCoord);
                }
                treeView1.Nodes.Add(nodeTexCoords);
            }
            ;
            if (m.getNumNormals() > 0)
            {
                TreeNode nodeNormals = new TreeNode("Normals (" + m.getNumNormals() + ")");
                for (int i = 0; i < m.getNumNormals(); i++)
                {
                    TreeNode nodeNormal      = new TreeNode("Normal " + i);
                    TreeNode nodeNormalValue = new TreeNode(m.getNormal(i).ToString());
                    nodeNormal.Nodes.Add(nodeNormalValue);
                    nodeNormals.Nodes.Add(nodeNormal);
                }
                treeView1.Nodes.Add(nodeNormals);
            }
        }
示例#2
0
 public bool saveObjModel(string fileName)
 {
     System.IO.StreamWriter file = new System.IO.StreamWriter(fileName);
     file.WriteLine("# obj file exported by objFileExplorer");
     for (int i = 0; i < xyzs.Count; i++)
     {
         file.WriteLine("v " + xyzs[i].ToString().Replace(',', '.'));
     }
     for (int i = 0; i < texCoords.Count; i++)
     {
         file.WriteLine("vt " + texCoords[i].ToString().Replace(',', '.'));
     }
     for (int i = 0; i < normals.Count; i++)
     {
         file.WriteLine("vn " + normals[i].ToString().Replace(',', '.'));
     }
     for (int i = 0; i < objects.Count; i++)
     {
         ObjObject obj = objects[i];
         file.WriteLine("o " + obj.getName());
         for (int j = 0; j < obj.getNumFaces(); j++)
         {
             ObjFace face = faces[obj.getFirstFace() + j];
             file.Write("f");
             for (int k = 0; k < face.getNumVerts(); k++)
             {
                 int           faceVertIndex  = k + face.getFirstVert();
                 ObjFaceVertex faceVertex     = faceVerts[faceVertIndex];
                 string        faceVertString = " " + faceVertex.ToString();
                 file.Write(faceVertString);
             }
             file.WriteLine();
         }
     }
     for (int i = 0; i < groups.Count; i++)
     {
         ObjGroup g = groups[i];
         file.WriteLine("g " + g.getName());
         for (int j = 0; j < g.getNumFaces(); j++)
         {
             ObjFace face = faces[g.getFirstFace() + j];
             file.Write("f");
             for (int k = 0; k < face.getNumVerts(); k++)
             {
                 int           faceVertIndex  = k + face.getFirstVert();
                 ObjFaceVertex faceVertex     = faceVerts[faceVertIndex];
                 string        faceVertString = " " + faceVertex.ToString();
                 file.Write(faceVertString);
             }
             file.WriteLine();
         }
     }
     if (groups.Count == 0 && objects.Count == 0)
     {
         for (int j = 0; j < faces.Count; j++)
         {
             ObjFace face = faces[j];
             file.Write("f");
             for (int k = 0; k < face.getNumVerts(); k++)
             {
                 int           faceVertIndex  = k + face.getFirstVert();
                 ObjFaceVertex faceVertex     = faceVerts[faceVertIndex];
                 string        faceVertString = " " + faceVertex.ToString();
                 file.Write(faceVertString);
             }
             file.WriteLine();
         }
     }
     file.Close();
     return(false);
 }