Exemple #1
0
        private void Triangulate(DecalProjection projection, MeshBuilder builder, ref List <ClipPointData> polygon)
        {
            List <Vector3> vertices = builder.Vertices;
            int            index    = polygon[0].index;
            Vector3        vector   = vertices[index];

            for (int i = 2; i < polygon.Count; i++)
            {
                ClipPointData data2   = polygon[i - 1];
                int           num3    = data2.index;
                ClipPointData data3   = polygon[i];
                int           num4    = data3.index;
                Vector3       vector2 = vertices[num3];
                Vector3       vector3 = vertices[num4];
                Ray           ray     = projection.Ray;
                Vector3       vector4 = Vector3.Cross(vector - vector2, vector - vector3);
                if (Vector3.Dot(-ray.direction, vector4.normalized) > 0f)
                {
                    builder.AddTriangle(index, num3, num4);
                }
                else
                {
                    builder.AddTriangle(index, num4, num3);
                }
            }
        }
Exemple #2
0
 private void AddAllPolygonPointsAndTransformToWorld(MeshBuilder builder, ref List <ClipPointData> polygon, Quaternion rotation, Vector3 position)
 {
     for (int i = 0; i < polygon.Count; i++)
     {
         ClipPointData data   = polygon[i];
         Vector3       vertex = data.vertexData.vertex;
         vertex = ((Vector3)(rotation * vertex)) + position;
         data.vertexData.vertex = vertex;
         data.index             = builder.AddVertex(data.vertexData);
         polygon[i]             = data;
     }
 }
        private bool GetIntersect(ClipPointData fromPoint, ClipPointData toPoint, Vector2 clipEdgeFrom, Vector2 clipEdgeTo, out ClipPointData resultPoint)
        {
            Vector2 vector  = toPoint.point2D - fromPoint.point2D;
            Vector2 vector2 = clipEdgeTo - clipEdgeFrom;
            float   a       = (vector.x * vector2.y) - (vector.y * vector2.x);

            if (Mathf.Approximately(a, 0f))
            {
                resultPoint = new ClipPointData();
                return(false);
            }
            Vector2 vector3    = clipEdgeFrom - fromPoint.point2D;
            float   lerpFactor = ((vector3.x * vector2.y) - (vector3.y * vector2.x)) / a;

            resultPoint = ClipPointData.Lerp(fromPoint, toPoint, lerpFactor);
            return(true);
        }
Exemple #4
0
        private bool ClipByDepth(ClipEdge2D[] clipPlane, float depthTest, ref List <ClipPointData> polygon)
        {
            bool flag = false;

            for (int i = 0; i < polygon.Count; i++)
            {
                ClipPointData data   = polygon[i];
                Vector3       vertex = data.vertexData.vertex;
                if ((vertex.z > depthTest) || (vertex.z < -depthTest))
                {
                    flag = true;
                }
                polygon[i] = data.ToDepthSpace();
            }
            if (flag)
            {
                polygon = this.polygonClipper.GetIntersectedPolygon(polygon, clipPlane);
            }
            return(polygon.Count > 2);
        }
Exemple #5
0
 public static ClipPointData Lerp(ClipPointData from, ClipPointData to, float lerpFactor) =>
 new ClipPointData
 {
     point2D    = Vector2.LerpUnclamped(from.point2D, to.point2D, lerpFactor),
     vertexData = VertexData.Lerp(from.vertexData, to.vertexData, lerpFactor)
 };