public void OnSceneGUI()
        {
            var tbf = target as BoneFollowerGraphic;
            var skeletonGraphicComponent = tbf.SkeletonGraphic;

            if (skeletonGraphicComponent == null)
            {
                return;
            }

            var   transform     = skeletonGraphicComponent.transform;
            var   skeleton      = skeletonGraphicComponent.Skeleton;
            var   canvas        = skeletonGraphicComponent.canvas;
            float positionScale = canvas == null ? 1f : skeletonGraphicComponent.canvas.referencePixelsPerUnit;

            if (string.IsNullOrEmpty(boneName.stringValue))
            {
                SpineHandles.DrawBones(transform, skeleton, positionScale);
                SpineHandles.DrawBoneNames(transform, skeleton, positionScale);
                Handles.Label(tbf.transform.position, "No bone selected", EditorStyles.helpBox);
            }
            else
            {
                var targetBone = tbf.bone;
                if (targetBone == null)
                {
                    return;
                }

                SpineHandles.DrawBoneWireframe(transform, targetBone, SpineHandles.TransformContraintColor, positionScale);
                Handles.Label(targetBone.GetWorldPosition(transform, positionScale), targetBone.Data.Name, SpineHandles.BoneNameStyle);
            }
        }
Exemple #2
0
        void OnSceneGUI(SceneView sceneView)
        {
            if (skeleton == null || skeletonRenderer == null || !skeletonRenderer.valid || isPrefab)
            {
                return;
            }

            var transform = skeletonRenderer.transform;

            if (showPaths)
            {
                SpineHandles.DrawPaths(transform, skeleton);
            }
            if (showConstraints)
            {
                SpineHandles.DrawConstraints(transform, skeleton);
            }
            if (showBoneNames)
            {
                SpineHandles.DrawBoneNames(transform, skeleton);
            }
            if (showShapes)
            {
                SpineHandles.DrawBoundingBoxes(transform, skeleton);
            }

            if (bone != null)
            {
                SpineHandles.DrawBone(skeletonRenderer.transform, bone, 1.5f, Color.cyan);
                Handles.Label(bone.GetWorldPosition(skeletonRenderer.transform) + (Vector3.down * 0.15f), bone.Data.Name, SpineHandles.BoneNameStyle);
            }
        }
        public void OnSceneGUI()
        {
            var skeletonRenderer = (SkeletonRenderer)target;
            var skeleton         = skeletonRenderer.skeleton;
            var transform        = skeletonRenderer.transform;

            if (skeleton == null)
            {
                return;
            }

            if (showPaths)
            {
                SpineHandles.DrawPaths(transform, skeleton);
            }
            SpineHandles.DrawBones(transform, skeleton);
            if (showConstraints)
            {
                SpineHandles.DrawConstraints(transform, skeleton);
            }
            if (showBoneNames)
            {
                SpineHandles.DrawBoneNames(transform, skeleton);
            }
            if (showShapes)
            {
                SpineHandles.DrawBoundingBoxes(transform, skeleton);
            }
        }
        static void DrawPointAttachmentWithLabel(PointAttachment point, Bone bone, Transform transform)
        {
            Vector3 labelOffset = new Vector3(0f, -0.2f, 0f);

            SpineHandles.DrawPointAttachment(bone, point, transform);
            Handles.Label(labelOffset + point.GetWorldPosition(bone, transform), point.Name, SpineHandles.PointNameStyle);
        }
        public void OnSceneGUI()
        {
            var tbf = target as BoneFollower;
            var skeletonRendererComponent = tbf.skeletonRenderer;

            if (skeletonRendererComponent == null)
            {
                return;
            }

            var transform = skeletonRendererComponent.transform;
            var skeleton  = skeletonRendererComponent.skeleton;

            if (string.IsNullOrEmpty(tbf.boneName))
            {
                SpineHandles.DrawBones(transform, skeleton);
                SpineHandles.DrawBoneNames(transform, skeleton);
                Handles.Label(tbf.transform.position, "No bone selected", EditorStyles.helpBox);
            }
            else
            {
                var targetBone = tbf.bone;
                if (targetBone == null)
                {
                    return;
                }
                SpineHandles.DrawBoneWireframe(transform, targetBone, SpineHandles.TransformContraintColor);
                Handles.Label(targetBone.GetWorldPosition(transform), targetBone.Data.Name, SpineHandles.BoneNameStyle);
            }
        }
