Exemple #1
0
 private void AddHoveredGoal(RigGoalController controller)
 {
     hoveredGoals.Add(controller);
     if (hoveredGoals.Count == 1 && controller.gameObject.layer == 21)
     {
         controller.gameObject.layer = 22;
     }
 }
Exemple #2
0
        private void AddHumanCurve(GameObject gObject, RigController controller)
        {
            RigGoalController goalController = controller.RootObject.GetComponent <RigGoalController>();

            RigGoalController[] controllers = goalController.GetComponentsInChildren <RigGoalController>();
            foreach (RigGoalController ctrl in controllers)
            {
                AddGoalCurve(ctrl, controller);
            }
        }
 private void AddSegmentHierarchy(RigGoalController controller, int frame)
 {
     for (int i = 0; i < controller.AnimToRoot.Count; i++)
     {
         AnimationSet anim = controller.AnimToRoot[i];
         if (null != anim)
         {
             AddSegmentKeyframes(frame, anim);
         }
     }
 }
Exemple #4
0
 public void SelectGoal(RigGoalController controller)
 {
     if (selectedGoal != null)
     {
         UnSelectGoal(selectedGoal);
     }
     goalGizmo.gameObject.SetActive(true);
     selectedGoal = controller;
     controller.gameObject.layer = 20;
     goalGizmo.Init(controller);
 }
Exemple #5
0
 private void RemoveHoverGoal(RigGoalController controller)
 {
     if (controller.gameObject.layer == 22)
     {
         controller.gameObject.layer = 21;
     }
     hoveredGoals.Remove(controller);
     if (hoveredGoals.Count > 0 && hoveredGoals[0].gameObject.layer == 21)
     {
         hoveredGoals[0].gameObject.layer = 22;
     }
 }
        public void GenerateGoalController(RigController rootController, Transform transform, List <Transform> path)
        {
            string boneName = transform.name;

            if (boneName.Contains("mixamorig:"))
            {
                boneName = boneName.Split(':')[1];
            }
            Joint joint = JointsList.Find(x => x.Name == boneName);

            if (null != joint)
            {
                SphereCollider collider = transform.gameObject.AddComponent <SphereCollider>();
                collider.isTrigger = true;
                RigGoalController controller = transform.gameObject.AddComponent <RigGoalController>();
                controller.SetPathToRoot(rootController, path);
                controller.IsGoal          = joint.isGoal;
                controller.stiffness       = joint.stiffness;
                controller.ShowCurve       = joint.showCurve;
                controller.LowerAngleBound = joint.LowerAngleBound;
                controller.UpperAngleBound = joint.UpperAngleBound;

                if (joint.isGoal)
                {
                    controller.gameObject.layer = 21;
                    controller.goalCollider     = collider;
                    controller.tag = "Goal";
                    if (!transform.TryGetComponent <MeshFilter>(out MeshFilter filter))
                    {
                        filter = transform.gameObject.AddComponent <MeshFilter>();
                    }
                    filter.mesh = mesh;
                    if (!transform.TryGetComponent(out MeshRenderer renderer))
                    {
                        renderer = transform.gameObject.AddComponent <MeshRenderer>();
                    }
                    renderer.material       = new Material(material);
                    controller.MeshRenderer = renderer;

                    controller.UseGoal(false);
                }
            }
            path.Add(transform);
            foreach (Transform child in transform)
            {
                GenerateGoalController(rootController, child, new List <Transform>(path));
            }
        }
Exemple #7
0
        public void Init(RigGoalController controller)
        {
            Controller = controller;

            Matrix4x4 targetMatrix = controller.transform.localToWorldMatrix;

            Maths.DecomposeMatrix(targetMatrix, out Vector3 pos, out Quaternion rot, out Vector3 scale);
            transform.position   = pos;
            transform.rotation   = rot;
            transform.localScale = scale;

            if (!isListening)
            {
                GlobalState.ObjectMovingEvent.AddListener(ResetPosition);
                GlobalState.Animation.onFrameEvent.AddListener(ResetPosition);
                isListening = true;
            }
        }
