コード例 #1
0
ファイル: GTreeRenderer.cs プロジェクト: ComradeCrunchy/Ranch
 internal void ResetTrees()
 {
     if (nativeData != null)
     {
         nativeData.Dispose();
         nativeData = null;
     }
 }
コード例 #2
0
ファイル: GTreeRenderer.cs プロジェクト: ComradeCrunchy/Ranch
        private void CullAndCalculateTreeTransform()
        {
            if (nativeData == null)
            {
                nativeData = new GTreeNativeData(terrain.TerrainData.Foliage.TreeInstances);
            }

            bool willSkipFrame = false;


            try
            {
                for (int i = 0; i < prototypes.Count; ++i)
                {
                    prototypePivotOffset[i]       = prototypes[i].PivotOffset;
                    prototypeBaseRotation[i]      = prototypes[i].BaseRotation;
                    prototypeBaseScale[i]         = prototypes[i].BaseScale;
                    prototypeBounds[i]            = prototypes[i].GetBoundingSphere();
                    prototypeWillDoFrustumTest[i] = IsInstancingEnabledForAllMaterials(prototypes[i]);
                }

                GCullAndCalculateTreeTransformJob job = new GCullAndCalculateTreeTransformJob()
                {
                    instances                  = nativeData.instances,
                    prototypeIndices           = nativeData.prototypeIndices,
                    transforms                 = nativeData.trs,
                    prototypePivotOffset       = prototypePivotOffset,
                    prototypeBaseRotation      = prototypeBaseRotation,
                    prototypeBaseScale         = prototypeBaseScale,
                    cullResult                 = nativeData.cullResults,
                    cullBoxMin                 = cullBoxMin,
                    cullBoxMax                 = cullBoxMax,
                    flagCulled                 = CULLED,
                    flagVisible                = VISIBLE,
                    flagBillboard              = BILLBOARD,
                    terrainPos                 = terrainPosition,
                    terrainSize                = terrainSize,
                    cameraPos                  = camera.transform.position,
                    treeDistance               = treeDistance,
                    billboardStart             = billboardStart,
                    cullVolumeBias             = cullVolumeBias,
                    prototypeBounds            = prototypeBounds,
                    prototypeWillDoFrustumTest = prototypeWillDoFrustumTest,
                    frustum = frustumPlanes
                };

                JobHandle handle = job.Schedule(nativeData.instances.Length, 100);
                handle.Complete();
            }
            catch (System.InvalidOperationException)
            {
                foliage.TreeAllChanged();
                willSkipFrame = true;
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);
            }

            prototypePivotOffset.Dispose();
            prototypeBaseRotation.Dispose();
            prototypeBaseScale.Dispose();
            prototypeBounds.Dispose();
            prototypeWillDoFrustumTest.Dispose();
            frustumPlanes.Dispose();

            if (willSkipFrame)
            {
                throw new GSkipFrameException();
            }
        }