예제 #1
0
 public void deleteInternal(VoxelSurface voxelSurface)
 {
     if (!voxelSurface.IsDestroyed)
     {
         throw new InvalidOperationException();
     }
     surfaces.Remove(voxelSurface);
 }
예제 #2
0
        public VoxelSurface CreateSurface(AbstractHermiteGrid grid, Matrix world)
        {
            var vertices  = new List <Vector3>();
            var indices   = new List <int>();
            var materials = new List <DCVoxelMaterial>();

            var algo = new DualContouringAlgorithm();

            algo.GenerateSurface(vertices, indices, materials, grid);


            var triangleNormals = dcMeshBuilder.generateTriangleNormals(indices, vertices);

            var uniqueMaterials = materials.Distinct().ToArray();

            if (!uniqueMaterials.Any())
            {
                return new VoxelSurface(this)
                       {
                           WorldMatrix = world
                       }
            }
            ;


            var ret = new VoxelSurface(this);

            ret.WorldMatrix = world;
            surfaces.Add(ret);


            foreach (var imat in uniqueMaterials)
            {
                var mat = imat;


                var mesh = new RawMeshData(
                    indices.Where((i, index) => materials[index / 3] == mat).Select(i => vertices[i].dx()).ToArray(),
                    indices.Select((i, index) => triangleNormals[index / 3].dx()).Where((i, index) => materials[index / 3] == mat).ToArray(),
                    indices.Where((i, index) => materials[index / 3] == mat).Select(i => new Vector2().dx()).ToArray(),
                    indices.Where((i, index) => materials[index / 3] == mat).Select(i => new Vector3().dx()).ToArray()
                    );

                var actualMat = mat;
                if (actualMat == null)
                {
                    actualMat = defaultMaterial;
                }
                ret.MeshesWithMaterial.Add(new MeshWithMaterial(mesh, actualMat, renderDataFactory.CreateMeshPartData(mesh)));
            }

            return(ret);
        }