예제 #1
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);
                }
            }
        }
예제 #2
0
    public static bool RayDirectedTriangleIntersect(GDirectedTriangle _triangle, GRay _ray, bool _rayDirectionCheck, bool _triangleDirectionCheck, out float distance)
    {
        if (!RayTriangleCalculate(_triangle[0], _triangle[1], _triangle[2], _ray.origin, _ray.direction, out distance, out float u, out float v))
        {
            return(false);
        }
        bool intersect = true;

        intersect &= !_rayDirectionCheck || distance > 0;
        intersect &= !_triangleDirectionCheck || Vector3.Dot(_triangle.normal, _ray.direction) < 0;
        return(intersect);
    }
예제 #3
0
 static Vector3[] RenegerateNormals(int[] _indices, Vector3[] _verticies)
 {
     Vector3[]      normals  = new Vector3[_verticies.Length];
     GMeshPolygon[] polygons = URender.GetPolygons(_indices);
     foreach (var polygon in polygons)
     {
         GDirectedTriangle triangle = polygon.GetDirectedTriangle(_verticies);
         Vector3           normal   = triangle.normal;
         foreach (var indice in polygon.indices)
         {
             normals[indice] += normal;
         }
     }
     normals = normals.ToArray(normal => normal.normalized);
     return(normals);
 }
예제 #4
0
        protected static int RayDirectedTriangleIntersect(GMeshPolygon[] _polygons, Vector3[] _verticies, GRay _ray, out Vector3 hitPoint, out GDirectedTriangle hitTriangle)
        {
            collisionPoint = Vector3.zero;
            float minDistance = float.MaxValue;
            int   index       = _polygons.LastIndex(p =>
            {
                GDirectedTriangle triangle = p.GetDirectedTriangle(_verticies);
                bool intersect             = UGeometry.RayDirectedTriangleIntersect(triangle, _ray, true, true, out float distance);
                if (intersect && minDistance > distance)
                {
                    collisionTriangle = triangle;
                    collisionPoint    = _ray.GetPoint(distance);
                    minDistance       = distance;
                    return(true);
                }
                return(false);
            });

            hitPoint    = collisionPoint;
            hitTriangle = collisionTriangle;
            return(index);
        }
예제 #5
0
 public static bool RayDirectedTriangleIntersect(GDirectedTriangle _triangle, GRay _ray, bool _rayDirectionCheck, bool _triangleDirectionCheck) => RayDirectedTriangleIntersect(_triangle, _ray, _rayDirectionCheck, _triangleDirectionCheck, out float distance);