public LodNode(LodNode parent, LodProperties lodProperties, int lodLevel, Vector3 origin, Vector3 forward, Vector3 right) { this.parent = parent; this.lodProperties = lodProperties; this.lodLevel = lodLevel; this.origin = origin; this.forward = forward; this.right = right; this.children = null; this.gameObject = new GameObject("Chunk " + lodLevel); this.gameObject.transform.SetParent(lodProperties.gameObject.transform, false); this.meshFilter = this.gameObject.AddComponent <MeshFilter>(); this.meshRenderer = this.gameObject.AddComponent <MeshRenderer>(); this.plane = new LodFace(LodNode.CHUNK_RESOLUTION, lodProperties.heightGenerator, origin, lodProperties.up, forward, right).GenerateMesh(); this.meshRenderer.sharedMaterial = lodProperties.material; this.meshFilter.mesh = this.plane; }
void Start() { LodHeightGenerator.Properties properties = new LodHeightGenerator.Properties(); properties.strength = 0.28f; properties.frequency = 1f; properties.lacunarity = 2.3f; properties.persistence = 0.40f; properties.octaves = 8; Perlin perlin = new Perlin(0); this.heightGenerator = new LodHeightGenerator(perlin, properties); this.material.SetTexture("_Gradients2D", PerlinTextureGenerator.CreateGradientsTexture(perlin)); this.material.SetTexture("_Permutation2D", PerlinTextureGenerator.CreatePermutationTexture(perlin)); this.material.SetFloat("_Strength", properties.strength); this.material.SetFloat("_Frequency", properties.frequency); this.material.SetFloat("_Lacunarity", properties.lacunarity); this.material.SetFloat("_Persistence", properties.persistence); this.material.SetInt("_Octaves", properties.octaves); this.rootGameObjects = new GameObject[6]; this.roots = new LodNode[6]; for (int i = 0; i < 6; i++) { this.rootGameObjects[i] = new GameObject("Face (" + i + ")"); this.rootGameObjects[i].transform.SetParent(this.transform, false); Vector3 up = LodManager.directions[i]; LodProperties lodProperties = new LodProperties(); lodProperties.gameObject = this.rootGameObjects[i]; lodProperties.material = this.material; lodProperties.up = up; lodProperties.heightGenerator = this.heightGenerator; this.roots[i] = new LodNode(null, lodProperties, 0, up, LodFace.GetForward(up), LodFace.GetRight(up)); } }