/// <summary> /// Add mesh data to the given mesh for a voxel in the given chunk at the given localPosition. Renders at the given position with the given size /// </summary> /// <param name="addToMeshData">The mesh to add the voxel to</param> /// <param name="chunk">The chunk the voxel is in</param> /// <param name="localPosition">The position in the chunk of the voxel</param> /// <param name="position">The position in the scene to render at</param> /// <param name="voxelSize">The size of the voxel</param> public override void AddMeshData(MeshData addToMeshData, Chunk chunk, IntVector3 localPosition, Vector3 position, float voxelSize) { // Ensure we have faces if (!VoxelData.Faces.HasAny) { return; } // Gather visibility data OrdinalBoolean visibility = new OrdinalBoolean(); visibility.IsUp = !chunk.IsSolid(localPosition.X, localPosition.Y + 1, localPosition.Z, OrdinalDirections.Down); visibility.IsDown = !chunk.IsSolid(localPosition.X, localPosition.Y - 1, localPosition.Z, OrdinalDirections.Up); visibility.IsNorth = !chunk.IsSolid(localPosition.X, localPosition.Y, localPosition.Z + 1, OrdinalDirections.South); visibility.IsSouth = !chunk.IsSolid(localPosition.X, localPosition.Y, localPosition.Z - 1, OrdinalDirections.North); visibility.IsEast = !chunk.IsSolid(localPosition.X + 1, localPosition.Y, localPosition.Z, OrdinalDirections.West); visibility.IsWest = !chunk.IsSolid(localPosition.X - 1, localPosition.Y, localPosition.Z, OrdinalDirections.East); // Create the actual data for the appropriate style switch (Style) { case VoxelStyle.Block: BlockMesher.CreateComplexBlockMeshData(addToMeshData, position, Orientation, Rotation, visibility, VoxelData, voxelSize); break; case VoxelStyle.Wedge: BlockMesher.CreateComplexWedgeMeshData(addToMeshData, position, Orientation, Rotation, visibility, VoxelData, voxelSize); break; case VoxelStyle.Corner: BlockMesher.CreateComplexCornerMeshData(addToMeshData, position, Orientation, Rotation, visibility, VoxelData, voxelSize); break; case VoxelStyle.InverseCorner: BlockMesher.CreateComplexInverseCornerMeshData(addToMeshData, position, Orientation, Rotation, visibility, VoxelData, voxelSize); break; default: BlockMesher.CreateSimpleBlockMeshData(addToMeshData, position, visibility, VoxelData, voxelSize); break; } }
/// <summary> /// Add mesh data to the given mesh for a voxel in the given chunk at the given localPosition. Renders at the given position with the given size /// </summary> /// <param name="addToMeshData">The mesh to add the voxel to</param> /// <param name="chunk">The chunk the voxel is in</param> /// <param name="localPosition">The position in the chunk of the voxel</param> /// <param name="position">The position in the scene to render at</param> /// <param name="voxelSize">The size of the voxel</param> public virtual void AddMeshData(MeshData addToMeshData, Chunk chunk, IntVector3 localPosition, Vector3 position, float voxelSize) { // Ensure we have faces if (!VoxelData.Faces.HasAny) { return; } // Gather visibility data OrdinalBoolean visibility = new OrdinalBoolean(); visibility.IsUp = !chunk.IsSolid(localPosition.X, localPosition.Y + 1, localPosition.Z, OrdinalDirections.Down); visibility.IsDown = !chunk.IsSolid(localPosition.X, localPosition.Y - 1, localPosition.Z, OrdinalDirections.Up); visibility.IsNorth = !chunk.IsSolid(localPosition.X, localPosition.Y, localPosition.Z + 1, OrdinalDirections.South); visibility.IsSouth = !chunk.IsSolid(localPosition.X, localPosition.Y, localPosition.Z - 1, OrdinalDirections.North); visibility.IsEast = !chunk.IsSolid(localPosition.X + 1, localPosition.Y, localPosition.Z, OrdinalDirections.West); visibility.IsWest = !chunk.IsSolid(localPosition.X - 1, localPosition.Y, localPosition.Z, OrdinalDirections.East); // Create the actual data BlockMesher.CreateSimpleBlockMeshData(addToMeshData, position, visibility, VoxelData, voxelSize); }