Esempio n. 1
0
        public static MDagPath AddDynamicChainControl(ref MDagPath hairSystem, MSelectionList jointChains = null, ConstantValue.HairPointLockType pointLock = ConstantValue.HairPointLockType.Base)
        {
            //get bones
            if (jointChains == null)
            {
                jointChains = BasicFunc.GetSelectedList();
            }
            if (jointChains.length == 0)
            {
                return(null);
            }

            MDagPath dagPath_startJoint = new MDagPath(), dagPath_endJoint = new MDagPath();

            if (jointChains.length == 1)
            {
                BasicFunc.Select(jointChains);
                jointChains.getDagPath((uint)0, dagPath_startJoint);
                MGlobal.executeCommand("select -hierarchy " + dagPath_startJoint.fullPathName);
                jointChains = BasicFunc.GetSelectedList(MFn.Type.kJoint);
            }


            jointChains.getDagPath(0, dagPath_startJoint);
            jointChains.getDagPath(jointChains.length - 1, dagPath_endJoint);

            MDagPath startCurveDagPath = JointProcess.CreateJointsCurve(jointChains);
            MDagPath outCurveDagPath   = CurveToHair(ref hairSystem, startCurveDagPath, pointLock);

            JointProcess.AddIKHandle(dagPath_startJoint, dagPath_endJoint, JointProcess.IKSolverType.Spline, outCurveDagPath.fullPathName);

            BasicFunc.SetTransformParent(BasicFunc.GetParent(startCurveDagPath), BasicFunc.GetParent(dagPath_startJoint));

            return(outCurveDagPath);
        }
Esempio n. 2
0
        public static void CreateSpiderNetCurves(MSelectionList selected = null, bool convertToHair = true, bool addConstraint = true, bool bindJoints = true)
        {
            if (selected == null)
            {
                selected = BasicFunc.GetSelectedList();
            }
            List <MDagPath>        verticalCurves = new List <MDagPath>(), horizontalCurves = new List <MDagPath>();
            List <List <MVector> > colList = new List <List <MVector> >();

            List <MDagPath[]> jointPairToBind = new List <MDagPath[]>();

            int rowCount = 0;

            foreach (MDagPath dag in selected.DagPaths())
            {
                List <MFnTransform> transList  = BasicFunc.GetHierachyChainTrans(dag);
                List <MVector>      vectorList = new List <MVector>();
                if (transList.Count > rowCount)
                {
                    rowCount = transList.Count;
                }
                for (int i = 0; i < transList.Count; i++)
                {
                    vectorList.Add(transList[i].getTranslation(MSpace.Space.kWorld));
                }
                if (bindJoints)
                {
                    jointPairToBind.Add(new MDagPath[2] {
                        transList[0].dagPath, transList[transList.Count - 1].dagPath
                    });
                }
                colList.Add(vectorList);
                verticalCurves.Add(CreateLoopCircleByPos(vectorList, false, false, string.Format("netCurve_column_{0:d4}", (colList.Count - 1))));
            }
            List <List <MVector> > rowList = new List <List <MVector> >();

            for (int i = 0; i < rowCount; i++)
            {
                List <MVector> rowCircle = new List <MVector>();
                for (int j = 0; j < colList.Count; j++)
                {
                    rowCircle.Add(colList[j][i]);
                }
                rowList.Add(rowCircle);
                horizontalCurves.Add(CreateLoopCircleByPos(rowCircle, false, true, string.Format("netCurve_row_{0:d4}", (rowCircle.Count - 1))));
            }
            if (convertToHair)
            {
                MDagPath       hairSystem         = new MDagPath();
                MSelectionList listToDynamicCurve = new MSelectionList();
                Debug.Log("vertical to dynamic count:" + verticalCurves.Count);
                for (int i = 0; i < verticalCurves.Count; i++)
                {
                    listToDynamicCurve.add(verticalCurves[i]);
                }
                MDagPath[] verticalOutputCurves = CurvesToHairs(ref hairSystem, listToDynamicCurve, ConstantValue.HairPointLockType.Base);
                Debug.Log("vertical dynamic result count:" + verticalOutputCurves.Length);
                BasicFunc.RenameDagList(verticalOutputCurves, "netDyCurve_vertical_{0:d2}");
                listToDynamicCurve.clear();
                Debug.Log("horizontal to dynamic count:" + horizontalCurves.Count);
                for (int i = 0; i < horizontalCurves.Count; i++)
                {
                    listToDynamicCurve.add(horizontalCurves[i]);
                }
                MDagPath[] horizontalOutputCurves = CurvesToHairs(ref hairSystem, listToDynamicCurve, ConstantValue.HairPointLockType.None);
                Debug.Log("horizontal dynamic result count:" + horizontalOutputCurves.Length);
                BasicFunc.RenameDagList(horizontalOutputCurves, "netDyCurve_horizontal_{0:d2}");
                if (bindJoints)
                {
                    for (int i = 0; i < verticalOutputCurves.Length; i++)
                    {
                        JointProcess.AddIKHandle(jointPairToBind[i][0], jointPairToBind[i][1], JointProcess.IKSolverType.Spline, verticalOutputCurves[i].fullPathName);
                    }
                }
                if (addConstraint)
                {
                    MSelectionList outputCurveList = new MSelectionList();
                    for (int i = 0; i < verticalOutputCurves.Length; i++)
                    {
                        outputCurveList.add(verticalOutputCurves[i]);
                    }
                    for (int i = 0; i < horizontalOutputCurves.Length; i++)
                    {
                        outputCurveList.add(horizontalOutputCurves[i]);
                    }
                    AddDynamicConstraint(outputCurveList);
                }
            }
            else if (bindJoints)
            {
                for (int i = 0; i < jointPairToBind.Count; i++)
                {
                    JointProcess.AddIKHandle(jointPairToBind[i][0], jointPairToBind[i][1], JointProcess.IKSolverType.Spline, verticalCurves[i].fullPathName);
                }
            }
        }