Example #1
0
        public static void DoPositionHandle(Vector3 position, Quaternion rotation,
                                            RuntimeHandleAxis selectedAxis = RuntimeHandleAxis.None, bool snapMode = false, LockObject lockObject = null)
        {
            float screenScale = GetScreenScale(position, Camera.current);

            Matrix4x4 transform = Matrix4x4.TRS(position, rotation, new Vector3(screenScale, screenScale, screenScale));

            LinesMaterial.SetPass(0);

            GL.Begin(GL.LINES);

            bool xLocked = lockObject != null && lockObject.PositionX;
            bool yLocked = lockObject != null && lockObject.PositionY;
            bool zLocked = lockObject != null && lockObject.PositionZ;

            DoAxes(position, transform, selectedAxis, xLocked, yLocked, zLocked);

            const float s = 0.2f;
            Vector3     x = Vector3.right * s;
            Vector3     y = Vector3.up * s;
            Vector3     z = Vector3.forward * s;


            if (snapMode)
            {
                GL.End();

                LinesBillboardMaterial.SetPass(0);
                GL.PushMatrix();
                GL.MultMatrix(transform);
                GL.Begin(GL.LINES);

                if (selectedAxis == RuntimeHandleAxis.Snap)
                {
                    GL.Color(SelectionColor);
                }
                else
                {
                    GL.Color(AltColor);
                }

                float   s2 = s / 2 * HandleScale;
                Vector3 p0 = new Vector3(s2, s2, 0);
                Vector3 p1 = new Vector3(s2, -s2, 0);
                Vector3 p2 = new Vector3(-s2, -s2, 0);
                Vector3 p3 = new Vector3(-s2, s2, 0);

                GL.Vertex(p0);
                GL.Vertex(p1);
                GL.Vertex(p1);
                GL.Vertex(p2);
                GL.Vertex(p2);
                GL.Vertex(p3);
                GL.Vertex(p3);
                GL.Vertex(p0);

                GL.End();
                GL.PopMatrix();
            }
            else
            {
                Camera  camera = Camera.current;
                Vector3 toCam  = transform.inverse.MultiplyVector(camera.transform.position - position);

                float fx = Mathf.Sign(Vector3.Dot(toCam, x)) * HandleScale;
                float fy = Mathf.Sign(Vector3.Dot(toCam, y)) * HandleScale;
                float fz = Mathf.Sign(Vector3.Dot(toCam, z)) * HandleScale;

                x.x *= fx;
                y.y *= fy;
                z.z *= fz;

                Vector3 xy = x + y;
                Vector3 xz = x + z;
                Vector3 yz = y + z;

                x  = transform.MultiplyPoint(x);
                y  = transform.MultiplyPoint(y);
                z  = transform.MultiplyPoint(z);
                xy = transform.MultiplyPoint(xy);
                xz = transform.MultiplyPoint(xz);
                yz = transform.MultiplyPoint(yz);


                if (!xLocked && !zLocked)
                {
                    GL.Color(selectedAxis != RuntimeHandleAxis.XZ ? YColor : SelectionColor);
                    GL.Vertex(position);
                    GL.Vertex(z);
                    GL.Vertex(z);
                    GL.Vertex(xz);
                    GL.Vertex(xz);
                    GL.Vertex(x);
                    GL.Vertex(x);
                    GL.Vertex(position);
                }

                if (!xLocked && !yLocked)
                {
                    GL.Color(selectedAxis != RuntimeHandleAxis.XY ? ZColor : SelectionColor);
                    GL.Vertex(position);
                    GL.Vertex(y);
                    GL.Vertex(y);
                    GL.Vertex(xy);
                    GL.Vertex(xy);
                    GL.Vertex(x);
                    GL.Vertex(x);
                    GL.Vertex(position);
                }

                if (!yLocked && !zLocked)
                {
                    GL.Color(selectedAxis != RuntimeHandleAxis.YZ ? XColor : SelectionColor);
                    GL.Vertex(position);
                    GL.Vertex(y);
                    GL.Vertex(y);
                    GL.Vertex(yz);
                    GL.Vertex(yz);
                    GL.Vertex(z);
                    GL.Vertex(z);
                    GL.Vertex(position);
                }
                GL.End();


                GL.Begin(GL.QUADS);

                if (!xLocked && !zLocked)
                {
                    GL.Color(YColorTransparent);
                    GL.Vertex(position);
                    GL.Vertex(z);
                    GL.Vertex(xz);
                    GL.Vertex(x);
                }

                if (!xLocked && !yLocked)
                {
                    GL.Color(ZColorTransparent);
                    GL.Vertex(position);
                    GL.Vertex(y);
                    GL.Vertex(xy);
                    GL.Vertex(x);
                }

                if (!yLocked && !zLocked)
                {
                    GL.Color(XColorTransparent);
                    GL.Vertex(position);
                    GL.Vertex(y);
                    GL.Vertex(yz);
                    GL.Vertex(z);
                }

                GL.End();
            }

            ShapesMaterial.SetPass(0);


            if (!xLocked && !yLocked && !zLocked)
            {
                Graphics.DrawMeshNow(Arrows, transform);
                if (selectedAxis == RuntimeHandleAxis.X)
                {
                    Graphics.DrawMeshNow(SelectionArrowX, transform);
                }
                else if (selectedAxis == RuntimeHandleAxis.Y)
                {
                    Graphics.DrawMeshNow(SelectionArrowY, transform);
                }
                else if (selectedAxis == RuntimeHandleAxis.Z)
                {
                    Graphics.DrawMeshNow(SelectionArrowZ, transform);
                }
            }
            else
            {
                if (xLocked)
                {
                    Graphics.DrawMeshNow(DisabledArrowX, transform);
                }
                else
                {
                    if (selectedAxis == RuntimeHandleAxis.X)
                    {
                        Graphics.DrawMeshNow(SelectionArrowX, transform);
                    }
                    else
                    {
                        Graphics.DrawMeshNow(ArrowX, transform);
                    }
                }

                if (yLocked)
                {
                    Graphics.DrawMeshNow(DisabledArrowY, transform);
                }
                else
                {
                    if (selectedAxis == RuntimeHandleAxis.Y)
                    {
                        Graphics.DrawMeshNow(SelectionArrowY, transform);
                    }
                    else
                    {
                        Graphics.DrawMeshNow(ArrowY, transform);
                    }
                }

                if (zLocked)
                {
                    Graphics.DrawMeshNow(DisabledArrowZ, transform);
                }
                else
                {
                    if (selectedAxis == RuntimeHandleAxis.Z)
                    {
                        Graphics.DrawMeshNow(SelectionArrowZ, transform);
                    }
                    else
                    {
                        Graphics.DrawMeshNow(ArrowZ, transform);
                    }
                }
            }
        }
