foreach (var g in objectsToCut) { print(g); Vector3 position = transform.position; Vector3 originalPos = g.transform.position; Vector3 originalScale = g.transform.localScale; Quaternion originalRot = g.transform.rotation; var mf = g.transform.GetComponent<MeshFilter>(); var mr = g.transform.GetComponent<MeshRenderer>(); var mesh = mf.mesh; var subMeshCount = mesh.subMeshCount; var triangles = new List<int[]>(); var vertices = mesh.vertices; var normals = mesh.normals; var uv = mesh.uv; var mats = mr.materials; for (int i = 0; i < subMeshCount; i++) { triangles.Add(mesh.GetTriangles(i)); } Plane cutPlane = new(g.transform.InverseTransformDirection(cutNormal), g.transform.InverseTransformPoint(position)); var t = Task.Run(() => Cutter.AsyncCut(cutPlane, originalPos, originalRot, originalScale, mf, mr, mesh , subMeshCount, triangles, vertices, normals, uv, mats, g )); tasks.Add(t); }
public static TaskResult AsyncCut(Plane cutPlane, Vector3 originalPosition, Quaternion originalRotation, Vector3 originalScale, MeshFilter originalMeshFilter, MeshRenderer originalMeshRenderer, Mesh mesh, int subMeshCount, List<int[]> triangles , Vector3[] vertices , Vector3[] normals , Vector2[] uv, Material[] materials , GameObject originalObject )
public class TaskResult { public GeneratedMesh leftMesh; public GeneratedMesh rightMesh; public Vector3 position; public Quaternion rotation; public Vector3 scale; public Material[] materials; public MeshFilter originalMeshFilter; public MeshRenderer originalMeshRenderer; public GameObject originalObject; public TaskResult(GeneratedMesh leftMesh, GeneratedMesh rightMesh, Vector3 position, Quaternion rotation, Vector3 scale, Material[] materials , MeshFilter originalMeshFilter , MeshRenderer originalMeshRenderer , GameObject originalObject ) { this.leftMesh = leftMesh; this.rightMesh = rightMesh; this.position = position; this.rotation = rotation; this.scale = scale; this.materials = materials; this.originalMeshFilter = originalMeshFilter; this.originalMeshRenderer = originalMeshRenderer; this.originalObject = originalObject; } }
public async void FooAsync()
public async Task FooAsync()