Exemple #6
0
        public void OnSceneGUI()
        {
            var skeletonRenderer = (SkeletonRenderer)target;

            if (loadingFailed)
            {
                return;
            }

            var skeleton = skeletonRenderer.Skeleton;

            if (skeleton == null)
            {
                loadingFailed = true;
                return;
            }
            var transform = skeletonRenderer.transform;

            if (skeleton == null)
            {
                return;
            }

            SpineHandles.DrawBones(transform, skeleton);
        }
Exemple #7
0
 public static void DrawBoundingBoxes(Transform transform, Skeleton skeleton)
 {
     foreach (var slot in skeleton.Slots)
     {
         var bba = slot.Attachment as BoundingBoxAttachment;
         if (bba != null)
         {
             SpineHandles.DrawBoundingBox(slot, bba, transform);
         }
     }
 }
Exemple #8
0
 public static void DrawPaths(Transform transform, Skeleton skeleton)
 {
     foreach (Slot s in skeleton.DrawOrder)
     {
         var p = s.Attachment as PathAttachment;
         if (p != null)
         {
             SpineHandles.DrawPath(s, p, transform, true);
         }
     }
 }
Exemple #9
0
        public static void DrawPath(Slot s, PathAttachment p, Transform t, bool includeName)
        {
            int worldVerticesLength = p.WorldVerticesLength;

            if (pathVertexBuffer == null || pathVertexBuffer.Length < worldVerticesLength)
            {
                pathVertexBuffer = new float[worldVerticesLength];
            }

            float[] pv = pathVertexBuffer;
            p.ComputeWorldVertices(s, pv);

            var ocolor = Handles.color;

            Handles.color = SpineHandles.PathColor;

            Matrix4x4 m = t.localToWorldMatrix;
            const int step = 6;
            int       n = worldVerticesLength - step;
            Vector3   p0, p1, p2, p3;

            for (int i = 2; i < n; i += step)
            {
                p0 = m.MultiplyPoint(new Vector3(pv[i], pv[i + 1]));
                p1 = m.MultiplyPoint(new Vector3(pv[i + 2], pv[i + 3]));
                p2 = m.MultiplyPoint(new Vector3(pv[i + 4], pv[i + 5]));
                p3 = m.MultiplyPoint(new Vector3(pv[i + 6], pv[i + 7]));
                DrawCubicBezier(p0, p1, p2, p3);
            }

            n += step;
            if (p.Closed)
            {
                p0 = m.MultiplyPoint(new Vector3(pv[n - 4], pv[n - 3]));
                p1 = m.MultiplyPoint(new Vector3(pv[n - 2], pv[n - 1]));
                p2 = m.MultiplyPoint(new Vector3(pv[0], pv[1]));
                p3 = m.MultiplyPoint(new Vector3(pv[2], pv[3]));
                DrawCubicBezier(p0, p1, p2, p3);
            }

            const float endCapSize = 0.05f;
            Vector3     firstPoint = m.MultiplyPoint(new Vector3(pv[2], pv[3]));

            SpineHandles.DrawDot(firstPoint, endCapSize);

            //if (!p.Closed) SpineHandles.DrawDot(m.MultiplyPoint(new Vector3(pv[n - 4], pv[n - 3])), endCapSize);
            if (includeName)
            {
                Handles.Label(firstPoint + new Vector3(0, 0.1f), p.Name, PathNameStyle);
            }

            Handles.color = ocolor;
        }
        public void DoRenderPreview(bool drawHandles)
        {
            if (this.PreviewUtilityCamera.activeTexture == null || this.PreviewUtilityCamera.targetTexture == null)
            {
                return;
            }

            GameObject go = previewGameObject;

            if (requiresRefresh && go != null)
            {
                go.GetComponent <Renderer>().enabled = true;

                if (!EditorApplication.isPlaying)
                {
                    skeletonAnimation.Update((Time.realtimeSinceStartup - animationLastTime));
                }

                animationLastTime = Time.realtimeSinceStartup;

                if (!EditorApplication.isPlaying)
                {
                    skeletonAnimation.LateUpdate();
                }

                var thisPreviewUtilityCamera = this.PreviewUtilityCamera;

                if (drawHandles)
                {
                    Handles.SetCamera(thisPreviewUtilityCamera);
                    Handles.color = OriginColor;

                    float scale = skeletonDataAsset.scale;
                    Handles.DrawLine(new Vector3(-1000 * scale, 0, 0), new Vector3(1000 * scale, 0, 0));
                    Handles.DrawLine(new Vector3(0, 1000 * scale, 0), new Vector3(0, -1000 * scale, 0));
                }

                thisPreviewUtilityCamera.Render();

                if (drawHandles)
                {
                    Handles.SetCamera(thisPreviewUtilityCamera);
                    SpineHandles.DrawBoundingBoxes(skeletonAnimation.transform, skeletonAnimation.skeleton);
                    if (SkeletonDataAssetInspector.showAttachments)
                    {
                        SpineHandles.DrawPaths(skeletonAnimation.transform, skeletonAnimation.skeleton);
                    }
                }

                go.GetComponent <Renderer>().enabled = false;
            }
        }
        public void OnSceneGUI()
        {
            var skeletonRenderer = (SkeletonRenderer)target;
            var skeleton         = skeletonRenderer.Skeleton;
            var transform        = skeletonRenderer.transform;

            if (skeleton == null)
            {
                return;
            }

            SpineHandles.DrawBones(transform, skeleton);
        }
        void DoRenderPreview(bool drawHandles)
        {
            if (this.PreviewUtilityCamera.activeTexture == null || this.PreviewUtilityCamera.targetTexture == null)
            {
                return;
            }

            GameObject go = this.m_previewInstance;

            if (m_requireRefresh && go != null)
            {
                go.GetComponent <Renderer>().enabled = true;

                if (!EditorApplication.isPlaying)
                {
                    m_skeletonAnimation.Update((Time.realtimeSinceStartup - m_lastTime));
                }

                m_lastTime = Time.realtimeSinceStartup;

                if (!EditorApplication.isPlaying)
                {
                    m_skeletonAnimation.LateUpdate();
                }

                var c = this.PreviewUtilityCamera;

                if (drawHandles)
                {
                    Handles.SetCamera(c);
                    Handles.color = m_originColor;

                    Handles.DrawLine(new Vector3(-1000 * m_skeletonDataAsset.scale, 0, 0), new Vector3(1000 * m_skeletonDataAsset.scale, 0, 0));
                    Handles.DrawLine(new Vector3(0, 1000 * m_skeletonDataAsset.scale, 0), new Vector3(0, -1000 * m_skeletonDataAsset.scale, 0));
                }

                c.Render();

                if (drawHandles)
                {
                    Handles.SetCamera(c);
                    SpineHandles.DrawBoundingBoxes(m_skeletonAnimation.transform, m_skeletonAnimation.skeleton);
                    if (showAttachments)
                    {
                        SpineHandles.DrawPaths(m_skeletonAnimation.transform, m_skeletonAnimation.skeleton);
                    }
                }

                go.GetComponent <Renderer>().enabled = false;
            }
        }