Example #2
0
        public static void DoRotationHandle(Quaternion rotation, Vector3 position, RuntimeHandleAxis selectedAxis = RuntimeHandleAxis.None, LockObject lockObject = null)
        {
            float     screenScale = GetScreenScale(position, Camera.current);
            float     radius      = HandleScale;
            Vector3   scale       = new Vector3(screenScale, screenScale, screenScale);
            Matrix4x4 xTranform   = Matrix4x4.TRS(Vector3.zero, rotation * Quaternion.AngleAxis(-90, Vector3.up), Vector3.one);
            Matrix4x4 yTranform   = Matrix4x4.TRS(Vector3.zero, rotation * Quaternion.AngleAxis(-90, Vector3.right), Vector3.one);
            Matrix4x4 zTranform   = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
            Matrix4x4 objToWorld  = Matrix4x4.TRS(position, Quaternion.identity, scale);

            bool xLocked      = lockObject != null && lockObject.RotationX;
            bool yLocked      = lockObject != null && lockObject.RotationY;
            bool zLocked      = lockObject != null && lockObject.RotationZ;
            bool screenLocked = lockObject != null && lockObject.RotationScreen;

            LinesClipMaterial.SetPass(0);
            GL.PushMatrix();
            GL.MultMatrix(objToWorld);

            GL.Begin(GL.LINES);
            if (xLocked)
            {
                GL.Color(DisabledColor);
            }
            else
            {
                GL.Color(selectedAxis != RuntimeHandleAxis.X ? XColor : SelectionColor);
            }
            RuntimeGraphics.DrawCircleGL(xTranform, radius);

            if (yLocked)
            {
                GL.Color(DisabledColor);
            }
            else
            {
                GL.Color(selectedAxis != RuntimeHandleAxis.Y ? YColor : SelectionColor);
            }
            RuntimeGraphics.DrawCircleGL(yTranform, radius);

            if (zLocked)
            {
                GL.Color(DisabledColor);
            }
            else
            {
                GL.Color(selectedAxis != RuntimeHandleAxis.Z ? ZColor : SelectionColor);
            }
            RuntimeGraphics.DrawCircleGL(zTranform, radius);
            GL.End();

            GL.PopMatrix();

            LinesBillboardMaterial.SetPass(0);
            GL.PushMatrix();
            GL.MultMatrix(objToWorld);

            GL.Begin(GL.LINES);
            if (xLocked && yLocked && zLocked)
            {
                GL.Color(DisabledColor);
            }
            else
            {
                GL.Color(selectedAxis != RuntimeHandleAxis.Free ? AltColor : SelectionColor);
            }
            RuntimeGraphics.DrawCircleGL(Matrix4x4.identity, radius);

            if (screenLocked)
            {
                GL.Color(DisabledColor);
            }
            else
            {
                GL.Color(selectedAxis != RuntimeHandleAxis.Screen ? AltColor : SelectionColor);
            }
            RuntimeGraphics.DrawCircleGL(Matrix4x4.identity, radius * 1.1f);
            GL.End();

            GL.PopMatrix();
        }
