Esempio n. 1
0
        private void buildMeshNodes()
        {
            MItDependencyNodes it = new MItDependencyNodes(MFn.Type.kMesh);

            while (!it.isDone)
            {
                // Get the dag node of the mesh.
                MFnDagNode dagNode = new MFnDagNode(it.thisNode);
                // Create a new mesh.
                MayaMesh meshNode = new MayaMesh();
                // Add the mesh to the all meshes list.
                allMeshes.Add(meshNode);
                // Configure the mesh node
                meshNode.name = dagNode.fullPathName;
                dagNode.getPath(meshNode.mayaObjectPath);
                meshNode.id = allMeshes.Count - 1;
                // The first parent of a mesh is the source transform, even with instances.
                meshNode.sourceXForm = pathXformMap[(new MFnDagNode(dagNode.parent(0))).fullPathName];
                // Set the source Xform to know it's a source for an instance (its mesh).
                meshNode.sourceXForm.isSourceXform = true;
                // If the mesh has more than one parent, it has been instanced.  We need to know this for computing local positions.
                meshNode.isInstanced = dagNode.isInstanced();
                // Add the map to the dictionary to search by name.
                pathMeshMap[meshNode.name] = meshNode;
                it.next();
            }
        }
Esempio n. 2
0
        public void readBinaryFile( string file )
        {
            // TODO: Reset data.

            BinaryReader br = new BinaryReader(new FileStream(file, FileMode.Open));

            // Mesh count.
            int meshCount = br.ReadInt32();
            // Read all meshes.
            for( int currMesh = 0; currMesh < meshCount; ++currMesh )
            {
                MayaMesh mesh = new MayaMesh();
                // Mesh name.
                mesh.name = br.ReadString();
                //Mesh id.
                mesh.id = br.ReadInt32();
                // Vertex count.
                int vertexCount = br.ReadInt32();
                // Read all vertices.
                for( int currVert = 0; currVert < vertexCount; ++currVert )
                {
                    Vertex vert = new Vertex();
                    // Read position.
                    vert.position.x = br.ReadSingle();
                    vert.position.y = br.ReadSingle();
                    vert.position.z = br.ReadSingle();
                    // Read normal.
                    vert.normal.x = br.ReadSingle();
                    vert.normal.y = br.ReadSingle();
                    vert.normal.z = br.ReadSingle();
                    // Read texcoord.
                    vert.texcoord.x = br.ReadSingle();
                    vert.texcoord.y = br.ReadSingle();

                    mesh.vertices.Add(vert);
                }
                // Read index count.
                int indexCount = br.ReadInt32();
                // Read all indices.
                for( int currIdx = 0; currIdx < indexCount; ++currIdx )
                {
                    mesh.indices.Add(br.ReadUInt32());
                }

                allMeshes.Add(mesh);
            }

            // Read xform count.
            int xformCount = br.ReadInt32();
            for( int currXform = 0; currXform < xformCount; ++currXform )
            {
                MayaXform xform = new MayaXform();
                // Read name.
                xform.name = br.ReadString();
                // Read id.
                xform.id = br.ReadInt32();
                // Read parent id.
                int parentId = br.ReadInt32();
                if( parentId != -1 )
                {
                    xform.parent = allXforms[parentId];
                }
                // Read matrix.
                for( int x = 0; x < 4; ++x )
                {
                    for( int y = 0; y < 4; ++y )
                    {
                        xform.matrix[x,y] = br.ReadSingle();
                    }
                }
                // Read source xform bool.
                xform.isSourceXform = br.ReadBoolean();
                // Read mesh id.
                int meshId = br.ReadInt32();
                if( meshId != -1 )
                {
                    xform.mesh = allMeshes[meshId];
                }
                // Read children count.
                int childCount = br.ReadInt32();
                // Read all children ids.
                for( int currChild = 0; currChild < childCount; ++currChild )
                {
                    int childId = br.ReadInt32();
                    xform.children.Add(allXforms[childId]);
                }

                allXforms.Add(xform);
            }

            br.Close();
        }
