Exemplo 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();
            }
        }
Exemplo n.º 2
0
        private void buildXformTree()
        {
            // Get the very root of the Maya DAG.
            MItDag rootIt = new MItDag();

            rootXform.isRoot = true;
            rootXform.name   = "root";
            MFnDagNode rootDagNode = new MFnDagNode(rootIt.root());

            rootDagNode.getPath(rootXform.mayaObjectPath);

            // Process all children transforms of the root.
            processXform(rootXform);
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 5
0
        private void buildXformTree()
        {
            // Get the very root of the Maya DAG.
            MItDag rootIt = new MItDag();
            rootXform.isRoot = true;
            rootXform.name = "root";
            MFnDagNode rootDagNode = new MFnDagNode(rootIt.root());
            rootDagNode.getPath(rootXform.mayaObjectPath);

            // Process all children transforms of the root.
            processXform(rootXform);
        }
Exemplo n.º 6
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();
     }
 }
Exemplo n.º 7
0
        private void buildLightNodes()
        {
            MItDependencyNodes it = new MItDependencyNodes(MFn.Type.kLight);
            while( !it.isDone )
            {
                MObject mayaObj = it.thisNode;
                if( shouldPruneLight(mayaObj) )
                {
                    it.next();
                    continue;
                }

                // Create a new light and add it to the all lights list.
                MayaLight light = new MayaLight();
                allLights.Add(light);
                light.id = allLights.Count - 1;
                // Get the dag node of the light for its name and parent.
                MFnDagNode dagNode = new MFnDagNode(mayaObj);
                dagNode.getPath(light.mayaObjectPath);
                light.name = dagNode.fullPathName;
                // First parent is the source transform node.
                light.sourceXform = pathXformMap[(new MFnDagNode(dagNode.parent(0))).fullPathName];
                // Add the light to the dictionary to search by name.
                pathLightMap[light.name] = light;

                //
                // NOTE: Parent transforms of light sources in Maya can NOT be frozen,
                //       so accessing them is guaranteed to not be frozen.
                //

                if( mayaObj.hasFn(MFn.Type.kAmbientLight) )
                {
                    MFnAmbientLight mayaLight = new MFnAmbientLight(mayaObj);
                    light.type = MayaLight.Type.kAmbient;
                    light.color = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                }
                else if( mayaObj.hasFn(MFn.Type.kDirectionalLight) )
                {
                    MFnDirectionalLight mayaLight = new MFnDirectionalLight(mayaObj);
                    light.type = MayaLight.Type.kDirectional;
                    light.color = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                }
                else if( mayaObj.hasFn(MFn.Type.kPointLight) )
                {
                    MFnPointLight mayaLight = new MFnPointLight(mayaObj);
                    light.type = MayaLight.Type.kPoint;
                    light.color = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                    light.range = (float)mayaLight.centerOfIllumination;
                }
                else if( mayaObj.hasFn(MFn.Type.kSpotLight) )
                {
                    MFnSpotLight mayaLight = new MFnSpotLight(mayaObj);
                    light.type = MayaLight.Type.kSpot;
                    light.color = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                    light.range = (float)mayaLight.centerOfIllumination;
                    float mayaConeAngle = (float)(mayaLight.coneAngle * 0.5);
                    light.coneInnerAngle = 57.29578f * mayaConeAngle;
                    light.coneOuterAngle = 57.29578f * (mayaConeAngle + Math.Abs((float)mayaLight.penumbraAngle));
                }

                it.next();
            }
        }
Exemplo n.º 8
0
        private void buildLightNodes()
        {
            MItDependencyNodes it = new MItDependencyNodes(MFn.Type.kLight);

            while (!it.isDone)
            {
                MObject mayaObj = it.thisNode;
                if (shouldPruneLight(mayaObj))
                {
                    it.next();
                    continue;
                }

                // Create a new light and add it to the all lights list.
                MayaLight light = new MayaLight();
                allLights.Add(light);
                light.id = allLights.Count - 1;
                // Get the dag node of the light for its name and parent.
                MFnDagNode dagNode = new MFnDagNode(mayaObj);
                dagNode.getPath(light.mayaObjectPath);
                light.name = dagNode.fullPathName;
                // First parent is the source transform node.
                light.sourceXform = pathXformMap[(new MFnDagNode(dagNode.parent(0))).fullPathName];
                // Add the light to the dictionary to search by name.
                pathLightMap[light.name] = light;

                //
                // NOTE: Parent transforms of light sources in Maya can NOT be frozen,
                //       so accessing them is guaranteed to not be frozen.
                //

                if (mayaObj.hasFn(MFn.Type.kAmbientLight))
                {
                    MFnAmbientLight mayaLight = new MFnAmbientLight(mayaObj);
                    light.type      = MayaLight.Type.kAmbient;
                    light.color     = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                }
                else if (mayaObj.hasFn(MFn.Type.kDirectionalLight))
                {
                    MFnDirectionalLight mayaLight = new MFnDirectionalLight(mayaObj);
                    light.type      = MayaLight.Type.kDirectional;
                    light.color     = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                }
                else if (mayaObj.hasFn(MFn.Type.kPointLight))
                {
                    MFnPointLight mayaLight = new MFnPointLight(mayaObj);
                    light.type      = MayaLight.Type.kPoint;
                    light.color     = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                    light.range     = (float)mayaLight.centerOfIllumination;
                }
                else if (mayaObj.hasFn(MFn.Type.kSpotLight))
                {
                    MFnSpotLight mayaLight = new MFnSpotLight(mayaObj);
                    light.type      = MayaLight.Type.kSpot;
                    light.color     = new Color(mayaLight.color.r, mayaLight.color.g, mayaLight.color.b, mayaLight.color.a);
                    light.intensity = mayaLight.intensity;
                    light.range     = (float)mayaLight.centerOfIllumination;
                    float mayaConeAngle = (float)(mayaLight.coneAngle * 0.5);
                    light.coneInnerAngle = 57.29578f * mayaConeAngle;
                    light.coneOuterAngle = 57.29578f * (mayaConeAngle + Math.Abs((float)mayaLight.penumbraAngle));
                }

                it.next();
            }
        }