示例#1
0
        private void CreateWorldGround()
        {
            DefaultMesh mesh = new DefaultMesh();

            Vector3I negativeWorldSize = ((-_worldSize / 2) * Constant.ChunkSize);

            negativeWorldSize.Y = 0;
            Vector3I positiveWorldSize = ((_worldSize / 2) * Constant.ChunkSize);

            positiveWorldSize.Y = _worldSize.Y * Constant.ChunkSizeY;

            mesh.Position.Add(new Vector3(positiveWorldSize.X - 0.5f, -0.5f, negativeWorldSize.Z - 0.5f)); //0
            mesh.Position.Add(new Vector3(positiveWorldSize.X - 0.5f, -0.5f, positiveWorldSize.Z - 0.5f)); //1
            mesh.Position.Add(new Vector3(negativeWorldSize.X - 0.5f, -0.5f, positiveWorldSize.Z - 0.5f)); //2
            mesh.Position.Add(new Vector3(negativeWorldSize.X - 0.5f, -0.5f, negativeWorldSize.Z - 0.5f)); //3

            mesh.TexCoord.Add(new Vector2(0, 0));
            mesh.TexCoord.Add(new Vector2(_worldSize.X * Constant.ChunkSizeX, 0));
            mesh.TexCoord.Add(new Vector2(_worldSize.X * Constant.ChunkSizeX, _worldSize.Z * Constant.ChunkSizeZ));
            mesh.TexCoord.Add(new Vector2(0, _worldSize.Z * Constant.ChunkSizeZ));

            mesh.Normal.Add(-Vector3.UnitY);
            mesh.Normal.Add(-Vector3.UnitY);
            mesh.Normal.Add(-Vector3.UnitY);
            mesh.Normal.Add(-Vector3.UnitY);

            mesh.IDs.Add(0);
            mesh.IDs.Add(2);
            mesh.IDs.Add(1);
            mesh.IDs.Add(0);
            mesh.IDs.Add(3);
            mesh.IDs.Add(2);

            mesh = mesh.Transform(Matrix4x4.CreateScale(_voxelSize));

            _groundGeometry      = VAOLoader.FromMesh(mesh, _geometryShader);
            _groundDepthGeometry = VAOLoader.FromMesh(mesh, _depthShader);
        }
示例#2
0
 public VoxelMesh Transform(Matrix4x4 transform)
 {
     return(new VoxelMesh(this, DefaultMesh.Transform(transform)));
 }