Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Displays the linear limit 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 DisplayLinearLimitHandles(Joint joint, Matrix4x4 bindpose)
 {
     if (joint is ConfigurableJoint)
     {
         ConfigurableJoint thisJoint      = joint as ConfigurableJoint;
         float             newLinearLimit = 0f;
         if (SceneGUI.BeginHandles(thisJoint, "Change Linear Limits"))
         {
             newLinearLimit = JointHandles.LinearLimit(thisJoint, bindpose);
         }
         if (SceneGUI.EndHandles())
         {
             SoftJointLimit limit = thisJoint.linearLimit;
             limit.limit           = newLinearLimit;
             thisJoint.linearLimit = limit;
             return(true);
         }
     }
     else if (joint is SpringJoint)
     {
         SpringJoint thisJoint       = joint as SpringJoint;
         Vector2     newLinearLimits = new Vector2(thisJoint.minDistance, thisJoint.maxDistance);
         if (SceneGUI.BeginHandles(thisJoint, "Change Linear Limits"))
         {
             newLinearLimits = JointHandles.SpringLimit(thisJoint, bindpose);
         }
         if (SceneGUI.EndHandles())
         {
             thisJoint.minDistance = newLinearLimits.x;
             thisJoint.maxDistance = newLinearLimits.y;
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// Displays the scene GUI handles.
        /// </summary>
        protected override void DisplaySceneGUIHandles()
        {
            base.DisplaySceneGUIHandles();
            AnimationCurve newSpeedCurve = null;

            if (
                SceneGUI.BeginHandles(this.Target, "Change Movement Speed Curve") &&
                s_HandleTogglePreference.CurrentValue
                )
            {
                Vector3 up = this.Target.transform.InverseTransformDirection(Vector3.up);
                newSpeedCurve = FalloffHandles.DiscGraph(
                    target.GetHashCode(),
                    this.Target.SpeedCurve,
                    Vector3.zero,
                    Quaternion.LookRotation(Vector3.forward - Vector3.Dot(Vector3.forward, up) * up, up),
                    s_HandleColorPreference.CurrentValue,
                    "Run Speed", "Walk Speed", "Distance", "Speed"
                    );
            }
            if (SceneGUI.EndHandles())
            {
                this.Target.SpeedCurve = newSpeedCurve;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Displays the angular limit 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 DisplayAngularLimitHandles(Joint joint, Matrix4x4 bindpose)
        {
            if (joint == null)
            {
                return(false);
            }
            Matrix4x4 oldMatrix = Handles.matrix;

            Handles.matrix = Matrix4x4.identity;
            bool result = false;

            if (joint is ConfigurableJoint)
            {
                JointAngularLimits newAngularLimits = new JointAngularLimits(joint as ConfigurableJoint);
                if (SceneGUI.BeginHandles(joint, "Change Angular Limits"))
                {
                    newAngularLimits = JointHandles.AngularLimit(
                        joint as ConfigurableJoint, bindpose, AngularLimitHandleSize
                        );
                }
                if (SceneGUI.EndHandles())
                {
                    newAngularLimits.ApplyToJoint(joint as ConfigurableJoint);
                    result = true;
                }
            }
            else if (joint is CharacterJoint)
            {
                JointAngularLimits newAngularLimits = new JointAngularLimits(joint as CharacterJoint);
                if (SceneGUI.BeginHandles(joint, "Change Angular Limits"))
                {
                    newAngularLimits = JointHandles.AngularLimit(
                        joint as CharacterJoint, bindpose, AngularLimitHandleSize
                        );
                }
                if (SceneGUI.EndHandles())
                {
                    newAngularLimits.ApplyToJoint(joint as CharacterJoint);
                    result = true;
                }
            }
            else if (joint is HingeJoint)
            {
                JointLimits newLimits = (joint as HingeJoint).limits;
                if (SceneGUI.BeginHandles(joint, "Change Angular Limits"))
                {
                    newLimits = JointHandles.AngularLimit(
                        joint as HingeJoint, bindpose, AngularLimitHandleSize
                        );
                }
                if (SceneGUI.EndHandles())
                {
                    (joint as HingeJoint).limits = newLimits;
                    result = true;
                }
            }
            Handles.matrix = oldMatrix;
            return(result);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Displays the scene GUI handles.
 /// </summary>
 protected override void DisplaySceneGUIHandles()
 {
     base.DisplaySceneGUIHandles();
     // hearing
     if (s_HearingHandleTogglePreference.CurrentValue)
     {
         AnimationCurve newHearing = null;
         Matrix4x4      oldMatrix  = Handles.matrix;
         Handles.matrix = Matrix4x4.identity;
         if (SceneGUI.BeginHandles(this.Target, "Change Hearing Zone"))
         {
             newHearing = FalloffHandles.SphereGraph(
                 target.GetHashCode(),
                 this.Target.HearingFalloff,
                 this.Target.transform.position,
                 s_HearingHandleColorPreference.CurrentValue,
                 "", "", "Distance", "Hearing Falloff"
                 );
         }
         if (SceneGUI.EndHandles())
         {
             this.Target.HearingFalloff = newHearing;
         }
         Handles.matrix = oldMatrix;
     }
     // vision
     if (s_VisionHandleTogglePreference.CurrentValue)
     {
         float newAngle    = this.Target.VisionAngle;
         float newDistance = this.Target.VisionDistance;
         if (SceneGUI.BeginHandles(this.Target, "Change Vision Zone"))
         {
             Color c = Handles.color;
             Handles.color = s_VisionHandleColorPreference.CurrentValue;
             Vector3 up = this.Target.transform.InverseTransformDirection(Vector3.up);
             newAngle = ArcHandles.SolidWedge(
                 target.GetHashCode(),
                 this.Target.VisionAngle,
                 Vector3.zero,
                 Quaternion.LookRotation(Vector3.forward - Vector3.Dot(Vector3.forward, up) * up, up),
                 ref newDistance,
                 string.Format("{0:#} Degrees", this.Target.VisionAngle),
                 string.Format("Vision Distance: {0:#.###}", this.Target.VisionDistance)
                 );
             Handles.color = c;
         }
         if (SceneGUI.EndHandles())
         {
             this.Target.VisionAngle    = newAngle;
             this.Target.VisionDistance = newDistance;
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Displays the scene GUI handles.
        /// </summary>
        protected override void DisplaySceneGUIHandles()
        {
            base.DisplaySceneGUIHandles();
            HashSet <Object> undoObjects = new HashSet <Object>();

            for (int i = 0; i < this.Target.GetLeaves(ref s_Leaves); ++i)
            {
                undoObjects.Add(s_Leaves[i].BackFace);
                undoObjects.Add(s_Leaves[i].FrontFace);
            }
            undoObjects.Remove(null);
            Helix     newHelix  = null;
            Matrix4x4 oldMatrix = Handles.matrix;

            for (int i = 0; i < s_Leaves.Count; ++i)
            {
                if (s_Leaves[i].FrontFace == null || s_Leaves[i].BackFace == null)
                {
                    continue;
                }
                Handles.matrix = s_Leaves[i].FrontFace.transform.localToWorldMatrix;
                if (
                    SceneGUI.BeginHandles(undoObjects.ToArray(), "Modify Plant Leaf") &&
                    HelixMeshRibbonEditor.IsHandleEnabled
                    )
                {
                    newHelix = HelixHandles.MeshRibbon(
                        s_Leaves[i].FrontFace,
                        Vector3.zero,
                        Quaternion.identity,
                        Vector3.one,
                        HelixMeshRibbonEditor.HandleColor
                        );
                }
                if (SceneGUI.EndHandles())
                {
                    s_Leaves[i].FrontFace.Helix = newHelix;
                    s_Leaves[i].BackFace.Helix  = newHelix;
                }
            }
            Handles.matrix = oldMatrix;
        }
Ejemplo n.º 7
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);
        }
        /// <summary>
        /// Displays the scene GUI handles.
        /// </summary>
        protected override void DisplaySceneGUIHandles()
        {
            base.DisplaySceneGUIHandles();
            Helix newHelix = null;

            if (SceneGUI.BeginHandles(target, "Change Helix Mesh Ribbon") && s_HandleTogglePreference.CurrentValue)
            {
                newHelix = HelixHandles.MeshRibbon(
                    this.Target,
                    Vector3.zero,
                    Quaternion.identity,
                    Vector3.one,
                    s_HandleColorPreference.CurrentValue
                    );
            }
            if (SceneGUI.EndHandles())
            {
                this.Target.Helix = newHelix;
            }
        }
        /// <summary>
        /// Displays the viewport handle.
        /// </summary>
        protected override void DisplaySceneGUIHandles()
        {
            base.DisplaySceneGUIHandles();
            Helix newHelix = null;

            if (
                SceneGUI.BeginHandles(this.Target, "Change Helix Particle Emitter") &&
                s_HandleTogglePreference.CurrentValue
                )
            {
                newHelix = HelixHandles.WireHelix(
                    target.GetHashCode(),
                    this.Target.Helix,
                    Vector3.zero,
                    Quaternion.identity,
                    Vector3.one,
                    s_HandleColorPreference.CurrentValue
                    );
            }
            if (SceneGUI.EndHandles())
            {
                this.Target.Helix = newHelix;
            }
        }