private static void DrawSideArc(PlatformEffector2D effector)
        {
            // Calculate the surface angle in local-space.
            var rotation  = -Mathf.Deg2Rad * (90.0f + effector.rotationalOffset);
            var localSide = effector.transform.TransformVector(new Vector3(Mathf.Sin(rotation), Mathf.Cos(rotation), 0.0f)).normalized;

            // If the transform has created a degenerate local then we cannot draw the gizmo!
            if (localSide.sqrMagnitude < Mathf.Epsilon)
            {
                return;
            }

            // Calculate the side angles.
            var sideAngleLeft  = Mathf.Atan2(localSide.x, localSide.y);
            var sideAngleRight = sideAngleLeft + Mathf.PI;

            // Fetch the side arc.
            var sideArc            = Mathf.Clamp(effector.sideArc, 0.5f, 180.0f);
            var halfSideArcRadians = sideArc * 0.5f * Mathf.Deg2Rad;

            var fromAngleLeft  = new Vector3(Mathf.Sin(sideAngleLeft - halfSideArcRadians), Mathf.Cos(sideAngleLeft - halfSideArcRadians), 0.0f);
            var toAngleLeft    = new Vector3(Mathf.Sin(sideAngleLeft + halfSideArcRadians), Mathf.Cos(sideAngleLeft + halfSideArcRadians), 0.0f);
            var fromAngleRight = new Vector3(Mathf.Sin(sideAngleRight - halfSideArcRadians), Mathf.Cos(sideAngleRight - halfSideArcRadians), 0.0f);
            var toAngleRight   = new Vector3(Mathf.Sin(sideAngleRight + halfSideArcRadians), Mathf.Cos(sideAngleRight + halfSideArcRadians), 0.0f);

            // Fetch all the effector-collider bounds.
            foreach (var collider in effector.gameObject.GetComponents <Collider2D>().Where(collider => collider.enabled && collider.usedByEffector))
            {
                var center    = collider.bounds.center;
                var arcRadius = HandleUtility.GetHandleSize(center) * 0.8f;

                // arc background
                Handles.color = new Color(0, 1, 0.7f, 0.07f);
                Handles.DrawSolidArc(center, Vector3.back, fromAngleLeft, sideArc, arcRadius);
                Handles.DrawSolidArc(center, Vector3.back, fromAngleRight, sideArc, arcRadius);

                // arc frame
                Handles.color = new Color(0, 1, 0.7f, 0.7f);
                Handles.DrawWireArc(center, Vector3.back, fromAngleLeft, sideArc, arcRadius);
                Handles.DrawWireArc(center, Vector3.back, fromAngleRight, sideArc, arcRadius);
                Handles.DrawDottedLine(center, center + fromAngleLeft * arcRadius, 5.0f);
                Handles.DrawDottedLine(center, center + toAngleLeft * arcRadius, 5.0f);
                Handles.DrawDottedLine(center, center + fromAngleRight * arcRadius, 5.0f);
                Handles.DrawDottedLine(center, center + toAngleRight * arcRadius, 5.0f);
            }
        }