Example #3
0
 private void UpdatePointsMesh(Mesh target, RuntimeHandleAxis axis, Bounds bounds)
 {
     Vector3[] vertices = GetVertices(axis, bounds);
     target.vertices = vertices;
     target.RecalculateBounds();
 }
Example #4
0
 public override void Select(RuntimeHandleAxis axis)
 {
     base.Select(axis);
     SetColors();
 }
Example #5
0
        protected override void UpdateOverride()
        {
            if (!IsDragging)
            {
                RuntimeHandleAxis axis = GetAxis(out m_currentDot);
                if (m_currentAxis != axis)
                {
                    m_currentAxis = axis;
                    RecalculateBoundsAndRebuild();
                    m_selectedPointIndex = -1;
                    m_selectedEdgeIndex  = -1;
                }

                Vector3[] vertices = m_points.sharedMesh.vertices;
                if (vertices.Length == 0)
                {
                    return;
                }

                PickResult pointPickResult = PickPoint(vertices);
                pointPickResult.Distance *= 0.1f;
                PickResult edgePickResult = PickEdge(vertices);

                if (pointPickResult.Distance < edgePickResult.Distance)
                {
                    if (m_selectedEdgeIndex != -1)
                    {
                        Color[] colors = m_lines.sharedMesh.colors;
                        Color   color  = GetColor(m_currentAxis);
                        colors[m_selectedEdgeIndex * 2]     = color;
                        colors[m_selectedEdgeIndex * 2 + 1] = color;
                        m_lines.sharedMesh.colors           = colors;

                        m_selectedEdgeIndex = -1;
                    }

                    if (pointPickResult.Index != m_selectedPointIndex)
                    {
                        Color[] colors = m_points.sharedMesh.colors;
                        if (m_selectedPointIndex >= 0)
                        {
                            colors[m_selectedPointIndex] = GetColor(m_currentAxis);
                        }

                        m_selectedPointIndex = pointPickResult.Index;

                        if (m_selectedPointIndex >= 0)
                        {
                            colors[m_selectedPointIndex] = Appearance.Colors.SelectionColor;
                        }

                        m_points.sharedMesh.colors = colors;
                    }
                }
                else if (edgePickResult.Distance < pointPickResult.Distance)
                {
                    if (m_selectedPointIndex != -1)
                    {
                        Color[] colors = m_points.sharedMesh.colors;
                        colors[m_selectedPointIndex] = GetColor(m_currentAxis);
                        m_points.sharedMesh.colors   = colors;
                        m_selectedPointIndex         = -1;
                    }

                    if (edgePickResult.Index != m_selectedEdgeIndex)
                    {
                        Color[] colors = m_lines.sharedMesh.colors;
                        if (m_selectedEdgeIndex >= 0)
                        {
                            Color color = GetColor(m_currentAxis);
                            colors[m_selectedEdgeIndex * 2]     = color;
                            colors[m_selectedEdgeIndex * 2 + 1] = color;
                        }

                        m_selectedEdgeIndex = edgePickResult.Index;

                        if (m_selectedEdgeIndex >= 0)
                        {
                            Color color = Appearance.Colors.SelectionColor;
                            colors[m_selectedEdgeIndex * 2]     = color;
                            colors[m_selectedEdgeIndex * 2 + 1] = color;
                        }
                    }
                }
            }
        }
