├── ProjectSettings ├── ProjectVersion.txt ├── TagManager.asset ├── TimeManager.asset ├── AudioManager.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── DynamicsManager.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── Physics2DSettings.asset ├── ClusterInputManager.asset ├── EditorBuildSettings.asset └── UnityConnectSettings.asset ├── README.md ├── Assets ├── Materials │ ├── Hero.mat │ ├── Terrain.mat │ ├── Hero.mat.meta │ └── Terrain.mat.meta ├── Scenes │ ├── Earth.unity │ └── Earth.unity.meta ├── Textrues │ ├── land.png │ ├── moutain.png │ ├── wetland.png │ ├── DLGress002.psd │ ├── 20160314111306344.jpg │ ├── moutain.png.meta │ ├── 20160314111306344.jpg.meta │ ├── land.png.meta │ ├── wetland.png.meta │ └── DLGress002.psd.meta ├── Skyboxes │ ├── Textures │ │ ├── Sunny3 │ │ │ ├── Sunny3_up.tif │ │ │ ├── Sunny3_back.tif │ │ │ ├── Sunny3_down.tif │ │ │ ├── Sunny3_front.tif │ │ │ ├── Sunny3_left.tif │ │ │ ├── Sunny3_right.tif │ │ │ ├── Sunny3_back.tif.meta │ │ │ ├── Sunny3_down.tif.meta │ │ │ ├── Sunny3_front.tif.meta │ │ │ ├── Sunny3_left.tif.meta │ │ │ ├── Sunny3_right.tif.meta │ │ │ └── Sunny3_up.tif.meta │ │ ├── Sunny3 Skybox.mat.meta │ │ ├── Sunny3.meta │ │ └── Sunny3 Skybox.mat │ └── Textures.meta ├── Hex.prefab.meta ├── Materials.meta ├── Scenes.meta ├── Scripts.meta ├── Shaders.meta ├── Skyboxes.meta ├── Textrues.meta ├── Scripts │ ├── HeroController.meta │ ├── Chunk.cs.meta │ ├── ArrayCache.cs.meta │ ├── ChunkManager.cs.meta │ ├── LodPiece.cs.meta │ ├── MeshCreator.cs.meta │ ├── WorkThread.cs.meta │ ├── HeightMapFactory.cs.meta │ ├── HeightMapFilter.cs.meta │ ├── HeightMapVolcano.cs.meta │ ├── SurfaceMaskCreator.cs.meta │ ├── TerrainDyRectCreator.cs.meta │ ├── HeightMapFuzzyLandscaping.cs.meta │ ├── HeightMapParticleDeposition.cs.meta │ ├── HeroController │ │ ├── TerrainDemoHeroController.cs.meta │ │ └── TerrainDemoHeroController.cs │ ├── HeightMapVolcano.cs │ ├── ArrayCache.cs │ ├── HeightMapFilter.cs │ ├── MeshCreator.cs │ ├── LodPiece.cs │ ├── WorkThread.cs │ ├── SurfaceMaskCreator.cs │ ├── HeightMapParticleDeposition.cs │ ├── HeightMapFuzzyLandscaping.cs │ ├── HeightMapFactory.cs │ ├── ChunkManager.cs │ ├── TerrainDyRectCreator.cs │ └── Chunk.cs ├── Shaders │ ├── TerrainShader.shader.meta │ └── TerrainShader.shader └── Hex.prefab ├── .gitattributes ├── .gitignore ├── NoHumansAllowed.sln ├── UnityInfinityTerrainDemo.sln ├── NoHumansAllowed.csproj ├── UnityInfinityTerrainDemo.csproj └── NoHumansAllowed.Editor.csproj /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.5.0f3 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityInfinityRandomTerrainDemo 2 | # Unity无限随机地形Demo 3 | a demo of infinity random terrain by unity. 4 | -------------------------------------------------------------------------------- /Assets/Materials/Hero.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Materials/Hero.mat -------------------------------------------------------------------------------- /Assets/Scenes/Earth.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Scenes/Earth.unity -------------------------------------------------------------------------------- /Assets/Textrues/land.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Textrues/land.png -------------------------------------------------------------------------------- /Assets/Materials/Terrain.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Materials/Terrain.mat -------------------------------------------------------------------------------- /Assets/Textrues/moutain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Textrues/moutain.png -------------------------------------------------------------------------------- /Assets/Textrues/wetland.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Textrues/wetland.png -------------------------------------------------------------------------------- /Assets/Textrues/DLGress002.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Textrues/DLGress002.psd -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /Assets/Textrues/20160314111306344.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Textrues/20160314111306344.jpg -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_up.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Skyboxes/Textures/Sunny3/Sunny3_up.tif -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_back.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Skyboxes/Textures/Sunny3/Sunny3_back.tif -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_down.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Skyboxes/Textures/Sunny3/Sunny3_down.tif -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_front.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Skyboxes/Textures/Sunny3/Sunny3_front.tif -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_left.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Skyboxes/Textures/Sunny3/Sunny3_left.tif -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_right.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ldcf4/UnityInfinityRandomTerrainDemo/HEAD/Assets/Skyboxes/Textures/Sunny3/Sunny3_right.tif -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3 Skybox.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 53412155bc1016547b1a77b2333c0380 3 | NativeFormatImporter: 4 | userData: 5 | assetBundleName: 6 | assetBundleVariant: 7 | -------------------------------------------------------------------------------- /Assets/Hex.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a83849413b73f94fa7ee589a0b2b2f8 3 | timeCreated: 1488189835 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/Earth.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb830d7a095972345a02e38630818e6f 3 | timeCreated: 1490666449 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Materials/Hero.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2177d79fb388dfa4a8548407707f52ca 3 | timeCreated: 1490668034 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Materials/Terrain.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1ba403e68618a9343b2ae986cfc588ae 3 | timeCreated: 1482718860 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7829b324ff2387d47ac076a608ec5023 3 | folderAsset: yes 4 | timeCreated: 1482716708 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 315375037f3958a43b67e11924d765c3 3 | folderAsset: yes 4 | timeCreated: 1490666432 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c5e2464f2c3277e4484d12d4a815dc4e 3 | folderAsset: yes 4 | timeCreated: 1482716708 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f42618ce29837024ea800967a1f3fe53 3 | folderAsset: yes 4 | timeCreated: 1482716708 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Skyboxes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7811ae02b45f2a743a22d37e19effe0b 3 | folderAsset: yes 4 | timeCreated: 1487907021 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Textrues.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eecc941a80e1dd34cbae75b46b151430 3 | folderAsset: yes 4 | timeCreated: 1482716708 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1219dea1ec96874eaab6afcc71f9f47 3 | folderAsset: yes 4 | timeCreated: 1487907021 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/HeroController.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 478f1540ce5f7de4e91c445e92b7b5ab 3 | folderAsset: yes 4 | timeCreated: 1482716708 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2543f6b0b4d50f4468dd5a3bfd842d61 3 | folderAsset: yes 4 | timeCreated: 1487907021 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shaders/TerrainShader.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1d9d075443452bc40ad9f9136af755a5 3 | timeCreated: 1482716771 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/Chunk.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb28f0dd91ef5ee4984047638ff705d7 3 | timeCreated: 1490692275 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/ArrayCache.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 14fe38d07f59c3d4199b8175c0c3da33 3 | timeCreated: 1490667528 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/ChunkManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 498fc6622b5f15e4eb3eb8a949142cbb 3 | timeCreated: 1490692275 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/LodPiece.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5faed090f46ca7641b105ac0109b7a45 3 | timeCreated: 1490667528 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/MeshCreator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 26a7f4095ae79144aa9921a0ddfc7fa4 3 | timeCreated: 1482716718 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/WorkThread.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: da02f674308ea9244b744196cdba3b80 3 | timeCreated: 1490844861 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/HeightMapFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 871b3e7d9f946e04b8ef03d5cc077716 3 | timeCreated: 1482716719 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/HeightMapFilter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3cf6ba077bc21664580a914508350d0d 3 | timeCreated: 1491019064 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/HeightMapVolcano.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 96af0ac580356ef4485a801c05831fce 3 | timeCreated: 1491036716 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/SurfaceMaskCreator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a21795f06a002845874f1609afba0cc 3 | timeCreated: 1482716720 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/TerrainDyRectCreator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 196fcf6ec66da384face9aaf328df955 3 | timeCreated: 1490339420 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/HeightMapFuzzyLandscaping.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 38d1217ca26aa0048bbfd1959c481166 3 | timeCreated: 1490952644 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/HeightMapParticleDeposition.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5838a456641e73748812368513a6bfa6 3 | timeCreated: 1491029124 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/HeroController/TerrainDemoHeroController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 29effc3f34fb9dd4aa0dd385c45564e2 3 | timeCreated: 1490597389 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /Assets/Scripts/HeightMapVolcano.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | /// 5 | /// 转换成火山,把某个高度以上的倒置 6 | /// 7 | public class HeightMapVolcano 8 | { 9 | 10 | public static void ToVolcano(float[,] map,int size,float volcano_height) 11 | { 12 | for (int i = 0; i < size; i++) 13 | { 14 | for (int j = 0; j < size; j++) 15 | { 16 | if (map[j,i]>volcano_height) 17 | { 18 | map[j, i] = volcano_height - (map[j, i] - volcano_height); 19 | } 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | 49 | #vs 50 | .vs 51 | Library 52 | Temp -------------------------------------------------------------------------------- /NoHumansAllowed.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2017 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoHumansAllowed", "NoHumansAllowed.csproj", "{13AF218E-66D1-174B-EA5E-53DD25FA03DB}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {13AF218E-66D1-174B-EA5E-53DD25FA03DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {13AF218E-66D1-174B-EA5E-53DD25FA03DB}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {13AF218E-66D1-174B-EA5E-53DD25FA03DB}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {13AF218E-66D1-174B-EA5E-53DD25FA03DB}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /UnityInfinityTerrainDemo.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2017 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityInfinityTerrainDemo", "UnityInfinityTerrainDemo.csproj", "{0F85567D-25C3-51E0-6D0F-FA45B790A858}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {0F85567D-25C3-51E0-6D0F-FA45B790A858}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {0F85567D-25C3-51E0-6D0F-FA45B790A858}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {0F85567D-25C3-51E0-6D0F-FA45B790A858}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {0F85567D-25C3-51E0-6D0F-FA45B790A858}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Assets/Scripts/HeroController/TerrainDemoHeroController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class TerrainDemoHeroController : MonoBehaviour 5 | { 6 | public Camera Cam; 7 | public float HeroMoveSpeed; 8 | public Vector3 HeroFixPos=new Vector3(0,1,0); 9 | public Vector3 CameraFixPos = new Vector3(0, 7, 0); 10 | 11 | private Vector3 m_target_pos=new Vector3(0,1,0); 12 | 13 | private void Awake() 14 | { 15 | 16 | } 17 | 18 | // Update is called once per frame 19 | void Update() 20 | { 21 | if (Input.GetMouseButton(0)) 22 | { 23 | Ray ray = Cam.ScreenPointToRay(Input.mousePosition); 24 | RaycastHit hit; 25 | if (Physics.Raycast(ray, out hit)) 26 | { 27 | m_target_pos=hit.point+ HeroFixPos; 28 | } 29 | } 30 | transform.position = Vector3.MoveTowards(transform.position, m_target_pos, HeroMoveSpeed * Time.deltaTime); 31 | transform.LookAt(m_target_pos); 32 | 33 | Cam.transform.position = transform.position + CameraFixPos; 34 | Cam.transform.LookAt(transform.position); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Assets/Scripts/ArrayCache.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | public class ArrayCache 4 | { 5 | private Dictionary> m_v3_cache = new Dictionary>(); 6 | public T[] GetOneArray(int num) 7 | { 8 | Stack target_arrays = null; 9 | if (m_v3_cache.TryGetValue(num, out target_arrays)) 10 | { 11 | if (target_arrays.Count > 0) 12 | { 13 | return target_arrays.Pop(); 14 | } 15 | } 16 | return new T[num]; 17 | } 18 | 19 | public void GiveBack(T[] array) 20 | { 21 | int num = array.Length; 22 | Stack target_array = null; 23 | if (!m_v3_cache.TryGetValue(num, out target_array)) 24 | { 25 | target_array = new Stack(); 26 | m_v3_cache.Add(num, target_array); 27 | } 28 | target_array.Push(array); 29 | } 30 | 31 | public string GetDebugInfo() 32 | { 33 | string ret = ""; 34 | foreach (var item in m_v3_cache) 35 | { 36 | ret += string.Format("({0}:{1}); ", item.Key, item.Value.Count); 37 | } 38 | return ret; 39 | } 40 | } -------------------------------------------------------------------------------- /Assets/Scripts/HeightMapFilter.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using UnityEngine; 4 | 5 | [Serializable] 6 | public struct FIRFilterConfig 7 | { 8 | public int times; 9 | [Range(0,1)] 10 | public float k; 11 | } 12 | 13 | public class HeightMapFilter 14 | { 15 | public static void FilterFIR(float[,] map,int size,int times,float k) 16 | { 17 | for (int t = 0; t < times; t++) 18 | { 19 | for (int y = 0; y < size; y++) 20 | { 21 | for (int x = 0; x < size; x++) 22 | { 23 | if (x == 0 ) 24 | map[x, y] = map[x,y]*k + (1 - k) * map[x, y]; 25 | else 26 | map[x, y] = map[x - 1, y] * k + (1 - k) * map[x, y]; 27 | } 28 | } 29 | for (int x = 0; x < size; x++) 30 | { 31 | for (int y = 0; y < size; y++) 32 | { 33 | if (y == 0) 34 | map[x, y] = map[x, y] * k + (1 - k) * map[x, y]; 35 | else 36 | map[x, y] = map[x, y - 1] * k + (1 - k) * map[x, y]; 37 | } 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Assets/Textrues/moutain.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 73de9c829fe2b154badade22c1398c9f 3 | timeCreated: 1482716746 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -1 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: -1 33 | aniso: 16 34 | mipBias: -1 35 | wrapMode: 0 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 0 49 | spriteTessellationDetail: -1 50 | textureType: 0 51 | buildTargetSettings: [] 52 | spriteSheet: 53 | serializedVersion: 2 54 | sprites: [] 55 | outline: [] 56 | spritePackingTag: 57 | userData: 58 | assetBundleName: 59 | assetBundleVariant: 60 | -------------------------------------------------------------------------------- /Assets/Scripts/MeshCreator.cs: -------------------------------------------------------------------------------- 1 | 2 | using UnityEngine; 3 | using UnityEngine.Rendering; 4 | 5 | class MeshCreator 6 | { 7 | public static GameObject DrawMesh(Vector3[] vers, Vector2[] uvs, int[] tris, Material mat, string objname) 8 | { 9 | var plane = new GameObject(objname); 10 | Mesh mesh = plane.AddComponent().mesh; 11 | var renderer = plane.AddComponent(); 12 | renderer.material = mat; 13 | renderer.shadowCastingMode = ShadowCastingMode.Off; 14 | //给mesh 赋值 15 | mesh.Clear(); 16 | mesh.vertices = vers; 17 | mesh.uv = uvs; 18 | mesh.triangles = tris; 19 | //重置法线 20 | mesh.RecalculateNormals(); 21 | //重置范围 22 | mesh.RecalculateBounds(); 23 | return plane; 24 | } 25 | 26 | public static GameObject DrawMesh(Vector3[] vers, Vector3[] normals, Vector2[] uvs, int[] tris, Material mat, string objname) 27 | { 28 | var plane = new GameObject(objname); 29 | Mesh mesh = plane.AddComponent().mesh; 30 | var renderer = plane.AddComponent(); 31 | renderer.material = mat; 32 | renderer.shadowCastingMode = ShadowCastingMode.Off; 33 | //给mesh 赋值 34 | mesh.Clear(); 35 | mesh.vertices = vers; 36 | mesh.uv = uvs; 37 | mesh.triangles = tris; 38 | //重置法线 39 | mesh.normals = normals; 40 | //重置范围 41 | mesh.RecalculateBounds(); 42 | return plane; 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Assets/Textrues/20160314111306344.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 262c5987413d3944294b0ab8265e30a5 3 | timeCreated: 1482716730 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -1 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: -1 33 | aniso: 16 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 0 49 | spriteTessellationDetail: -1 50 | textureType: 0 51 | buildTargetSettings: [] 52 | spriteSheet: 53 | serializedVersion: 2 54 | sprites: [] 55 | outline: [] 56 | spritePackingTag: 57 | userData: 58 | assetBundleName: 59 | assetBundleVariant: 60 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_back.tif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 68287fe10cd30434b9c21ff1c55f613f 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 4 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 1 9 | sRGBTexture: 1 10 | linearTexture: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: 0.25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 6 23 | cubemapConvolution: 0 24 | seamlessCubemap: 0 25 | textureFormat: -1 26 | maxTextureSize: 512 27 | textureSettings: 28 | filterMode: 1 29 | aniso: 1 30 | mipBias: 0 31 | wrapMode: 1 32 | nPOTScale: 1 33 | lightmap: 0 34 | compressionQuality: 50 35 | spriteMode: 0 36 | spriteExtrude: 1 37 | spriteMeshType: 1 38 | alignment: 0 39 | spritePivot: {x: 0.5, y: 0.5} 40 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 41 | spritePixelsToUnits: 100 42 | alphaUsage: 1 43 | alphaIsTransparency: 0 44 | spriteTessellationDetail: -1 45 | textureType: 0 46 | textureShape: 1 47 | maxTextureSizeSet: 0 48 | compressionQualitySet: 0 49 | textureFormatSet: 0 50 | platformSettings: 51 | - buildTarget: DefaultTexturePlatform 52 | maxTextureSize: 512 53 | textureFormat: -1 54 | textureCompression: 1 55 | compressionQuality: 50 56 | crunchedCompression: 0 57 | allowsAlphaSplitting: 0 58 | overridden: 0 59 | spriteSheet: 60 | serializedVersion: 2 61 | sprites: [] 62 | outline: [] 63 | spritePackingTag: 64 | userData: 65 | assetBundleName: 66 | assetBundleVariant: 67 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_down.tif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e3e214f8620f35a4cb4e415a4b8c19cf 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 4 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 1 9 | sRGBTexture: 1 10 | linearTexture: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: 0.25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 6 23 | cubemapConvolution: 0 24 | seamlessCubemap: 0 25 | textureFormat: -1 26 | maxTextureSize: 512 27 | textureSettings: 28 | filterMode: 1 29 | aniso: 1 30 | mipBias: 0 31 | wrapMode: 1 32 | nPOTScale: 1 33 | lightmap: 0 34 | compressionQuality: 50 35 | spriteMode: 0 36 | spriteExtrude: 1 37 | spriteMeshType: 1 38 | alignment: 0 39 | spritePivot: {x: 0.5, y: 0.5} 40 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 41 | spritePixelsToUnits: 100 42 | alphaUsage: 1 43 | alphaIsTransparency: 0 44 | spriteTessellationDetail: -1 45 | textureType: 0 46 | textureShape: 1 47 | maxTextureSizeSet: 0 48 | compressionQualitySet: 0 49 | textureFormatSet: 0 50 | platformSettings: 51 | - buildTarget: DefaultTexturePlatform 52 | maxTextureSize: 512 53 | textureFormat: -1 54 | textureCompression: 1 55 | compressionQuality: 50 56 | crunchedCompression: 0 57 | allowsAlphaSplitting: 0 58 | overridden: 0 59 | spriteSheet: 60 | serializedVersion: 2 61 | sprites: [] 62 | outline: [] 63 | spritePackingTag: 64 | userData: 65 | assetBundleName: 66 | assetBundleVariant: 67 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_front.tif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a6c23ad66d37f0e4c8c86d7c5293ac7c 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 4 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 1 9 | sRGBTexture: 1 10 | linearTexture: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: 0.25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 6 23 | cubemapConvolution: 0 24 | seamlessCubemap: 0 25 | textureFormat: -1 26 | maxTextureSize: 512 27 | textureSettings: 28 | filterMode: 1 29 | aniso: 1 30 | mipBias: 0 31 | wrapMode: 1 32 | nPOTScale: 1 33 | lightmap: 0 34 | compressionQuality: 50 35 | spriteMode: 0 36 | spriteExtrude: 1 37 | spriteMeshType: 1 38 | alignment: 0 39 | spritePivot: {x: 0.5, y: 0.5} 40 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 41 | spritePixelsToUnits: 100 42 | alphaUsage: 1 43 | alphaIsTransparency: 0 44 | spriteTessellationDetail: -1 45 | textureType: 0 46 | textureShape: 1 47 | maxTextureSizeSet: 0 48 | compressionQualitySet: 0 49 | textureFormatSet: 0 50 | platformSettings: 51 | - buildTarget: DefaultTexturePlatform 52 | maxTextureSize: 512 53 | textureFormat: -1 54 | textureCompression: 1 55 | compressionQuality: 50 56 | crunchedCompression: 0 57 | allowsAlphaSplitting: 0 58 | overridden: 0 59 | spriteSheet: 60 | serializedVersion: 2 61 | sprites: [] 62 | outline: [] 63 | spritePackingTag: 64 | userData: 65 | assetBundleName: 66 | assetBundleVariant: 67 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_left.tif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a3134e5f9749c449ad2289cfe93f5d5 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 4 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 1 9 | sRGBTexture: 1 10 | linearTexture: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: 0.25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 6 23 | cubemapConvolution: 0 24 | seamlessCubemap: 0 25 | textureFormat: -1 26 | maxTextureSize: 512 27 | textureSettings: 28 | filterMode: 1 29 | aniso: 1 30 | mipBias: 0 31 | wrapMode: 1 32 | nPOTScale: 1 33 | lightmap: 0 34 | compressionQuality: 50 35 | spriteMode: 0 36 | spriteExtrude: 1 37 | spriteMeshType: 1 38 | alignment: 0 39 | spritePivot: {x: 0.5, y: 0.5} 40 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 41 | spritePixelsToUnits: 100 42 | alphaUsage: 1 43 | alphaIsTransparency: 0 44 | spriteTessellationDetail: -1 45 | textureType: 0 46 | textureShape: 1 47 | maxTextureSizeSet: 0 48 | compressionQualitySet: 0 49 | textureFormatSet: 0 50 | platformSettings: 51 | - buildTarget: DefaultTexturePlatform 52 | maxTextureSize: 512 53 | textureFormat: -1 54 | textureCompression: 1 55 | compressionQuality: 50 56 | crunchedCompression: 0 57 | allowsAlphaSplitting: 0 58 | overridden: 0 59 | spriteSheet: 60 | serializedVersion: 2 61 | sprites: [] 62 | outline: [] 63 | spritePackingTag: 64 | userData: 65 | assetBundleName: 66 | assetBundleVariant: 67 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_right.tif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e349c3f4b36417b48b65112d7bd0b54e 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 4 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 1 9 | sRGBTexture: 1 10 | linearTexture: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: 0.25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 6 23 | cubemapConvolution: 0 24 | seamlessCubemap: 0 25 | textureFormat: -1 26 | maxTextureSize: 512 27 | textureSettings: 28 | filterMode: 1 29 | aniso: 1 30 | mipBias: 0 31 | wrapMode: 1 32 | nPOTScale: 1 33 | lightmap: 0 34 | compressionQuality: 50 35 | spriteMode: 0 36 | spriteExtrude: 1 37 | spriteMeshType: 1 38 | alignment: 0 39 | spritePivot: {x: 0.5, y: 0.5} 40 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 41 | spritePixelsToUnits: 100 42 | alphaUsage: 1 43 | alphaIsTransparency: 0 44 | spriteTessellationDetail: -1 45 | textureType: 0 46 | textureShape: 1 47 | maxTextureSizeSet: 0 48 | compressionQualitySet: 0 49 | textureFormatSet: 0 50 | platformSettings: 51 | - buildTarget: DefaultTexturePlatform 52 | maxTextureSize: 512 53 | textureFormat: -1 54 | textureCompression: 1 55 | compressionQuality: 50 56 | crunchedCompression: 0 57 | allowsAlphaSplitting: 0 58 | overridden: 0 59 | spriteSheet: 60 | serializedVersion: 2 61 | sprites: [] 62 | outline: [] 63 | spritePackingTag: 64 | userData: 65 | assetBundleName: 66 | assetBundleVariant: 67 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3/Sunny3_up.tif.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 05f6c978afe090d4d8f0af42a61bbe7f 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 4 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 1 9 | sRGBTexture: 1 10 | linearTexture: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: 0.25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 6 23 | cubemapConvolution: 0 24 | seamlessCubemap: 0 25 | textureFormat: -1 26 | maxTextureSize: 512 27 | textureSettings: 28 | filterMode: 1 29 | aniso: 1 30 | mipBias: 0 31 | wrapMode: 1 32 | nPOTScale: 1 33 | lightmap: 0 34 | compressionQuality: 50 35 | spriteMode: 0 36 | spriteExtrude: 1 37 | spriteMeshType: 1 38 | alignment: 0 39 | spritePivot: {x: 0.5, y: 0.5} 40 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 41 | spritePixelsToUnits: 100 42 | alphaUsage: 1 43 | alphaIsTransparency: 0 44 | spriteTessellationDetail: -1 45 | textureType: 0 46 | textureShape: 1 47 | maxTextureSizeSet: 0 48 | compressionQualitySet: 0 49 | textureFormatSet: 0 50 | platformSettings: 51 | - buildTarget: DefaultTexturePlatform 52 | maxTextureSize: 512 53 | textureFormat: -1 54 | textureCompression: 1 55 | compressionQuality: 50 56 | crunchedCompression: 0 57 | allowsAlphaSplitting: 0 58 | overridden: 0 59 | spriteSheet: 60 | serializedVersion: 2 61 | sprites: [] 62 | outline: [] 63 | spritePackingTag: 64 | userData: 65 | assetBundleName: 66 | assetBundleVariant: 67 | -------------------------------------------------------------------------------- /Assets/Shaders/TerrainShader.shader: -------------------------------------------------------------------------------- 1 | Shader "Terrain/TerrainShader" { 2 | Properties{ 3 | _MainTex("Base (RGB)", 2D) = "white" {} 4 | _SecondTex("Second (RGB)",2D) = "white"{} 5 | _ThirdTex("ThirdTex (RGB)",2D) = "white"{} 6 | _FourthTex("FourthTex (RGB)",2D) = "white"{} 7 | _Mask("Mask(RG)",2D) = "white"{} 8 | } 9 | SubShader{ 10 | Tags{ "Queue" = "Geometry" "RenderType" = "Opaque" } 11 | // ZWrite Off 12 | LOD 200 13 | 14 | CGPROGRAM 15 | // #pragma surface surf Unlit 16 | #pragma surface surf Lambert 17 | #pragma target 3.0 18 | 19 | sampler2D _MainTex; 20 | sampler2D _SecondTex; 21 | sampler2D _ThirdTex; 22 | sampler2D _FourthTex; 23 | sampler2D _Mask; 24 | 25 | struct Input { 26 | float2 uv_MainTex; 27 | //float2 uv_SecondTex; 28 | //float2 uv_ThirdTex; 29 | //float2 uv_FourthTex; 30 | float2 uv_Mask; 31 | }; 32 | 33 | void surf(Input IN, inout SurfaceOutput o) { 34 | half4 c1 = tex2D(_MainTex, IN.uv_MainTex); 35 | half4 c2 = tex2D(_SecondTex, IN.uv_MainTex); 36 | half4 c3 = tex2D(_ThirdTex, IN.uv_MainTex); 37 | half4 c4 = tex2D(_FourthTex, IN.uv_MainTex); 38 | //half4 c2 = tex2D(_SecondTex, IN.uv_SecondTex); 39 | //half4 c3 = tex2D(_ThirdTex, IN.uv_ThirdTex); 40 | //half4 c4 = tex2D(_FourthTex, IN.uv_FourthTex); 41 | half4 cm = tex2D(_Mask, IN.uv_Mask); 42 | //o.Albedo = c1.rgb*cm.r + c2.rgb*cm.g + c3.rgb*cm.b; 43 | o.Albedo = c1.rgb*cm.r + c2.rgb*cm.g + c3.rgb*cm.b + c4.rgb*cm.a; 44 | o.Alpha = c1.a; 45 | } 46 | 47 | // inline half4 LightingUnlit(SurfaceOutput s, fixed3 lightDir, fixed atten) 48 | // { 49 | // half4 c = half4(1, 1, 1, 1); 50 | // c.rgb = s.Albedo; 51 | // c.a = s.Alpha; 52 | // return c; 53 | // } 54 | 55 | ENDCG 56 | } 57 | FallBack "Diffuse" 58 | } -------------------------------------------------------------------------------- /Assets/Scripts/LodPiece.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class LodPiece 5 | { 6 | public Mesh mesh; //此片的网格 7 | public int LodLevel; //LOD等级 8 | public int offset_x; //偏移的 段 数 9 | public int offset_y; //同上 10 | public Rect box; //此片的范围 11 | public Vector3[] vers; //此片的顶点数组 12 | public Vector3[] nors; //法线数组 13 | public Vector2[] uvs; //uv数组 14 | public int[] indexes; //三角形顶点索引数组 15 | 16 | public int last_lod_level; //上次LOD等级 17 | public bool[] last_is_biger_level; //上次周围的片Lod等级是否大于此片的数组 18 | 19 | /// 20 | /// 判断是否需要更新 21 | /// 22 | /// 23 | /// 24 | public bool CheckNeedUpdate(bool[] new_biger_level) 25 | { 26 | if (mesh == null) return false; 27 | if (LodLevel != last_lod_level) 28 | { 29 | last_lod_level = LodLevel; 30 | return true; 31 | } 32 | for (int i = 0; i < 4; i++) 33 | { 34 | if (new_biger_level[i] != last_is_biger_level[i]) 35 | { 36 | last_lod_level = LodLevel; 37 | return true; 38 | } 39 | } 40 | return false; 41 | } 42 | 43 | public void SetLastBigLevel(bool[] new_biger_level) 44 | { 45 | for (int i = 0; i < 4; i++) 46 | { 47 | last_is_biger_level[i] = new_biger_level[i]; 48 | } 49 | } 50 | 51 | public void UpdateMeshData() 52 | { 53 | if (mesh!=null) 54 | { 55 | mesh.Clear(); 56 | mesh.vertices = vers; 57 | mesh.uv = uvs; 58 | mesh.triangles = indexes; 59 | mesh.normals = nors; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Assets/Textrues/land.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: da40bc6a8acf66e42878dea3f9fc150c 3 | timeCreated: 1482716766 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: -1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: 16 32 | mipBias: -1 33 | wrapMode: 0 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | - buildTarget: Standalone 62 | maxTextureSize: 2048 63 | textureFormat: -1 64 | textureCompression: 1 65 | compressionQuality: 50 66 | crunchedCompression: 0 67 | allowsAlphaSplitting: 0 68 | overridden: 0 69 | - buildTarget: Android 70 | maxTextureSize: 2048 71 | textureFormat: -1 72 | textureCompression: 1 73 | compressionQuality: 50 74 | crunchedCompression: 0 75 | allowsAlphaSplitting: 0 76 | overridden: 0 77 | spriteSheet: 78 | serializedVersion: 2 79 | sprites: [] 80 | outline: [] 81 | spritePackingTag: 82 | userData: 83 | assetBundleName: 84 | assetBundleVariant: 85 | -------------------------------------------------------------------------------- /Assets/Textrues/wetland.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a1c5dd01b0cc3f7428ff074a6bcbc5ef 3 | timeCreated: 1482716760 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: -1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: 16 32 | mipBias: -1 33 | wrapMode: 0 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | - buildTarget: Standalone 62 | maxTextureSize: 2048 63 | textureFormat: -1 64 | textureCompression: 1 65 | compressionQuality: 50 66 | crunchedCompression: 0 67 | allowsAlphaSplitting: 0 68 | overridden: 0 69 | - buildTarget: Android 70 | maxTextureSize: 2048 71 | textureFormat: -1 72 | textureCompression: 1 73 | compressionQuality: 50 74 | crunchedCompression: 0 75 | allowsAlphaSplitting: 0 76 | overridden: 0 77 | spriteSheet: 78 | serializedVersion: 2 79 | sprites: [] 80 | outline: [] 81 | spritePackingTag: 82 | userData: 83 | assetBundleName: 84 | assetBundleVariant: 85 | -------------------------------------------------------------------------------- /Assets/Textrues/DLGress002.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: abbfcdd5128d0f6419871a0e240c0502 3 | timeCreated: 1482716763 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: -1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: 16 32 | mipBias: -1 33 | wrapMode: 0 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | - buildTarget: Standalone 62 | maxTextureSize: 2048 63 | textureFormat: -1 64 | textureCompression: 1 65 | compressionQuality: 50 66 | crunchedCompression: 0 67 | allowsAlphaSplitting: 0 68 | overridden: 0 69 | - buildTarget: Android 70 | maxTextureSize: 2048 71 | textureFormat: -1 72 | textureCompression: 1 73 | compressionQuality: 50 74 | crunchedCompression: 0 75 | allowsAlphaSplitting: 0 76 | overridden: 0 77 | spriteSheet: 78 | serializedVersion: 2 79 | sprites: [] 80 | outline: [] 81 | spritePackingTag: 82 | userData: 83 | assetBundleName: 84 | assetBundleVariant: 85 | -------------------------------------------------------------------------------- /Assets/Hex.prefab: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1001 &100100000 4 | Prefab: 5 | m_ObjectHideFlags: 1 6 | serializedVersion: 2 7 | m_Modification: 8 | m_TransformParent: {fileID: 0} 9 | m_Modifications: [] 10 | m_RemovedComponents: [] 11 | m_ParentPrefab: {fileID: 0} 12 | m_RootGameObject: {fileID: 1678267974175748} 13 | m_IsPrefabParent: 1 14 | --- !u!1 &1678267974175748 15 | GameObject: 16 | m_ObjectHideFlags: 0 17 | m_PrefabParentObject: {fileID: 0} 18 | m_PrefabInternal: {fileID: 100100000} 19 | serializedVersion: 5 20 | m_Component: 21 | - component: {fileID: 4015799739700140} 22 | - component: {fileID: 212054013166877934} 23 | m_Layer: 0 24 | m_Name: Hex 25 | m_TagString: Untagged 26 | m_Icon: {fileID: 0} 27 | m_NavMeshLayer: 0 28 | m_StaticEditorFlags: 0 29 | m_IsActive: 1 30 | --- !u!4 &4015799739700140 31 | Transform: 32 | m_ObjectHideFlags: 1 33 | m_PrefabParentObject: {fileID: 0} 34 | m_PrefabInternal: {fileID: 100100000} 35 | m_GameObject: {fileID: 1678267974175748} 36 | m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} 37 | m_LocalPosition: {x: 0, y: 0, z: 0} 38 | m_LocalScale: {x: 1, y: 1, z: 1} 39 | m_Children: [] 40 | m_Father: {fileID: 0} 41 | m_RootOrder: 0 42 | m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} 43 | --- !u!212 &212054013166877934 44 | SpriteRenderer: 45 | m_ObjectHideFlags: 1 46 | m_PrefabParentObject: {fileID: 0} 47 | m_PrefabInternal: {fileID: 100100000} 48 | m_GameObject: {fileID: 1678267974175748} 49 | m_Enabled: 1 50 | m_CastShadows: 0 51 | m_ReceiveShadows: 0 52 | m_MotionVectors: 1 53 | m_LightProbeUsage: 0 54 | m_ReflectionProbeUsage: 0 55 | m_Materials: 56 | - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} 57 | m_StaticBatchInfo: 58 | firstSubMesh: 0 59 | subMeshCount: 0 60 | m_StaticBatchRoot: {fileID: 0} 61 | m_ProbeAnchor: {fileID: 0} 62 | m_LightProbeVolumeOverride: {fileID: 0} 63 | m_ScaleInLightmap: 1 64 | m_PreserveUVs: 0 65 | m_IgnoreNormalsForChartDetection: 0 66 | m_ImportantGI: 0 67 | m_SelectedEditorRenderState: 0 68 | m_MinimumChartSize: 4 69 | m_AutoUVMaxDistance: 0.5 70 | m_AutoUVMaxAngle: 89 71 | m_LightmapParameters: {fileID: 0} 72 | m_SortingLayerID: 0 73 | m_SortingOrder: 0 74 | m_Sprite: {fileID: 21300000, guid: 9b355b4f0a395d349b79d530ba4c8360, type: 3} 75 | m_Color: {r: 1, g: 1, b: 1, a: 1} 76 | m_FlipX: 0 77 | m_FlipY: 0 78 | -------------------------------------------------------------------------------- /Assets/Skyboxes/Textures/Sunny3 Skybox.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_PrefabParentObject: {fileID: 0} 8 | m_PrefabInternal: {fileID: 0} 9 | m_Name: Sunny3 Skybox 10 | m_Shader: {fileID: 104, guid: 0000000000000000f000000000000000, type: 0} 11 | m_ShaderKeywords: 12 | m_LightmapFlags: 5 13 | m_CustomRenderQueue: -1 14 | stringTagMap: {} 15 | m_SavedProperties: 16 | serializedVersion: 2 17 | m_TexEnvs: 18 | - first: 19 | name: _BackTex 20 | second: 21 | m_Texture: {fileID: 2800000, guid: 68287fe10cd30434b9c21ff1c55f613f, type: 3} 22 | m_Scale: {x: 1, y: 1} 23 | m_Offset: {x: 0, y: 0} 24 | - first: 25 | name: _DownTex 26 | second: 27 | m_Texture: {fileID: 2800000, guid: e3e214f8620f35a4cb4e415a4b8c19cf, type: 3} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - first: 31 | name: _FrontTex 32 | second: 33 | m_Texture: {fileID: 2800000, guid: a6c23ad66d37f0e4c8c86d7c5293ac7c, type: 3} 34 | m_Scale: {x: 1, y: 1} 35 | m_Offset: {x: 0, y: 0} 36 | - first: 37 | name: _LeftTex 38 | second: 39 | m_Texture: {fileID: 2800000, guid: 7a3134e5f9749c449ad2289cfe93f5d5, type: 3} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - first: 43 | name: _MainTex 44 | second: 45 | m_Texture: {fileID: 0} 46 | m_Scale: {x: 1, y: 1} 47 | m_Offset: {x: 0, y: 0} 48 | - first: 49 | name: _RightTex 50 | second: 51 | m_Texture: {fileID: 2800000, guid: e349c3f4b36417b48b65112d7bd0b54e, type: 3} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - first: 55 | name: _UpTex 56 | second: 57 | m_Texture: {fileID: 2800000, guid: 05f6c978afe090d4d8f0af42a61bbe7f, type: 3} 58 | m_Scale: {x: 1, y: 1} 59 | m_Offset: {x: 0, y: 0} 60 | m_Floats: 61 | - first: 62 | name: _Exposure 63 | second: 1.2 64 | - first: 65 | name: _Rotation 66 | second: 0 67 | m_Colors: 68 | - first: 69 | name: _Color 70 | second: {r: 1, g: 1, b: 1, a: 1} 71 | - first: 72 | name: _Tint 73 | second: {r: 0.5, g: 0.5, b: 0.5, a: 0.5} 74 | --- !u!1002 &2100001 75 | EditorExtensionImpl: 76 | serializedVersion: 6 77 | -------------------------------------------------------------------------------- /Assets/Scripts/WorkThread.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Threading; 4 | using System.Collections.Generic; 5 | 6 | public class WorkThread 7 | { 8 | private Thread m_thread; 9 | private Queue m_work_queue; 10 | private Queue m_complete_queue; 11 | private bool isRun = false; 12 | private Dictionary m_loading_map; 13 | 14 | private Thread m_normal_thread; 15 | private Queue m_normal_queue; 16 | private bool isNormalRun = false; 17 | 18 | public WorkThread() 19 | { 20 | m_work_queue = new Queue(); 21 | m_complete_queue = new Queue(); 22 | m_loading_map = new Dictionary(); 23 | m_thread = new Thread(BackgroundWork); 24 | 25 | m_normal_queue = new Queue(); 26 | m_normal_thread = new Thread(OnUpdateNormal); 27 | } 28 | 29 | private void BackgroundWork() 30 | { 31 | while (true) 32 | { 33 | while (m_work_queue.Count > 0) 34 | { 35 | var ck = m_work_queue.Dequeue(); 36 | ck.DoHardWork(); 37 | m_complete_queue.Enqueue(ck); 38 | } 39 | Thread.Sleep(100); 40 | } 41 | } 42 | 43 | public void AddWork(Chunk ck) 44 | { 45 | //ck.DoHardWork(); 46 | //ck.HardWorkComplete(); 47 | 48 | var key = ChunkManager.GetKey(ck.id_x, ck.id_y); 49 | m_loading_map.Add(key, ck); 50 | m_work_queue.Enqueue(ck); 51 | if (!isRun) 52 | { 53 | isRun = true; 54 | m_thread.Start(); 55 | } 56 | } 57 | public void OnMainThreadUpdate(ref bool needUpdateNormal) 58 | { 59 | while (m_complete_queue.Count>0) 60 | { 61 | var ck = m_complete_queue.Dequeue(); 62 | ck.HardWorkComplete(); 63 | var key = ChunkManager.GetKey(ck.id_x, ck.id_y); 64 | m_loading_map.Remove(key); 65 | needUpdateNormal = true; 66 | } 67 | } 68 | 69 | public bool CheckIsLoading(int idx,int idy) 70 | { 71 | var key = ChunkManager.GetKey(idx, idy); 72 | return m_loading_map.ContainsKey(key); 73 | } 74 | 75 | private void OnUpdateNormal() 76 | { 77 | while (true) 78 | { 79 | while (m_normal_queue.Count>0) 80 | { 81 | var ck = m_normal_queue.Dequeue(); 82 | ck.UpdateNormals(); 83 | } 84 | Thread.Sleep(10); 85 | } 86 | } 87 | 88 | public void AddUpdateNormlWork(Chunk ck) 89 | { 90 | //ck.UpdateNormals(); 91 | 92 | m_normal_queue.Enqueue(ck); 93 | if (!isNormalRun) 94 | { 95 | isNormalRun = true; 96 | m_normal_thread.Start(); 97 | } 98 | } 99 | 100 | public void Stop() 101 | { 102 | m_thread.Abort(); 103 | m_normal_thread.Abort(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Assets/Scripts/SurfaceMaskCreator.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using UnityEngine; 3 | 4 | public class SurfaceMaskCreator 5 | { 6 | public static Color[] GeneralMaskData(int segment, float MaxHeight, float[,] m_ver_ht, float min) 7 | { 8 | Color[] maskcolors = new Color[(segment + 1) * (segment + 1)]; 9 | float total_dis = MaxHeight - min; 10 | float each_height = total_dis / 5; 11 | float[] optimal = new float[4]; 12 | float opt, low, high, percent; 13 | Color[] carray = new Color[4] { new Color(1, 0, 0, 0), new Color(0, 1, 0, 0), new Color(0, 0, 1, 0), new Color(0, 0, 0, 1) }; 14 | for (int i = 0; i < 4; i++) 15 | { 16 | optimal[i] = (i + 1) * each_height + min; 17 | } 18 | for (int i = 0; i < segment + 1; i++) 19 | { 20 | for (int j = 0; j < segment + 1; j++) 21 | { 22 | float ht = m_ver_ht[j, i]; 23 | int key = i * (segment + 1) + j; 24 | if (ht <= each_height + min) 25 | { 26 | maskcolors[key] = new Color(1, 0, 0, 0); 27 | } 28 | else if (ht >= (MaxHeight - each_height)) 29 | { 30 | maskcolors[key] = new Color(0, 0, 0, 1); 31 | } 32 | else 33 | { 34 | maskcolors[key] = new Color(0, 0, 0, 0); 35 | for (int k = 0; k < 4; k++) 36 | { 37 | opt = optimal[k]; 38 | low = opt - each_height; 39 | high = opt + each_height; 40 | if (ht >= low && ht < opt) 41 | { 42 | percent = (ht - low) / each_height; 43 | //maskcolors[key] += (carray[k] * percent); 44 | ColorAdd(ref maskcolors[key], ref carray[k], percent); 45 | } 46 | else if (ht >= opt && ht < high) 47 | { 48 | percent = (high - ht) / each_height; 49 | //maskcolors[key] += (carray[k] * percent); 50 | ColorAdd(ref maskcolors[key], ref carray[k], percent); 51 | } 52 | } 53 | } 54 | } 55 | } 56 | return maskcolors; 57 | } 58 | public static Texture2D CreateMask(int segment) 59 | { 60 | var mask = new Texture2D(segment + 1, segment + 1, TextureFormat.ARGB32, true) 61 | { 62 | wrapMode = TextureWrapMode.Clamp 63 | }; 64 | return mask; 65 | } 66 | 67 | /// 68 | /// ret += (add * per) 性能优化写法 69 | /// 70 | /// 最终被加的颜色 71 | /// 用于加的基本色 72 | /// 百分比 73 | private static void ColorAdd(ref Color ret,ref Color add,float per) 74 | { 75 | ret.a += (add.a * per); 76 | ret.r += (add.r * per); 77 | ret.g += (add.g * per); 78 | ret.b += (add.b * per); 79 | } 80 | 81 | } 82 | 83 | -------------------------------------------------------------------------------- /Assets/Scripts/HeightMapParticleDeposition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | [Serializable] 5 | public struct ParticleDepositionConfig 6 | { 7 | public int size; 8 | public int seed; 9 | public int deposition_time; 10 | public int deposition_deap; 11 | public int deposition_size; 12 | public float each_h; 13 | } 14 | 15 | /// 16 | /// 粒子沉积 17 | /// 18 | public class HeightMapParticleDeposition 19 | { 20 | 21 | public static float[,] CreateMap(int size,int seed,int deposition_time,int deposition_deap,int deposition_size, float each_h,out float max) 22 | { 23 | float[,] ret = new float[size, size]; 24 | Random rand = new Random(seed); 25 | for (int i = 0; i < deposition_time; i++) 26 | { 27 | int posx = rand.Next(size - 1); 28 | int posy = rand.Next(size - 1); 29 | for (int j = 0; j < deposition_deap; j++) 30 | { 31 | double angle = rand.NextDouble() * Math.PI * 2; 32 | 33 | int offset = rand.Next(deposition_size); 34 | int offsetx = (int)(Math.Sin(angle) * offset); 35 | int offsety = (int)(Math.Cos(angle) * offset); 36 | int tempx = posx; 37 | int tempy = posy; 38 | if (posx + offsetx >= 0 && posx + offsetx < size) tempx += offsetx; 39 | if (posy + offsety >= 0 && posy + offsety < size) tempy += offsety; 40 | Deposition(ret, size, tempx, tempy, each_h); 41 | } 42 | } 43 | max = 0; 44 | for (int i = 0; i < size; i++) 45 | { 46 | for (int j = 0; j < size; j++) 47 | { 48 | if (ret[j,i]>max) 49 | { 50 | max = ret[j, i]; 51 | } 52 | } 53 | } 54 | return ret; 55 | } 56 | 57 | public static void Deposition(float[,] map,int size,int pos_x,int pos_y,float each_h) 58 | { 59 | float target_h = map[pos_x, pos_y]; 60 | if (pos_x>0 && map[pos_x-1,pos_y]+each_h<=target_h) 61 | { 62 | Deposition(map, size, pos_x - 1, pos_y, each_h); 63 | } 64 | else if (pos_y0 && map[pos_x,pos_y-1]+each_h<=target_h) 73 | { 74 | Deposition(map, size, pos_x, pos_y - 1, each_h); 75 | } 76 | else if (pos_x>0&&pos_y0 && map[pos_x+1,pos_y-1]+each_h <= target_h) 85 | { 86 | Deposition(map, size, pos_x+1, pos_y - 1, each_h); 87 | } 88 | else if (pos_x>0 && pos_y>0 && map[pos_x-1,pos_y-1]+each_h <= target_h) 89 | { 90 | Deposition(map, size, pos_x-1, pos_y - 1, each_h); 91 | } 92 | else 93 | { 94 | map[pos_x, pos_y] += each_h; 95 | } 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /Assets/Scripts/HeightMapFuzzyLandscaping.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | 4 | [Serializable] 5 | public struct LineMapConfig 6 | { 7 | public int size; 8 | public int seed; 9 | public int max; 10 | public int line_num; 11 | public int smooth_step; 12 | } 13 | 14 | public class HeightMapFuzzyLandscaping 15 | { 16 | public static float[,] CreateHeightMap(int size,int seed,float max,int step) 17 | { 18 | float[,] map = new float[size, size]; 19 | Random ran = new Random(seed); 20 | 21 | for (int i = 0; i < size; i++) 22 | { 23 | for (int j = 0; j < size; j++) 24 | { 25 | map[j, i] = (float)ran.NextDouble() * max; 26 | } 27 | } 28 | 29 | //JamesMcNeillSmooth(map, size); 30 | Smooth(map, size, step); 31 | 32 | return map; 33 | } 34 | 35 | public static float[,] CreateMapByLine(int size ,int seed ,float max,int line_num,int smooth_step) 36 | { 37 | float[,] map = new float[size, size]; 38 | Random ran = new Random(seed); 39 | 40 | for (int line_index = 0; line_index < line_num; line_index++) 41 | { 42 | float x_start = ran.Next(size - 1); 43 | float y_start = ran.Next(size - 1); 44 | double angle = ran.NextDouble() * Math.PI * 2; 45 | float x_diff = (float)Math.Sin(angle); 46 | float y_diff = (float)Math.Cos(angle); 47 | float curt_value = (float)ran.NextDouble() * max; 48 | do 49 | { 50 | map[(int)x_start, (int)y_start] = curt_value; 51 | x_start = x_start + x_diff; 52 | y_start = y_start + y_diff; 53 | if (x_diff*x_diff0f) 62 | &&(x_start0f)); 63 | } 64 | 65 | //JamesMcNeillSmooth(map, size); 66 | Smooth(map, size, smooth_step); 67 | 68 | return map; 69 | } 70 | 71 | public static void JamesMcNeillSmooth(float[,] map,int width) 72 | { 73 | //int row_offset = 0; 74 | int row_offset = width; 75 | 76 | for (int square_size = width; square_size > 1; square_size /= 2) 77 | { 78 | for (int x1 = row_offset; x1 < width; x1+=square_size) 79 | { 80 | for (int y1 = row_offset; y1 < width; y1+= square_size) 81 | { 82 | //Calculate the four corner offsets 83 | int x2 = ((x1 + square_size) % width); 84 | int y2 = ((y1 + square_size) % width); 85 | 86 | float i1 = map[x1, y1]; 87 | float i2 = map[x2, y1]; 88 | float i3 = map[x1, y2]; 89 | float i4 = map[x2, y2]; 90 | 91 | //weighted averages , 权重平均值 92 | float p1 = ((i1 * 9) + (i2 * 3) + (i3 * 3) + (i4)) / 16; 93 | float p2 = ((i1 * 3) + (i2 * 9) + (i3) + (i4 * 3)) / 16; 94 | float p3 = ((i1 * 3) + (i2) + (i3 * 9) + (i4 * 3)) / 16; 95 | float p4 = ((i1) + (i2 * 3) + (i3 * 3) + (i4 * 9)) / 16; 96 | 97 | //Calcuate the center points of each quadrant 98 | int x3 = ((x1 + square_size / 4) % width); 99 | int y3 = ((y1 + square_size / 4) % width); 100 | x2 = ((x3 + square_size/2) % width); 101 | y2 = ((y3 + square_size/2) % width); 102 | 103 | //set the points to the averages calcuated above 104 | //设置上面计算得的平均值 105 | map[x3, y3] = p1; 106 | map[x2, y3] = p2; 107 | map[x3, y2] = p3; 108 | map[x2, y2] = p4; 109 | } 110 | } 111 | row_offset = square_size / 4; 112 | } 113 | } 114 | 115 | public static void Smooth(float[,] map,int size,int step) 116 | { 117 | for (int y = 0; y < size; y+=step) 118 | { 119 | for (int x = 0; x < size; x+=step) 120 | { 121 | float total = 0; 122 | for (int y_local = y; y_local < y+step ; y_local++) 123 | { 124 | for (int x_local = x; x_local < x+step; x_local++) 125 | { 126 | total += map[x_local, y_local]; 127 | } 128 | } 129 | float avg = total / (step * step); 130 | for (int y_local = y; y_local < y+step; y_local++) 131 | { 132 | for (int x_local = x; x_local < x+step; x_local++) 133 | { 134 | map[x_local, y_local] = avg; 135 | } 136 | } 137 | } 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /NoHumansAllowed.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {13AF218E-66D1-174B-EA5E-53DD25FA03DB} 9 | Library 10 | Assembly-CSharp 11 | 512 12 | {E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 13 | .NETFramework 14 | v3.5 15 | Unity Subset v3.5 16 | 17 | Game:1 18 | StandaloneWindows:5 19 | 5.5.0f3 20 | 21 | 4 22 | 23 | 24 | pdbonly 25 | false 26 | Temp\UnityVS_bin\Debug\ 27 | Temp\UnityVS_obj\Debug\ 28 | prompt 29 | 4 30 | DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_5_0;UNITY_5_5;UNITY_5;UNITY_ANALYTICS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_SCRIPTING_NEW_CSHARP_COMPILER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VIDEO;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE 31 | false 32 | 33 | 34 | pdbonly 35 | false 36 | Temp\UnityVS_bin\Release\ 37 | Temp\UnityVS_obj\Release\ 38 | prompt 39 | 4 40 | TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_5_0;UNITY_5_5;UNITY_5;UNITY_ANALYTICS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_SCRIPTING_NEW_CSHARP_COMPILER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VIDEO;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE 41 | false 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | Library\UnityAssemblies\UnityEngine.dll 54 | 55 | 56 | Library\UnityAssemblies\UnityEngine.UI.dll 57 | 58 | 59 | Library\UnityAssemblies\UnityEngine.Networking.dll 60 | 61 | 62 | Library\UnityAssemblies\UnityEngine.PlaymodeTestsRunner.dll 63 | 64 | 65 | Library\UnityAssemblies\UnityEngine.Analytics.dll 66 | 67 | 68 | Library\UnityAssemblies\UnityEngine.HoloLens.dll 69 | 70 | 71 | Library\UnityAssemblies\UnityEngine.VR.dll 72 | 73 | 74 | Library\UnityAssemblies\UnityEditor.dll 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /UnityInfinityTerrainDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {0F85567D-25C3-51E0-6D0F-FA45B790A858} 9 | Library 10 | Assembly-CSharp 11 | 512 12 | {E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 13 | .NETFramework 14 | v3.5 15 | Unity Subset v3.5 16 | 17 | 18 | Game:1 19 | StandaloneWindows:5 20 | 5.5.0f3 21 | 22 | 23 | 4 24 | 25 | 26 | pdbonly 27 | false 28 | Temp\UnityVS_bin\Debug\ 29 | Temp\UnityVS_obj\Debug\ 30 | prompt 31 | 4 32 | DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_5_0;UNITY_5_5;UNITY_5;UNITY_ANALYTICS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_SCRIPTING_NEW_CSHARP_COMPILER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VIDEO;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE 33 | false 34 | 35 | 36 | pdbonly 37 | false 38 | Temp\UnityVS_bin\Release\ 39 | Temp\UnityVS_obj\Release\ 40 | prompt 41 | 4 42 | TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_5_0;UNITY_5_5;UNITY_5;UNITY_ANALYTICS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_SCRIPTING_NEW_CSHARP_COMPILER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VIDEO;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE 43 | false 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Library\UnityAssemblies\UnityEngine.dll 56 | 57 | 58 | Library\UnityAssemblies\UnityEngine.UI.dll 59 | 60 | 61 | Library\UnityAssemblies\UnityEngine.Networking.dll 62 | 63 | 64 | Library\UnityAssemblies\UnityEngine.PlaymodeTestsRunner.dll 65 | 66 | 67 | Library\UnityAssemblies\UnityEngine.Analytics.dll 68 | 69 | 70 | Library\UnityAssemblies\UnityEngine.HoloLens.dll 71 | 72 | 73 | Library\UnityAssemblies\UnityEngine.VR.dll 74 | 75 | 76 | Library\UnityAssemblies\UnityEditor.dll 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Assets/Scripts/HeightMapFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | public enum TerrainType 5 | { 6 | Normal, //普通 7 | Basin, //盆地 8 | Hill //山 9 | } 10 | 11 | [Serializable] 12 | public struct HeightMapConfig 13 | { 14 | [Range(5,14)] 15 | public int Iterations; 16 | [Range(0.1f,1f)] 17 | public float H; 18 | public float min; 19 | public float max; 20 | public int seed; 21 | public TerrainType type; 22 | } 23 | 24 | /** 25 | 随机分形地形生成 26 | http://www.cnblogs.com/lookof/archive/2009/03/18/1415259.html 27 | ************/ 28 | 29 | class HeightMapFactory 30 | { 31 | /// 32 | /// 使用分形算法(菱形-四边形)计算出高度图 33 | /// 34 | /// 迭代次数 35 | /// 粗糙度常数 36 | /// 最小值 37 | /// 最大值 38 | /// 随机数种子 39 | /// 类型 40 | public static float[,] CreateHeightMapByFractal(int Iterations, float H, float min, float max, int seed, TerrainType type) 41 | { 42 | int Segment = 1 << Iterations; 43 | float[,] heightmap = new float[Segment + 1, Segment + 1]; 44 | for (int i = 0; i < Segment + 1; i++) 45 | { 46 | for (int j = 0; j < Segment + 1; j++) 47 | { 48 | heightmap[j, i] = -100; 49 | } 50 | } 51 | GeneralHeightMapByFractal(Iterations, H, min, max, seed, type, heightmap); 52 | return heightmap; 53 | } 54 | 55 | /// 56 | /// 使用分形算法计算出高度图 57 | /// 58 | /// 迭代次数 59 | /// 粗糙度常数 60 | /// 最小值 61 | /// 最大值 62 | /// 随机数种子 63 | /// 类型 64 | public static void GeneralHeightMapByFractal(int Iterations, float H, float min, float max,int seed,TerrainType type, float[,] heightmap) 65 | { 66 | int Segment = 1 << Iterations; 67 | float random_range = (max - min); 68 | var rand = new System.Random(seed); 69 | float centerh = min + random_range * 0.5f; 70 | float rd = 0; 71 | if (type==TerrainType.Normal) //普通 72 | { 73 | heightmap[0, 0] = rd + centerh; 74 | heightmap[Segment, 0] = rd + centerh; 75 | heightmap[0, Segment] = rd + centerh; 76 | heightmap[Segment, Segment] = rd + centerh; 77 | heightmap[Segment / 2, Segment / 2] = rd + centerh; 78 | } 79 | else if (type == TerrainType.Basin) //盆地 80 | { 81 | heightmap[0, 0] = max; 82 | heightmap[Segment, 0] = max; 83 | heightmap[0, Segment] = max; 84 | heightmap[Segment, Segment] = max; 85 | heightmap[Segment / 2, Segment / 2] = min; 86 | heightmap[0, Segment / 2] = max; 87 | heightmap[Segment, Segment / 2] = max; 88 | heightmap[Segment / 2, 0] = max; 89 | heightmap[Segment / 2, Segment] = max; 90 | } 91 | else if (type == TerrainType.Hill ) //山 92 | { 93 | heightmap[0, 0] = min; 94 | heightmap[Segment, 0] = min; 95 | heightmap[0, Segment] = min; 96 | heightmap[Segment, Segment] = min; 97 | heightmap[Segment / 2, Segment / 2] = max; 98 | } 99 | 100 | float random_factor = Mathf.Pow(2, -H); 101 | for (int i = 1; i <= Iterations; i++) 102 | { 103 | int curt_segment = Segment / (1 << (i - 1)); 104 | int rectnum = 1 << (i - 1); 105 | random_range = random_range * random_factor; 106 | for (int iterI = 0; iterI < rectnum; iterI++) 107 | { 108 | for (int iterJ = 0; iterJ < rectnum; iterJ++) 109 | { 110 | int basex = iterJ * curt_segment; 111 | int basey = iterI * curt_segment; 112 | int centerx = basex + curt_segment / 2; 113 | int centery = basey + curt_segment / 2; 114 | float leftdown = heightmap[basex, basey]; 115 | float rightdown = heightmap[basex + curt_segment, basey]; 116 | float lefttop = heightmap[basex, basey+curt_segment]; 117 | float rightop = heightmap[basex + curt_segment, basey + curt_segment]; 118 | float centerht = GetHeight(leftdown, rightdown, lefttop, rightop, random_range,rand); 119 | SetHeight(centerx, centery, heightmap, centerht);//矩形中点 120 | } 121 | } 122 | 123 | for (int iterI = 0; iterI < rectnum; iterI++) 124 | { 125 | for (int iterJ = 0; iterJ < rectnum; iterJ++) 126 | { 127 | int basex = iterJ * curt_segment; 128 | int basey = iterI * curt_segment; 129 | int centerx = basex + curt_segment / 2; 130 | int centery = basey + curt_segment / 2; 131 | float leftdown = heightmap[basex, basey]; 132 | float rightdown = heightmap[basex + curt_segment, basey]; 133 | float lefttop = heightmap[basex, basey + curt_segment]; 134 | float rightop = heightmap[basex + curt_segment, basey + curt_segment]; 135 | float center = heightmap[centerx, centery]; 136 | 137 | int left = centerx - curt_segment; 138 | if (left < 0) 139 | { 140 | left += Segment; 141 | } 142 | int right = centerx + curt_segment; 143 | if (right>=Segment) 144 | { 145 | right -= Segment; 146 | } 147 | int down = centery - curt_segment; 148 | if (down < 0) 149 | { 150 | down += Segment; 151 | } 152 | int top = centery + curt_segment; 153 | if (top>=Segment) 154 | { 155 | top -= Segment; 156 | } 157 | //下面为中点的四个相邻点 158 | float temp0 = GetHeight(heightmap[left, centery], lefttop, center, leftdown, random_range,rand); 159 | SetHeight(basex, centery, heightmap, temp0); 160 | if (iterI == rectnum - 1) 161 | {//只有最后一横才需要加上它上面的点 162 | float temp1 = GetHeight(lefttop, heightmap[centerx, top], rightop, center, random_range,rand); 163 | SetHeight(centerx, basey + curt_segment, heightmap, temp1); 164 | } 165 | if (iterJ==rectnum-1) 166 | {//只有最后一纵才需要加上它右边的点 167 | float temp2 = GetHeight(center, rightop, heightmap[right, centery], rightdown, random_range,rand); 168 | SetHeight(basex + curt_segment, centery, heightmap, temp2); 169 | } 170 | float temp3 = GetHeight(leftdown, center, rightdown, heightmap[centerx, down], random_range,rand); 171 | SetHeight(centerx, basey, heightmap, temp3); 172 | } 173 | } 174 | } 175 | } 176 | 177 | private static void SetHeight(int idx,int idy,float[,] heightmap,float targetht) 178 | { 179 | //heightmap[idx, idy] = targetht; 180 | if (heightmap[idx, idy] < -50f) 181 | { 182 | heightmap[idx, idy] = targetht; 183 | } 184 | } 185 | 186 | //分形(4个相邻点的平均值+一个随机值) 187 | private static float GetHeight(float p0, float p1, float p2, float p3, float random_range,System.Random rand) 188 | { 189 | float rd = ((float)rand.NextDouble() - 0.5f) * 2 * random_range; 190 | return ((p0 + p1 + p2 + p3) / 4.0f + rd); 191 | } 192 | 193 | } 194 | -------------------------------------------------------------------------------- /Assets/Scripts/ChunkManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | public class ChunkManager : MonoBehaviour 5 | { 6 | public const int LOD_LEVEL_MAX = 4; //最大Lod级别 7 | public static ChunkManager Instence = null; 8 | 9 | [Header("heightmap")] 10 | public HeightMapConfig config; //高度图生成配置 11 | [Header("filter")] 12 | public FIRFilterConfig filter_config; //过滤器, 13 | [Header("chunk")] 14 | public Vector2 ChunkSize=new Vector2(128,128); //单片Chunk大小 15 | public Vector2 AddSize=new Vector2(64,64); //添加周围Chunk的范围 16 | public Vector2 RemoveSize=new Vector2(160,160); //移除自身的范围 17 | public float CL = 1.0f; //计算Lod等级的常数 18 | [Header("mesh")] 19 | public Material MeshMat; //绘制网格所用的材质 20 | public int MeshPieceSegment = 32; //单片网格有多少 段 21 | public int MeshPieceNum = 8; //单个Chunk有多少 片 网格 22 | [Header("hero")] 23 | public Transform hero; //主角,用于计算LOD等级 24 | 25 | public ArrayCache cache_v3; //此3项为顶点、UV、三角索引 缓存类 26 | public ArrayCache cache_v2; 27 | public ArrayCache cache_int; 28 | 29 | private Vector2 m_MeshSegmentSize; //网格最细分时每段的大小 30 | private int m_TotalMeshSegmentNum; //单个Chunk中,总共分多少段网格 31 | 32 | private Dictionary chunk_map; //所有Chunk容器 33 | private Queue remove_queue; //移除队列 34 | private Queue add_queue; //待添加队列 35 | private Stack cache_chunk; //缓存本来应该被释放的Chunk 36 | private bool needUpdateNormal = false; //本次是否需要重新计算法线(Normal) 37 | private WorkThread m_thread_work; //后台线程 38 | 39 | /// 40 | /// 计算Chunk存储时的key 41 | /// 42 | /// 43 | /// 44 | /// 45 | public static long GetKey(int id_x,int id_y) 46 | { 47 | ulong ret = (uint)id_x; 48 | uint temp = (uint)id_y; 49 | ulong key = (ret << 32) | temp; 50 | return (long)key; 51 | } 52 | 53 | private void Awake() 54 | { 55 | Instence = this; 56 | cache_int = new ArrayCache(); 57 | cache_v2 = new ArrayCache(); 58 | cache_v3 = new ArrayCache(); 59 | cache_chunk = new Stack(); 60 | chunk_map = new Dictionary(); 61 | remove_queue = new Queue(); 62 | add_queue = new Queue(); 63 | m_TotalMeshSegmentNum = MeshPieceNum * MeshPieceSegment; 64 | m_MeshSegmentSize = ChunkSize / m_TotalMeshSegmentNum; 65 | m_thread_work = new WorkThread(); 66 | AddChunk(0,0); 67 | } 68 | 69 | /// 70 | /// 创建Chunk,并将其添加到队列中去 71 | /// 72 | /// 73 | /// 74 | private void AddChunk(int idx, int idy) 75 | { 76 | if (m_thread_work.CheckIsLoading(idx, idy)) return; 77 | //needUpdateNormal = true; 78 | Chunk ck = null; 79 | if (cache_chunk.Count > 0) 80 | ck = cache_chunk.Pop(); 81 | else 82 | ck = new Chunk(); 83 | ck.id_x = idx; 84 | ck.id_y = idy; 85 | ck.box.x = ck.id_x * ChunkSize.x; 86 | ck.box.y = ck.id_y * ChunkSize.y; 87 | ck.box.size = ChunkSize; 88 | ck.box_add.position = ck.box.position + (ChunkSize - AddSize) / 2; 89 | ck.box_add.size = AddSize; 90 | ck.box_remove.position = ck.box.position + (ChunkSize - RemoveSize) / 2; 91 | ck.box_remove.size = RemoveSize; 92 | add_queue.Enqueue(ck); //添加到待添加队列中 93 | } 94 | 95 | /// 96 | /// 添加到容器中 97 | /// 98 | /// 99 | public void AddToMap(Chunk ck) 100 | { 101 | lock (chunk_map) 102 | {//因为在后台线程中有调用此方法,可能与主线程的foreach冲突 103 | long key = GetKey(ck.id_x, ck.id_y); 104 | Debug.Log("add to map key:" + ck.id_x + "_" + ck.id_y); 105 | chunk_map.Add(key, ck); 106 | } 107 | } 108 | 109 | /// 110 | /// 从容器中取对应Chunk 111 | /// 112 | /// 113 | /// 114 | /// 115 | /// 116 | public bool GetChunk(int id_x,int id_y,out Chunk ret) 117 | { 118 | long key = GetKey(id_x, id_y); 119 | return chunk_map.TryGetValue(key, out ret); 120 | } 121 | 122 | void Update() 123 | { 124 | lock (chunk_map) 125 | { 126 | Vector3 hero_pos = hero.position; 127 | UpdateRemove(hero_pos); 128 | UpdateAdd(hero_pos); 129 | UpdateLod(hero_pos); 130 | m_thread_work.OnMainThreadUpdate(ref needUpdateNormal); 131 | } 132 | } 133 | 134 | /// 135 | /// 检查是否有需要移除的Chunk 136 | /// 137 | /// 138 | private void UpdateRemove(Vector3 hero_pos) 139 | { 140 | foreach (var temp in chunk_map) 141 | { 142 | var ck = temp.Value; 143 | if (hero_pos.x < ck.box_remove.xMin || hero_pos.x > ck.box_remove.xMax || hero_pos.z < ck.box_remove.yMin || hero_pos.z > ck.box_remove.yMax) 144 | { 145 | remove_queue.Enqueue(ck); //将需要移除的Chunk放入移除队列 146 | ck.DestroyGameObject(); 147 | } 148 | } 149 | while (remove_queue.Count>0)//移除不可以放在foreach循环中,所以用此方法从容器中移除 150 | { 151 | var ck = remove_queue.Dequeue(); 152 | var key = GetKey(ck.id_x, ck.id_y); 153 | chunk_map.Remove(key); 154 | cache_chunk.Push(ck); 155 | } 156 | } 157 | 158 | /// 159 | /// 检查是否有需要添加的Chunk 160 | /// 161 | /// 162 | private void UpdateAdd(Vector3 hero_pos) 163 | { 164 | foreach (var temp in chunk_map) 165 | { 166 | var ck = temp.Value; 167 | if (hero_pos.x >= ck.box.xMin && hero_pos.x <= ck.box.xMax 168 | && hero_pos.z >= ck.box.yMin && hero_pos.z <= ck.box.yMax) 169 | { 170 | bool isLeft = hero_pos.x < ck.box_add.xMin; 171 | bool isRight = hero_pos.x > ck.box_add.xMax; 172 | bool isUp = hero_pos.z > ck.box_add.yMax; 173 | bool isDown = hero_pos.z < ck.box_add.yMin; 174 | if (isLeft && ck.Left==null) 175 | AddChunk(ck.id_x - 1, ck.id_y); 176 | if (isRight && ck.Right==null) 177 | AddChunk(ck.id_x + 1, ck.id_y); 178 | if (isUp && ck.Up==null) 179 | AddChunk(ck.id_x, ck.id_y + 1); 180 | if (isDown && ck.Down==null) 181 | AddChunk(ck.id_x, ck.id_y - 1); 182 | if (isLeft && isUp && ck.LeftUp==null) 183 | AddChunk(ck.id_x - 1, ck.id_y + 1); 184 | if (isLeft && isDown && ck.LeftDown==null) 185 | AddChunk(ck.id_x - 1, ck.id_y - 1); 186 | if (isRight && isUp && ck.RightUp==null) 187 | AddChunk(ck.id_x + 1, ck.id_y + 1); 188 | if (isRight && isDown && ck.RightDown==null) 189 | AddChunk(ck.id_x + 1, ck.id_y - 1); 190 | } 191 | } 192 | 193 | while (add_queue.Count>0) //添加也不可以放到foreach循环中,否则会出错 194 | { 195 | var ck = add_queue.Dequeue(); 196 | HeightMapConfig lcfg = config; 197 | lcfg.seed = config.seed + ck.id_x + ck.id_y; 198 | //让粗糙度渐变,这个只是测试用,具体可根据实际情况确定 199 | lcfg.H = config.H + ((Mathf.Sin(ck.id_x)) / 8) + ((Mathf.Cos(ck.id_y)) / 8); 200 | Debug.Log("Current H:" + lcfg.H); 201 | ck.GeneralData(lcfg, m_TotalMeshSegmentNum, m_MeshSegmentSize, MeshMat, MeshPieceSegment, MeshPieceNum); //此步需要访问相邻Chunk,当多个Chunk需要添加时,应当保证执行过此步的Chunk都已经存放到容器中了 202 | m_thread_work.AddWork(ck); 203 | } 204 | } 205 | 206 | /// 207 | /// 刷新所有的Chunk的Lod网格 208 | /// 209 | /// 210 | private void UpdateLod(Vector3 hero_pos) 211 | { 212 | foreach (var temp in chunk_map) 213 | { 214 | var ck = temp.Value; 215 | if (needUpdateNormal) //此帧是否需要重新计算法线 216 | { 217 | m_thread_work.AddUpdateNormlWork(ck); 218 | } 219 | ck.UpdateLodLevel(hero_pos); //划分Lod等级 220 | ck.CheckSidesLodLevel(); //强制检查LOD等级,使相邻的片的Lod等级差不超过1 221 | ck.UpdateLod(); //更具LOD更新网格 222 | } 223 | needUpdateNormal = false; 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /NoHumansAllowed.Editor.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {EA5B46D6-3085-59AD-6347-7CA43540DF96} 9 | Library 10 | Assembly-CSharp-Editor 11 | 512 12 | {E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 13 | .NETFramework 14 | v3.5 15 | Unity Full v3.5 16 | 17 | 18 | Editor:5 19 | StandaloneWindows:5 20 | 5.5.0f3 21 | 22 | 23 | 4 24 | 25 | 26 | pdbonly 27 | false 28 | Temp\UnityVS_bin\Debug\ 29 | Temp\UnityVS_obj\Debug\ 30 | prompt 31 | 4 32 | DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_5_0;UNITY_5_5;UNITY_5;UNITY_ANALYTICS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_SCRIPTING_NEW_CSHARP_COMPILER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VIDEO;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE 33 | false 34 | 35 | 36 | pdbonly 37 | false 38 | Temp\UnityVS_bin\Release\ 39 | Temp\UnityVS_obj\Release\ 40 | prompt 41 | 4 42 | TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_5_0;UNITY_5_5;UNITY_5;UNITY_ANALYTICS;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_SCRIPTING_NEW_CSHARP_COMPILER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VIDEO;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE 43 | false 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Library\UnityAssemblies\UnityEngine.dll 56 | 57 | 58 | Library\UnityAssemblies\UnityEditor.dll 59 | 60 | 61 | Library\UnityAssemblies\UnityEditor.Advertisements.dll 62 | 63 | 64 | Library\UnityAssemblies\nunit.framework.dll 65 | 66 | 67 | Library\UnityAssemblies\UnityEditor.EditorTestsRunner.dll 68 | 69 | 70 | Library\UnityAssemblies\UnityEngine.UI.dll 71 | 72 | 73 | Library\UnityAssemblies\UnityEditor.UI.dll 74 | 75 | 76 | Library\UnityAssemblies\UnityEngine.Networking.dll 77 | 78 | 79 | Library\UnityAssemblies\UnityEditor.Networking.dll 80 | 81 | 82 | Library\UnityAssemblies\UnityEditor.PlaymodeTestsRunner.dll 83 | 84 | 85 | Library\UnityAssemblies\UnityEngine.PlaymodeTestsRunner.dll 86 | 87 | 88 | Library\UnityAssemblies\UnityEditor.TreeEditor.dll 89 | 90 | 91 | Library\UnityAssemblies\UnityEngine.Analytics.dll 92 | 93 | 94 | Library\UnityAssemblies\UnityEditor.Analytics.dll 95 | 96 | 97 | Library\UnityAssemblies\UnityEditor.HoloLens.dll 98 | 99 | 100 | Library\UnityAssemblies\UnityEngine.HoloLens.dll 101 | 102 | 103 | Library\UnityAssemblies\UnityEditor.VR.dll 104 | 105 | 106 | Library\UnityAssemblies\UnityEngine.VR.dll 107 | 108 | 109 | Library\UnityAssemblies\UnityEditor.Graphs.dll 110 | 111 | 112 | Library\UnityAssemblies\UnityEditor.Android.Extensions.dll 113 | 114 | 115 | Library\UnityAssemblies\UnityEditor.WindowsStandalone.Extensions.dll 116 | 117 | 118 | Library\UnityAssemblies\SyntaxTree.VisualStudio.Unity.Bridge.dll 119 | 120 | 121 | 122 | 123 | {13AF218E-66D1-174B-EA5E-53DD25FA03DB} 124 | NoHumansAllowed 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /Assets/Scripts/TerrainDyRectCreator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | public class TerrainDyRectCreator : MonoBehaviour 5 | { 6 | private const int LOD_LEVEL_MAX= 4; 7 | 8 | [Header("Heightmap")] 9 | public HeightMapConfig config; 10 | [Header("LineHeightmap")] 11 | public LineMapConfig config_line; 12 | [Header("ParticleDeposition")] 13 | public ParticleDepositionConfig config_particle; 14 | [Header("Filter")] 15 | public FIRFilterConfig fir_config; 16 | 17 | [Header("Mesh")] 18 | public int PieceMechSegment = 16; //每篇网格多少段 19 | public int PieceNum = 4; //多少篇网格 20 | public Material PieceMat; 21 | 22 | private int MeshSegment = 64; //世界总共分多少网格片段 23 | 24 | private Vector2 m_mesh_segment_size; 25 | private Vector3[,] m_mesh_vers; 26 | private Vector3[,] m_mesh_normals; 27 | private Vector2[,] m_mesh_uvs; 28 | private int ver_num_each_line; 29 | 30 | private int m_heightmap_len = 0; 31 | private float[,] m_heightmap; 32 | 33 | private LodPiece[,] m_piecees; 34 | private System.Diagnostics.Stopwatch m_watch; 35 | private string log_msg = string.Empty; 36 | 37 | private ArrayCache m_cache_v3; 38 | private ArrayCache m_cache_v2; 39 | private ArrayCache m_cache_int; 40 | 41 | private Vector2 FixedWorldSize = new Vector2(128, 128); 42 | 43 | public Transform hero; 44 | 45 | private void Awake() 46 | { 47 | m_cache_v3 = new ArrayCache(); 48 | m_cache_v2 = new ArrayCache(); 49 | m_cache_int = new ArrayCache(); 50 | 51 | float max = 0; 52 | 53 | m_watch = new System.Diagnostics.Stopwatch(); 54 | m_heightmap_len = 1 << config.Iterations; 55 | m_heightmap = HeightMapFactory.CreateHeightMapByFractal(config.Iterations, config.H, config.min, config.max, config.seed, config.type); 56 | max = config.max; 57 | HeightMapFilter.FilterFIR(m_heightmap, m_heightmap_len + 1, fir_config.times, fir_config.k); 58 | 59 | //m_heightmap_len = config_line.size -1; 60 | //m_heightmap = HeightMapFuzzyLandscaping.CreateHeightMap(config_line.size, config_line.seed, config_line.max,config_line.smooth_step); 61 | 62 | //m_heightmap_len = config_line.size - 1; 63 | //m_heightmap = HeightMapFuzzyLandscaping.CreateMapByLine(config_line.size, config_line.seed, config_line.max, config_line.line_num,config_line.smooth_step); 64 | 65 | //m_heightmap_len = config_particle.size - 1; 66 | //m_heightmap = HeightMapParticleDeposition.CreateMap(config_particle.size, config_particle.seed, config_particle.deposition_time, config_particle.deposition_deap, config_particle.deposition_size,config_particle.each_h,out max); 67 | //HeightMapVolcano.ToVolcano(m_heightmap, m_heightmap_len + 1, max * 0.5f); 68 | //HeightMapFilter.FilterFIR(m_heightmap, m_heightmap_len + 1, fir_config.times, fir_config.k); 69 | 70 | 71 | InitMeshMap(); 72 | var mask = SurfaceMaskCreator.CreateMask(m_heightmap_len); 73 | var maskcolor = SurfaceMaskCreator.GeneralMaskData(m_heightmap_len, max, m_heightmap, 0); 74 | mask.SetPixels(maskcolor); 75 | mask.Apply(); 76 | PieceMat.SetTexture("_Mask", mask); 77 | } 78 | 79 | private void InitMeshMap() 80 | { 81 | MeshSegment = PieceMechSegment * PieceNum; 82 | m_mesh_segment_size = FixedWorldSize / MeshSegment; 83 | ver_num_each_line = MeshSegment + 1; 84 | m_mesh_vers = new Vector3[ver_num_each_line, ver_num_each_line]; 85 | m_mesh_uvs = new Vector2[ver_num_each_line, ver_num_each_line]; 86 | m_mesh_normals = new Vector3[ver_num_each_line, ver_num_each_line]; 87 | Vector2 one_uv = new Vector2(m_mesh_segment_size.x / FixedWorldSize.x, m_mesh_segment_size.y / FixedWorldSize.y); 88 | for (int i = 0; i < ver_num_each_line; i++) 89 | { 90 | for (int j = 0; j < ver_num_each_line; j++) 91 | { 92 | float posx = m_mesh_segment_size.x * j; 93 | float posy = m_mesh_segment_size.y * i; 94 | float uu = one_uv.x * j; 95 | float vv = one_uv.y * i; 96 | int index_x = Mathf.RoundToInt(m_heightmap_len * uu); 97 | int index_y = Mathf.RoundToInt(m_heightmap_len * vv); 98 | float ht = m_heightmap[index_x, index_y]; 99 | m_mesh_uvs[j, i] = new Vector2(uu, vv); 100 | m_mesh_vers[j, i] = new Vector3(posx, ht, posy); 101 | } 102 | } 103 | for (int i = 0; i < ver_num_each_line; i++) 104 | { 105 | for (int j = 0; j < ver_num_each_line; j++) 106 | { 107 | Vector3 p0 = m_mesh_vers[j, i]; 108 | Vector3 p1 = GetVer(j + 1, i); 109 | Vector3 p2 = GetVer(j, i - 1); 110 | Vector3 p3 = GetVer(j - 1, i); 111 | Vector3 p4 = GetVer(j, i + 1); 112 | 113 | Vector3 v01 = p1 - p0; 114 | Vector3 v02 = p2 - p0; 115 | Vector3 v03 = p3 - p0; 116 | Vector3 v04 = p4 - p0; 117 | v01.Normalize(); 118 | v02.Normalize(); 119 | v03.Normalize(); 120 | v04.Normalize(); 121 | 122 | Vector3 n1 = Vector3.Cross(v04, v01); 123 | Vector3 n2 = Vector3.Cross(v01, v02); 124 | Vector3 n3 = Vector3.Cross(v02, v03); 125 | Vector3 n4 = Vector3.Cross(v03, v04); 126 | 127 | Vector3 nor = n1 + n2 + n3 + n4; 128 | nor.Normalize(); 129 | m_mesh_normals[j, i] = nor; 130 | } 131 | } 132 | Debug.LogFormat("ver num {0}", ver_num_each_line* ver_num_each_line); 133 | int size_of_vector3 = 12; 134 | int size_of_vector2 = 8; 135 | long total_total = (size_of_vector3+ size_of_vector3+ size_of_vector2)*ver_num_each_line*ver_num_each_line; 136 | Debug.LogFormat("total(ver+uv+normal) cache size:{0}Byte==={1}MB", total_total, total_total / 1024f / 1024f); 137 | } 138 | 139 | private Vector3 GetVer(int index_x,int index_y) 140 | { 141 | float posx = m_mesh_segment_size.x * index_x; 142 | float posy = m_mesh_segment_size.y * index_y; 143 | if (index_x < 0) index_x = 0; 144 | if (index_x >= ver_num_each_line) index_x = ver_num_each_line-1; 145 | if (index_y < 0) index_y = 0; 146 | if (index_y >= ver_num_each_line) index_y = ver_num_each_line-1; 147 | float ht = m_mesh_vers[index_x, index_y].y; 148 | return new Vector3(posx,ht,posy); 149 | } 150 | 151 | private void InitPiece() 152 | {//test 153 | GameObject piece_root = new GameObject("piece_root"); 154 | m_piecees = new LodPiece[PieceNum, PieceNum]; 155 | for (int i = 0; i < PieceNum; i++) 156 | { 157 | for (int j = 0; j < PieceNum; j++) 158 | { 159 | int offset_x = j * PieceMechSegment; 160 | int offset_y = i * PieceMechSegment; 161 | LodPiece piece = new LodPiece() 162 | { 163 | offset_x = offset_x, 164 | offset_y = offset_y, 165 | LodLevel = LOD_LEVEL_MAX, 166 | box = new Rect(offset_x * m_mesh_segment_size.x, offset_y * m_mesh_segment_size.y, PieceMechSegment * m_mesh_segment_size.x, PieceMechSegment * m_mesh_segment_size.y) 167 | }; 168 | m_piecees[j, i] = piece; 169 | GameObject obj = CreatePiece(piece, "piece_" + j + "_" + i); 170 | obj.transform.SetParent(piece_root.transform); 171 | } 172 | } 173 | } 174 | 175 | private GameObject CreatePiece(LodPiece piece,string name) 176 | { 177 | int each_offset = 1 << piece.LodLevel; 178 | int segment = PieceMechSegment / each_offset; 179 | int ver_num = (segment + 1) * (segment + 1); 180 | bool[] isLevelBiger = new bool[] { false, false, false, false }; 181 | Vector3[] vers = new Vector3[ver_num]; 182 | Vector3[] nors = new Vector3[ver_num]; 183 | Vector2[] uvs = new Vector2[ver_num]; 184 | int[] indexes = new int[segment * segment * 6]; 185 | UpdatePieceLod(vers, nors, uvs, indexes, segment, piece, isLevelBiger); 186 | GameObject obj = MeshCreator.DrawMesh(vers, nors, uvs, indexes, PieceMat, name); 187 | piece.mesh = obj.GetComponent().mesh; 188 | piece.vers = vers; 189 | piece.nors = nors; 190 | piece.uvs = uvs; 191 | piece.indexes = indexes; 192 | piece.last_lod_level = piece.LodLevel; 193 | piece.last_is_biger_level = isLevelBiger; 194 | obj.AddComponent(); 195 | return obj; 196 | } 197 | 198 | private void UpdatePieceLod(Vector3[] vers,Vector3[] nors,Vector2[] uvs, int[] indexes,int segment,LodPiece piece, bool[] isLevelBiger) 199 | { 200 | int each_offset = 1 << piece.LodLevel; 201 | for (int i = 0; i < segment + 1; i++) 202 | { 203 | for (int j = 0; j < segment + 1; j++) 204 | { 205 | int index_x = piece.offset_x + each_offset * j; 206 | int index_y = piece.offset_y + each_offset * i; 207 | int index = i * (segment + 1) + j; 208 | vers[index] = m_mesh_vers[index_x, index_y]; 209 | nors[index] = m_mesh_normals[index_x, index_y]; 210 | uvs[index] = m_mesh_uvs[index_x, index_y]; 211 | } 212 | } 213 | InitPieceIndexes(segment, indexes, isLevelBiger); 214 | } 215 | 216 | private void InitPieceIndexes(int segment,int[] indexes, bool[] isLevelBiger) 217 | { 218 | int index = 0; 219 | for (int i = 0; i < segment; i+=2) //4个格子一起画三角 220 | { 221 | for (int j = 0; j < segment; j+=2) 222 | { 223 | int p00 = i * (segment + 1) + j; 224 | int p10 = p00 + 1; 225 | int p20 = p00 + 2; 226 | int p01 = (i + 1) * (segment + 1) + j; 227 | int p11 = p01 + 1; 228 | int p21 = p01 + 2; 229 | int p02 = (i + 2) * (segment + 1) + j; 230 | int p12 = p02 + 1; 231 | int p22 = p02 + 2; 232 | if (isLevelBiger[0] && j==0) //左边 233 | { 234 | indexes[index] = p00; 235 | indexes[index + 1] = p02; 236 | indexes[index + 2] = p11; 237 | index += 3; 238 | } 239 | else 240 | { 241 | indexes[index] = p00; 242 | indexes[index + 1] = p01; 243 | indexes[index + 2] = p11; 244 | 245 | indexes[index + 3] = p01; 246 | indexes[index + 4] = p02; 247 | indexes[index + 5] = p11; 248 | index += 6; 249 | } 250 | if (isLevelBiger[1] && j==segment-2) //右边 251 | { 252 | indexes[index] = p11; 253 | indexes[index + 1] = p22; 254 | indexes[index + 2] = p20; 255 | index += 3; 256 | } 257 | else 258 | { 259 | indexes[index] = p11; 260 | indexes[index + 1] = p21; 261 | indexes[index + 2] = p20; 262 | 263 | indexes[index + 3] = p11; 264 | indexes[index + 4] = p22; 265 | indexes[index + 5] = p21; 266 | index += 6; 267 | } 268 | if (isLevelBiger[2]&&i==0) //下 269 | { 270 | indexes[index] = p00; 271 | indexes[index + 1] = p11; 272 | indexes[index + 2] = p20; 273 | index += 3; 274 | } 275 | else 276 | { 277 | indexes[index] = p00; 278 | indexes[index + 1] = p11; 279 | indexes[index + 2] = p10; 280 | 281 | indexes[index + 3] = p10; 282 | indexes[index + 4] = p11; 283 | indexes[index + 5] = p20; 284 | index += 6; 285 | } 286 | if (isLevelBiger[3]&&i==segment-2) //上 287 | { 288 | indexes[index] = p02; 289 | indexes[index + 1] = p22; 290 | indexes[index + 2] = p11; 291 | index += 3; 292 | } 293 | else 294 | { 295 | indexes[index] = p02; 296 | indexes[index + 1] = p12; 297 | indexes[index + 2] = p11; 298 | 299 | indexes[index + 3] = p12; 300 | indexes[index + 4] = p22; 301 | indexes[index + 5] = p11; 302 | index += 6; 303 | } 304 | 305 | } 306 | } 307 | for (int i = index; i < indexes.Length; i++) 308 | { 309 | indexes[i] = 0; 310 | } 311 | } 312 | 313 | // Use this for initialization 314 | void Start() 315 | { 316 | InitPiece(); 317 | } 318 | 319 | /// 320 | /// 划分格子的Lod级别 321 | /// 322 | private void UpdateLodLevel() 323 | { 324 | var cam = Camera.main; 325 | float CL = 0.6f; 326 | Vector3 pos = hero.position; 327 | for (int i = 0; i < PieceNum; i++) 328 | { 329 | for (int j = 0; j < PieceNum; j++) 330 | { 331 | LodPiece ps = m_piecees[j, i]; 332 | Vector2 center = ps.box.position + ps.box.size / 2; 333 | float distence = Vector2.Distance(center, new Vector2(pos.x, pos.z)); 334 | ps.LodLevel = Mathf.FloorToInt((distence / ps.box.width) * CL); 335 | if (ps.LodLevel > LOD_LEVEL_MAX) 336 | { 337 | ps.LodLevel = LOD_LEVEL_MAX; 338 | } 339 | } 340 | } 341 | for (int i = 0; i < PieceNum; i++) 342 | { 343 | for (int j = 0; j < PieceNum; j++) 344 | { 345 | LodPiece ps = m_piecees[j, i]; 346 | CheckSideLodLevel(j, i, ps); 347 | } 348 | } 349 | } 350 | 351 | /// 352 | /// 检查周围4个格子的Lod级别是否符合:Lod级别不超过此格子的级别+1,这个条件。否则,直接强制划分Lod级别,并递归划分 353 | /// 354 | /// 355 | /// 356 | /// 357 | private void CheckSideLodLevel(int j,int i,LodPiece ps) 358 | { 359 | if (j>0 && m_piecees[j-1,i].LodLevel-ps.LodLevel>1) 360 | { 361 | m_piecees[j - 1, i].LodLevel = ps.LodLevel + 1; 362 | CheckSideLodLevel(j - 1, i, m_piecees[j - 1, i]); 363 | } 364 | if (j1) 365 | { 366 | m_piecees[j + 1, i].LodLevel = ps.LodLevel + 1; 367 | CheckSideLodLevel(j + 1, i, m_piecees[j + 1, i]); 368 | } 369 | if (i>0 && m_piecees[j,i-1].LodLevel-ps.LodLevel>1) 370 | { 371 | m_piecees[j, i - 1].LodLevel = ps.LodLevel + 1; 372 | CheckSideLodLevel(j, i - 1, m_piecees[j, i - 1]); 373 | } 374 | if (i1) 375 | { 376 | m_piecees[j, i + 1].LodLevel = ps.LodLevel + 1; 377 | CheckSideLodLevel(j, i + 1, m_piecees[j, i + 1]); 378 | } 379 | } 380 | 381 | private void LookUpSideLodLevel(int j,int i,int LodLevel,bool [] isLevelBiger) 382 | { 383 | isLevelBiger[0] = false; 384 | if (j>0) 385 | { 386 | isLevelBiger[0] = m_piecees[j - 1, i].LodLevel > LodLevel; 387 | } 388 | isLevelBiger[1] = false; 389 | if (j LodLevel; 392 | } 393 | isLevelBiger[2] = false; 394 | if (i>0) 395 | { 396 | isLevelBiger[2] = m_piecees[j, i - 1].LodLevel > LodLevel; 397 | } 398 | isLevelBiger[3] = false; 399 | if (i LodLevel; 402 | } 403 | } 404 | 405 | private void UpdateLod() 406 | { 407 | bool[] isLevelBiger = new bool[4]; 408 | for (int i = 0; i < PieceNum; i++) 409 | { 410 | for (int j = 0; j < PieceNum; j++) 411 | { 412 | LodPiece piece = m_piecees[j, i]; 413 | LookUpSideLodLevel(j, i, piece.LodLevel, isLevelBiger); 414 | if (piece.CheckNeedUpdate(isLevelBiger)) 415 | { 416 | int each_offset = 1 << piece.LodLevel; 417 | int segment = PieceMechSegment / each_offset; 418 | int ver_num = (segment + 1) * (segment + 1); 419 | if (ver_num != piece.vers.Length) 420 | { 421 | m_cache_v3.GiveBack(piece.vers); 422 | piece.vers = m_cache_v3.GetOneArray(ver_num); 423 | m_cache_v3.GiveBack(piece.nors); 424 | piece.nors = m_cache_v3.GetOneArray(ver_num); 425 | m_cache_v2.GiveBack(piece.uvs); 426 | piece.uvs = m_cache_v2.GetOneArray(ver_num); 427 | m_cache_int.GiveBack(piece.indexes); 428 | piece.indexes = m_cache_int.GetOneArray(segment * segment * 6); 429 | } 430 | UpdatePieceLod(piece.vers, piece.nors, piece.uvs, piece.indexes, segment, piece, isLevelBiger); 431 | var mesh = piece.mesh; 432 | mesh.Clear(); 433 | mesh.vertices = piece.vers; 434 | mesh.uv = piece.uvs; 435 | mesh.triangles = piece.indexes; 436 | mesh.normals = piece.nors; 437 | } 438 | } 439 | } 440 | } 441 | 442 | // Update is called once per frame 443 | void Update() 444 | { 445 | m_watch.Reset(); 446 | m_watch.Start(); 447 | UpdateLodLevel(); 448 | m_watch.Stop(); 449 | long lod_level_t = m_watch.ElapsedMilliseconds; 450 | m_watch.Reset(); 451 | m_watch.Start(); 452 | UpdateLod(); 453 | m_watch.Stop(); 454 | long lod_t = m_watch.ElapsedMilliseconds; 455 | //log_msg=string.Format("update level t:{0}, lod mesh t:{1}\nint num:{2}!\nv3 num:{3}!\nv2 num:{4}!", lod_level_t, lod_t,m_cache_int.GetDebugInfo(),m_cache_v3.GetDebugInfo(),m_cache_v2.GetDebugInfo()); 456 | log_msg = string.Format("update level t:{0}, lod mesh t:{1}", lod_level_t, lod_t); 457 | } 458 | 459 | private void OnGUI() 460 | { 461 | int w = Screen.width, h = Screen.height; 462 | 463 | GUIStyle style = new GUIStyle(); 464 | 465 | Rect rect = new Rect(0, 60, w, h * 2 / 100); 466 | style.alignment = TextAnchor.UpperLeft; 467 | style.fontSize = 24; 468 | style.normal.textColor = new Color(0.0f, 0.0f, 0.5f, 1.0f); 469 | GUI.Label(rect, log_msg, style); 470 | } 471 | } 472 | -------------------------------------------------------------------------------- /Assets/Scripts/Chunk.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class Chunk 4 | { 5 | //以下为获取周围Chunk的快捷方法 6 | public Chunk Left 7 | { 8 | get 9 | { 10 | Chunk ret = null; 11 | ChunkManager.Instence.GetChunk(id_x - 1, id_y, out ret); 12 | return ret; 13 | } 14 | } 15 | public Chunk Right 16 | { 17 | get 18 | { 19 | Chunk ret = null; 20 | ChunkManager.Instence.GetChunk(id_x + 1, id_y, out ret); 21 | return ret; 22 | } 23 | } 24 | public Chunk Up 25 | { 26 | get 27 | { 28 | Chunk ret = null; 29 | ChunkManager.Instence.GetChunk(id_x, id_y + 1, out ret); 30 | return ret; 31 | } 32 | } 33 | public Chunk Down 34 | { 35 | get 36 | { 37 | Chunk ret = null; 38 | ChunkManager.Instence.GetChunk(id_x, id_y - 1, out ret); 39 | return ret; 40 | } 41 | } 42 | public Chunk LeftUp 43 | { 44 | get 45 | { 46 | Chunk ret = null; 47 | ChunkManager.Instence.GetChunk(id_x - 1, id_y + 1, out ret); 48 | return ret; 49 | } 50 | } 51 | public Chunk RightUp 52 | { 53 | get 54 | { 55 | Chunk ret = null; 56 | ChunkManager.Instence.GetChunk(id_x + 1, id_y + 1, out ret); 57 | return ret; 58 | } 59 | } 60 | public Chunk LeftDown 61 | { 62 | get 63 | { 64 | Chunk ret = null; 65 | ChunkManager.Instence.GetChunk(id_x - 1, id_y - 1, out ret); 66 | return ret; 67 | } 68 | } 69 | public Chunk RightDown 70 | { 71 | get 72 | { 73 | Chunk ret = null; 74 | ChunkManager.Instence.GetChunk(id_x + 1, id_y - 1, out ret); 75 | return ret; 76 | } 77 | } 78 | 79 | public Rect box; //块范围 80 | public Rect box_add; //添加相邻块的范围 81 | public Rect box_remove; //移除相邻快的范围 82 | public int id_x; 83 | public int id_y; 84 | 85 | private float[,] m_height_map; //高度图 86 | private int m_heightmap_len; //高度图段数,不是高度图的像素点数量 87 | 88 | private Vector3[,] m_mesh_vers; //预计算 顶点数组 89 | private Vector3[,] m_mesh_normals; //预计算 法线数组 90 | private Vector2[,] m_mesh_uvs; //预计算 UV数组 91 | 92 | private Vector2 m_mesh_segment_size; //一段的大小 93 | private int m_mesh_segment; //此Chunk总共的段数(单方向) 94 | 95 | private int m_mesh_piece_segment; //单片网格的段数 96 | private int m_mesh_piece_num; //此Chunk有多少片网格(单方向) 97 | private LodPiece[,] m_piecees; //片 信息map 98 | 99 | private Material m_chunk_mat; //此Chunk中所有网格共享此材质 100 | private GameObject obj; //此Chunk的根GameObject 101 | 102 | private HeightMapConfig m_cfg; //生成高度图的配置 103 | private Texture2D mask; //用于控制地表显示哪张贴图的遮罩 104 | private Color[] maskcolor; //遮罩信息,每个通道分别代表一张贴图 105 | 106 | private bool isNormalUpdated=false; //是否更新过法线 107 | 108 | /// 109 | /// 销毁根GameObject和材质 110 | /// 111 | public void DestroyGameObject() 112 | { 113 | if (m_piecees!=null) 114 | { 115 | var cache_v3 = ChunkManager.Instence.cache_v3; 116 | var cache_V2 = ChunkManager.Instence.cache_v2; 117 | var cache_int = ChunkManager.Instence.cache_int; 118 | for (int i = 0; i < m_mesh_piece_num; i++) 119 | { 120 | for (int j = 0; j < m_mesh_piece_num; j++) 121 | { 122 | LodPiece ps = m_piecees[j, i]; 123 | cache_v3.GiveBack(ps.vers); 124 | cache_v3.GiveBack(ps.nors); 125 | cache_V2.GiveBack(ps.uvs); 126 | cache_int.GiveBack(ps.indexes); 127 | ps.vers = null; 128 | ps.nors = null; 129 | ps.uvs = null; 130 | ps.indexes = null; 131 | ps.mesh = null; 132 | } 133 | } 134 | } 135 | if (obj!=null) 136 | { 137 | GameObject.Destroy(obj); 138 | obj = null; 139 | } 140 | if (m_chunk_mat!=null) 141 | { 142 | Object.Destroy(m_chunk_mat); 143 | m_chunk_mat = null; 144 | } 145 | if (mask!=null) 146 | { 147 | Object.Destroy(mask); 148 | mask = null; 149 | maskcolor = null; 150 | } 151 | } 152 | 153 | /// 154 | /// 生成基本高度图,会更具周围Chunk拷贝边界的高度信息 155 | /// 156 | private void GenralBaseHeightMap() 157 | { 158 | if (m_height_map==null) 159 | m_height_map= new float[m_heightmap_len + 1, m_heightmap_len + 1]; 160 | for (int i = 0; i < m_heightmap_len + 1; i++) 161 | { 162 | for (int j = 0; j < m_heightmap_len + 1; j++) 163 | { 164 | m_height_map[j, i] = -100; 165 | } 166 | } 167 | CopySideMap(); 168 | } 169 | 170 | private void CopySideMap() 171 | { 172 | if (Left != null) 173 | { 174 | var left_map = Left.m_height_map; 175 | for (int i = 0; i < m_heightmap_len + 1; i++) 176 | { 177 | m_height_map[0, i] = left_map[m_heightmap_len, i]; 178 | } 179 | } 180 | if (Right != null) 181 | { 182 | var right_map = Right.m_height_map; 183 | for (int i = 0; i < m_heightmap_len + 1; i++) 184 | { 185 | m_height_map[m_heightmap_len, i] = right_map[0, i]; 186 | } 187 | } 188 | if (Up != null) 189 | { 190 | var up_map = Up.m_height_map; 191 | for (int i = 0; i < m_heightmap_len + 1; i++) 192 | { 193 | m_height_map[i, m_heightmap_len] = up_map[i, 0]; 194 | } 195 | } 196 | if (Down != null) 197 | { 198 | var down_map = Down.m_height_map; 199 | for (int i = 0; i < m_heightmap_len + 1; i++) 200 | { 201 | m_height_map[i, 0] = down_map[i, m_heightmap_len]; 202 | } 203 | } 204 | } 205 | 206 | /// 207 | /// 生成高度图和预计算网格信息 208 | /// 209 | /// 210 | /// 211 | /// 212 | /// 213 | /// 214 | /// 215 | public void GeneralData(HeightMapConfig config,int mesh_segment, Vector2 mesh_segment_size,Material mat, int mesh_piece_segment, int mesh_piece_num) 216 | { 217 | m_heightmap_len = 1 << config.Iterations; 218 | m_cfg = config; 219 | mask = SurfaceMaskCreator.CreateMask(m_heightmap_len); 220 | m_chunk_mat = new Material(mat); 221 | m_chunk_mat.SetTexture("_Mask", mask); 222 | m_mesh_segment = mesh_segment; 223 | m_mesh_segment_size = mesh_segment_size; 224 | m_mesh_piece_segment = mesh_piece_segment; 225 | m_mesh_piece_num = mesh_piece_num; 226 | } 227 | 228 | /// 229 | /// 耗时计算,再后台线程中执行 230 | /// 231 | public void DoHardWork() 232 | { 233 | GenralBaseHeightMap(); 234 | HeightMapFactory.GeneralHeightMapByFractal(m_cfg.Iterations, m_cfg.H, m_cfg.min, m_cfg.max, m_cfg.seed, m_cfg.type, m_height_map); 235 | var fcfg = ChunkManager.Instence.filter_config; 236 | HeightMapFilter.FilterFIR(m_height_map, m_heightmap_len + 1, fcfg.times, fcfg.k); 237 | CopySideMap(); 238 | maskcolor = SurfaceMaskCreator.GeneralMaskData(m_heightmap_len, m_cfg.max, m_height_map, m_cfg.min); 239 | InitMesh(); 240 | InitPiece(); 241 | ChunkManager.Instence.AddToMap(this); 242 | } 243 | 244 | /// 245 | /// 耗时计算完成后执行 246 | /// 247 | public void HardWorkComplete() 248 | { 249 | mask.SetPixels(maskcolor); 250 | mask.Apply(); 251 | CreatePieces(); 252 | } 253 | 254 | /// 255 | /// 预计算网格信息 256 | /// 257 | private void InitMesh() 258 | { 259 | int ver_num_each_line = m_mesh_segment + 1; 260 | if (m_mesh_vers==null) 261 | { 262 | m_mesh_vers = new Vector3[ver_num_each_line, ver_num_each_line]; 263 | m_mesh_uvs = new Vector2[ver_num_each_line, ver_num_each_line]; 264 | m_mesh_normals = new Vector3[ver_num_each_line, ver_num_each_line]; 265 | } 266 | Vector2 one_uv = new Vector2(m_mesh_segment_size.x / box.width, m_mesh_segment_size.y / box.height); 267 | for (int i = 0; i < ver_num_each_line; i++) 268 | { 269 | for (int j = 0; j < ver_num_each_line; j++) 270 | { 271 | float posx = m_mesh_segment_size.x * j+box.x; 272 | float posy = m_mesh_segment_size.y * i+box.y; 273 | float uu = one_uv.x * j; 274 | float vv = one_uv.y * i; 275 | int index_x = Mathf.RoundToInt(m_heightmap_len * uu); 276 | int index_y = Mathf.RoundToInt(m_heightmap_len * vv); 277 | float ht = m_height_map[index_x, index_y]; 278 | m_mesh_uvs[j, i] = new Vector2(uu, vv); 279 | m_mesh_vers[j, i] = new Vector3(posx, ht, posy); 280 | } 281 | } 282 | UpdateNormals(); 283 | } 284 | 285 | /// 286 | /// 初始化片的数据 287 | /// 288 | private void InitPiece() 289 | { 290 | if (m_piecees == null) 291 | m_piecees = new LodPiece[m_mesh_piece_num, m_mesh_piece_num]; 292 | Vector2 piecesize = m_mesh_segment_size * m_mesh_piece_segment; 293 | for (int i = 0; i < m_mesh_piece_num; i++) 294 | { 295 | for (int j = 0; j < m_mesh_piece_num; j++) 296 | { 297 | LodPiece piece = m_piecees[j, i]; 298 | if (piece == null) 299 | { 300 | piece = new LodPiece(); 301 | m_piecees[j, i] = piece; 302 | } 303 | int offset_x = j * m_mesh_piece_segment; 304 | int offset_y = i * m_mesh_piece_segment; 305 | piece.offset_x = offset_x; 306 | piece.offset_y = offset_y; 307 | piece.LodLevel = ChunkManager.LOD_LEVEL_MAX; 308 | piece.box = new Rect(offset_x * m_mesh_segment_size.x + box.x, offset_y * m_mesh_segment_size.y + box.y, piecesize.x, piecesize.y); 309 | } 310 | } 311 | var cache_v3 = ChunkManager.Instence.cache_v3; 312 | var cache_v2 = ChunkManager.Instence.cache_v2; 313 | var cache_int = ChunkManager.Instence.cache_int; 314 | for (int i = 0; i < m_mesh_piece_num; i++) 315 | {//需要分2次循环执行,否则LookUpSideLodLevel会出错 316 | for (int j = 0; j < m_mesh_piece_num; j++) 317 | { 318 | bool[] isLevelBiger = new bool[] { false, false, false, false }; 319 | LodPiece piece = m_piecees[j, i]; 320 | int each_offset = 1 << piece.LodLevel; 321 | int segment = m_mesh_piece_segment / each_offset; 322 | int ver_num = (segment + 1) * (segment + 1); 323 | Vector3[] vers = cache_v3.GetOneArray(ver_num); 324 | Vector3[] nors = cache_v3.GetOneArray(ver_num); 325 | Vector2[] uvs = cache_v2.GetOneArray(ver_num); 326 | int[] indexes = cache_int.GetOneArray(segment * segment * 6); 327 | LookUpSideLodLevel(j, i, piece.LodLevel, isLevelBiger); 328 | UpdatePieceLod(vers, nors, uvs, indexes, segment, piece, isLevelBiger); 329 | piece.vers = vers; 330 | piece.nors = nors; 331 | piece.uvs = uvs; 332 | piece.indexes = indexes; 333 | piece.last_lod_level = piece.LodLevel; 334 | piece.last_is_biger_level = isLevelBiger; 335 | } 336 | } 337 | } 338 | 339 | /// 340 | /// 创建所有的片 341 | /// 342 | private void CreatePieces() 343 | { 344 | GameObject piece_root = new GameObject("chunk_"+id_x+"_"+id_y); 345 | obj = piece_root; 346 | for (int i = 0; i < m_mesh_piece_num; i++) 347 | { 348 | for (int j = 0; j < m_mesh_piece_num; j++) 349 | { 350 | LodPiece piece = m_piecees[j, i]; 351 | GameObject obj = MeshCreator.DrawMesh(piece.vers, piece.nors, piece.uvs, piece.indexes, m_chunk_mat, "piece_" + j + "_" + i); 352 | piece.mesh = obj.GetComponent().mesh; 353 | obj.AddComponent(); 354 | obj.transform.SetParent(piece_root.transform); 355 | } 356 | } 357 | piece_root.transform.SetParent(ChunkManager.Instence.transform); 358 | } 359 | 360 | /// 361 | /// 刷新单片的网格信息(顶点、UV等) 362 | /// 363 | /// 364 | /// 365 | /// 366 | /// 367 | /// 368 | /// 369 | /// 370 | private void UpdatePieceLod(Vector3[] vers, Vector3[] nors, Vector2[] uvs, int[] indexes, int segment, LodPiece piece, bool[] isLevelBiger) 371 | { 372 | int each_offset = 1 << piece.LodLevel; 373 | for (int i = 0; i < segment + 1; i++) 374 | { 375 | for (int j = 0; j < segment + 1; j++) 376 | { 377 | int index_x = piece.offset_x + each_offset * j; 378 | int index_y = piece.offset_y + each_offset * i; 379 | int index = i * (segment + 1) + j; 380 | vers[index] = m_mesh_vers[index_x, index_y]; 381 | nors[index] = m_mesh_normals[index_x, index_y]; 382 | uvs[index] = m_mesh_uvs[index_x, index_y]; 383 | } 384 | } 385 | InitPieceIndexes(segment, indexes, isLevelBiger); 386 | } 387 | 388 | /// 389 | /// 计算三角形索引数组 390 | /// 391 | /// 392 | /// 393 | /// 394 | private void InitPieceIndexes(int segment, int[] indexes, bool[] isLevelBiger) 395 | { 396 | int index = 0; 397 | for (int i = 0; i < segment; i += 2) //4个格子一起画三角 398 | { 399 | for (int j = 0; j < segment; j += 2) 400 | { 401 | int p00 = i * (segment + 1) + j; 402 | int p10 = p00 + 1; 403 | int p20 = p00 + 2; 404 | int p01 = (i + 1) * (segment + 1) + j; 405 | int p11 = p01 + 1; 406 | int p21 = p01 + 2; 407 | int p02 = (i + 2) * (segment + 1) + j; 408 | int p12 = p02 + 1; 409 | int p22 = p02 + 2; 410 | if (isLevelBiger[0] && j == 0) //左边 411 | { 412 | indexes[index] = p00; 413 | indexes[index + 1] = p02; 414 | indexes[index + 2] = p11; 415 | index += 3; 416 | } 417 | else 418 | { 419 | indexes[index] = p00; 420 | indexes[index + 1] = p01; 421 | indexes[index + 2] = p11; 422 | 423 | indexes[index + 3] = p01; 424 | indexes[index + 4] = p02; 425 | indexes[index + 5] = p11; 426 | index += 6; 427 | } 428 | if (isLevelBiger[1] && j == segment - 2) //右边 429 | { 430 | indexes[index] = p11; 431 | indexes[index + 1] = p22; 432 | indexes[index + 2] = p20; 433 | index += 3; 434 | } 435 | else 436 | { 437 | indexes[index] = p11; 438 | indexes[index + 1] = p21; 439 | indexes[index + 2] = p20; 440 | 441 | indexes[index + 3] = p11; 442 | indexes[index + 4] = p22; 443 | indexes[index + 5] = p21; 444 | index += 6; 445 | } 446 | if (isLevelBiger[2] && i == 0) //下 447 | { 448 | indexes[index] = p00; 449 | indexes[index + 1] = p11; 450 | indexes[index + 2] = p20; 451 | index += 3; 452 | } 453 | else 454 | { 455 | indexes[index] = p00; 456 | indexes[index + 1] = p11; 457 | indexes[index + 2] = p10; 458 | 459 | indexes[index + 3] = p10; 460 | indexes[index + 4] = p11; 461 | indexes[index + 5] = p20; 462 | index += 6; 463 | } 464 | if (isLevelBiger[3] && i == segment - 2) //上 465 | { 466 | indexes[index] = p02; 467 | indexes[index + 1] = p22; 468 | indexes[index + 2] = p11; 469 | index += 3; 470 | } 471 | else 472 | { 473 | indexes[index] = p02; 474 | indexes[index + 1] = p12; 475 | indexes[index + 2] = p11; 476 | 477 | indexes[index + 3] = p12; 478 | indexes[index + 4] = p22; 479 | indexes[index + 5] = p11; 480 | index += 6; 481 | } 482 | 483 | } 484 | } 485 | for (int i = index; i < indexes.Length; i++) 486 | { 487 | indexes[i] = 0; 488 | } 489 | } 490 | 491 | /// 492 | /// 划分格子的Lod级别 493 | /// 494 | public void UpdateLodLevel(Vector3 pos) 495 | { 496 | var cl = ChunkManager.Instence.CL; 497 | for (int i = 0; i < m_mesh_piece_num; i++) 498 | { 499 | for (int j = 0; j < m_mesh_piece_num; j++) 500 | { 501 | LodPiece ps = m_piecees[j, i]; 502 | Vector2 center = ps.box.position + ps.box.size / 2; 503 | float distence = Vector2.Distance(center, new Vector2(pos.x, pos.z)); 504 | ps.LodLevel = Mathf.FloorToInt((distence / ps.box.width) * cl); 505 | if(ps.LodLevel>ChunkManager.LOD_LEVEL_MAX) 506 | { 507 | ps.LodLevel = ChunkManager.LOD_LEVEL_MAX; 508 | } 509 | } 510 | } 511 | 512 | } 513 | 514 | /// 515 | /// 检查所有的片的LOD级别是否符合规范 516 | /// 517 | public void CheckSidesLodLevel() 518 | { 519 | for (int i = 0; i < m_mesh_piece_num; i++) 520 | { 521 | for (int j = 0; j < m_mesh_piece_num; j++) 522 | { 523 | LodPiece ps = m_piecees[j, i]; 524 | CheckSideLodLevel(j, i, ps); 525 | } 526 | } 527 | } 528 | 529 | /// 530 | /// 检查周围4个格子的Lod级别是否符合:Lod级别不超过此格子的级别+1。否则,直接强制划分Lod级别,并递归划分 531 | /// 532 | /// 533 | /// 534 | /// 535 | private void CheckSideLodLevel(int j, int i, LodPiece ps) 536 | { 537 | if (j > 0 && m_piecees[j - 1, i].LodLevel - ps.LodLevel > 1) 538 | { 539 | m_piecees[j - 1, i].LodLevel = ps.LodLevel + 1; 540 | CheckSideLodLevel(j - 1, i, m_piecees[j - 1, i]); 541 | } 542 | if (j < m_mesh_piece_num - 1 && m_piecees[j + 1, i].LodLevel - ps.LodLevel > 1) 543 | { 544 | m_piecees[j + 1, i].LodLevel = ps.LodLevel + 1; 545 | CheckSideLodLevel(j + 1, i, m_piecees[j + 1, i]); 546 | } 547 | if (i > 0 && m_piecees[j, i - 1].LodLevel - ps.LodLevel > 1) 548 | { 549 | m_piecees[j, i - 1].LodLevel = ps.LodLevel + 1; 550 | CheckSideLodLevel(j, i - 1, m_piecees[j, i - 1]); 551 | } 552 | if (i < m_mesh_piece_num - 1 && m_piecees[j, i + 1].LodLevel - ps.LodLevel > 1) 553 | { 554 | m_piecees[j, i + 1].LodLevel = ps.LodLevel + 1; 555 | CheckSideLodLevel(j, i + 1, m_piecees[j, i + 1]); 556 | } 557 | if (j==0 && Left!=null && Left.m_piecees[m_mesh_piece_num-1,i].LodLevel-ps.LodLevel>1) 558 | { 559 | Left.m_piecees[m_mesh_piece_num - 1, i].LodLevel = ps.LodLevel + 1; 560 | Left.CheckSideLodLevel(m_mesh_piece_num - 1, i, Left.m_piecees[m_mesh_piece_num - 1, i]); 561 | } 562 | if (j==m_mesh_piece_num-1 && Right!=null && Right.m_piecees[0,i].LodLevel-ps.LodLevel>1) 563 | { 564 | Right.m_piecees[0, i].LodLevel = ps.LodLevel + 1; 565 | Right.CheckSideLodLevel(0, i, Right.m_piecees[0, i]); 566 | } 567 | if (i==0 && Down!=null && Down.m_piecees[j,m_mesh_piece_num-1].LodLevel-ps.LodLevel>1) 568 | { 569 | Down.m_piecees[j, m_mesh_piece_num - 1].LodLevel = ps.LodLevel + 1; 570 | Down.CheckSideLodLevel(j, m_mesh_piece_num - 1, Down.m_piecees[j, m_mesh_piece_num - 1]); 571 | } 572 | if (i==m_mesh_piece_num-1 && Up!=null && Up.m_piecees[j,0].LodLevel-ps.LodLevel>1) 573 | { 574 | Up.m_piecees[j, 0].LodLevel = ps.LodLevel + 1; 575 | Up.CheckSideLodLevel(j, 0, Up.m_piecees[j, 0]); 576 | } 577 | } 578 | 579 | /// 580 | /// 查找周围4个片的LOD是否比此片大 581 | /// 582 | /// 583 | /// 584 | /// 585 | /// 586 | private void LookUpSideLodLevel(int j, int i, int LodLevel, bool[] isLevelBiger) 587 | { 588 | isLevelBiger[0] = false; 589 | if (j > 0) 590 | { 591 | isLevelBiger[0] = m_piecees[j - 1, i].LodLevel > LodLevel; 592 | } 593 | else if (Left!=null) 594 | { 595 | isLevelBiger[0] = Left.m_piecees[m_mesh_piece_num - 1, i].LodLevel > LodLevel; 596 | } 597 | isLevelBiger[1] = false; 598 | if (j < m_mesh_piece_num - 1) 599 | { 600 | isLevelBiger[1] = m_piecees[j + 1, i].LodLevel > LodLevel; 601 | } 602 | else if (Right!=null) 603 | { 604 | isLevelBiger[1] = Right.m_piecees[0, i].LodLevel > LodLevel; 605 | } 606 | isLevelBiger[2] = false; 607 | if (i > 0) 608 | { 609 | isLevelBiger[2] = m_piecees[j, i - 1].LodLevel > LodLevel; 610 | } 611 | else if (Down!=null) 612 | { 613 | isLevelBiger[2] = Down.m_piecees[j, m_mesh_piece_num - 1].LodLevel > LodLevel; 614 | } 615 | isLevelBiger[3] = false; 616 | if (i < m_mesh_piece_num - 1) 617 | { 618 | isLevelBiger[3] = m_piecees[j, i + 1].LodLevel > LodLevel; 619 | } 620 | else if (Up!=null) 621 | { 622 | isLevelBiger[3] = Up.m_piecees[j, 0].LodLevel > LodLevel; 623 | } 624 | } 625 | 626 | /// 627 | /// 更新所有片的网格 628 | /// 629 | public void UpdateLod() 630 | { 631 | var m_cache_v3 = ChunkManager.Instence.cache_v3; 632 | var m_cache_v2 = ChunkManager.Instence.cache_v2; 633 | var m_cache_int = ChunkManager.Instence.cache_int; 634 | bool[] isLevelBiger = new bool[4]; 635 | for (int i = 0; i < m_mesh_piece_num; i++) 636 | { 637 | for (int j = 0; j < m_mesh_piece_num; j++) 638 | { 639 | LodPiece piece = m_piecees[j, i]; 640 | LookUpSideLodLevel(j, i, piece.LodLevel, isLevelBiger); 641 | if (isNormalUpdated || piece.CheckNeedUpdate(isLevelBiger)) 642 | { 643 | piece.SetLastBigLevel(isLevelBiger); 644 | int each_offset = 1 << piece.LodLevel; 645 | int segment = m_mesh_piece_segment / each_offset; 646 | int ver_num = (segment + 1) * (segment + 1); 647 | if (ver_num != piece.vers.Length) 648 | { 649 | m_cache_v3.GiveBack(piece.vers); 650 | piece.vers = m_cache_v3.GetOneArray(ver_num); 651 | m_cache_v3.GiveBack(piece.nors); 652 | piece.nors = m_cache_v3.GetOneArray(ver_num); 653 | m_cache_v2.GiveBack(piece.uvs); 654 | piece.uvs = m_cache_v2.GetOneArray(ver_num); 655 | m_cache_int.GiveBack(piece.indexes); 656 | piece.indexes = m_cache_int.GetOneArray(segment * segment * 6); 657 | } 658 | UpdatePieceLod(piece.vers, piece.nors, piece.uvs, piece.indexes, segment, piece, isLevelBiger); 659 | piece.UpdateMeshData(); 660 | } 661 | } 662 | } 663 | isNormalUpdated = false; 664 | } 665 | 666 | /// 667 | /// 重新计算此Chunk的所有顶点的法线信息 668 | /// 669 | public void UpdateNormals() 670 | { 671 | int ver_num_each_line = m_mesh_segment + 1; 672 | for (int i = 0; i < ver_num_each_line; i++) 673 | { 674 | for (int j = 0; j < ver_num_each_line; j++) 675 | { 676 | Vector3 p0 = m_mesh_vers[j, i]; 677 | Vector3 p1 = GetVer(j + 1, i); 678 | Vector3 p2 = GetVer(j, i - 1); 679 | Vector3 p3 = GetVer(j - 1, i); 680 | Vector3 p4 = GetVer(j, i + 1); 681 | 682 | Vector3 v01 = p1 - p0; 683 | Vector3 v02 = p2 - p0; 684 | Vector3 v03 = p3 - p0; 685 | Vector3 v04 = p4 - p0; 686 | v01.Normalize(); 687 | v02.Normalize(); 688 | v03.Normalize(); 689 | v04.Normalize(); 690 | 691 | Vector3 n1 = Vector3.Cross(v04, v01); 692 | Vector3 n2 = Vector3.Cross(v01, v02); 693 | Vector3 n3 = Vector3.Cross(v02, v03); 694 | Vector3 n4 = Vector3.Cross(v03, v04); 695 | 696 | Vector3 nor = n1 + n2 + n3 + n4; 697 | nor.Normalize(); 698 | m_mesh_normals[j, i] = nor; 699 | } 700 | } 701 | isNormalUpdated = true; 702 | } 703 | 704 | /// 705 | /// 取顶点,可能是相邻Chunk中的点,用于计算法线 706 | /// 707 | /// 708 | /// 709 | /// 710 | private Vector3 GetVer(int index_x, int index_y) 711 | { 712 | Vector3 ret = new Vector3() 713 | { 714 | x = m_mesh_segment_size.x * index_x + box.x, 715 | z = m_mesh_segment_size.y * index_y + box.y 716 | }; 717 | float ht = 0; 718 | int ver_num_each_line = m_mesh_segment + 1; 719 | if (index_x<0) 720 | { 721 | if (index_y < 0) 722 | { 723 | if (LeftDown != null) 724 | ht = LeftDown.m_mesh_vers[ver_num_each_line - 1 - 1, ver_num_each_line - 1 - 1].y; 725 | else 726 | ht = m_mesh_vers[0, 0].y; 727 | } 728 | else if (index_y < ver_num_each_line) 729 | { 730 | if (Left != null) 731 | ht = Left.m_mesh_vers[ver_num_each_line - 1 - 1, index_y].y; 732 | else 733 | ht = m_mesh_vers[0, index_y].y; 734 | } 735 | else 736 | { 737 | if (LeftUp != null) 738 | ht = LeftUp.m_mesh_vers[ver_num_each_line - 1 - 1, 0 + 1].y; 739 | else 740 | ht = m_mesh_vers[0, ver_num_each_line-1].y; 741 | } 742 | } 743 | else if (index_x < ver_num_each_line) 744 | { 745 | if (index_y<0) 746 | { 747 | if (Down != null) 748 | ht = Down.m_mesh_vers[index_x, ver_num_each_line - 1 - 1].y; 749 | else 750 | ht = m_mesh_vers[index_x, 0].y; 751 | } 752 | else if (index_y