Ejemplo n.º 2
0
        private void ShowAngularLimitSpan(bool freeMotion, ArticulationBody body, ArticulationBody parentBody, Color color, Vector3 axis, Matrix4x4 space, ArticulationDrive drive, Vector3 zeroDirection)
        {
            // check if it's a free span - show only a solid disc in this case
            if (freeMotion)
            {
                using (new Handles.DrawingScope(space))
                {
                    color.a       = 0.3f;
                    Handles.color = color;
                    Handles.DrawSolidDisc(Vector3.zero, axis, GizmoLinearSize);
                }

                return;
            }

            // here we know the angle is limited - show a span
            float totalAngle = drive.upperLimit - drive.lowerLimit;

            Quaternion zeroPose = Quaternion.FromToRotation(Vector3.forward, Vector3.Cross(axis, zeroDirection));

            Quaternion lowerRotation = Quaternion.AngleAxis(drive.lowerLimit, axis);
            Quaternion upperRotation = Quaternion.AngleAxis(drive.upperLimit, axis);

            Vector3 from = lowerRotation * zeroDirection;
            Vector3 to   = upperRotation * zeroDirection;

            // Nb: Cylinder cap is oriented along Z
            using (new Handles.DrawingScope(space))
            {
                color.a       = 0.3f;
                Handles.color = color;
                Handles.DrawSolidArc(Vector3.zero, axis, from, totalAngle, GizmoLinearSize);

                Handles.color = Color.red;
                Handles.CylinderHandleCap(0, from * GizmoLinearSize, lowerRotation * zeroPose, CapScale, EventType.Repaint);

                Handles.color = Color.green;
                Handles.CylinderHandleCap(0, to * GizmoLinearSize, upperRotation * zeroPose, CapScale, EventType.Repaint);
            }
        }
        private static void DrawSurfaceArc(PlatformEffector2D effector)
        {
            float num  = 0.0174532924f * (effector.surfaceArc * 0.5f + effector.transform.eulerAngles.z);
            float num2 = Mathf.Clamp(effector.surfaceArc, 0.5f, 360f);
            float num3 = num2 * 0.0174532924f;

            foreach (Collider2D current in from collider in effector.gameObject.GetComponents <Collider2D>()
                     where collider.enabled && collider.usedByEffector
                     select collider)
            {
                Vector3 center     = current.bounds.center;
                float   handleSize = HandleUtility.GetHandleSize(center);
                Vector3 vector     = new Vector3(-Mathf.Sin(num), Mathf.Cos(num), 0f);
                Vector3 a          = new Vector3(-Mathf.Sin(num - num3), Mathf.Cos(num - num3), 0f);
                Handles.color = new Color(0f, 1f, 1f, 0.03f);
                Handles.DrawSolidArc(center, Vector3.back, vector, num2, handleSize);
                Handles.color = new Color(0f, 1f, 1f, 0.7f);
                Handles.DrawWireArc(center, Vector3.back, vector, num2, handleSize);
                Handles.DrawDottedLine(center, center + vector * handleSize, 5f);
                Handles.DrawDottedLine(center, center + a * handleSize, 5f);
            }
        }
Ejemplo n.º 4
0
        public void DrawMuscleHandle(Transform t, int humanId)
        {
            Vector3    vector2;
            Animator   component    = base.gameObject.GetComponent(typeof(Animator)) as Animator;
            Avatar     avatar       = component.avatar;
            int        index        = HumanTrait.MuscleFromBone(humanId, 0);
            int        num2         = HumanTrait.MuscleFromBone(humanId, 1);
            int        num3         = HumanTrait.MuscleFromBone(humanId, 2);
            float      axisLength   = avatar.GetAxisLength(humanId);
            Quaternion preRotation  = avatar.GetPreRotation(humanId);
            Quaternion postRotation = avatar.GetPostRotation(humanId);

            preRotation  = t.parent.rotation * preRotation;
            postRotation = t.rotation * postRotation;
            Color      color     = new Color(1f, 1f, 1f, 0.5f);
            Quaternion zYRoll    = avatar.GetZYRoll(humanId, Vector3.zero);
            Vector3    limitSign = avatar.GetLimitSign(humanId);
            Vector3    axis      = (Vector3)(postRotation * Vector3.right);
            Vector3    vector4   = t.position + ((Vector3)(axis * axisLength));

            Handles.color = Color.white;
            Handles.DrawLine(t.position, vector4);
            if (index != -1)
            {
                Quaternion quaternion4 = avatar.GetZYPostQ(humanId, t.parent.rotation, t.rotation);
                float      angle       = this.m_MuscleMinEdit[index];
                float      num6        = this.m_MuscleMaxEdit[index];
                axis          = (Vector3)(postRotation * Vector3.right);
                vector2       = (Vector3)(quaternion4 * Vector3.forward);
                Handles.color = Color.black;
                Vector3 center = t.position + ((Vector3)((axis * axisLength) * 0.75f));
                axis          = (Vector3)((postRotation * Vector3.right) * limitSign.x);
                vector2       = (Vector3)(Quaternion.AngleAxis(angle, axis) * vector2);
                Handles.color = Color.yellow;
                Handles.color = Handles.xAxisColor * color;
                Handles.DrawSolidArc(center, axis, vector2, num6 - angle, axisLength * 0.25f);
                vector2       = (Vector3)(postRotation * Vector3.forward);
                Handles.color = Handles.centerColor;
                Handles.DrawLine(center, center + ((Vector3)((vector2 * axisLength) * 0.25f)));
            }
            if (num2 != -1)
            {
                float num7 = this.m_MuscleMinEdit[num2];
                float num8 = this.m_MuscleMaxEdit[num2];
                axis          = (Vector3)((preRotation * Vector3.up) * limitSign.y);
                vector2       = (Vector3)((preRotation * zYRoll) * Vector3.right);
                Handles.color = Color.black;
                vector2       = (Vector3)(Quaternion.AngleAxis(num7, axis) * vector2);
                Handles.color = Color.yellow;
                Handles.color = Handles.yAxisColor * color;
                Handles.DrawSolidArc(t.position, axis, vector2, num8 - num7, axisLength * 0.25f);
            }
            if (num3 != -1)
            {
                float num9  = this.m_MuscleMinEdit[num3];
                float num10 = this.m_MuscleMaxEdit[num3];
                axis          = (Vector3)((preRotation * Vector3.forward) * limitSign.z);
                vector2       = (Vector3)((preRotation * zYRoll) * Vector3.right);
                Handles.color = Color.black;
                vector2       = (Vector3)(Quaternion.AngleAxis(num9, axis) * vector2);
                Handles.color = Color.yellow;
                Handles.color = Handles.zAxisColor * color;
                Handles.DrawSolidArc(t.position, axis, vector2, num10 - num9, axisLength * 0.25f);
            }
        }
