void CreationSubdivisionJoint(SPCRJointDynamicsController Controller, int HDivCount, int VDivCount)
    {
        var VCurve = new List <CurveData>();
        var HCurve = new List <CurveData>();

        var RootTbl = Controller._RootPointTbl;

#if UNITY_2018_3_OR_NEWER
        PrefabUtility.UnpackPrefabInstance(Controller.gameObject, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction);
#else//UNITY_2018_3_OR_NEWER
        PrefabUtility.DisconnectPrefabInstance(Controller.gameObject);
#endif//UNITY_2018_3_OR_NEWER

        for (int i = 0; i < RootTbl.Length; ++i)
        {
            float Length = 0.0f;
            var   Curve  = new CurveData();
            var   Point  = RootTbl[i];
            while (Point != null)
            {
                Curve.Keys.Add(new CurveKey()
                {
                    Length = Length,
                    Value  = Point.transform.position,
                });
                var NextPoint = Controller.GetChildJointDynamicsPoint(Point);
                if (NextPoint != null)
                {
                    Length += (NextPoint.transform.position - Point.transform.position).magnitude;
                }
                Point = NextPoint;
            }
            Curve.CreateSpileData(Length, false);
            VCurve.Add(Curve);
        }

        for (int v = 0; v <= VDivCount; ++v)
        {
            float Rate     = (float)v / (float)VDivCount;
            var   Curve    = new CurveData();
            var   OldPoint = VCurve[0].ComputeLinear(Rate);
            float Length   = 0.0f;
            for (int i = 0; i < VCurve.Count; ++i)
            {
                var NewPoint = VCurve[i].ComputeLinear(Rate);
                Length += (NewPoint - OldPoint).magnitude;
                Curve.Keys.Add(new CurveKey()
                {
                    Length = Length,
                    Value  = NewPoint,
                });
                OldPoint = NewPoint;
            }
            Curve.CreateSpileData(Length, true);
            HCurve.Add(Curve);
        }

        var RootPointList = new List <SPCRJointDynamicsPoint>();
        for (int h = 0; h < HDivCount; ++h)
        {
            float Rate   = (float)h / (float)HDivCount;
            var   parent = Controller._RootTransform;
            for (int i = 0; i < HCurve.Count; ++i)
            {
                var Position = HCurve[i].ComputeSpline(Rate);
                var go       = new GameObject(h.ToString("D3") + "_" + i.ToString("D3"));
                var pt       = go.AddComponent <SPCRJointDynamicsPoint>();
                go.transform.SetParent(parent);
                go.transform.position = Position;
                if (i == 0)
                {
                    RootPointList.Add(pt);
                }
                parent = go.transform;
            }
        }

        for (int i = 0; i < RootTbl.Length; ++i)
        {
            SetTransformScaleZero(RootTbl[i].transform);
        }

        Controller._RootPointTbl = RootPointList.ToArray();
        Controller.UpdateJointConnection();

        GenerateMeshFromBoneConstraints(Controller);
    }
Exemplo n.º 2
0
 private static void UpdateJointConnection(SPCRJointDynamicsController controller)
 {
     controller.UpdateJointConnection();
     SceneView.RepaintAll();
 }