コード例 #1
0
        // Token: 0x06000CBD RID: 3261 RVA: 0x0005DE68 File Offset: 0x0005C268
        public static void addInstance(AssetReference <FoliageInstancedMeshInfoAsset> assetReference, Vector3 position, Quaternion rotation, Vector3 scale, bool clearWhenBaked)
        {
            FoliageTile orAddTile = FoliageSystem.getOrAddTile(position);
            Matrix4x4   newMatrix = Matrix4x4.TRS(position, rotation, scale);

            orAddTile.addInstance(new FoliageInstanceGroup(assetReference, newMatrix, clearWhenBaked));
        }
コード例 #2
0
        // Token: 0x06000C79 RID: 3193 RVA: 0x0005D3F4 File Offset: 0x0005B7F4
        public void bakeFoliageSurface(FoliageBakeSettings bakeSettings, FoliageTile foliageTile)
        {
            FoliageInfoCollectionAsset foliageInfoCollectionAsset = Assets.find <FoliageInfoCollectionAsset>(this.foliage);

            if (foliageInfoCollectionAsset == null)
            {
                return;
            }
            bool activeSelf = base.gameObject.activeSelf;

            if (!activeSelf)
            {
                base.gameObject.SetActive(true);
            }
            Bounds  worldBounds = foliageTile.worldBounds;
            Vector3 min         = worldBounds.min;
            Vector3 max         = worldBounds.max;
            Bounds  bounds      = this.surfaceCollider.bounds;
            Vector3 min2        = bounds.min;
            Vector3 max2        = bounds.max;

            foliageInfoCollectionAsset.bakeFoliage(bakeSettings, this, new Bounds
            {
                min = new Vector3(Mathf.Max(min.x, min2.x), min2.y, Mathf.Max(min.z, min2.z)),
                max = new Vector3(Mathf.Min(max.x, max2.x), max2.y, Mathf.Min(max.z, max2.z))
            }, 1f);
            if (!activeSelf)
            {
                base.gameObject.SetActive(false);
            }
        }