Ejemplo n.º 5
0
        public void DrawMuscleHandle(Transform t, int humanId)
        {
            Avatar     avatar       = (this.gameObject.GetComponent(typeof(Animator)) as Animator).avatar;
            int        index1       = HumanTrait.MuscleFromBone(humanId, 0);
            int        index2       = HumanTrait.MuscleFromBone(humanId, 1);
            int        index3       = HumanTrait.MuscleFromBone(humanId, 2);
            float      axisLength   = avatar.GetAxisLength(humanId);
            Quaternion preRotation  = avatar.GetPreRotation(humanId);
            Quaternion postRotation = avatar.GetPostRotation(humanId);
            Quaternion quaternion1  = t.parent.rotation * preRotation;
            Quaternion quaternion2  = t.rotation * postRotation;
            Color      color        = new Color(1f, 1f, 1f, 0.5f);
            Quaternion zyRoll       = avatar.GetZYRoll(humanId, Vector3.zero);
            Vector3    limitSign    = avatar.GetLimitSign(humanId);
            Vector3    vector3_1    = quaternion2 * Vector3.right;
            Vector3    p2           = t.position + vector3_1 * axisLength;

            Handles.color = Color.white;
            Handles.DrawLine(t.position, p2);
            if (index1 != -1)
            {
                Quaternion zyPostQ   = avatar.GetZYPostQ(humanId, t.parent.rotation, t.rotation);
                float      angle     = this.m_MuscleMinEdit[index1];
                float      num       = this.m_MuscleMaxEdit[index1];
                Vector3    vector3_2 = quaternion2 * Vector3.right;
                Vector3    vector3_3 = zyPostQ * Vector3.forward;
                Handles.color = Color.black;
                Vector3 vector3_4 = t.position + vector3_2 * axisLength * 0.75f;
                Vector3 vector3_5 = quaternion2 * Vector3.right * limitSign.x;
                Vector3 from      = Quaternion.AngleAxis(angle, vector3_5) * vector3_3;
                Handles.color = Color.yellow;
                Handles.color = Handles.xAxisColor * color;
                Handles.DrawSolidArc(vector3_4, vector3_5, from, num - angle, axisLength * 0.25f);
                Vector3 vector3_6 = quaternion2 * Vector3.forward;
                Handles.color = Handles.centerColor;
                Handles.DrawLine(vector3_4, vector3_4 + vector3_6 * axisLength * 0.25f);
            }
            if (index2 != -1)
            {
                float   angle     = this.m_MuscleMinEdit[index2];
                float   num       = this.m_MuscleMaxEdit[index2];
                Vector3 vector3_2 = quaternion1 * Vector3.up * limitSign.y;
                Vector3 vector3_3 = quaternion1 * zyRoll * Vector3.right;
                Handles.color = Color.black;
                Vector3 from = Quaternion.AngleAxis(angle, vector3_2) * vector3_3;
                Handles.color = Color.yellow;
                Handles.color = Handles.yAxisColor * color;
                Handles.DrawSolidArc(t.position, vector3_2, from, num - angle, axisLength * 0.25f);
            }
            if (index3 == -1)
            {
                return;
            }
            float   angle1    = this.m_MuscleMinEdit[index3];
            float   num1      = this.m_MuscleMaxEdit[index3];
            Vector3 vector3_7 = quaternion1 * Vector3.forward * limitSign.z;
            Vector3 vector3_8 = quaternion1 * zyRoll * Vector3.right;

            Handles.color = Color.black;
            Vector3 from1 = Quaternion.AngleAxis(angle1, vector3_7) * vector3_8;

            Handles.color = Color.yellow;
            Handles.color = Handles.zAxisColor * color;
            Handles.DrawSolidArc(t.position, vector3_7, from1, num1 - angle1, axisLength * 0.25f);
        }
