diff --git a/Assets/Materials/Lefa.mat b/Assets/Materials/Lefa.mat index ff43276..65b09ed 100644 --- a/Assets/Materials/Lefa.mat +++ b/Assets/Materials/Lefa.mat @@ -11,7 +11,7 @@ Material: m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} m_ShaderKeywords: m_LightmapFlags: 4 - m_EnableInstancingVariants: 0 + m_EnableInstancingVariants: 1 m_DoubleSidedGI: 0 m_CustomRenderQueue: -1 stringTagMap: {} diff --git a/Assets/Materials/PineLefa.mat b/Assets/Materials/PineLefa.mat index 2d95fef..67212ae 100644 --- a/Assets/Materials/PineLefa.mat +++ b/Assets/Materials/PineLefa.mat @@ -11,7 +11,7 @@ Material: m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} m_ShaderKeywords: m_LightmapFlags: 4 - m_EnableInstancingVariants: 0 + m_EnableInstancingVariants: 1 m_DoubleSidedGI: 0 m_CustomRenderQueue: -1 stringTagMap: {} diff --git a/Assets/Materials/Trunk.mat b/Assets/Materials/Trunk.mat index 67fd18e..cc8f9a4 100644 --- a/Assets/Materials/Trunk.mat +++ b/Assets/Materials/Trunk.mat @@ -11,7 +11,7 @@ Material: m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} m_ShaderKeywords: m_LightmapFlags: 4 - m_EnableInstancingVariants: 0 + m_EnableInstancingVariants: 1 m_DoubleSidedGI: 0 m_CustomRenderQueue: -1 stringTagMap: {} diff --git a/Assets/Scripts/Lorax.cs b/Assets/Scripts/Lorax.cs index c7254da..ad34829 100644 --- a/Assets/Scripts/Lorax.cs +++ b/Assets/Scripts/Lorax.cs @@ -26,6 +26,9 @@ public class Lorax : MonoBehaviour { private int LastSeed = -1; private Vector3[][] TreePositions; + private int ChunkSize = 20; + private GameObject[] Chunks; + void Start() { } @@ -48,10 +51,16 @@ public class Lorax : MonoBehaviour { TotalChances[x + 1] = Counter + Chances[x]; Counter = TotalChances[x + 1]; } + Chunks = new GameObject[(500 / ChunkSize) * (500 / ChunkSize)]; TreePositions = new Vector3[cap][]; for (int y = 0; y < cap; y++) { TreePositions[y] = new Vector3[cap]; for (int x = 0; x < cap; x++) { + int CurrentChunk = (int)((Mathf.Floor(y * Denseness / ChunkSize) * 20) + Mathf.Floor(x * Denseness / ChunkSize)); + if (Chunks[CurrentChunk] == null) { + Chunks[CurrentChunk] = new GameObject("Chunk " + CurrentChunk); + Chunks[CurrentChunk].transform.parent = transform; + } if (Random.value > TreeChance) { continue; } @@ -79,10 +88,17 @@ public class Lorax : MonoBehaviour { } } var rot = Quaternion.Euler(0, 360 * Random.value, 0); - var obj = GameObject.Instantiate(Chosen, pos, rot, gameObject.transform); + var obj = GameObject.Instantiate(Chosen, pos, rot, Chunks[CurrentChunk].transform); } } } } } + + public GameObject GetChunkAt(float x, float y) { + y += 250; + x += 250; + int CurrentChunk = (int)((Mathf.Floor(y / ChunkSize) * 20) + Mathf.Floor(x / ChunkSize)); + return Chunks[CurrentChunk]; + } } diff --git a/Raw Assets/Models/tree_but_leaves.blend b/Raw Assets/Models/tree_but_leaves.blend index 6d085cc..d580db9 100644 Binary files a/Raw Assets/Models/tree_but_leaves.blend and b/Raw Assets/Models/tree_but_leaves.blend differ diff --git a/Raw Assets/Models/tree_but_leaves.blend1 b/Raw Assets/Models/tree_but_leaves.blend1 index 4788404..6d085cc 100644 Binary files a/Raw Assets/Models/tree_but_leaves.blend1 and b/Raw Assets/Models/tree_but_leaves.blend1 differ