Example #6
0
        public void RecalculateBoundsAndRebuild()
        {
            m_rotation   = Quaternion.identity;
            m_position   = Vector3.zero;
            m_localScale = Vector3.one;
            m_bounds     = new Bounds();

            if (m_txtSize1 != null)
            {
                m_txtSize1.text = string.Empty;
            }

            if (m_txtSize2 != null)
            {
                m_txtSize2.text = string.Empty;
            }


            if (RealTargets == null || RealTargets.Length == 0)
            {
                return;
            }

            if (ActiveRealTargets.Length == 1 && ActiveRealTargets[0].GetComponent <ExposeToEditor>())
            {
                ExposeToEditor exposeToEditor = ActiveRealTargets[0].GetComponent <ExposeToEditor>();

                m_bounds     = exposeToEditor.Bounds;
                m_position   = exposeToEditor.transform.position;
                m_rotation   = exposeToEditor.transform.rotation;
                m_localScale = exposeToEditor.transform.lossyScale;

                if (m_bounds.extents == Vector3.zero)
                {
                    if (m_lines != null)
                    {
                        m_lines.sharedMesh.Clear();
                    }

                    if (m_points != null)
                    {
                        m_points.sharedMesh.Clear();
                    }
                    return;
                }
            }
            else
            {
                Renderer[] renderers = ActiveRealTargets.Where(t => t != null).SelectMany(t => t.GetComponentsInChildren <Renderer>()).ToArray();
                if (renderers.Length == 0)
                {
                    if (m_lines != null)
                    {
                        m_lines.sharedMesh.Clear();
                    }

                    if (m_points != null)
                    {
                        m_points.sharedMesh.Clear();
                    }

                    return;
                }
                else
                {
                    m_bounds = renderers[0].bounds;
                    for (int i = 1; i < renderers.Length; ++i)
                    {
                        Renderer renderer = renderers[i];
                        m_bounds.Encapsulate(renderer.bounds);
                    }
                }
            }

            if (m_lines == null && m_points == null)
            {
                return;
            }

            m_lines.transform.position    = m_position;
            m_lines.transform.rotation    = m_rotation;
            m_lines.transform.localScale  = m_localScale;
            m_points.transform.position   = m_position;
            m_points.transform.rotation   = m_rotation;
            m_points.transform.localScale = m_localScale;

            m_currentAxis = GetAxis(out m_currentDot);
            BuildPointsMesh(m_points.sharedMesh, m_currentAxis, m_bounds);
            BuildLineMesh(m_lines.sharedMesh, m_currentAxis, m_bounds);

            if (m_txtSize1 != null)
            {
                m_txtSize1.gameObject.layer = Editor.CameraLayerSettings.RuntimeGraphicsLayer + Window.Index;
            }
            if (m_txtSize2 != null)
            {
                m_txtSize2.gameObject.layer = Editor.CameraLayerSettings.RuntimeGraphicsLayer + Window.Index;
            }

            UpdateText();
            UpdateFontSize();
        }