Ejemplo n.º 6
0
        public void DrawMuscleHandle(Transform t, int humanId)
        {
            Animator   animator    = base.gameObject.GetComponent(typeof(Animator)) as Animator;
            Avatar     avatar      = animator.avatar;
            int        num         = HumanTrait.MuscleFromBone(humanId, 0);
            int        num2        = HumanTrait.MuscleFromBone(humanId, 1);
            int        num3        = HumanTrait.MuscleFromBone(humanId, 2);
            float      axisLength  = avatar.GetAxisLength(humanId);
            Quaternion quaternion  = avatar.GetPreRotation(humanId);
            Quaternion quaternion2 = avatar.GetPostRotation(humanId);

            quaternion  = t.parent.rotation * quaternion;
            quaternion2 = t.rotation * quaternion2;
            Color      b         = new Color(1f, 1f, 1f, 0.5f);
            Quaternion zYRoll    = avatar.GetZYRoll(humanId, Vector3.zero);
            Vector3    limitSign = avatar.GetLimitSign(humanId);
            Vector3    vector    = quaternion2 * Vector3.right;
            Vector3    p         = t.position + vector * axisLength;

            Handles.color = Color.white;
            Handles.DrawLine(t.position, p);
            if (num != -1)
            {
                Quaternion zYPostQ = avatar.GetZYPostQ(humanId, t.parent.rotation, t.rotation);
                float      num4    = this.m_MuscleMinEdit[num];
                float      num5    = this.m_MuscleMaxEdit[num];
                vector = quaternion2 * Vector3.right;
                Vector3 vector2 = zYPostQ * Vector3.forward;
                Handles.color = Color.black;
                Vector3 vector3 = t.position + vector * axisLength * 0.75f;
                vector = quaternion2 * Vector3.right * limitSign.x;
                Quaternion rotation = Quaternion.AngleAxis(num4, vector);
                vector2       = rotation * vector2;
                Handles.color = Color.yellow;
                Handles.color = Handles.xAxisColor * b;
                Handles.DrawSolidArc(vector3, vector, vector2, num5 - num4, axisLength * 0.25f);
                vector2       = quaternion2 * Vector3.forward;
                Handles.color = Handles.centerColor;
                Handles.DrawLine(vector3, vector3 + vector2 * axisLength * 0.25f);
            }
            if (num2 != -1)
            {
                float num6 = this.m_MuscleMinEdit[num2];
                float num7 = this.m_MuscleMaxEdit[num2];
                vector = quaternion * Vector3.up * limitSign.y;
                Vector3 vector2 = quaternion * zYRoll * Vector3.right;
                Handles.color = Color.black;
                Quaternion rotation2 = Quaternion.AngleAxis(num6, vector);
                vector2       = rotation2 * vector2;
                Handles.color = Color.yellow;
                Handles.color = Handles.yAxisColor * b;
                Handles.DrawSolidArc(t.position, vector, vector2, num7 - num6, axisLength * 0.25f);
            }
            if (num3 != -1)
            {
                float num8 = this.m_MuscleMinEdit[num3];
                float num9 = this.m_MuscleMaxEdit[num3];
                vector = quaternion * Vector3.forward * limitSign.z;
                Vector3 vector2 = quaternion * zYRoll * Vector3.right;
                Handles.color = Color.black;
                Quaternion rotation3 = Quaternion.AngleAxis(num8, vector);
                vector2       = rotation3 * vector2;
                Handles.color = Color.yellow;
                Handles.color = Handles.zAxisColor * b;
                Handles.DrawSolidArc(t.position, vector, vector2, num9 - num8, axisLength * 0.25f);
            }
        }
