Beispiel #1
0
        /// <summary>
        /// Called when a mesh has been generated
        /// </summary>
        /// <param name="mesh">Mesh data</param>
        public void setMesh(MeshData meshData)
        {
            densityData.setChangeData(densityChangeData);

            regenReq = false;
            if (regenFlag)
            {
                regenFlag = false;
                regenReq  = true;
                MeshFactory.requestMesh(this);
            }

            hasMesh = true;
            if (meshData.indexArray.Length == 0)
            {
                return;
            }

            if (chunk == null)
            {
                chunk = ChunkPool.getChunk();
                if (LOD > 2)
                {
                    chunk.transform.position = position - new Vector3(0f, (NodeManager.LODSize[LOD] / 2f), 0f);
                }
                else
                {
                    chunk.transform.position = position;
                }

                //chunk.GetComponent<MeshFilter>().mesh.subMeshCount = QuixelEngine.materials.Length;
                chunk.GetComponent <MeshRenderer>().materials = QuixelEngine.materials;
            }

            empty = false;
            Mesh mesh = new Mesh();

            mesh.subMeshCount = QuixelEngine.materials.Length;
            mesh.vertices     = meshData.triangleArray;

            for (int i = 0; i < QuixelEngine.materials.Length; i++)
            {
                if (meshData.indexArray[i].Length > 0)
                {
                    mesh.SetTriangles(meshData.indexArray[i], i);
                }
            }
            //mesh.triangles = meshData.indexArray;
            mesh.uv = meshData.uvArray;

            mesh.normals = meshData.normalArray;
            //mesh.RecalculateBounds();
            mesh.Optimize();

            chunk.GetComponent <MeshFilter>().mesh = mesh;

            if (LOD == 0 && collides)
            {
                chunk.GetComponent <MeshCollider>().sharedMesh = mesh;
            }
            meshData.dispose();

            renderCheck();
            switch (renderType)
            {
            case RenderType.BACK:
                if (chunk != null)
                {
                    chunk.layer = 9;
                }
                break;

            case RenderType.FRONT:
                if (chunk != null)
                {
                    chunk.layer = 8;
                }
                break;
            }
            if (parent != null)
            {
                parent.renderCheck();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Disposes of subnodes
        /// </summary>
        public void dispose()
        {
            //If already disposed, exit.
            if (disposed)
            {
                return;
            }

            disposed = true;

            for (int i = 0; i < 8; i++)
            {
                if (subNodes[i] != null)
                {
                    subNodes[i].dispose();
                    subNodes[i] = null;
                }
            }

            if (permanent)
            {
                if (chunk != null)
                {
                    chunk.GetComponent <MeshFilter>().renderer.enabled = false;
                }
                return;
            }

            NodeManager.nodeCount[LOD]--;

            hasMesh = false;
            if (parent != null)
            {
                parent.renderCheck();
            }

            //Remove this node from the neighbor of existing nodes.
            for (int i = 0; i < 6; i++)
            {
                if (neighborNodes[i] != null)
                {
                    neighborNodes[i].neighborNodes[oppositeNeighbor[i]] = null;
                }
            }

            if (chunk != null)
            {
                UnityEngine.Object.Destroy(chunk.GetComponent <MeshFilter>().sharedMesh);
                Mesh mesh = chunk.GetComponent <MeshCollider>().sharedMesh;
                if (mesh != null)
                {
                    UnityEngine.Object.Destroy(mesh);
                }

                ChunkPool.recycleChunk(chunk);
            }

            if (densityData != null)
            {
                DensityPool.recycleDensityData(densityData);
            }
            if (densityChangeData != null)
            {
                DensityPool.recycleDensityData(densityChangeData);
            }
        }