Example #7
0
        public static void DoScaleHandle(Vector3 scale, Vector3 position, Quaternion rotation, RuntimeHandleAxis selectedAxis = RuntimeHandleAxis.None)
        {
            float     sScale         = GetScreenScale(position, Camera.current);
            Matrix4x4 linesTransform = Matrix4x4.TRS(position, rotation, scale * sScale);

            LinesMaterial.SetPass(0);

            GL.Begin(GL.LINES);
            DoAxes(position, linesTransform, selectedAxis);
            GL.End();

            Matrix4x4 rotM = Matrix4x4.TRS(Vector3.zero, rotation, scale);

            ShapesMaterial.SetPass(0);
            Vector3 screenScale = new Vector3(sScale, sScale, sScale);
            Vector3 xOffset     = rotM.MultiplyVector(Vector3.right) * sScale;
            Vector3 yOffset     = rotM.MultiplyVector(Vector3.up) * sScale;
            Vector3 zOffset     = rotM.MultiplyVector(Vector3.forward) * sScale;

            if (selectedAxis == RuntimeHandleAxis.X)
            {
                Graphics.DrawMeshNow(SelectionCube, Matrix4x4.TRS(position + xOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeY, Matrix4x4.TRS(position + yOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeZ, Matrix4x4.TRS(position + zOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeUniform, Matrix4x4.TRS(position, rotation, screenScale * 1.35f));
            }
            else if (selectedAxis == RuntimeHandleAxis.Y)
            {
                Graphics.DrawMeshNow(CubeX, Matrix4x4.TRS(position + xOffset, rotation, screenScale));
                Graphics.DrawMeshNow(SelectionCube, Matrix4x4.TRS(position + yOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeZ, Matrix4x4.TRS(position + zOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeUniform, Matrix4x4.TRS(position, rotation, screenScale * 1.35f));
            }
            else if (selectedAxis == RuntimeHandleAxis.Z)
            {
                Graphics.DrawMeshNow(CubeX, Matrix4x4.TRS(position + xOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeY, Matrix4x4.TRS(position + yOffset, rotation, screenScale));
                Graphics.DrawMeshNow(SelectionCube, Matrix4x4.TRS(position + zOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeUniform, Matrix4x4.TRS(position, rotation, screenScale * 1.35f));
            }
            else if (selectedAxis == RuntimeHandleAxis.Free)
            {
                Graphics.DrawMeshNow(CubeX, Matrix4x4.TRS(position + xOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeY, Matrix4x4.TRS(position + yOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeZ, Matrix4x4.TRS(position + zOffset, rotation, screenScale));
                Graphics.DrawMeshNow(SelectionCube, Matrix4x4.TRS(position, rotation, screenScale * 1.35f));
            }
            else
            {
                Graphics.DrawMeshNow(CubeX, Matrix4x4.TRS(position + xOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeY, Matrix4x4.TRS(position + yOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeZ, Matrix4x4.TRS(position + zOffset, rotation, screenScale));
                Graphics.DrawMeshNow(CubeUniform, Matrix4x4.TRS(position, rotation, screenScale * 1.35f));
            }
        }
Example #8
0
        public static void DoPositionHandle(Vector3 position, Quaternion rotation, RuntimeHandleAxis selectedAxis = RuntimeHandleAxis.None)
        {
            float     screenScale = GetScreenScale(position, Camera.current);
            Matrix4x4 transform   = Matrix4x4.TRS(position, rotation, new Vector3(screenScale, screenScale, screenScale));

            LinesMaterial.SetPass(0);

            GL.Begin(GL.LINES);
            DoAxes(position, transform, selectedAxis);

            const float s = 0.2f;
            Vector3     x = Vector3.right * s;
            Vector3     y = Vector3.up * s;
            Vector3     z = Vector3.forward * s;

            Camera  camera = Camera.current;
            Vector3 toCam  = camera.transform.position - position;

            float fx = Mathf.Sign(Vector3.Dot(toCam, x));
            float fy = Mathf.Sign(Vector3.Dot(toCam, y));
            float fz = Mathf.Sign(Vector3.Dot(toCam, z));

            x.x *= fx;
            y.y *= fy;
            z.z *= fz;

            Vector3 xy = x + y;
            Vector3 xz = x + z;
            Vector3 yz = y + z;

            x  = transform.MultiplyPoint(x);
            y  = transform.MultiplyPoint(y);
            z  = transform.MultiplyPoint(z);
            xy = transform.MultiplyPoint(xy);
            xz = transform.MultiplyPoint(xz);
            yz = transform.MultiplyPoint(yz);

            GL.Color(selectedAxis != RuntimeHandleAxis.XZ ? YColor : SelectionColor);
            GL.Vertex(position);
            GL.Vertex(z);
            GL.Vertex(z);
            GL.Vertex(xz);
            GL.Vertex(xz);
            GL.Vertex(x);
            GL.Vertex(x);
            GL.Vertex(position);
            GL.Color(selectedAxis != RuntimeHandleAxis.XY ? ZColor : SelectionColor);
            GL.Vertex(position);
            GL.Vertex(y);
            GL.Vertex(y);
            GL.Vertex(xy);
            GL.Vertex(xy);
            GL.Vertex(x);
            GL.Vertex(x);
            GL.Vertex(position);
            GL.Color(selectedAxis != RuntimeHandleAxis.YZ ? XColor : SelectionColor);
            GL.Vertex(position);
            GL.Vertex(y);
            GL.Vertex(y);
            GL.Vertex(yz);
            GL.Vertex(yz);
            GL.Vertex(z);
            GL.Vertex(z);
            GL.Vertex(position);
            GL.End();

            GL.Begin(GL.QUADS);
            GL.Color(YColorTransparent);
            GL.Vertex(position);
            GL.Vertex(z);
            GL.Vertex(xz);
            GL.Vertex(x);
            GL.Color(ZColorTransparent);
            GL.Vertex(position);
            GL.Vertex(y);
            GL.Vertex(xy);
            GL.Vertex(x);
            GL.Color(XColorTransparent);
            GL.Vertex(position);
            GL.Vertex(y);
            GL.Vertex(yz);
            GL.Vertex(z);
            GL.End();

            ShapesMaterial.SetPass(0);
            Graphics.DrawMeshNow(Arrows, transform);
            if (selectedAxis == RuntimeHandleAxis.X)
            {
                Graphics.DrawMeshNow(SelectionArrowX, transform);
            }
            else if (selectedAxis == RuntimeHandleAxis.Y)
            {
                Graphics.DrawMeshNow(SelectionArrowY, transform);
            }
            else if (selectedAxis == RuntimeHandleAxis.Z)
            {
                Graphics.DrawMeshNow(SelectionArrowZ, transform);
            }
        }
 public override void Select(RuntimeHandleAxis axis)
 {
     base.Select(axis);
     OnVertexSnappingModeChaged();
     SetColors();
 }