Exemple #1
0
        public FinalizeBuild ScheduleBuild()
        {
            NeedsRebuild = false;

            var meshVertices  = new NativeList <float3>(Allocator.TempJob);
            var meshNormals   = new NativeList <float3>(Allocator.TempJob);
            var meshTriangles = new NativeList <int>(Allocator.TempJob);
            var meshColors    = new NativeList <Color32>(Allocator.TempJob);
            var meshMaterials = new NativeList <int>(Allocator.TempJob);

            ChunkBuildJob <TIndexer> polygonizerJob = new ChunkBuildJob <TIndexer>
            {
                Voxels = voxels,
                PolygonizationProperties = world.CMSProperties.Data,
                MeshVertices             = meshVertices,
                MeshNormals   = meshNormals,
                MeshTriangles = meshTriangles,
                MeshColors    = meshColors,
                MeshMaterials = meshMaterials,
            };

            var handle = polygonizerJob.Schedule();

            return(() =>
            {
                handle.Complete();

                var vertices = new List <Vector3>(meshVertices.Length);
                var indices = new List <int>(meshTriangles.Length);
                var materials = new List <int>(meshMaterials.Length);
                var colors = new List <Color32>(meshColors.Length);
                var normals = new List <Vector3>(meshNormals.Length);

                for (int i = 0; i < meshVertices.Length; i++)
                {
                    vertices.Add(meshVertices[i]);
                }
                for (int i = 0; i < meshTriangles.Length; i++)
                {
                    indices.Add(meshTriangles[i]);
                }
                for (int i = 0; i < meshMaterials.Length; i++)
                {
                    materials.Add(meshMaterials[i]);
                }
                for (int i = 0; i < meshColors.Length; i++)
                {
                    colors.Add(meshColors[i]);
                }
                for (int i = 0; i < meshNormals.Length; i++)
                {
                    normals.Add(meshNormals[i]);
                }

                meshVertices.Dispose();
                meshNormals.Dispose();
                meshTriangles.Dispose();
                meshColors.Dispose();
                meshMaterials.Dispose();

                if (mesh == null)
                {
                    mesh = new Mesh();
                }

                mesh.Clear(false);
                mesh.SetVertices(vertices);
                mesh.SetNormals(normals);
                mesh.SetTriangles(indices, 0);
                if (colors.Count > 0)
                {
                    mesh.SetColors(colors);
                }
            });
        }
Exemple #2
0
 public void FillCell(int x, int y, int z, int cellIndex, NativeArray <int> materials, NativeArray <float> intersections, NativeArray <float3> normals)
 {
     ChunkBuildJob <TIndexer> .FillCell(voxels, x, y, z, cellIndex, materials, intersections, normals);
 }