예제 #1
0
        /// <summary>
        /// Checks if mesh generation on other thread or on the GPU is finished. If so, it is applied to the mesh.
        /// </summary>
        public void Update()
        {
            if (cookie != null && cookie.IsCompleted)
            {
                MeshData result = method.EndInvoke(cookie);
                ApplyToMesh(result);
                UpdateDistances();
                cookie = null;
                method = null;
            }

            if (isComputingOnGPU && gpuReadbackReq.done)
            {
                isComputingOnGPU = false;

                if (gpuReadbackReq.hasError)
                {
                    computeBuffer.Dispose();
                    computeBuffer    = null;
                    configurationOld = bool4.True;
                    GetNeighbors();
                }
                else
                {
                    var      a  = gpuReadbackReq.GetData <Vector3>().ToArray();
                    MeshData md = new MeshData(a, planet.quadMesh.normals, planet.quadMesh.uv);

                    //print(md.vertices.Length + ", [0]: " + md.vertices[0].ToString("F4") + ", [1089]: " + md.vertices[1089].ToString("F4"));
                    method = SpherifyAndDisplace;
                    cookie = method.BeginInvoke(md, null, null);
                    computeBuffer.Dispose();
                    computeBuffer = null;
                }
            }

            //Foliage Stuff:

            if (planet.generateDetails && (planet.generateFoliageInEveryBiome || planet.foliageBiomes.Contains(uniformBiome))) //Generating details if enabled and right biome.
            {
                if (level >= planet.grassLevel && foliageRenderer == null && renderedQuad && collider && distance < planet.dtDisSqr && planet.detailObjectsGenerating < planet.detailObjectsGeneratingSimultaneously)
                {
                    var        down = planet.Vector3Down(renderedQuad.transform.position);
                    Ray        ray  = new Ray(collider.bounds.center - (down * 500), down);
                    RaycastHit hit;

                    if (collider.Raycast(ray, out hit, 5000f)) //Only start foliage generation if the collider is working, it needs a few frames to initialize
                    {
                        foliageRenderer        = renderedQuad.AddComponent <FoliageRenderer>();
                        foliageRenderer.planet = planet;
                        foliageRenderer.quad   = this;
                        planet.detailObjectsGenerating++;
                    }
                }
                if (foliageRenderer != null && distance > planet.dtDisSqr)
                {
                    MonoBehaviour.Destroy(foliageRenderer);
                    foliageRenderer = null;
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Resets all variables. Used for pooling.
 /// </summary>
 public void Reset()
 {
     uniformBiome     = 0;
     parent           = null;
     children         = null;
     neighbors        = null;
     configuration    = bool4.False;
     hasSplit         = false;
     isSplitting      = false;
     initialized      = false;
     isComputingOnGPU = false;
     computeBuffer    = null;
     configurationOld = bool4.True;
     collider         = null;
     neighborIds      = null;
     meshOffset       = Vector3.zero;
     foliageRenderer  = null;
     distance         = Mathf.Infinity;
     coroutine        = null;
     level            = 1;
     msd            = 0f;
     gpuReadbackReq = new AsyncGPUReadbackRequest();
 }