Пример #1
0
        public TerrainChunk(TerrainViewer terrainViewer, Vector2 coord, GlobalSettings globalSettings, HeightMapSettings heightMapSettings, MeshSettings meshSettings, LodInfo[] detailLevels, int colliderLodIndex, Material material)
        {
            this.coord             = coord;
            this.detailLevels      = detailLevels;
            this.colliderLodIndex  = colliderLodIndex;
            this.heightMapSettings = heightMapSettings;
            this.globalSettings    = globalSettings;
            this.meshSettings      = meshSettings;
            this.terrainViewer     = terrainViewer;

            var position = coord * meshSettings.meshWorldSize;

            sampleCentre = position / meshSettings.meshScale;
            bounds       = new Bounds(position, Vector2.one * meshSettings.meshWorldSize);


            meshObject            = new GameObject("Terrain Chunk");
            meshRenderer          = meshObject.AddComponent <MeshRenderer>();
            meshFilter            = meshObject.AddComponent <MeshFilter>();
            meshCollider          = meshObject.AddComponent <MeshCollider>();
            meshRenderer.material = material;

            meshObject.transform.position = new Vector3(position.x, 0, position.y);
            meshObject.transform.parent   = terrainViewer.ChunkParent;
            SetVisible(false);

            lodMeshes = new LodMesh[detailLevels.Length];
            for (var i = 0; i < detailLevels.Length; ++i)
            {
                lodMeshes[i] = new LodMesh(detailLevels[i].lod);
                lodMeshes[i].updateCallback += UpdateTerrainChunk;
                if (i == colliderLodIndex)
                {
                    lodMeshes[i].updateCallback += UpdateCollisionMesh;
                }
            }

            maxViewDst = detailLevels[detailLevels.Length - 1].visibleDstThreshold;
        }
Пример #2
0
 public void RequestMesh(HeightMap heightMap, MeshSettings meshSettings)
 {
     hasRequestedMesh = true;
     ThreadedDataRequester.RequestData(() => MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, lod), OnMeshDataReceived);
 }