private void Awake() { _generator = _generators[method]; UpdateGenerator(_generator); /* * // Add meshfilter + renderer * if (GetComponent<MeshFilter>() == null) { * meshFilter = gameObject.AddComponent<MeshFilter>(); * } * * if (GetComponent<MeshRenderer>() == null) { * gameObject.AddComponent<MeshRenderer>(); * } */ // Generate new mesh if it's null if (meshFilter.mesh == null) { meshFilter.mesh = new Mesh { name = "generatedMesh" }; } }
/// <summary> /// Method to ask the generator to produce a new mesh. /// </summary> /// <param name="generator"></param> private void UpdateGenerator(VoxelGenerator generator) { if (_generator == null) { _generator = _generators[method]; } _generator.density = density; _generator.size = size; _generator.gridSize = gridSize; _generator.threshold = threshold; _generator.position = transform.position; _generator.smoothShade = smoothShade; meshFilter.mesh = _generator.UpdateMesh(meshFilter.mesh); }
private void Update() { // Method change if (_lastMethod != method) { _generator = _generators[method]; _lastMethod = method; Debug.Log($"Voxel method changed to {method.ToString()}."); } if (debugAllFrameUpdate) { UpdateGenerator(_generator); } }