Exemple #8
0
 void UpdateFromSelection()
 {
     ClearCurves();
     foreach (GameObject gObject in Selection.SelectedObjects)
     {
         AddCurve(gObject);
         if (gObject.TryGetComponent(out RigController skinController))
         {
             if ((ToolsManager.CurrentToolName() == "Animation"))
             {
                 AddHumanCurve(gObject, skinController);
             }
             else
             {
                 //Only display curve for Rig's root
                 RigGoalController goalController = skinController.RootObject.GetComponent <RigGoalController>();
                 AddGoalCurve(goalController, skinController);
             }
         }
     }
 }
        /// <summary>
        /// Initialize Curve manipulation for Rigs
        /// </summary>
        public CurveManipulation(GameObject target, RigGoalController controller, int frame, Transform mouthpiece, AnimationTool.CurveEditMode manipMode, int zoneSize, double tangentContinuity)
        {
            isHuman            = true;
            manipulationMode   = manipMode;
            initialMouthMatrix = mouthpiece.worldToLocalMatrix;
            Frame      = frame;
            Target     = target;
            continuity = tangentContinuity;

            List <AnimationSet> previousSets = new List <AnimationSet>();

            controller.AnimToRoot.ForEach(x =>
            {
                if (null != x)
                {
                    previousSets.Add(new AnimationSet(x));
                }
            });
            humanData = new HumanData()
            {
                Animations      = previousSets,
                Controller      = controller,
                ObjectAnimation = new AnimationSet(controller.Animation),
                InitFrameMatrix = controller.MatrixAtFrame(frame)
            };
            if (manipulationMode == AnimationTool.CurveEditMode.Segment)
            {
                startFrame = frame - zoneSize;
                endFrame   = frame + zoneSize;
                AddSegmentHierarchy(controller, frame);
                AddSegmentKeyframes(frame, controller.Animation);
            }
            if (manipulationMode == AnimationTool.CurveEditMode.Tangents)
            {
                startFrame = humanData.ObjectAnimation.GetCurve(AnimatableProperty.RotationX).GetPreviousKeyFrame(frame);
                endFrame   = humanData.ObjectAnimation.GetCurve(AnimatableProperty.RotationX).GetNextKeyFrame(frame);
            }
        }
Exemple #10
0
        private void AddGoalCurve(RigGoalController goalController, RigController skinController)
        {
            if (!goalController.ShowCurve)
            {
                return;
            }

            AnimationSet goalAnimation = GlobalState.Animation.GetObjectAnimation(goalController.gameObject);

            if (null == goalAnimation)
            {
                return;
            }

            Curve rotationX = goalAnimation.GetCurve(AnimatableProperty.RotationX);

            if (rotationX.keys.Count == 0)
            {
                return;
            }

            int frameStart = Mathf.Clamp(rotationX.keys[0].frame, GlobalState.Animation.StartFrame, GlobalState.Animation.EndFrame);
            int frameEnd   = Mathf.Clamp(rotationX.keys[rotationX.keys.Count - 1].frame, GlobalState.Animation.StartFrame, GlobalState.Animation.EndFrame);

            List <Vector3> positions = new List <Vector3>();
            GameObject     curve3D   = curves.TryGetValue(goalController.gameObject, out GameObject current) ? current : Instantiate(curvePrefab, curvesParent);

            Vector3 forwardOffset = (skinController.transform.forward * skinController.transform.localScale.x) * currentCurveOffset;

            goalController.CheckAnimations();
            for (int i = frameStart; i <= frameEnd; i++)
            {
                Vector3 position = curve3D.transform.InverseTransformDirection(goalController.FramePosition(i) - (forwardOffset * i));
                positions.Add(position);
            }
            LineRenderer line = curve3D.GetComponent <LineRenderer>();

            line.positionCount = positions.Count;
            line.SetPositions(positions.ToArray());

            line.startWidth = lineWidth / GlobalState.WorldScale;
            line.endWidth   = line.startWidth;

            curve3D.transform.position = forwardOffset * GlobalState.Animation.CurrentFrame;

            MeshCollider collider = curve3D.GetComponent <MeshCollider>();
            Mesh         lineMesh = new Mesh();

            line.BakeMesh(lineMesh);
            collider.sharedMesh = lineMesh;
            curves[goalController.gameObject] = curve3D;
            if (goalCurves.ContainsKey(skinController))
            {
                goalCurves[skinController].Add(curve3D);
            }
            else
            {
                goalCurves[skinController] = new List <GameObject>();
                goalCurves[skinController].Add(curve3D);
            }
        }
Exemple #11
0
 private void UnSelectGoal(RigGoalController controller)
 {
     goalGizmo.gameObject.SetActive(false);
     controller.gameObject.layer = 21;
     selectedGoal = null;
 }
Exemple #12
0
 public void StartPose(RigGoalController controller, Transform mouthpiece)
 {
     poseManip = new PoseManipulation(controller.transform, controller.PathToRoot, mouthpiece, controller.RootController, PoseMode);
 }