예제 #1
0
        public static List <MDagPath> GetHierachyChain(MDagPath startDag, MFn.Type filterType = MFn.Type.kInvalid, MDagPath endDag = null)
        {
            MFnTransform currentTrans = new MFnTransform(startDag);
            //no need for trans data , so mfntransform(mobject) is used
            List <MDagPath> result = new List <MDagPath>();

            result.Add(startDag);
            while (currentTrans.childCount > 0)
            {
                int nextIndex = 0;
                if (filterType != MFn.Type.kInvalid)
                {
                    bool filterOK = false;
                    for (int i = 0; i < currentTrans.childCount; i++)
                    {
                        MObject mo = currentTrans.child((uint)i);
                        if (mo.hasFn(filterType))
                        {
                            nextIndex = i;
                            filterOK  = true;
                            break;
                        }
                    }
                    if (!filterOK)
                    {
                        break;
                    }
                }
                currentTrans = new MFnTransform(currentTrans.child((uint)nextIndex));
                MDagPath dag = currentTrans.dagPath;
                result.Add(dag);
                if (endDag != null && dag.fullPathName == endDag.fullPathName)
                {
                    break;
                }
            }
            return(result);
        }
예제 #2
0
        public static List <MayaObject> GetSelectedObjects(MFn.Type filter = MFn.Type.kInvalid)
        {
            MSelectionList selectionList = new MSelectionList();

            MGlobal.getActiveSelectionList(selectionList);
            IEnumerable <MDagPath> listAsDags;

            if (filter == MFn.Type.kInvalid)
            {
                listAsDags = selectionList.DagPaths();
            }
            else
            {
                listAsDags = selectionList.DagPaths(filter);
            }

            List <MayaObject> selectedObjects = new List <MayaObject>((int)selectionList.length);
            var mDagPaths = listAsDags as MDagPath[] ?? listAsDags.ToArray();

            selectedObjects.AddRange(mDagPaths.Select(dagObj => new MayaObject(dagObj)));

            return(selectedObjects);
        }
예제 #3
0
 private static void AddChildrenToList(List <MDagPath> dagList, MFnTransform rootTrans, MFn.Type filterType = MFn.Type.kInvalid)
 {
     if (filterType == MFn.Type.kInvalid || rootTrans.dagPath.hasFn(filterType))
     {
         dagList.Add(rootTrans.dagPath);
     }
     if (rootTrans.childCount > 0)
     {
         for (int i = 0; i < rootTrans.childCount; i++)
         {
             MObject  mo  = rootTrans.child((uint)i);
             MDagPath dag = MDagPath.getAPathTo(mo);
             AddChildrenToList(dagList, new MFnTransform(dag), filterType);
         }
     }
 }
예제 #4
0
        private void doScan(MItDag.TraversalType traversalType, MFn.Type filter, bool quiet)
        {
            MItDag dagIterator = new MItDag(traversalType, filter);

            //	Scan the entire DAG and output the name and depth of each node

            if (traversalType == MItDag.TraversalType.kBreadthFirst)
            {
                if (!quiet)
                {
                    MGlobal.displayInfo(Environment.NewLine + "Starting Breadth First scan of the Dag");
                }
                else
                if (!quiet)
                {
                    MGlobal.displayInfo(Environment.NewLine + "Starting Depth First scan of the Dag");
                }
            }

            switch (filter)
            {
            case MFn.Type.kCamera:
                if (!quiet)
                {
                    MGlobal.displayInfo(": Filtering for Cameras\n");
                }
                break;

            case MFn.Type.kLight:
                if (!quiet)
                {
                    MGlobal.displayInfo(": Filtering for Lights\n");
                }
                break;

            case MFn.Type.kNurbsSurface:
                if (!quiet)
                {
                    MGlobal.displayInfo(": Filtering for Nurbs Surfaces\n");
                }
                break;

            default:
                MGlobal.displayInfo(Environment.NewLine);
                break;
            }


            int objectCount = 0;

            for ( ; !dagIterator.isDone; dagIterator.next())
            {
                MDagPath dagPath = new MDagPath();

                try
                {
                    dagIterator.getPath(dagPath);
                }
                catch (System.Exception)
                {
                    continue;
                }

                MFnDagNode dagNode = null;
                try
                {
                    dagNode = new MFnDagNode(dagPath);
                }
                catch (System.Exception)
                {
                    continue;
                }

                if (!quiet)
                {
                    MGlobal.displayInfo(dagNode.name + ": " + dagNode.typeName + Environment.NewLine);
                }

                if (!quiet)
                {
                    MGlobal.displayInfo("  dagPath: " + dagPath.fullPathName + Environment.NewLine);
                }

                objectCount += 1;
                if (dagPath.hasFn(MFn.Type.kCamera))
                {
                    MFnCamera camera = null;
                    try
                    {
                        camera = new MFnCamera(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Camera data
                    //
                    if (!quiet)
                    {
                        MGlobal.displayInfo("  eyePoint: " + MPointToString(camera.eyePoint(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  upDirection: " + MVectorToString(camera.upDirection(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  viewDirection: " + MVectorToString(camera.viewDirection(MSpace.Space.kWorld)) + Environment.NewLine);

                        MGlobal.displayInfo("  aspectRatio: " + Convert.ToString(camera.aspectRatio) + Environment.NewLine);

                        MGlobal.displayInfo("  horizontalFilmAperture: " + Convert.ToString(camera.horizontalFilmAperture) + Environment.NewLine);

                        MGlobal.displayInfo("  verticalFilmAperture: " + Convert.ToString(camera.verticalFilmAperture) + Environment.NewLine);
                    }
                }
                else if (dagPath.hasFn(MFn.Type.kLight))
                {
                    MFnLight light = null;
                    try
                    {
                        light = new MFnLight(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Light data
                    //
                    MColor color = light.color;
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  color: [%f, %f, %f]\n", color.r, color.g, color.b));
                    }
                    color = light.shadowColor;
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  shadowColor: [%f, %f, %f]\n", color.r, color.g, color.b));
                        MGlobal.displayInfo("  intensity: " + Convert.ToString(light.intensity) + Environment.NewLine);
                    }
                }
                else if (dagPath.hasFn(MFn.Type.kNurbsSurface))
                {
                    MFnNurbsSurface surface = null;
                    try
                    {
                        surface = new MFnNurbsSurface(dagPath);
                    }
                    catch (System.Exception)
                    {
                        continue;
                    }

                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);

                    // Extract some interesting Surface data
                    //
                    if (!quiet)
                    {
                        MGlobal.displayInfo(string.Format("  numCVs: %d * %s", surface.numCVsInU, surface.numCVsInV) + Environment.NewLine);
                        MGlobal.displayInfo(string.Format("  numKnots: %d * %s\n", surface.numKnotsInU, surface.numKnotsInV) + Environment.NewLine);
                        MGlobal.displayInfo(string.Format("  numSpans: %d * %s\n", surface.numSpansInU, surface.numSpansInV) + Environment.NewLine);
                    }
                }
                else
                {
                    // Get the translation/rotation/scale data
                    //
                    printTransformData(dagPath, quiet);
                }
            }

            setResult(objectCount);
        }