Ejemplo n.º 7
0
        public void DrawMuscleHandle(Transform t, int humanId)
        {
            Animator animator = gameObject.GetComponent(typeof(Animator)) as Animator;
            Avatar   avatar   = animator.avatar;

            int mx = HumanTrait.MuscleFromBone(humanId, 0);
            int my = HumanTrait.MuscleFromBone(humanId, 1);
            int mz = HumanTrait.MuscleFromBone(humanId, 2);

            float      axisLen = avatar.GetAxisLength(humanId);
            Quaternion preQ    = avatar.GetPreRotation(humanId);
            Quaternion postQ   = avatar.GetPostRotation(humanId);

            preQ  = t.parent.rotation * preQ;
            postQ = t.rotation * postQ;

            Vector3 normal;
            Vector3 from;

            Color      alpha  = new Color(1, 1, 1, 0.5f);
            Quaternion zyRoll = avatar.GetZYRoll(humanId, Vector3.zero);
            Vector3    sign   = avatar.GetLimitSign(humanId);

            // Draw axis
            normal = postQ * Vector3.right;
            Vector3 axisEnd = t.position + (normal * axisLen);

            Handles.color = Color.white;
            Handles.DrawLine(t.position, axisEnd);

            if (mx != -1)
            {
                Quaternion zyPostQ = avatar.GetZYPostQ(humanId, t.parent.rotation, t.rotation);

                float minx = m_MuscleMinEdit[mx];
                float maxx = m_MuscleMaxEdit[mx];

                normal = postQ * Vector3.right;
                from   = zyPostQ * Vector3.forward;

                Handles.color = Color.black;
                //Handles.DrawLine (t.position, t.position + (from * axisLen * 0.75f));

                Vector3 xDoF = t.position + (normal * axisLen * 0.75f);

                normal = postQ * Vector3.right * sign.x;
                Quaternion q = Quaternion.AngleAxis(minx, normal);
                from = q * from;

                Handles.color = Color.yellow;
                //Handles.DrawLine (t.position, t.position + (from * axisLen * 0.75f));

                // Draw Muscle range
                Handles.color = Handles.xAxisColor * alpha;
                Handles.DrawSolidArc(xDoF, normal, from, maxx - minx, axisLen * 0.25f);

                from          = postQ * Vector3.forward;
                Handles.color = Handles.centerColor;
                Handles.DrawLine(xDoF, xDoF + (from * axisLen * 0.25f));
            }

            if (my != -1)
            {
                float miny = m_MuscleMinEdit[my];
                float maxy = m_MuscleMaxEdit[my];

                normal = preQ * Vector3.up * sign.y;
                from   = preQ * zyRoll * Vector3.right;

                Handles.color = Color.black;
                //Handles.DrawLine (t.position, t.position + (from * axisLen * 0.75f));

                Quaternion q = Quaternion.AngleAxis(miny, normal);
                from = q * from;

                Handles.color = Color.yellow;
                //Handles.DrawLine (t.position, t.position + (from * axisLen * 0.75f));

                // Draw Muscle range
                Handles.color = Handles.yAxisColor * alpha;
                Handles.DrawSolidArc(t.position, normal, from, maxy - miny, axisLen * 0.25f);
            }
            if (mz != -1)
            {
                float minz = m_MuscleMinEdit[mz];
                float maxz = m_MuscleMaxEdit[mz];

                normal = preQ * Vector3.forward * sign.z;
                from   = preQ * zyRoll * Vector3.right;

                Handles.color = Color.black;
                //Handles.DrawLine (t.position, t.position + (from * axisLen * 0.75f));

                Quaternion q = Quaternion.AngleAxis(minz, normal);
                from = q * from;

                Handles.color = Color.yellow;
                //Handles.DrawLine (t.position, t.position + (from * axisLen * 0.75f));

                // Draw Muscle range
                Handles.color = Handles.zAxisColor * alpha;
                Handles.DrawSolidArc(t.position, normal, from, maxz - minz, axisLen * 0.25f);
            }
        }