Ejemplo n.º 1
0
        /// <summary>
        /// Looks for all visual mesh tasks and writes the generated meshes to the chunk.
        /// </summary>
        /// <param name="taskStack">The task stack.</param>
        /// <param name="chunk">The chunk to update.</param>
        private void UpdateVisualMesh(RemeshTaskStack taskStack, BlockChunk chunk)
        {
            var meshFilter   = chunk.GetComponent <MeshFilter>();
            var meshRenderer = chunk.GetComponent <MeshRenderer>();
            var visualMesh   = meshFilter.sharedMesh;

            ApplyVertexData <VisualRemeshTask>(taskStack, visualMesh);

            var materials = new Material[visualMesh.subMeshCount];

            int baseVertex   = 0;
            int submeshIndex = 0;

            for (int i = 0; i < taskStack.TaskCount; i++)
            {
                var task = taskStack.GetTask(i);

                if (task is VisualRemeshTask vis)
                {
                    var newMesh = vis.Finish();
                    visualMesh.SetTriangles(newMesh.Triangles, submeshIndex, true, baseVertex);
                    materials[submeshIndex] = m_BlockList.GetMaterial(vis.MaterialID);

                    submeshIndex++;
                    baseVertex += newMesh.Vertices.Count;
                }
            }

            meshFilter.sharedMesh        = visualMesh;
            meshRenderer.sharedMaterials = materials;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Looks for all collision mesh tasks and writes the generated meshes to the chunk.
        /// </summary>
        /// <param name="taskStack">The task stack.</param>
        /// <param name="chunk">The chunk to update.</param>
        private void UpdateCollisionMesh(RemeshTaskStack taskStack, BlockChunk chunk)
        {
            var meshCollider  = chunk.GetComponent <MeshCollider>();
            var collisionMesh = meshCollider.sharedMesh;

            ApplyVertexData <CollisionRemeshTask>(taskStack, collisionMesh);

            int baseVertex   = 0;
            int submeshIndex = 0;

            for (int i = 0; i < taskStack.TaskCount; i++)
            {
                var task = taskStack.GetTask(i);

                if (task is CollisionRemeshTask vis)
                {
                    var newMesh = vis.Finish();
                    collisionMesh.SetTriangles(newMesh.Triangles, submeshIndex, true, baseVertex);

                    submeshIndex++;
                    baseVertex += newMesh.Vertices.Count;
                }
            }

            meshCollider.sharedMesh = collisionMesh;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Pulls vertex data from the task stack and puts it into the procMesh.
        /// </summary>
        /// <param name="taskStack">The task stack to pull from.</param>
        /// <param name="submeshCount">The number of submeshes being generated.</param>
        /// <typeparam name="T">The type of task to look for.</typeparam>
        private void GetVertexData <T>(RemeshTaskStack taskStack, out int submeshCount)
        {
            m_ProcMesh.Clear();
            submeshCount = 0;

            for (int i = 0; i < taskStack.TaskCount; i++)
            {
                var task = taskStack.GetTask(i);

                if (task is T)
                {
                    var newMesh = task.Finish();
                    m_ProcMesh.Vertices.AddRange(newMesh.Vertices);
                    m_ProcMesh.Normals.AddRange(newMesh.Normals);
                    m_ProcMesh.UVs.AddRange(newMesh.UVs);
                    submeshCount++;
                }
            }
        }