Exemplo n.º 1
0
 /// <summary>
 /// Creates a new voxel chunk mesher.
 /// </summary>
 /// <param name="chunkProperties">The chunk properties to handle.</param>
 /// <param name="greedyMesher">The greedy mesher to use.</param>
 internal VoxelChunkMesher(ChunkProperties chunkProperties, GreedyMesher greedyMesher)
 {
     m_ChunkProperties = chunkProperties;
     m_GreedyMesher    = greedyMesher;
     m_Mesh            = new ProcMesh();
     m_Task            = Task.Run(Remesh);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Runs a greedy meshing algorithm over a single axis.
        /// </summary>
        /// <param name="offset">The offset along the plane axis.</param>
        /// <param name="side">The side of the block being targeted.</param>
        /// <param name="mesh">The proc mesh to add the vertices to.</param>
        public void Mesh(int offset, int side, ProcMesh mesh)
        {
            m_QuadBuilder.Mesh = mesh;

            foreach (var q in PlaneIterator())
            {
                if (!q.Quad.Active)
                {
                    continue;
                }

                FindNextQuad(q, out int w, out int h);

                var quadMesh = new QuadBuilder.QuadMesh
                {
                    X               = q.X,
                    Y               = q.Y,
                    W               = w - q.X + 1,
                    H               = h - q.Y + 1,
                    Side            = side,
                    Offset          = offset,
                    TextureIndex    = q.Quad.TextureIndex,
                    TextureRotation = q.Quad.Rotation,
                };

                m_QuadBuilder.WriteQuad(quadMesh);
                ClearQuad(q, w, h);
            }

            m_QuadBuilder.Mesh = null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Applies the vertex data from the given proc mesh to the target Unity mesh.
        /// </summary>
        /// <param name="root">The generated mesh.</param>
        /// <param name="mesh">The target mesh.</param>
        private void AssignVertexData(ProcMesh root, Mesh mesh)
        {
            mesh.SetVertices(root.Vertices.Select(v => new Vector3(v.X, v.Y, v.Z)).ToList());

            if (root.Normals.Count > 0)
            {
                mesh.SetNormals(root.Normals.Select(v => new Vector3(v.X, v.Y, v.Z)).ToList());
            }

            if (root.UVs.Count > 0)
            {
                mesh.SetUVs(0, root.UVs.Select(v => new Vector3(v.X, v.Y, v.Z)).ToList());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Compiles the vertex data from a layered proc mesh into a single layered mesh.
        /// </summary>
        /// <param name="procMesh">The layered proc mesh.</param>
        /// <returns>The single layered mesh.</returns>
        private ProcMesh CompileRootMesh(LayeredProcMesh procMesh)
        {
            ProcMesh root = new ProcMesh();

            for (int i = 0; i < procMesh.TotalLayers; i++)
            {
                var layer = procMesh.GetLayer(i);
                root.Vertices.AddRange(layer.Vertices);
                root.Normals.AddRange(layer.Normals);
                root.UVs.AddRange(layer.UVs);
            }

            return(root);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new chunk mesh builder.
 /// </summary>
 /// <param name="blockList">The block list to read from.</param>
 internal ChunkMeshBuilder(BlockListManager blockList)
 {
     m_BlockList = blockList;
     m_ProcMesh  = new ProcMesh();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new chunk mesh builder.
 /// </summary>
 /// <param name="blockWorld">The block world this mesh builder is acting on.</param>
 internal ChunkMeshBuilder(BlockWorld blockWorld)
 {
     m_BlockWorld = blockWorld;
     m_ProcMesh   = new ProcMesh();
 }