示例#1
0
        private void getXformData(MayaXform xform)
        {
            // Get the maya transform node to get data from.
            MFnTransform mayaXform = new MFnTransform(xform.mayaObjectPath);

            // Get the matrix.
            MMatrix mayaMatrix = mayaXform.transformationMatrix;

            mayaMatrix.get(xform.matrix);
        }
示例#2
0
        private void processXform(MayaXform xform)
        {
            // Add the current Xform to the list of all xforms.
            allXforms.Add(xform);

            // Set the Xform's id.
            xform.id = allXforms.Count - 1;

            // Add the current Xform to the map based on its path.
            pathXformMap[xform.name] = xform;

            // Build data for this xform.
            if (!xform.isRoot)
            {
                getXformData(xform);
            }

            MFnDagNode dagNode = new MFnDagNode(xform.mayaObjectPath);

            for (uint childIdx = 0; childIdx < dagNode.childCount; ++childIdx)
            {
                // If the child isn't a transform node, or it is a kManipulator3D (maya api bug), skip it.
                MObject childObj = dagNode.child(childIdx);
                if (!childObj.hasFn(MFn.Type.kTransform) || childObj.hasFn(MFn.Type.kManipulator3D))
                {
                    continue;
                }

                // Create a node for the child transform, parent it to this xform, and process the child's children.
                MFnDagNode childNode = new MFnDagNode(childObj);
                // Strip out nodes we don't care about.
                if (xformsToIgnore.Contains(childNode.fullPathName))
                {
                    continue;
                }
                MayaXform childXform = new MayaXform();
                childXform.name = childNode.fullPathName;
                childNode.getPath(childXform.mayaObjectPath);
                childXform.parent = xform;
                xform.children.Add(childXform);
                processXform(childXform);
            }
        }
示例#3
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();
        }
示例#4
0
        private void processXform( MayaXform xform )
        {
            // Add the current Xform to the list of all xforms.
            allXforms.Add(xform);

            // Set the Xform's id.
            xform.id = allXforms.Count - 1;

            // Add the current Xform to the map based on its path.
            pathXformMap[xform.name] = xform;

            // Build data for this xform.
            if( !xform.isRoot )
            {
                getXformData(xform);
            }

            MFnDagNode dagNode = new MFnDagNode(xform.mayaObjectPath);
            for( uint childIdx = 0; childIdx < dagNode.childCount; ++childIdx )
            {
                // If the child isn't a transform node, or it is a kManipulator3D (maya api bug), skip it.
                MObject childObj = dagNode.child(childIdx);
                if( !childObj.hasFn(MFn.Type.kTransform) || childObj.hasFn(MFn.Type.kManipulator3D) )
                {
                    continue;
                }

                // Create a node for the child transform, parent it to this xform, and process the child's children.
                MFnDagNode childNode = new MFnDagNode(childObj);
                // Strip out nodes we don't care about.
                if( xformsToIgnore.Contains(childNode.fullPathName) )
                {
                    continue;
                }
                MayaXform childXform = new MayaXform();
                childXform.name = childNode.fullPathName;
                childNode.getPath(childXform.mayaObjectPath);
                childXform.parent = xform;
                xform.children.Add(childXform);
                processXform(childXform);
            }
        }
示例#5
0
        private void getXformData( MayaXform xform )
        {
            // Get the maya transform node to get data from.
            MFnTransform mayaXform = new MFnTransform(xform.mayaObjectPath);

            // Get the matrix.
            MMatrix mayaMatrix = mayaXform.transformationMatrix;
            mayaMatrix.get(xform.matrix);
        }
示例#6
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();
        }