Exemple #13
0
        public static void DrawBone(Transform transform, Bone b, float boneScale, Color color, float skeletonRenderScale = 1f)
        {
            var   pos    = new Vector3(b.WorldX * skeletonRenderScale, b.WorldY * skeletonRenderScale, 0);
            float length = b.Data.Length;

            if (length > 0)
            {
                Quaternion  rot   = Quaternion.Euler(0, 0, b.WorldRotationX);
                Vector3     scale = Vector3.one * length * b.WorldScaleX;
                const float my    = 1.5f;
                scale.y *= (SpineEditorUtilities.Preferences.handleScale + 1f) * 0.5f;
                scale.y  = Mathf.Clamp(scale.x, -my, my);
                SpineHandles.GetBoneMaterial(color).SetPass(0);
                Graphics.DrawMeshNow(SpineHandles.BoneMesh, transform.localToWorldMatrix * Matrix4x4.TRS(pos, rot, scale));
            }
            else
            {
                var wp = transform.TransformPoint(pos);
                DrawBoneCircle(wp, color, transform.forward, boneScale * skeletonRenderScale);
            }
        }
Exemple #14
0
        public static void DrawConstraints(Transform transform, Skeleton skeleton, float skeletonRenderScale = 1f)
        {
            Vector3     targetPos;
            Vector3     pos;
            bool        active;
            Color       handleColor;
            const float Thickness = 4f;
            Vector3     normal    = transform.forward;

            // Transform Constraints
            handleColor = SpineHandles.TransformContraintColor;
            foreach (var tc in skeleton.TransformConstraints)
            {
                var targetBone = tc.Target;
                targetPos = targetBone.GetWorldPosition(transform, skeletonRenderScale);

                if (tc.TranslateMix > 0)
                {
                    if (tc.TranslateMix != 1f)
                    {
                        Handles.color = handleColor;
                        foreach (var b in tc.Bones)
                        {
                            pos = b.GetWorldPosition(transform, skeletonRenderScale);
                            Handles.DrawDottedLine(targetPos, pos, Thickness);
                        }
                    }
                    SpineHandles.DrawBoneCircle(targetPos, handleColor, normal, 1.3f * skeletonRenderScale);
                    Handles.color = handleColor;
                    SpineHandles.DrawCrosshairs(targetPos, 0.2f, targetBone.A, targetBone.B, targetBone.C, targetBone.D, transform, skeletonRenderScale);
                }
            }

            // IK Constraints
            handleColor = SpineHandles.IkColor;
            foreach (var ikc in skeleton.IkConstraints)
            {
                Bone targetBone = ikc.Target;
                targetPos = targetBone.GetWorldPosition(transform, skeletonRenderScale);
                var bones = ikc.Bones;
                active = ikc.Mix > 0;
                if (active)
                {
                    pos = bones.Items[0].GetWorldPosition(transform, skeletonRenderScale);
                    switch (bones.Count)
                    {
                    case 1: {
                        Handles.color = handleColor;
                        Handles.DrawLine(targetPos, pos);
                        SpineHandles.DrawBoneCircle(targetPos, handleColor, normal);
                        var m = bones.Items[0].GetMatrix4x4();
                        m.m03 = targetBone.WorldX * skeletonRenderScale;
                        m.m13 = targetBone.WorldY * skeletonRenderScale;
                        SpineHandles.DrawArrowhead(transform.localToWorldMatrix * m);
                        break;
                    }

                    case 2: {
                        Bone    childBone = bones.Items[1];
                        Vector3 child     = childBone.GetWorldPosition(transform, skeletonRenderScale);
                        Handles.color = handleColor;
                        Handles.DrawLine(child, pos);
                        Handles.DrawLine(targetPos, child);
                        SpineHandles.DrawBoneCircle(pos, handleColor, normal, 0.5f);
                        SpineHandles.DrawBoneCircle(child, handleColor, normal, 0.5f);
                        SpineHandles.DrawBoneCircle(targetPos, handleColor, normal);
                        var m = childBone.GetMatrix4x4();
                        m.m03 = targetBone.WorldX * skeletonRenderScale;
                        m.m13 = targetBone.WorldY * skeletonRenderScale;
                        SpineHandles.DrawArrowhead(transform.localToWorldMatrix * m);
                        break;
                    }
                    }
                }
                //Handles.Label(targetPos, ikc.Data.Name, SpineHandles.BoneNameStyle);
            }

            // Path Constraints
            handleColor = SpineHandles.PathColor;
            foreach (var pc in skeleton.PathConstraints)
            {
                active = pc.TranslateMix > 0;
                if (active)
                {
                    foreach (var b in pc.Bones)
                    {
                        SpineHandles.DrawBoneCircle(b.GetWorldPosition(transform, skeletonRenderScale), handleColor, normal, 1f * skeletonRenderScale);
                    }
                }
            }
        }