Пример #1
0
        public static MDagPath CreateJointsCurve(MSelectionList jointDagPathList)
        {
            int    count     = (int)jointDagPathList.length;
            string curveName = "curve_";

            MVector[] vectors = new MVector[count];
            for (int i = 0; i < count; i++)
            {
                MDagPath dagPath = new MDagPath();
                jointDagPathList.getDagPath((uint)i, dagPath);
                if (i == 0)
                {
                    curveName += dagPath.partialPathName + "_";
                }
                else if (i == count - 1)
                {
                    curveName += dagPath.partialPathName;
                }
                MFnTransform ptTrans = new MFnTransform(dagPath);
                vectors[i] = ptTrans.getTranslation(MSpace.Space.kWorld);
                //MGlobal.displayInfo(BasicFunc::ToCMDSParamStr(vectors[i]));
            }
            MDagPath curveDagPath = BasicFunc.CreateCurve(vectors, curveName);

            //MGlobal.displayInfo("create Finish");


            return(curveDagPath);
        }
        protected override bool connectObjectAndConstraint(MDGModifier modifier)
        {
            MObject transform = transformObject();
            if ( transform.isNull )
            {
                throw new InvalidOperationException("Failed to get transformObject()");
            }

            MFnTransform transformFn = new MFnTransform(transform);
            MVector translate = transformFn.getTranslation(MSpace.Space.kTransform);
            MPlug translatePlug = transformFn.findPlug("translate");

            if (MPlug.FreeToChangeState.kFreeToChange == translatePlug.isFreeToChange())
            {
                MFnNumericData nd = new MFnNumericData();

                MObject translateData = nd.create(MFnNumericData.Type.k3Double);
                nd.setData3Double(translate.x, translate.y, translate.z);
                modifier.newPlugValue(translatePlug, translateData);
                connectObjectAttribute(MPxTransform.geometry, GeometrySurfaceConstraint.constraintGeometry, false);
            }

            connectObjectAttribute(MPxTransform.parentInverseMatrix, GeometrySurfaceConstraint.constraintParentInverseMatrix, true, true);

            return true;
        }
Пример #3
0
        public static MDagPath AddParentCircle(MDagPath targetDagPath, bool createParallelGrp)
        {
            string   ctlName    = "ctl_" + targetDagPath.partialPathName;
            MDagPath ctlDagPath = BasicFunc.CreateCircle(ctlName);

            ctlName = ctlDagPath.fullPathName;
            MFnTransform targetTrans = new MFnTransform(targetDagPath);

            if (createParallelGrp)
            {
                MFnTransform parellelGrpTrans = new MFnTransform(AddEmptyGroup(new MFnTransform(targetTrans.parent(0))));
                parellelGrpTrans.setTranslation(targetTrans.getTranslation(MSpace.Space.kTransform), MSpace.Space.kTransform);
                //Debug.Log("finalLocalPos:"+BasicFunc.ToCMDSParamStr(parellelGrpTrans.getTranslation(MSpace.kTransform)));
                MEulerRotation rot = new MEulerRotation();
                targetTrans.getRotation(rot);
                parellelGrpTrans.setRotation(rot);
                SetTransformParent(ctlName, parellelGrpTrans.fullPathName);
            }

            MFnTransform circleTransform = new MFnTransform(ctlDagPath);

            circleTransform.setTranslation(new MVector(0, 0, 0), MSpace.Space.kTransform);
            circleTransform.setRotation(new MEulerRotation(0, 90 / ConstantValue.DPR, 0));
            FreezeTransform(circleTransform);
            return(ctlDagPath);
        }
Пример #4
0
        protected override bool connectObjectAndConstraint(MDGModifier modifier)
        {
            MObject transform = transformObject();

            if (transform.isNull)
            {
                throw new InvalidOperationException("Failed to get transformObject()");
            }

            MFnTransform transformFn   = new MFnTransform(transform);
            MVector      translate     = transformFn.getTranslation(MSpace.Space.kTransform);
            MPlug        translatePlug = transformFn.findPlug("translate");

            if (MPlug.FreeToChangeState.kFreeToChange == translatePlug.isFreeToChange())
            {
                MFnNumericData nd = new MFnNumericData();

                MObject translateData = nd.create(MFnNumericData.Type.k3Double);
                nd.setData3Double(translate.x, translate.y, translate.z);
                modifier.newPlugValue(translatePlug, translateData);
                connectObjectAttribute(MPxTransform.geometry, GeometrySurfaceConstraint.constraintGeometry, false);
            }

            connectObjectAttribute(MPxTransform.parentInverseMatrix, GeometrySurfaceConstraint.constraintParentInverseMatrix, true, true);

            return(true);
        }
Пример #5
0
        public static void CreateRelativeCurve(MSelectionList selected = null, ConstantValue.SampleType st = ConstantValue.SampleType.ObjectTrans, bool reOrder = true, bool closedArc = true, string ctlName = null)
        {
            if (selected == null)
            {
                selected = BasicFunc.GetSelectedList();
            }
            List <MVector> positions = new List <MVector>();

            switch (st)
            {
            case ConstantValue.SampleType.Vert:
            {
                MItSelectionList it_selectionList = new MItSelectionList(selected);
                MVector          totalWeight      = MVector.zero;
                for (; !it_selectionList.isDone; it_selectionList.next())
                {
                    MObject  component = new MObject();
                    MDagPath item      = new MDagPath();
                    it_selectionList.getDagPath(item, component);
                    MItMeshVertex it_verts = new MItMeshVertex(item, component);
                    for (; !it_verts.isDone; it_verts.next())
                    {
                        //Debug.Log(it_verts.index().ToString());
                        MPoint  point = it_verts.position(MSpace.Space.kWorld);
                        MVector pos   = new MVector(point.x, point.y, point.z);
                        //BasicFunc.CreateLocator(pos, "vert_" + it_verts.index());
                        positions.Add(pos);
                        totalWeight += pos;
                    }
                }
                break;
            }

            case ConstantValue.SampleType.Edge:
            {
                break;
            }

            case ConstantValue.SampleType.Poly:
            {
                break;
            }

            case ConstantValue.SampleType.ObjectTrans:
            {
                foreach (MDagPath dag in selected.DagPaths())
                {
                    MFnTransform trans = new MFnTransform(dag);
                    positions.Add(trans.getTranslation(MSpace.Space.kWorld));
                }
                break;
            }
            }
            if (ctlName == null)
            {
                ctlName = "samplerCurve_00";
            }
            CreateLoopCircleByPos(positions, reOrder, closedArc, ctlName);
        }
Пример #6
0
        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);
        }