Exemplo n.º 1
0
        private void ChangeMesh(ThreadableMesh mesh)
        {
            Mesh unityMesh = mesh;

            Filter.mesh = unityMesh;

            UnityEngine.Debug.Log(_timer.ElapsedMilliseconds);
            _timer.Stop();
        }
Exemplo n.º 2
0
        public static ThreadableMesh Build(VoxelData voxels)
        {
            List <Vector3> vertices  = new List <Vector3>();
            List <int>     triangles = new List <int>();
            List <Color>   colors    = new List <Color>();
            List <Vector2> uvs       = new List <Vector2>();
            List <Vector2> uvs1      = new List <Vector2> ();
            List <Vector3> normals   = new List <Vector3>();
            int            triIndex  = 0;

            for (int y = 0; y < voxels.Height; y++)
            {
                for (int z = 0; z < voxels.Depth; z++)
                {
                    for (int x = 0; x < voxels.Width; x++)
                    {
                        var voxel = voxels.GetVoxel(x, y, z);
                        if (voxel.Color.r == 0 && voxel.Color.g == 0 && voxel.Color.b == 0 && voxel.Color.a == 0)
                        {
                            continue;
                        }

                        // build
                        var cullingFaces = CalcCullingFaces(voxels, x, y, z);

                        if (cullingFaces == CullingFaces.All)
                        {
                            continue;
                        }

                        vertices.AddRange(MakeVertices(cullingFaces, x, y, z));
                        uvs.AddRange(MakeUVs(cullingFaces));
                        uvs1.AddRange(MakeTimeUvs(cullingFaces, voxel));
                        triangles.AddRange(MakeTriangles(cullingFaces, ref triIndex));
                        colors.AddRange(MakeColors(cullingFaces, voxel));
                        normals.AddRange(MakeNormals(cullingFaces, x, y, z));
                    }
                }
            }

            var mesh = new ThreadableMesh();

            mesh.Vertices  = vertices.ToArray();
            mesh.Triangles = triangles.ToArray();
            mesh.Colors    = colors.ToArray();
            mesh.Uvs1      = uvs1.ToArray();
            mesh.Uvs       = uvs.ToArray();
            mesh.Normals   = normals.ToArray();
            mesh.RecalculateTangets();// = tangets.ToArray();
            return(mesh);
        }