Пример #1
0
 // Use this for initialization
 void Start()
 {
     m_Target = new VCEMath.DrawTarget();
     m_CursorGizmoCube.m_Shrink = -0.03f;
     m_OffsetGizmoCube.m_Shrink = 0.03f;
     VCEStatusBar.ShowText("Pencil - Dot single voxel".ToLocalizationString(), 7, true);
 }
Пример #2
0
 // Use this for initialization
 protected void Start()
 {
     m_Target             = new VCEMath.DrawTarget();
     m_Begin              = null;
     m_End                = null;
     m_GizmoCube.m_Shrink = -0.04f;
     VCEStatusBar.ShowText(BrushDesc().ToLocalizationString(), 7, true);
 }
    public override void MainMethod()
    {
        if (VCEInput.s_Increase && !VCEInput.s_Shift)
        {
            if (m_Depth < 300)
            {
                m_Depth++;
            }
            m_GUIAlpha = 5;
        }
        else if (VCEInput.s_Decrease && !VCEInput.s_Shift)
        {
            if (m_Depth > 1)
            {
                m_Depth--;
            }
            m_GUIAlpha = 5;
        }
        //
        // Selecting, mouse dragging
        //
        if (m_Selecting)
        {
            if (VCEInput.s_Cancel)
            {
                ExitSelecting();
                return;
            }
            RaycastHit rch;

            // ray cast coord plane
            if (VCEMath.RayCastCoordPlane(VCEInput.s_PickRay, m_Coord, m_PlanePos, out rch))
            {
                m_End.x = Mathf.FloorToInt(rch.point.x);
                m_End.y = Mathf.FloorToInt(rch.point.y);
                m_End.z = Mathf.FloorToInt(rch.point.z);
                switch (m_Coord)
                {
                case ECoordPlane.XY: m_End.z = m_Begin.z + (m_Depth - 1) * m_NormalSign; break;

                case ECoordPlane.XZ: m_End.y = m_Begin.y == 0 && VCEditor.s_Scene.m_IsoData.GetVoxel(VCIsoData.IPosToKey(m_Begin)).Volume < 128 ?
                                               VCEditor.s_Scene.m_Setting.m_EditorSize.y - 1 :
                                               m_Begin.y + (m_Depth - 1) * m_NormalSign;
                    break;

                case ECoordPlane.ZY: m_End.x = m_Begin.x + (m_Depth - 1) * m_NormalSign; break;

                default: ExitSelecting(); return;
                }
            }
            else
            {
                ExitSelecting();
                return;
            }
            m_Iso.ClampPointI(m_Begin);
            m_Iso.ClampPointI(m_End);

            // Submit this selecting action !
            if (Input.GetMouseButtonUp(0) && m_Selecting)
            {
                Submit();
                m_Selecting  = false;
                m_NeedUpdate = true;
            }
        }         // End selecting

        //
        // Free mouse, prepare to select
        //
        else
        {
            // Mouse not on GUI
            if (!VCEInput.s_MouseOnUI)
            {
                // Click left mouse button
                if (Input.GetMouseButtonDown(0))
                {
                    // has draw target
                    if (m_Parent.m_Target.snapto != null && m_Parent.m_Target.cursor != null)
                    {
                        VCEMath.DrawTarget dtar = m_Parent.m_Target;
                        // snapto has voxel
                        if (m_Iso.GetVoxel(VCIsoData.IPosToKey(dtar.snapto)).Volume > 0)
                        {
                            m_Begin.x = dtar.snapto.x;
                            m_Begin.y = dtar.snapto.y;
                            m_Begin.z = dtar.snapto.z;
                        }
                        // snapto don't has voxel
                        else
                        {
                            m_Begin.x       = dtar.cursor.x;
                            m_Begin.y       = dtar.cursor.y;
                            m_Begin.z       = dtar.cursor.z;
                            dtar.rch.normal = -dtar.rch.normal;
                        }

                        // Assgin end
                        m_End.x = m_Begin.x;
                        m_End.y = m_Begin.y;
                        m_End.z = m_Begin.z;
                        // Assgin coord and position
                        // zy plane
                        if (Mathf.Abs(dtar.rch.normal.x) > 0.9f)
                        {
                            m_Coord      = ECoordPlane.ZY;
                            m_PlanePos   = dtar.rch.point.x;
                            m_Selecting  = true;
                            m_NormalSign = -Mathf.RoundToInt(Mathf.Sign(dtar.rch.normal.x));
                        }
                        // xz plane
                        else if (Mathf.Abs(dtar.rch.normal.y) > 0.9f)
                        {
                            m_Coord      = ECoordPlane.XZ;
                            m_PlanePos   = dtar.rch.point.y;
                            m_Selecting  = true;
                            m_NormalSign = -Mathf.RoundToInt(Mathf.Sign(dtar.rch.normal.y));
                        }
                        // xy plane
                        else if (Mathf.Abs(dtar.rch.normal.z) > 0.9f)
                        {
                            m_Coord      = ECoordPlane.XY;
                            m_PlanePos   = dtar.rch.point.z;
                            m_Selecting  = true;
                            m_NormalSign = -Mathf.RoundToInt(Mathf.Sign(dtar.rch.normal.z));
                        }
                        // it's impossible !!!
                        else
                        {
                            Debug.LogError("It's impossible !!");
                            ExitSelecting();
                        }
                    }
                    // Don't have draw target
                    else
                    {
                        // Select
                        if (!VCEInput.s_Shift && !VCEInput.s_Alt && !VCEInput.s_Control)
                        {
                            m_Selection.Clear();
                        }
                        m_NeedUpdate = true;
                    }
                }
            }

            if (m_MaterialSelectChange)
            {
                Submit();
                m_Selecting  = false;
                m_NeedUpdate = true;
            }
        }         // End free mouse
    }
    public override void OnGL()
    {
        // Draw selecting box
        if (m_Selecting)
        {
            Vector3 iMin = Vector3.zero;
            Vector3 iMax = Vector3.zero;
            iMin.x = Mathf.Min(m_Begin.x, m_End.x);
            iMin.y = Mathf.Min(m_Begin.y, m_End.y);
            iMin.z = Mathf.Min(m_Begin.z, m_End.z);
            iMax.x = Mathf.Max(m_Begin.x, m_End.x);
            iMax.y = Mathf.Max(m_Begin.y, m_End.y);
            iMax.z = Mathf.Max(m_Begin.z, m_End.z);
            iMin  -= Vector3.one * 0.07f;
            iMax  += Vector3.one * 1.07f;
            Vector3[] vec = new Vector3 [8]
            {
                new Vector3(iMax.x, iMax.y, iMax.z),
                new Vector3(iMin.x, iMax.y, iMax.z),
                new Vector3(iMin.x, iMin.y, iMax.z),
                new Vector3(iMax.x, iMin.y, iMax.z),
                new Vector3(iMax.x, iMax.y, iMin.z),
                new Vector3(iMin.x, iMax.y, iMin.z),
                new Vector3(iMin.x, iMin.y, iMin.z),
                new Vector3(iMax.x, iMin.y, iMin.z)
            };
            for (int i = 0; i < 8; ++i)
            {
                vec[i] = vec[i] * VCEditor.s_Scene.m_Setting.m_VoxelSize;
            }

            Color lineColor = new Color(0.0f, 0.2f, 0.5f, 1.0f);
            Color faceColor = new Color(0.0f, 0.2f, 0.5f, 1.0f);

            lineColor.a  = 1.0f;
            faceColor.a *= 0.4f + Mathf.Sin(Time.time * 6f) * 0.1f;

            GL.Begin(GL.LINES);
            GL.Color(lineColor);
            GL.Vertex(vec[0]); GL.Vertex(vec[1]); GL.Vertex(vec[1]); GL.Vertex(vec[2]);
            GL.Vertex(vec[2]); GL.Vertex(vec[3]); GL.Vertex(vec[3]); GL.Vertex(vec[0]);
            GL.Vertex(vec[4]); GL.Vertex(vec[5]); GL.Vertex(vec[5]); GL.Vertex(vec[6]);
            GL.Vertex(vec[6]); GL.Vertex(vec[7]); GL.Vertex(vec[7]); GL.Vertex(vec[4]);
            GL.Vertex(vec[0]); GL.Vertex(vec[4]); GL.Vertex(vec[1]); GL.Vertex(vec[5]);
            GL.Vertex(vec[2]); GL.Vertex(vec[6]); GL.Vertex(vec[3]); GL.Vertex(vec[7]);
            GL.End();

            GL.Begin(GL.QUADS);
            GL.Color(faceColor);
            GL.Vertex(vec[0]); GL.Vertex(vec[1]); GL.Vertex(vec[2]); GL.Vertex(vec[3]);
            GL.Vertex(vec[4]); GL.Vertex(vec[5]); GL.Vertex(vec[6]); GL.Vertex(vec[7]);
            GL.Vertex(vec[0]); GL.Vertex(vec[4]); GL.Vertex(vec[5]); GL.Vertex(vec[1]);
            GL.Vertex(vec[1]); GL.Vertex(vec[5]); GL.Vertex(vec[6]); GL.Vertex(vec[2]);
            GL.Vertex(vec[2]); GL.Vertex(vec[6]); GL.Vertex(vec[7]); GL.Vertex(vec[3]);
            GL.Vertex(vec[3]); GL.Vertex(vec[7]); GL.Vertex(vec[4]); GL.Vertex(vec[0]);
            GL.End();
        }
        // Draw pre-select face direction
        else
        {
            if (!VCEInput.s_MouseOnUI)
            {
                VCEMath.DrawTarget dtar = m_Parent.m_Target;
                if (dtar.cursor != null && dtar.snapto != null)
                {
                    if (m_Iso.GetVoxel(VCIsoData.IPosToKey(dtar.snapto)).Volume == 0)
                    {
                        return;
                    }
                    Vector3 iMin = dtar.rch.point;
                    Vector3 iMax = dtar.rch.point;
                    iMin += dtar.rch.normal * 0.03f;
                    iMax += dtar.rch.normal * 0.06f;

                    Color indicator_color = Color.white;
                    // zy plane
                    if (Mathf.Abs(dtar.rch.normal.x) > 0.9f)
                    {
                        iMin.y          = Mathf.Floor(iMin.y);
                        iMin.z          = Mathf.Floor(iMin.z);
                        iMax.y          = Mathf.Floor(iMax.y) + 1;
                        iMax.z          = Mathf.Floor(iMax.z) + 1;
                        indicator_color = new Color(0.9f, 0.1f, 0.2f, 1.0f);
                    }
                    // xz plane
                    else if (Mathf.Abs(dtar.rch.normal.y) > 0.9f)
                    {
                        iMin.x          = Mathf.Floor(iMin.x);
                        iMin.z          = Mathf.Floor(iMin.z);
                        iMax.x          = Mathf.Floor(iMax.x) + 1;
                        iMax.z          = Mathf.Floor(iMax.z) + 1;
                        indicator_color = new Color(0.5f, 1.0f, 0.1f, 1.0f);
                    }
                    // xy plane
                    else if (Mathf.Abs(dtar.rch.normal.z) > 0.9f)
                    {
                        iMin.y          = Mathf.Floor(iMin.y);
                        iMin.x          = Mathf.Floor(iMin.x);
                        iMax.y          = Mathf.Floor(iMax.y) + 1;
                        iMax.x          = Mathf.Floor(iMax.x) + 1;
                        indicator_color = new Color(0.1f, 0.6f, 1.0f, 1.0f);
                    }
                    Vector3[] vec = new Vector3 [8]
                    {
                        new Vector3(iMax.x, iMax.y, iMax.z),
                        new Vector3(iMin.x, iMax.y, iMax.z),
                        new Vector3(iMin.x, iMin.y, iMax.z),
                        new Vector3(iMax.x, iMin.y, iMax.z),
                        new Vector3(iMax.x, iMax.y, iMin.z),
                        new Vector3(iMin.x, iMax.y, iMin.z),
                        new Vector3(iMin.x, iMin.y, iMin.z),
                        new Vector3(iMax.x, iMin.y, iMin.z)
                    };
                    for (int i = 0; i < 8; ++i)
                    {
                        vec[i] = vec[i] * VCEditor.s_Scene.m_Setting.m_VoxelSize;
                    }

                    Color lineColor = indicator_color;
                    Color faceColor = indicator_color;

                    lineColor.a  = 1.0f;
                    faceColor.a *= 0.7f + Mathf.Sin(Time.time * 6f) * 0.1f;

                    GL.Begin(GL.LINES);
                    GL.Color(lineColor);
                    GL.Vertex(vec[0]); GL.Vertex(vec[1]); GL.Vertex(vec[1]); GL.Vertex(vec[2]);
                    GL.Vertex(vec[2]); GL.Vertex(vec[3]); GL.Vertex(vec[3]); GL.Vertex(vec[0]);
                    GL.Vertex(vec[4]); GL.Vertex(vec[5]); GL.Vertex(vec[5]); GL.Vertex(vec[6]);
                    GL.Vertex(vec[6]); GL.Vertex(vec[7]); GL.Vertex(vec[7]); GL.Vertex(vec[4]);
                    GL.Vertex(vec[0]); GL.Vertex(vec[4]); GL.Vertex(vec[1]); GL.Vertex(vec[5]);
                    GL.Vertex(vec[2]); GL.Vertex(vec[6]); GL.Vertex(vec[3]); GL.Vertex(vec[7]);
                    GL.End();

                    GL.Begin(GL.QUADS);
                    GL.Color(faceColor);
                    GL.Vertex(vec[0]); GL.Vertex(vec[1]); GL.Vertex(vec[2]); GL.Vertex(vec[3]);
                    GL.Vertex(vec[4]); GL.Vertex(vec[5]); GL.Vertex(vec[6]); GL.Vertex(vec[7]);
                    GL.Vertex(vec[0]); GL.Vertex(vec[4]); GL.Vertex(vec[5]); GL.Vertex(vec[1]);
                    GL.Vertex(vec[1]); GL.Vertex(vec[5]); GL.Vertex(vec[6]); GL.Vertex(vec[2]);
                    GL.Vertex(vec[2]); GL.Vertex(vec[6]); GL.Vertex(vec[7]); GL.Vertex(vec[3]);
                    GL.Vertex(vec[3]); GL.Vertex(vec[7]); GL.Vertex(vec[4]); GL.Vertex(vec[0]);
                    GL.End();
                }
            }     // End 'mouse on gui'
        }         // End 'draw preselect'
    }