public NativePlainMesh(NativePlainMesh a, NativePlainMesh b, Allocator allocator) { int aVxLen = a.vertices.Length; int bVxLen = b.vertices.Length; var vxs = new NativeArray <Vector3>(aVxLen + bVxLen, allocator); vxs.Slice(0, aVxLen).CopyFrom(a.vertices.Slice(0, aVxLen)); vxs.Slice(aVxLen, bVxLen).CopyFrom(b.vertices.Slice(0, bVxLen)); int aTrLen = a.triangles.Length; int bTrLen = b.triangles.Length; var trs = new NativeArray <int>(aTrLen + bTrLen, allocator); trs.Slice(0, aTrLen).CopyFrom(a.triangles.Slice(0, aTrLen)); trs.Slice(aTrLen, bTrLen).CopyFrom(b.triangles.Slice(0, bTrLen)); for (int i = aTrLen; i < aTrLen + bTrLen; ++i) { int prevIndex = trs[i]; trs[i] = prevIndex + aVxLen; } this.vertices = vxs; this.triangles = trs; }
public void Add(NativePlainMesh mesh) { var vertexLayout = new MeshLayout.Layout(this.vertices.Count, mesh.vertices.Length); var indexLayout = new MeshLayout.Layout(this.indices.Count, mesh.triangles.Length); this.vertices.Add(mesh.vertices); this.indices.Add(mesh.triangles); this.layouts.Add(new MeshLayout(vertexLayout, indexLayout)); }
public static NativePlainMesh Build(Shape shape, float depth, Allocator allocator) { var edges = Convert(shape.triangles, shape.paths, Allocator.Temp); int n = edges.Length; var vertices = new NativeArray <Vector3>(4 * n, allocator); var triangles = new NativeArray <int>(6 * n, allocator); int ti = 0; float r = 0.5f * depth; for (int i = 0, j = 0; i < edges.Length; ++i) { var edge = edges[i]; var a = shape.points[edge.a]; var b = shape.points[edge.b]; var dir = (b - a).normalized * r; var normal = new Vector2(-dir.y, dir.x); triangles[ti++] = j; triangles[ti++] = j + 1; triangles[ti++] = j + 2; triangles[ti++] = j; triangles[ti++] = j + 2; triangles[ti++] = j + 3; var a0 = new Vector3(a.x - normal.x, a.y - normal.y); var a1 = new Vector3(a.x + normal.x, a.y + normal.y); var b1 = new Vector3(b.x + normal.x, b.y + normal.y); var b0 = new Vector3(b.x - normal.x, b.y - normal.y); vertices[j++] = a0; vertices[j++] = a1; vertices[j++] = b1; vertices[j++] = b0; } var nativeMesh = new NativePlainMesh { vertices = vertices, triangles = triangles }; return(nativeMesh); }