Esempio n. 1
0
        /// <summary>
        /// Initializes the Quixel Engine
        /// </summary>
        /// <param name="mats">Array of materials.</param>
        /// <param name="terrainObj">Parent terrain object. (empty)</param>
        /// <param name="worldName">Name of the world. Used for paging. (empty)</param>
        public static void init(Material[] mats, GameObject terrainObj, string worldName)
        {
            MeshFactory.terrainObj = terrainObj;

            materials = mats;
            Debug.Log("Materials: " + mats.Length);
            DensityPool.init();
            MeshFactory.start();
            NodeManager.init(worldName);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the Quixel system. Should be called every step.
        /// </summary>
        public static void update()
        {
            DensityPool.update();
            MeshFactory.update();

            if (cameraObj != null)
            {
                NodeManager.setViewPosition(cameraObj.transform.position);
            }

            if (!Application.isPlaying)
            {
                active = false;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Continuously check if we have chunks to generate.
        /// </summary>
        private void generateLoop()
        {
            bool sleep = true;

            while (QuixelEngine.isActive())
            {
                sleep = false;

                MeshFactory.MeshRequest req = MeshFactory.getNextRequest();
                if (req == null)
                {
                    sleep = true;
                }
                else
                {
                    if (req.densities == null)
                    {
                        if (!req.hasDensities)
                        {
                            req.densities = DensityPool.getDensityData();
                        }
                        else
                        {
                            req.densities = req.node.densityData;
                        }
                    }

                    MeshFactory.GenerateMeshData(req);

                    lock (finishedQueue)
                        finishedQueue.Enqueue(req);
                }

                if (sleep)
                {
                    Thread.Sleep(30);
                }
                else
                {
                    Thread.Sleep(4);
                }
            }
        }
Esempio n. 4
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);
            }
        }