public static void BeautifulPole(MDagPath middleDag = null, bool clearFlag_x = true, bool clearFlag_y = true, bool clearFlag_z = true, bool useMoveSkinJointsTool = true)
        {
            if (middleDag == null || middleDag.node.isNull)
            {
                middleDag = BasicFunc.GetSelectedDagPath(0);
                if (middleDag == null || middleDag.node.isNull)
                {
                    Debug.Log("please select middle joint");
                    return;
                }
            }

            MFnTransform middleTrans = new MFnTransform(middleDag);

            if (middleTrans.parentCount == 0 || middleTrans.childCount == 0)
            {
                return;
            }
            MDagPath     parentDag      = MDagPath.getAPathTo(middleTrans.parent(0));
            MDagPath     childDag       = MDagPath.getAPathTo(middleTrans.child(0));
            MFnTransform parentTrans    = new MFnTransform(parentDag);
            MFnTransform childTrans     = new MFnTransform(childDag);
            MVector      parentWorldPos = parentTrans.getTranslation(MSpace.Space.kWorld);
            MVector      middleWorldPos = middleTrans.getTranslation(MSpace.Space.kWorld);
            MVector      childWorldPos  = childTrans.getTranslation(MSpace.Space.kWorld);
            //MVector vec_middleToParent = parentWorldPos - middleWorldPos;
            //MVector vec_childToMiddle = middleWorldPos - childWorldPos;
            //MVector verticalBack = BasicFunc.Cross(vec_middleToParent, vec_childToMiddle);

            float   length0     = (float)(middleWorldPos - parentWorldPos).length;
            float   length1     = (float)(middleWorldPos - childWorldPos).length;
            MVector posByWeight = BasicFunc.Lerp(parentWorldPos, childWorldPos, length0 / (length0 + length1));

            if (useMoveSkinJointsTool)
            {
                MoveSkinJointsTool(middleDag);
            }
            //middleTrans.setTranslation(posByWeight, MSpace.Space.kWorld);
            if (!clearFlag_x)
            {
                posByWeight.x = middleWorldPos.x;
            }
            if (!clearFlag_y)
            {
                posByWeight.y = middleWorldPos.y;
            }
            if (!clearFlag_z)
            {
                posByWeight.z = middleWorldPos.z;
            }
            middleTrans.setTranslation(posByWeight, MSpace.Space.kWorld);
            childTrans.setTranslation(childWorldPos, MSpace.Space.kWorld);
            //MFnIkJoint middleJoint = new MFnIkJoint(middleDag);
        }
Beispiel #2
0
        public static MDagPath CurveToHair(ref MDagPath hairSystemDagPath, MDagPath curveDagPath = null, ConstantValue.HairPointLockType pointLock = ConstantValue.HairPointLockType.Base)
        {
            if (curveDagPath == null)
            {
                curveDagPath = BasicFunc.GetSelectedDagPath(0);
            }
            bool           hairSystemReady = !hairSystemDagPath.node.isNull;
            MSelectionList targetList      = new MSelectionList();

            targetList.add(curveDagPath);
            if (hairSystemReady)
            {
                Debug.Log("hair system ready");
                targetList.add(hairSystemDagPath);
            }
            else
            {
                Debug.Log("hair system need to be created!");
            }
            BasicFunc.Select(targetList);


            string cmdStr    = "cmds.MakeCurvesDynamic(0,0,0,1,0)";
            string resultStr = MGlobal.executePythonCommandStringResult(cmdStr);

            MDagPath result = new MDagPath();

            //Debug.Log(curveDagPath.fullPathName);
            MFnTransform curveTrans = new MFnTransform(curveDagPath);

            if (curveTrans.parentCount > 0)
            {
                MDagPath follicleDagPath = MDagPath.getAPathTo(curveTrans.parent(0));
                MGlobal.executeCommand(string.Format("setAttr {0}.pointLock {1}", follicleDagPath.fullPathName, (int)pointLock));
                if (follicleDagPath.hasFn(MFn.Type.kFollicle))
                {
                    Debug.Log("follicle exist!");
                    ConvertHairSelection(HairSelectionType.OutputCurves, follicleDagPath);
                    result = BasicFunc.GetSelectedDagPath(0);
                    new MFnDependencyNode(result.node).setName("dy_" + curveDagPath.partialPathName);
                    if (!hairSystemReady)
                    {
                        ConvertHairSelection(HairSelectionType.HairSystem);
                        hairSystemDagPath = BasicFunc.GetSelectedDagPath(0);
                        hairSystemReady   = true;
                    }
                }
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// return Dynamic Output Curve
        /// </summary>
        /// <param name="hairSystemDagPath">exist hairsystem or container of created hairsystem</param>
        /// <param name="curveList"></param>
        /// <param name="pointLock">0-none, 1-base, 2-end,3-both</param>
        /// <returns></returns>
        public static MDagPath[] CurvesToHairs(ref MDagPath hairSystemDagPath, MSelectionList curveList = null, ConstantValue.HairPointLockType pointLock = ConstantValue.HairPointLockType.Base)
        {
            if (curveList == null)
            {
                curveList = BasicFunc.GetSelectedList();
            }

            bool hairSystemReady = false;

            if (!hairSystemDagPath.node.isNull)
            {
                //Debug.Log("hairSystem node is not null:" + hairSystemDagPath.fullPathName);
                curveList.add(hairSystemDagPath);
                hairSystemReady = true;
            }
            else
            {
                //Debug.Log("hairsystem node is null");
            }
            MGlobal.setActiveSelectionList(curveList);
            string cmdStr    = "cmds.MakeCurvesDynamic(0,0,0,1,0)";
            string resultStr = MGlobal.executePythonCommandStringResult(cmdStr);

            if (hairSystemReady)
            {
                //Debug.Log("remove hairSystem Selection");
                curveList.remove(curveList.length - 1);
            }
            List <MDagPath> results = new List <MDagPath>();

            for (int i = 0; i < curveList.length; i++)
            {
                MDagPath curveDagPath = new MDagPath();
                curveList.getDagPath((uint)i, curveDagPath);

                //Debug.Log(curveDagPath.fullPathName);
                MFnTransform curveTrans = new MFnTransform(curveDagPath);
                if (curveTrans.parentCount > 0)
                {
                    MDagPath follicleDagPath = MDagPath.getAPathTo(curveTrans.parent(0));
                    MGlobal.executeCommand(string.Format("setAttr {0}.pointLock {1}", follicleDagPath.fullPathName, (int)pointLock));
                    if (follicleDagPath.hasFn(MFn.Type.kFollicle))
                    {
                        Debug.Log("follicle exist!");
                        ConvertHairSelection(HairSelectionType.OutputCurves, follicleDagPath);
                        MDagPath result = BasicFunc.GetSelectedDagPath(0);
                        new MFnDependencyNode(result.node).setName("dy_" + curveDagPath.partialPathName);
                        results.Add(result);
                        if (!hairSystemReady)
                        {
                            ConvertHairSelection(HairSelectionType.HairSystem);
                            hairSystemDagPath = BasicFunc.GetSelectedDagPath(0);
                            //Debug.Log("assign hairSystem:" + hairSystemDagPath.fullPathName);
                            hairSystemReady = true;
                        }
                    }
                }
            }


            //error
            return(results.ToArray());
        }