Пример #1
0
        void OnInteractGUI(SceneView _sceneView, GameObject _meshObject)
        {
            Handles.color = GetPaintColor(m_PaintColor);
            if (m_PaintPosition != Vector3.zero)
            {
                Handles_Extend.DrawWireSphere(m_PaintPosition, Quaternion.identity, m_PaintSize);
            }

            if (Event.current.type == EventType.MouseMove)
            {
                Vector3 cameraLocal = _meshObject.transform.worldToLocalMatrix.MultiplyPoint(_sceneView.camera.transform.position);
                if (RayDirectedTriangleIntersect(m_Polygons, m_ModifingMesh.vertices, ObjLocalSpaceRay(_sceneView, _meshObject), out Vector3 hitPosition, out GDirectedTriangle hitTriangle) != -1)
                {
                    m_PaintPosition = hitPosition;
                    m_PaintAffectedIndices.Clear();
                    float sqrRaidus = m_PaintSize * m_PaintSize;
                    m_Verticies.FindAllIndexes(m_PaintAffectedIndices, (index, p) => {
                        bool normalPassed = false;
                        switch (m_PaintNormal)
                        {
                        case enum_PaintNormal.ViewNormal: normalPassed = Vector3.Dot(m_Normals[index], p - cameraLocal) < 0; break;

                        case enum_PaintNormal.TriangleNormal: normalPassed = Vector3.Dot(m_Normals[index], hitTriangle.normal) > 0; break;

                        case enum_PaintNormal.Every: normalPassed = true; break;
                        }
                        return(normalPassed && (hitPosition - p).sqrMagnitude < sqrRaidus);
                    });
                }
            }

            if (!m_AvailableDatas)
            {
                return;
            }
            if (Event.current.type == EventType.MouseDown)
            {
                int button = Event.current.button;
                if (button != 0 && button != 2)
                {
                    return;
                }
                switch (m_PaintMode)
                {
                default: throw new Exception("Invalid Type:" + m_PaintMode);

                case enum_PaintMode.Const:
                    m_PaintAffectedIndices.Traversal(index => m_VertexDatas[index] = ApplyModify(m_VertexDatas[index], m_PaintValue, m_PaintMode, m_PaintColor));
                    break;

                case enum_PaintMode.Modify:
                    float value = button == 0 ? m_PaintValue : -m_PaintValue;
                    m_PaintAffectedIndices.Traversal(index => m_VertexDatas[index] = ApplyModify(m_VertexDatas[index], value, m_PaintMode, m_PaintColor));
                    break;
                }
                OnDataChange();
            }
        }
Пример #2
0
        void OnDrawSceneHandles(SceneView _sceneView)
        {
            Handles.color = Color.white.SetAlpha(.5f);
            Handles.DrawWireCube(m_ModifingMesh.bounds.center, m_ModifingMesh.bounds.size * 1.2f);

            if (!m_SelectingPolygon)
            {
                return;
            }

            GMeshPolygon _mainPolygon = m_Polygons[m_SelectedPolygon];

            foreach (var subPolygon in m_SubPolygons)
            {
                GDirectedTriangle directedTriangle = m_Polygons[subPolygon].GetDirectedTriangle(m_Verticies);
                if (Vector3.Dot(directedTriangle.normal, _sceneView.camera.transform.forward) > 0)
                {
                    continue;
                }
                Handles.color = Color.yellow.SetAlpha(.1f);
                Handles.DrawAAConvexPolygon(directedTriangle.triangle.verticies);
                Handles.color = Color.yellow;
                Handles.DrawLines(directedTriangle.triangle.GetDrawLinesVerticies());
            }
            GTriangle mainTriangle = _mainPolygon.GetTriangle(m_Verticies);

            Handles.color = Color.green.SetAlpha(.3f);
            Handles.DrawAAConvexPolygon(mainTriangle.verticies);
            Handles.color = Color.green;
            Handles.DrawLines(mainTriangle.GetDrawLinesVerticies());

            if (!m_EditingVectors)
            {
                return;
            }
            Handles.color = Color.green;
            foreach (var indice in _mainPolygon.indices)
            {
                Handles_Extend.DrawArrow(m_Verticies[indice], m_VertexDatas[indice], .1f * m_GUISize, .01f * m_GUISize);
                if (m_SelectedVertexIndex == indice)
                {
                    continue;
                }
                Handles_Extend.DrawWireSphere(m_Verticies[indice], m_VertexDatas[indice], C_VertexSphereRadius * m_GUISize);
            }
            Handles.color = Color.yellow;
            foreach (var subPolygon in m_SubPolygons)
            {
                foreach (var indice in m_Polygons[subPolygon].indices)
                {
                    Handles.DrawLine(m_Verticies[indice], m_Verticies[indice] + m_VertexDatas[indice] * .03f * m_GUISize);
                }
            }
        }