Represents a voxel mesh structure stored in vertex buffer.
Beispiel #1
0
        /// <summary>
        /// Computes interpolated vertex on a cube edge between two voxels.
        /// </summary>
        /// <param name="v1">First voxel.</param>
        /// <param name="v2">Second voxel.</param>
        /// <returns>Interpolated vertex.</returns>
        private static VoxelMeshVertex ComputeEdge(Voxel v1, Voxel v2)
        {
            VoxelMeshVertex vertex = new VoxelMeshVertex();

            float interpolation = (seekValue - v1.Weight) / (v2.Weight - v1.Weight);

            if (interpolation >= 0 && interpolation <= 1)
            {
                vertex.Position = v1.Position + (v2.Position - v1.Position) * interpolation;
                vertex.Normal   = v1.Normal + (v2.Normal - v1.Normal) * interpolation;
                vertex.Ambient  = v1.Ambient + (v2.Ambient - v1.Ambient) * interpolation;
            }

            return(vertex);
        }
Beispiel #2
0
        /// <summary>
        /// Computes interpolated vertices on all cube edges.
        /// </summary>
        /// <param name="voxels">Voxels representing a cube.</param>
        /// <returns>Array of interpolated vertices.</returns>
        private static VoxelMeshVertex[] ComputeEdges(Voxel[] voxels)
        {
            VoxelMeshVertex[] interpolatedVertices = new VoxelMeshVertex[12];

            interpolatedVertices[0]  = ComputeEdge(voxels[0], voxels[1]);
            interpolatedVertices[1]  = ComputeEdge(voxels[1], voxels[2]);
            interpolatedVertices[2]  = ComputeEdge(voxels[2], voxels[3]);
            interpolatedVertices[3]  = ComputeEdge(voxels[3], voxels[0]);
            interpolatedVertices[4]  = ComputeEdge(voxels[4], voxels[5]);
            interpolatedVertices[5]  = ComputeEdge(voxels[5], voxels[6]);
            interpolatedVertices[6]  = ComputeEdge(voxels[6], voxels[7]);
            interpolatedVertices[7]  = ComputeEdge(voxels[7], voxels[4]);
            interpolatedVertices[8]  = ComputeEdge(voxels[0], voxels[4]);
            interpolatedVertices[9]  = ComputeEdge(voxels[1], voxels[5]);
            interpolatedVertices[10] = ComputeEdge(voxels[3], voxels[7]);
            interpolatedVertices[11] = ComputeEdge(voxels[2], voxels[6]);

            return(interpolatedVertices);
        }
Beispiel #3
0
        /// <summary>
        /// Computes interpolated vertices on all cube edges.
        /// </summary>
        /// <param name="voxels">Voxels representing a cube.</param>
        /// <returns>Array of interpolated vertices.</returns>
        private static VoxelMeshVertex[] ComputeEdges(Voxel[] voxels)
        {
            VoxelMeshVertex[] interpolatedVertices = new VoxelMeshVertex[12];

            interpolatedVertices[0] = ComputeEdge(voxels[0], voxels[1]);
            interpolatedVertices[1] = ComputeEdge(voxels[1], voxels[2]);
            interpolatedVertices[2] = ComputeEdge(voxels[2], voxels[3]);
            interpolatedVertices[3] = ComputeEdge(voxels[3], voxels[0]);
            interpolatedVertices[4] = ComputeEdge(voxels[4], voxels[5]);
            interpolatedVertices[5] = ComputeEdge(voxels[5], voxels[6]);
            interpolatedVertices[6] = ComputeEdge(voxels[6], voxels[7]);
            interpolatedVertices[7] = ComputeEdge(voxels[7], voxels[4]);
            interpolatedVertices[8] = ComputeEdge(voxels[0], voxels[4]);
            interpolatedVertices[9] = ComputeEdge(voxels[1], voxels[5]);
            interpolatedVertices[10] = ComputeEdge(voxels[3], voxels[7]);
            interpolatedVertices[11] = ComputeEdge(voxels[2], voxels[6]);

            return interpolatedVertices;
        }
Beispiel #4
0
        /// <summary>
        /// Computes interpolated vertex on a cube edge between two voxels.
        /// </summary>
        /// <param name="v1">First voxel.</param>
        /// <param name="v2">Second voxel.</param>
        /// <returns>Interpolated vertex.</returns>
        private static VoxelMeshVertex ComputeEdge(Voxel v1, Voxel v2)
        {
            VoxelMeshVertex vertex = new VoxelMeshVertex();

            float interpolation = (seekValue - v1.Weight) / (v2.Weight - v1.Weight);

            if (interpolation >= 0 && interpolation <= 1)
            {
                vertex.Position = v1.Position + (v2.Position - v1.Position) * interpolation;
                vertex.Normal = v1.Normal + (v2.Normal - v1.Normal) * interpolation;
                vertex.Ambient = v1.Ambient + (v2.Ambient - v1.Ambient) * interpolation;
            }

            return vertex;
        }