/// <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()); }
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); }
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); }