コード例 #3
0
        // Token: 0x06000CBF RID: 3263 RVA: 0x0005DF10 File Offset: 0x0005C310
        public static void drawTiles(Vector3 position, int drawDistance, Camera camera, Plane[] frustumPlanes)
        {
            int          num          = drawDistance * drawDistance;
            FoliageCoord foliageCoord = new FoliageCoord(position);

            for (int i = -drawDistance; i <= drawDistance; i++)
            {
                for (int j = -drawDistance; j <= drawDistance; j++)
                {
                    FoliageCoord foliageCoord2 = new FoliageCoord(foliageCoord.x + i, foliageCoord.y + j);
                    if (!FoliageSystem.activeTiles.ContainsKey(foliageCoord2))
                    {
                        FoliageTile tile = FoliageSystem.getTile(foliageCoord2);
                        if (tile != null)
                        {
                            int num2 = i * i + j * j;
                            if (num2 <= num)
                            {
                                float density = 1f;
                                float num3    = Mathf.Sqrt((float)num2);
                                if (num3 > 2f && drawDistance > 3)
                                {
                                    density = 1f - (num3 - 2f) / (float)(drawDistance - 1);
                                }
                                FoliageSystem.drawTileCullingChecks(tile, num2, density, camera, frustumPlanes);
                                FoliageSystem.activeTiles.Add(foliageCoord2, tile);
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
 // Token: 0x06000CC1 RID: 3265 RVA: 0x0005E02C File Offset: 0x0005C42C
 public static void drawTile(FoliageTile tile, int sqrDistance, float density, Camera camera)
 {
     if (tile == null)
     {
         return;
     }
     if (tile.hasInstances)
     {
         foreach (KeyValuePair <AssetReference <FoliageInstancedMeshInfoAsset>, FoliageInstanceList> keyValuePair in tile.instances)
         {
             FoliageInstanceList value = keyValuePair.Value;
             value.loadAsset();
             Mesh mesh = value.mesh;
             if (!(mesh == null))
             {
                 Material material = value.material;
                 if (!(material == null))
                 {
                     bool castShadows = value.castShadows;
                     if (!value.tileDither)
                     {
                         density = 1f;
                     }
                     density *= FoliageSettings.instanceDensity;
                     if (value.sqrDrawDistance == -1 || sqrDistance <= value.sqrDrawDistance)
                     {
                         if (FoliageSettings.forceInstancingOff || !SystemInfo.supportsInstancing)
                         {
                             foreach (List <Matrix4x4> list in value.matrices)
                             {
                                 int num = Mathf.RoundToInt((float)list.Count * density);
                                 for (int i = 0; i < num; i++)
                                 {
                                     Graphics.DrawMesh(mesh, list[i], material, LayerMasks.ENVIRONMENT, camera, 0, null, castShadows, true);
                                 }
                             }
                         }
                         else
                         {
                             ShadowCastingMode castShadows2 = (!castShadows) ? ShadowCastingMode.Off : ShadowCastingMode.On;
                             foreach (List <Matrix4x4> list2 in value.matrices)
                             {
                                 int count = Mathf.RoundToInt((float)list2.Count * density);
                                 Graphics.DrawMeshInstanced(mesh, 0, material, list2.GetInternalArray <Matrix4x4>(), count, null, castShadows2, true, LayerMasks.ENVIRONMENT, camera);
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         tile.readInstancesJob();
     }
 }
コード例 #5
0
        // Token: 0x06000CC4 RID: 3268 RVA: 0x0005E2A0 File Offset: 0x0005C6A0
        public static FoliageTile getOrAddTile(FoliageCoord tileCoord)
        {
            FoliageTile foliageTile;

            if (!FoliageSystem.tiles.TryGetValue(tileCoord, out foliageTile))
            {
                foliageTile = new FoliageTile(tileCoord);
                FoliageSystem.tiles.Add(tileCoord, foliageTile);
            }
            return(foliageTile);
        }
コード例 #6
0
 // Token: 0x06000CC8 RID: 3272 RVA: 0x0005E354 File Offset: 0x0005C754
 public override void write(IFormattedFileWriter writer)
 {
     writer.beginObject();
     writer.beginArray("Tiles");
     foreach (KeyValuePair <FoliageCoord, FoliageTile> keyValuePair in FoliageSystem.tiles)
     {
         FoliageTile value = keyValuePair.Value;
         writer.writeValue <FoliageTile>(value);
     }
     writer.endArray();
     writer.endObject();
 }
コード例 #7
0
 // Token: 0x06000CC0 RID: 3264 RVA: 0x0005E006 File Offset: 0x0005C406
 public static void drawTileCullingChecks(FoliageTile tile, int sqrDistance, float density, Camera camera, Plane[] frustumPlanes)
 {
     if (tile == null)
     {
         return;
     }
     if (!GeometryUtility.TestPlanesAABB(frustumPlanes, tile.worldBounds))
     {
         return;
     }
     FoliageSystem.drawTile(tile, sqrDistance, density, camera);
 }
コード例 #8
0
 // Token: 0x06000CBE RID: 3262 RVA: 0x0005DE94 File Offset: 0x0005C294
 protected static void clearTiles()
 {
     foreach (KeyValuePair <FoliageCoord, FoliageTile> keyValuePair in FoliageSystem.tiles)
     {
         FoliageTile value = keyValuePair.Value;
         if (value.hasInstances)
         {
             value.clearInstances();
         }
     }
     FoliageSystem.tiles.Clear();
 }
コード例 #9
0
        // Token: 0x06000CC7 RID: 3271 RVA: 0x0005E2F4 File Offset: 0x0005C6F4
        public override void read(IFormattedFileReader reader)
        {
            reader = reader.readObject();
            int num = reader.readArrayLength("Tiles");

            for (int i = 0; i < num; i++)
            {
                reader.readArrayIndex(i);
                FoliageTile foliageTile = new FoliageTile(FoliageCoord.ZERO);
                foliageTile.read(reader);
                FoliageSystem.tiles.Add(foliageTile.coord, foliageTile);
            }
        }
コード例 #10
0
 // Token: 0x06000CBA RID: 3258 RVA: 0x0005DD52 File Offset: 0x0005C152
 private static void bakePostTile(FoliageBakeSettings bakeSettings, FoliageTile foliageTile)
 {
     if (!bakeSettings.bakeInstancesMeshes)
     {
         return;
     }
     if (foliageTile.hasInstances)
     {
         foliageTile.writeInstances();
         if (foliageTile.clearPostBake)
         {
             foliageTile.clearInstances();
         }
     }
 }
コード例 #11
0
        // Token: 0x06000CAF RID: 3247 RVA: 0x0005D8AC File Offset: 0x0005BCAC
        public static void addCut(IShapeVolume cut)
        {
            Bounds        worldBounds   = cut.worldBounds;
            FoliageBounds foliageBounds = new FoliageBounds(worldBounds);

            for (int i = foliageBounds.min.x; i <= foliageBounds.max.x; i++)
            {
                for (int j = foliageBounds.min.y; j <= foliageBounds.max.y; j++)
                {
                    FoliageCoord tileCoord = new FoliageCoord(i, j);
                    FoliageTile  orAddTile = FoliageSystem.getOrAddTile(tileCoord);
                    orAddTile.addCut(cut);
                }
            }
        }
コード例 #12
0
 public static bool isTileBakeable(FoliageTile tile)
 {
     if (FoliageVolumeSystem.additiveVolumes.Count > 0)
     {
         Vector3 center = tile.worldBounds.center;
         for (int i = 0; i < FoliageVolumeSystem.additiveVolumes.Count; i++)
         {
             FoliageVolume volume = FoliageVolumeSystem.additiveVolumes[i];
             if (FoliageVolumeUtility.isPointInsideVolume(volume, center))
             {
                 return(true);
             }
         }
         return(false);
     }
     return(true);
 }
コード例 #13
0
 // Token: 0x06000CBB RID: 3259 RVA: 0x0005DD84 File Offset: 0x0005C184
 private static void bake(FoliageTile tile, List <IFoliageSurface> list)
 {
     FoliageSystem.bakePreTile(FoliageSystem.bakeSettings, tile);
     if (FoliageSystem.preBakeTile != null)
     {
         FoliageSystem.preBakeTile(FoliageSystem.bakeSettings, tile);
     }
     if (!FoliageSystem.bakeSettings.bakeApplyScale)
     {
         foreach (IFoliageSurface foliageSurface in list)
         {
             foliageSurface.bakeFoliageSurface(FoliageSystem.bakeSettings, tile);
         }
     }
     FoliageSystem.bakePostTile(FoliageSystem.bakeSettings, tile);
     if (FoliageSystem.postBakeTile != null)
     {
         FoliageSystem.postBakeTile(FoliageSystem.bakeSettings, tile);
     }
 }
コード例 #14
0
 // Token: 0x06000CB9 RID: 3257 RVA: 0x0005DCF8 File Offset: 0x0005C0F8
 private static void bakePreTile(FoliageBakeSettings bakeSettings, FoliageTile foliageTile)
 {
     if (!bakeSettings.bakeInstancesMeshes)
     {
         return;
     }
     if (!foliageTile.hasInstances)
     {
         foliageTile.readInstancesOnThread();
         foliageTile.clearPostBake = true;
     }
     if (foliageTile.hasInstances)
     {
         if (bakeSettings.bakeApplyScale)
         {
             foliageTile.applyScale();
         }
         else
         {
             foliageTile.clearGeneratedInstances();
         }
     }
 }
コード例 #15
0
        // Token: 0x06000C4A RID: 3146 RVA: 0x0005CB44 File Offset: 0x0005AF44
        public override int getInstanceCountInVolume(IShapeVolume volume)
        {
            Bounds        worldBounds   = volume.worldBounds;
            FoliageBounds foliageBounds = new FoliageBounds(worldBounds);
            int           num           = 0;

            for (int i = foliageBounds.min.x; i <= foliageBounds.max.x; i++)
            {
                for (int j = foliageBounds.min.y; j <= foliageBounds.max.y; j++)
                {
                    FoliageCoord tileCoord = new FoliageCoord(i, j);
                    FoliageTile  tile      = FoliageSystem.getTile(tileCoord);
                    if (tile != null)
                    {
                        if (!tile.hasInstances)
                        {
                            tile.readInstancesOnThread();
                        }
                        FoliageInstanceList foliageInstanceList;
                        if (tile.instances != null && tile.instances.TryGetValue(base.getReferenceTo <FoliageInstancedMeshInfoAsset>(), out foliageInstanceList))
                        {
                            foreach (List <Matrix4x4> list in foliageInstanceList.matrices)
                            {
                                foreach (Matrix4x4 matrix in list)
                                {
                                    if (volume.containsPoint(matrix.GetPosition()))
                                    {
                                        num++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(num);
        }
コード例 #16
0
        // Token: 0x06000CB6 RID: 3254 RVA: 0x0005DBA0 File Offset: 0x0005BFA0
        private static void bakeLocalBegin()
        {
            FoliageSystem.bakeLocalPosition = MainCamera.instance.transform.position;
            int          num          = 6;
            int          num2         = num * num;
            FoliageCoord foliageCoord = new FoliageCoord(FoliageSystem.bakeLocalPosition);
            Dictionary <FoliageTile, List <IFoliageSurface> > tileSurfacePairs = FoliageSystem.getTileSurfacePairs();

            for (int i = -num; i <= num; i++)
            {
                for (int j = -num; j <= num; j++)
                {
                    int num3 = i * i + j * j;
                    if (num3 <= num2)
                    {
                        FoliageCoord tileCoord = new FoliageCoord(foliageCoord.x + i, foliageCoord.y + j);
                        FoliageTile  tile      = FoliageSystem.getTile(tileCoord);
                        if (tile != null)
                        {
                            List <IFoliageSurface> value;
                            if (tileSurfacePairs.TryGetValue(tile, out value))
                            {
                                KeyValuePair <FoliageTile, List <IFoliageSurface> > item = new KeyValuePair <FoliageTile, List <IFoliageSurface> >(tile, value);
                                FoliageSystem.bakeQueue.Enqueue(item);
                            }
                        }
                    }
                }
            }
            FoliageSystem.bakeQueueTotal = FoliageSystem.bakeQueue.Count;
            if (FoliageSystem.< > f__mg$cache1 == null)
            {
                FoliageSystem.< > f__mg$cache1 = new FoliageSystemPostBakeHandler(FoliageSystem.bakeLocalEnd);
            }
            FoliageSystem.bakeEnd = FoliageSystem.< > f__mg$cache1;
            FoliageSystem.bakeEnd();
        }
コード例 #17
0
        // Token: 0x06000CB0 RID: 3248 RVA: 0x0005D934 File Offset: 0x0005BD34
        private static Dictionary <FoliageTile, List <IFoliageSurface> > getTileSurfacePairs()
        {
            Dictionary <FoliageTile, List <IFoliageSurface> > dictionary = new Dictionary <FoliageTile, List <IFoliageSurface> >();

            foreach (KeyValuePair <FoliageCoord, FoliageTile> keyValuePair in FoliageSystem.tiles)
            {
                FoliageTile value = keyValuePair.Value;
                if (FoliageVolumeUtility.isTileBakeable(value))
                {
                    dictionary.Add(value, new List <IFoliageSurface>());
                }
            }
            foreach (IFoliageSurface foliageSurface in FoliageSystem.surfaces)
            {
                FoliageBounds foliageSurfaceBounds = foliageSurface.getFoliageSurfaceBounds();
                for (int i = foliageSurfaceBounds.min.x; i <= foliageSurfaceBounds.max.x; i++)
                {
                    for (int j = foliageSurfaceBounds.min.y; j <= foliageSurfaceBounds.max.y; j++)
                    {
                        FoliageCoord tileCoord = new FoliageCoord(i, j);
                        FoliageTile  orAddTile = FoliageSystem.getOrAddTile(tileCoord);
                        if (FoliageVolumeUtility.isTileBakeable(orAddTile))
                        {
                            List <IFoliageSurface> list;
                            if (!dictionary.TryGetValue(orAddTile, out list))
                            {
                                list = new List <IFoliageSurface>();
                                dictionary.Add(orAddTile, list);
                            }
                            list.Add(foliageSurface);
                        }
                    }
                }
            }
            return(dictionary);
        }