Exemple #1
0
        protected override void BuildMeshComponents()
        {
            Vector2 center = MeshHelper.GetCenter(SplinePoints);

            for (int i = 0; i < SplinePoints.Length; i++)
            {
                SplinePoints[i] -= center;
            }

            var points = CatmullRomSpline.GetPoints(MeshHelper.ConvertVec2ToVec3(SplinePoints), Resolution);

            if (MinArea.HasValue)
            {
                points = SplineSimplification.Simplify(points, MinArea.Value, true, false);
            }
            Vertices = points.ToArray();

            var connections = Triangulation.TriangulationToInt3(new List <Vector2>(MeshHelper.ConvertVec3ToVec2(Vertices)));

            Triangles = new int[connections.Count * 3];
            for (int i = 0; i < connections.Count; i++)
            {
                Triangles[i * 3 + 0] = connections[i].A;
                Triangles[i * 3 + 1] = connections[i].B;
                Triangles[i * 3 + 2] = connections[i].C;
            }

            UVs = MeshHelper.UVUnwrap(Vertices);
        }
 public override void UpdateCollider()
 {
     if (UseDoubleCollider)
     {
         C_PC2D.points = MeshHelper.ConvertVec3ToVec2(Vertices);
     }
     else
     {
         C_EC2D.points = CatmullRomSpline.GetPoints(SplinePoints, Resolution, false).ToArray();
     }
 }
        public override void UpdateCollider()
        {
            if (useCircleCollider)
            {
                ((CircleCollider2D)C_C2D).radius = radius;
            }

            else
            {
                ((PolygonCollider2D)C_C2D).SetPath(0, MeshHelper.ConvertVec3ToVec2(Vertices));
            }
        }
        public override void UpdateCollider()
        {
            if (UseCircleCollider)
            {
                C_CC2D.radius = Radius;
            }

            else
            {
                C_PC2D.SetPath(0, MeshHelper.ConvertVec3ToVec2(Vertices));
            }
        }
Exemple #5
0
        protected override void BuildMeshComponents()
        {
            BaseVertices = ConvexVertices;

            Vertices = MeshHelper.ConvertVec2ToVec3(ConvexHull.QuickHull(MeshHelper.ConvertVec3ToVec2(ConvexVertices)).ToArray()); // oh no

            Triangles = new int[Vertices.Length * 3];

            for (int i = 1; i < Vertices.Length - 1; i++)
            {
                Triangles[i * 3 + 0] = 0;
                Triangles[i * 3 + 1] = i;
                Triangles[i * 3 + 2] = i + 1;
            }
            UVs = MeshHelper.UVUnwrap(Vertices);
        }
Exemple #6
0
        public static TriangulatedMesh ConvertToTriangulatedMesh(TriangulableMesh sourceMeshScript)
        {
            //check if mesh is already a triangulated one
            if (sourceMeshScript.GetType() == triangulatedMeshType)
            {
                return(sourceMeshScript.GetComponent <TriangulatedMesh>());
            }

            Object.DestroyImmediate(sourceMeshScript.GetComponent <Collider2D>());
            TriangulatedMesh triangulatedMesh = sourceMeshScript.gameObject.AddComponent <TriangulatedMesh>();

            Vector2[] points = MeshHelper.ConvertVec3ToVec2(sourceMeshScript.GetTriangulableVertices());
            List <Triangulation.IntTriple> connections = Triangulation.TriangulationToInt3(new List <Vector2>(points));

            triangulatedMesh.Build(points, connections, sourceMeshScript.C_MR.sharedMaterial);

            //delete base component
            Object.DestroyImmediate(sourceMeshScript);

            return(triangulatedMesh);
        }
Exemple #7
0
 public override void UpdateCollider()
 {
     C_PC2D.points = MeshHelper.ConvertVec3ToVec2(Vertices);
 }
 public override void UpdateCollider()
 {
     C_PC2D.SetPath(0, MeshHelper.ConvertVec3ToVec2(Vertices));
 }
 //convert to quad
 public QuadrangleMesh ToQuad(bool attachRigidbody = true)
 {
     return(QuadrangleMesh.AddQuadrangle(transform.position, MeshHelper.ConvertVec3ToVec2(Vertices), Space.World, C_MR.material, attachRigidbody));
 }