Example #1
0
        /// <summary>
        /// Displays the axis handles.
        /// </summary>
        /// <param name="joint">Joint.</param>
        /// <param name="bindpose">Bindpose.</param>
        /// <returns><see langword="true"/> if the handles changed; otherwise, <see langword="false"/>.</returns>
        public static bool DisplayAxisHandles(Joint joint, Matrix4x4 bindpose)
        {
            bool isChar  = joint is CharacterJoint;
            bool isConf  = joint is ConfigurableJoint;
            bool isHinge = joint is HingeJoint;

            if (!isChar && !isConf && !isHinge)
            {
                return(false);
            }
            bool      result    = false;
            Matrix4x4 oldMatrix = Handles.matrix;

            Handles.matrix = (
                joint.connectedBody == null ? Matrix4x4.identity : joint.connectedBody.transform.localToWorldMatrix
                ) * bindpose;
            Vector3 ax1 = Vector3.forward;
            Vector3 ax2 = Vector3.up;

            if (isChar)
            {
                ax1 = (joint as CharacterJoint).axis;
                ax2 = (joint as CharacterJoint).swingAxis;
            }
            else if (isConf)
            {
                ax1 = (joint as ConfigurableJoint).axis;
                ax2 = (joint as ConfigurableJoint).secondaryAxis;
            }
            else if (isHinge)
            {
                ax1 = (joint as HingeJoint).axis;
            }
            Quaternion axisOrientation = Quaternion.LookRotation(ax1, ax2) * s_BindposeAxisHandleOffset;

            if (SceneGUI.BeginHandles(joint, "Change Axes"))
            {
                axisOrientation = TransformHandles.Rotation(axisOrientation, Vector3.zero);
            }
            if (SceneGUI.EndHandles())
            {
                if (isChar)
                {
                    (joint as CharacterJoint).axis      = axisOrientation * s_PrimaryAxisHandleDirection;
                    (joint as CharacterJoint).swingAxis = axisOrientation * s_SecondaryAxisHandleDirection;
                }
                else if (isConf)
                {
                    (joint as ConfigurableJoint).axis          = axisOrientation * s_PrimaryAxisHandleDirection;
                    (joint as ConfigurableJoint).secondaryAxis = axisOrientation * s_SecondaryAxisHandleDirection;
                }
                else if (isHinge)
                {
                    (joint as HingeJoint).axis = axisOrientation * s_PrimaryAxisHandleDirection;
                }
                result = true;
            }
            Handles.matrix = oldMatrix;
            return(result);
        }
 private void Start()
 {
     instance    = this;
     selected    = new List <Selectable> ();
     myRenderer  = GetComponent <Renderer> ();
     myTransform = transform;
 }
Example #3
0
        /// <summary>
        /// Displays the anchor handles.
        /// </summary>
        /// <returns>
        /// <see langword="true"/>, if anchor handles was displayed, <see langword="false"/> otherwise.
        /// </returns>
        /// <param name="joint">Joint.</param>
        /// <param name="bindpose">Bindpose.</param>
        /// <returns><see langword="true"/> if the handles changed; otherwise, <see langword="false"/>.</returns>
        public static bool DisplayAnchorHandles(Joint joint, Matrix4x4 bindpose)
        {
            Vector3 anchor = joint.anchor;

            if (SceneGUI.BeginHandles(joint, "Change Anchor"))
            {
                Matrix4x4 oldMatrix = Handles.matrix;
                Handles.matrix = Matrix4x4.TRS(joint.transform.position, joint.transform.rotation, Vector3.one);
                anchor         = TransformHandles.Translation(
                    ObjectX.GenerateHashCode(joint.GetHashCode(), s_AnchorHandleHash), anchor, Quaternion.identity, 0.5f
                    );
                Handles.matrix = oldMatrix;
            }
            if (SceneGUI.EndHandles())
            {
                joint.anchor = anchor;
                return(true);
            }
            return(false);
        }