Esempio n. 3
0
 private void buildMeshNodes()
 {
     MItDependencyNodes it = new MItDependencyNodes(MFn.Type.kMesh);
     while( !it.isDone )
     {
         // Get the dag node of the mesh.
         MFnDagNode dagNode = new MFnDagNode(it.thisNode);
         // Create a new mesh.
         MayaMesh meshNode = new MayaMesh();
         // Add the mesh to the all meshes list.
         allMeshes.Add(meshNode);
         // Configure the mesh node
         meshNode.name = dagNode.fullPathName;
         dagNode.getPath(meshNode.mayaObjectPath);
         meshNode.id = allMeshes.Count - 1;
         // The first parent of a mesh is the source transform, even with instances.
         meshNode.sourceXForm = pathXformMap[(new MFnDagNode(dagNode.parent(0))).fullPathName];
         // Set the source Xform to know it's a source for an instance (its mesh).
         meshNode.sourceXForm.isSourceXform = true;
         // If the mesh has more than one parent, it has been instanced.  We need to know this for computing local positions.
         meshNode.isInstanced = dagNode.isInstanced();
         // Add the map to the dictionary to search by name.
         pathMeshMap[meshNode.name] = meshNode;
         it.next();
     }
 }
Esempio n. 4
0
        public void readBinaryFile(string file)
        {
            // TODO: Reset data.

            BinaryReader br = new BinaryReader(new FileStream(file, FileMode.Open));

            // Mesh count.
            int meshCount = br.ReadInt32();

            // Read all meshes.
            for (int currMesh = 0; currMesh < meshCount; ++currMesh)
            {
                MayaMesh mesh = new MayaMesh();
                // Mesh name.
                mesh.name = br.ReadString();
                //Mesh id.
                mesh.id = br.ReadInt32();
                // Vertex count.
                int vertexCount = br.ReadInt32();
                // Read all vertices.
                for (int currVert = 0; currVert < vertexCount; ++currVert)
                {
                    Vertex vert = new Vertex();
                    // Read position.
                    vert.position.x = br.ReadSingle();
                    vert.position.y = br.ReadSingle();
                    vert.position.z = br.ReadSingle();
                    // Read normal.
                    vert.normal.x = br.ReadSingle();
                    vert.normal.y = br.ReadSingle();
                    vert.normal.z = br.ReadSingle();
                    // Read texcoord.
                    vert.texcoord.x = br.ReadSingle();
                    vert.texcoord.y = br.ReadSingle();

                    mesh.vertices.Add(vert);
                }
                // Read index count.
                int indexCount = br.ReadInt32();
                // Read all indices.
                for (int currIdx = 0; currIdx < indexCount; ++currIdx)
                {
                    mesh.indices.Add(br.ReadUInt32());
                }

                allMeshes.Add(mesh);
            }

            // Read xform count.
            int xformCount = br.ReadInt32();

            for (int currXform = 0; currXform < xformCount; ++currXform)
            {
                MayaXform xform = new MayaXform();
                // Read name.
                xform.name = br.ReadString();
                // Read id.
                xform.id = br.ReadInt32();
                // Read parent id.
                int parentId = br.ReadInt32();
                if (parentId != -1)
                {
                    xform.parent = allXforms[parentId];
                }
                // Read matrix.
                for (int x = 0; x < 4; ++x)
                {
                    for (int y = 0; y < 4; ++y)
                    {
                        xform.matrix[x, y] = br.ReadSingle();
                    }
                }
                // Read source xform bool.
                xform.isSourceXform = br.ReadBoolean();
                // Read mesh id.
                int meshId = br.ReadInt32();
                if (meshId != -1)
                {
                    xform.mesh = allMeshes[meshId];
                }
                // Read children count.
                int childCount = br.ReadInt32();
                // Read all children ids.
                for (int currChild = 0; currChild < childCount; ++currChild)
                {
                    int childId = br.ReadInt32();
                    xform.children.Add(allXforms[childId]);
                }

                allXforms.Add(xform);
            }

            br.Close();
        }