示例#1
0
        public static void StuckNClothTimeWhenNotDynamic(MFnDependencyNode dn)
        {
            MPlug plug_isDynamic   = dn.findPlug(ConstantValue.plugName_nCloth_isDynamic);
            MPlug plug_currentTime = dn.findPlug(ConstantValue.plugName_nCloth_currentTime);

            if (plug_isDynamic != null && plug_currentTime != null)
            {
                MPlugArray inputArr_currentTime = new MPlugArray();
                plug_currentTime.connectedTo(inputArr_currentTime, true, false);
                MFnDependencyNode dn_time = new MFnDependencyNode(inputArr_currentTime[0].node);

                BindAttr.ProjectPlug(plug_isDynamic, dn_time.findPlug(ConstantValue.plugName_nClothTime_nodeState), 0, 1, (int)ConstantValue.TimeNodeState.Stuck, (int)ConstantValue.TimeNodeState.Normal);
            }
        }
示例#2
0
        public static void BindNCloth(MSelectionList selecteList = null)
        {
            if (selecteList == null)
            {
                selecteList = BasicFunc.GetSelectedList();
            }
            int count = (int)selecteList.length;

            if (count <= 1)
            {
                //Debug.Log("ncloth control switch target: select [ctl,ncloth0,ncloth1...]");
                return;
            }
            else
            {
                //Debug.Log("ncloth control switch target count:" + count);
            }
            MDagPath ctlDag = new MDagPath();

            selecteList.getDagPath(0, ctlDag);
            selecteList.remove(0);
            MFnDependencyNode dn_ctl = new MFnDependencyNode(ctlDag.node);

            BasicFunc.IterateSelectedDags((dag) =>
            {
                //Debug.Log("ncloth control set for:"+dag.fullPathName);
                MPlug ctlNewAttrPlug = BindAttr.AddBoolAttr(dn_ctl, "Dynamic_" + dag.partialPathName, true, "", false);
                dag.extendToShape();
                MFnDependencyNode dn_nCloth = new MFnDependencyNode(dag.node);
                MPlug plug_isDynamic        = dn_nCloth.findPlug(ConstantValue.plugName_nCloth_isDynamic);
                MPlug plug_currentTime      = dn_nCloth.findPlug(ConstantValue.plugName_nCloth_currentTime);
                if (plug_isDynamic != null && plug_currentTime != null)
                {
                    MPlugArray inputArr_currentTime = new MPlugArray();
                    plug_currentTime.connectedTo(inputArr_currentTime, true, false);
                    MFnDependencyNode dn_time = new MFnDependencyNode(inputArr_currentTime[0].node);

                    BindAttr.ProjectPlug(plug_isDynamic, dn_time.findPlug(ConstantValue.plugName_nClothTime_nodeState), 0, 1, (int)ConstantValue.TimeNodeState.Stuck, (int)ConstantValue.TimeNodeState.Normal);
                }
                BasicFunc.ConnectPlug(ctlNewAttrPlug, plug_isDynamic);
            }, MFn.Type.kNCloth, selecteList);


            //List<string> nclothNameList = new List<string>();
            //foreach (MDagPath dag in nclothList.DagPaths())
            //{
            //    nclothNameList.Add()
            //}
        }
示例#3
0
        public static List <MDagPath> AddBonesCTL(MSelectionList jointList = null, MFnTransform parentTrans = null)
        {
            if (jointList == null)
            {
                jointList = BasicFunc.GetSelectedList();
            }
            if (parentTrans == null)
            {
                parentTrans = new MFnTransform(BasicFunc.CreateEmptyGroup("grp_bonesCTL"));
            }
            if (jointList.length == 0)
            {
                return(null);
            }
            List <MDagPath> jointDags = new List <MDagPath>();

            for (int i = 0; i < jointList.length; i++)
            {
                MDagPath dag = new MDagPath();
                jointList.getDagPath((uint)i, dag);
                jointDags.Add(dag);
            }
            int count = jointDags.Count;

            MFnTransform[] jointTrans       = new MFnTransform[count];
            MFnTransform[] jointParentTrans = new MFnTransform[count];
            for (int i = 0; i < jointDags.Count; i++)
            {
                jointTrans[i]       = new MFnTransform(jointDags[i]);
                jointParentTrans[i] = new MFnTransform(MDagPath.getAPathTo(jointTrans[i].parent(0)));
            }
            MVector[] jointWorldPositions = new MVector[jointDags.Count];
            MVector   centerPos           = MVector.zero;

            for (int i = 0; i < count; i++)
            {
                jointWorldPositions[i] = jointTrans[i].getTranslation(MSpace.Space.kWorld);
                centerPos += jointWorldPositions[i];
            }
            centerPos = centerPos * (1.0f / count);

            double[] minDist_y = new double[count];
            double[] minDist_x = new double[count];

            if (count > 1)
            {
                for (int i = 0; i < count; i++)
                {
                    double closestY = double.MaxValue, closestX = double.MaxValue;
                    //int minDistIndex = 0;

                    for (int j = 0; j < count; j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }
                        MVector direct = jointWorldPositions[i] - jointWorldPositions[j];
                        direct.x = Math.Abs(direct.x);
                        direct.y = Math.Abs(direct.y);
                        if (direct.x >= direct.y)
                        {
                            if (direct.x < closestX)
                            {
                                closestX = direct.x;
                                //minDistIndex = j;
                            }
                        }
                        if (direct.y >= direct.x)
                        {
                            if (direct.y < closestY)
                            {
                                closestY = direct.y;
                            }
                        }
                    }
                    minDist_y[i] = closestY;
                    minDist_x[i] = closestX;
                }
            }
            else
            {
                minDist_x[0] = 1;
                minDist_y[0] = 1;
            }


            List <MDagPath> curves = new List <MDagPath>();

            for (int i = 0; i < count; i++)
            {
                float        width = (float)minDist_x[i] / 2, height = (float)minDist_y[i] / 2;
                MDagPath     curve      = BasicFunc.CreateCTL_Square("ctl_" + jointDags[i].partialPathName, height, width);
                MFnTransform curveTrans = new MFnTransform(curve);
                BasicFunc.SetTransformParent(curveTrans, parentTrans);
                curveTrans.setTranslation(jointWorldPositions[i] - centerPos, MSpace.Space.kTransform);
                BasicFunc.FreezeTransform(curveTrans);
                BasicFunc.SetTranslateLimit(curveTrans, -width / 2, -height / 2, 0, width / 2, height / 2, 0);

                MPlug plug_curveTX = curveTrans.findPlug(ConstantValue.plugName_tx);
                MPlug plug_curveTY = curveTrans.findPlug(ConstantValue.plugName_ty);
                MPlug plug_jointRY = jointParentTrans[i].findPlug(ConstantValue.plugName_ry);
                MPlug plug_jointRZ = jointParentTrans[i].findPlug(ConstantValue.plugName_rz);
                BindAttr.ProjectPlug(plug_curveTX, plug_jointRY, -width / 2, width / 2, -45, 45);
                BindAttr.ProjectPlug(plug_curveTY, plug_jointRZ, -height / 2, height / 2, -45, 45);
                curves.Add(curve);
            }
            return(curves);
        }