public void Update(VoxelMeshBuilder builder) { float[] vertices, colors, normals, lighting; uint[] indexes; int indexCount; builder.Finalize(out vertices, out colors, out normals, out lighting, out indexes, out indexCount); Update(vertices, indexes, colors, normals, lighting, indexCount); }
public virtual void BuildMesh(BufferUsageHint bufferUsage) { for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { for (int z = 0; z < Depth; z++) { Block block = Blocks[z, y, x]; if (block != Block.AIR) { Color4 voxelColor = block.GetColor4(); VoxelMeshBuilder useBuilder = voxelColor.A < 1f ? alphaBuilder : meshBuilder; IndexPosition blockIndex = new IndexPosition(x, y, z); Vector3 blockPos = new Vector3(x, y, z); Vector3 off = blockPos * useBuilder.CubeSize; bool blockAbove = !IsBlockTransparent(x, y + 1, z); bool blockBelow = !IsBlockTransparent(x, y - 1, z); bool blockLeft = !IsBlockTransparent(x - 1, y, z); bool blockForward = !IsBlockTransparent(x, y, z + 1); bool blockBackward = !IsBlockTransparent(x, y, z - 1); bool blockRight = !IsBlockTransparent(x + 1, y, z); if (blockAbove && blockBelow && blockLeft && blockForward && blockBackward && blockRight) { continue; } //VoxelAO ao = aoBuilder.Calculate(block, x, y, z, off, useBuilder); if (!blockLeft) { useBuilder.AddLeft(block, blockIndex, off, voxelColor); } if (!blockRight) { useBuilder.AddRight(block, blockIndex, off, voxelColor); } if (!blockBackward) { useBuilder.AddBack(block, blockIndex, off, voxelColor); } if (!blockForward) { useBuilder.AddFront(block, blockIndex, off, voxelColor); } if (!blockAbove) { useBuilder.AddTop(block, blockIndex, off, voxelColor); } if (!blockBelow) { useBuilder.AddBottom(block, blockIndex, off, voxelColor); } } } } } this.CreateOrUpdateMesh(bufferUsage); }
protected virtual void CreateMeshBuilders(float cubeSize) { meshBuilder = new VoxelMeshBuilder(this, cubeSize, 0.6f); alphaBuilder = new VoxelMeshBuilder(this, cubeSize, 0.6f); }
public VoxelMesh(BufferUsageHint usageHint, VoxelMeshBuilder builder) : base(usageHint, 4) { CreateBuffers(); Update(builder); }