public static void HandleBrush(GameObject aGO, Mesh aMesh, Vector3 brushPos, EF_BrushData brushData, EF_VTXPainterState aState)
        {
            if (aGO && aMesh)
            {
                Vector3[] verts   = aMesh.vertices;
                Vector3[] normals = aMesh.normals;


                //Check to see if the Object has colors
                Color[] colors = new Color[aMesh.vertexCount];
                if (aMesh.colors.Length > 0)
                {
                    colors = aMesh.colors;
                }
                else
                {
                    for (int i = 0; i < aMesh.vertexCount; i++)
                    {
                        colors[i] = Color.black;
                    }
                }


                //process the brush action
                for (int i = 0; i < verts.Length; i++)
                {
                    float mag = (aGO.transform.TransformPoint(verts[i]) - brushPos).magnitude;
                    if (mag > brushData.brushSize)
                    {
                        continue;
                    }

                    //Get Falloff
                    float curFalloff = 1f;
                    if (mag > brushData.falloffSize)
                    {
                        curFalloff = (brushData.brushSize / mag) * 0.1f;
                    }

                    switch (aState)
                    {
                    case EF_VTXPainterState.Sculpting:
                        verts[i] = SculptMesh(verts[i], normals[i], brushData, curFalloff);
                        break;

                    case EF_VTXPainterState.Painting:
                        colors[i] = PaintMesh(colors[i], brushData, curFalloff);
                        break;

                    default:
                        break;
                    }

                    //Draw Some Handles
                    Handles.color = Color.yellow;
                }


                //Handle any clean up we need
                switch (aState)
                {
                case EF_VTXPainterState.Sculpting:
                    aMesh.vertices = verts;
                    aMesh.RecalculateBounds();
                    aMesh.RecalculateNormals();
                    break;

                case EF_VTXPainterState.Painting:
                    aMesh.colors = colors;
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        void HandleKeyboardShortcuts(Event curEvent)
        {
            if (!curEvent.alt)
            {
                if (curEvent.type == EventType.KeyDown)
                {
                    //If the Paint key is Pressed
                    if (curEvent.keyCode == KeyCode.P)
                    {
                        if (m_CurrentState == EF_VTXPainterState.None)
                        {
                            //Debug.Log("Setting Painting");
                            m_CurrentState = EF_VTXPainterState.Painting;
                        }
                        else if (m_CurrentState == EF_VTXPainterState.Painting)
                        {
                            //Debug.Log("Setting None");
                            m_CurrentState = EF_VTXPainterState.None;
                        }
                    }

                    //if the sculpt key is pressed
                    if (curEvent.keyCode == KeyCode.S)
                    {
                        if (m_CurrentState == EF_VTXPainterState.None)
                        {
                            m_CurrentState = EF_VTXPainterState.Sculpting;
                        }
                        else if (m_CurrentState == EF_VTXPainterState.Sculpting)
                        {
                            m_CurrentState = EF_VTXPainterState.None;
                        }
                    }

                    //if the escape key is pressed
                    if (curEvent.keyCode == KeyCode.Escape)
                    {
                        m_CurrentState = EF_VTXPainterState.None;
                    }

                    //Brush size keyboard control
                    if (curEvent.keyCode == KeyCode.LeftBracket)
                    {
                        m_BrushData.brushSize -= 0.2f;
                        if (m_BrushData.brushSize <= m_BrushData.falloffSize)
                        {
                            m_BrushData.falloffSize = m_BrushData.brushSize;
                        }
                        m_BrushData.brushSize = Mathf.Clamp(m_BrushData.brushSize, m_MinBrushSize, float.MaxValue);
                    }

                    if (curEvent.keyCode == KeyCode.RightBracket)
                    {
                        m_BrushData.brushSize += 0.2f;
                        m_BrushData.brushSize  = Mathf.Clamp(m_BrushData.brushSize, m_MinBrushSize, float.MaxValue);
                    }

                    if (curEvent.keyCode == KeyCode.Semicolon)
                    {
                        m_BrushData.falloffSize -= 0.2f;
                        m_BrushData.falloffSize  = Mathf.Clamp(m_BrushData.falloffSize, m_MinBrushSize, float.MaxValue);
                    }

                    if (curEvent.keyCode == KeyCode.Quote)
                    {
                        m_BrushData.falloffSize += 0.2f;
                        if (m_BrushData.falloffSize >= m_BrushData.brushSize)
                        {
                            m_BrushData.brushSize = m_BrushData.falloffSize;
                        }
                        m_BrushData.falloffSize = Mathf.Clamp(m_BrushData.falloffSize, m_MinBrushSize, float.MaxValue);
                    }

                    if (curEvent.keyCode == KeyCode.Equals)
                    {
                        m_BrushData.opacity += 0.02f;
                    }

                    if (curEvent.keyCode == KeyCode.Minus)
                    {
                        m_BrushData.opacity -= 0.02f;
                    }
                    m_BrushData.opacity = Mathf.Clamp01(m_BrushData.opacity);


                    if (curEvent.control)
                    {
                        m_BrushData.sculptDir = -1;
                    }
                }

                //Reset any keyboard data stuff here
                if (curEvent.type == EventType.KeyUp)
                {
                    m_BrushData.sculptDir = 1;
                }
            }
        }