public static Node CreateRoot(Context.Constants constants, Context.Depth depth, Context.Branch branch) { GameObject gameObject = new GameObject("Chunk"); gameObject.transform.SetParent(branch.gameObject.transform, false); MeshFilter meshFilter = gameObject.AddComponent <MeshFilter>(); MeshRenderer meshRenderer = gameObject.AddComponent <MeshRenderer>(); meshRenderer.enabled = false; meshRenderer.sharedMaterial = constants.material; int[] path = new int[0]; int[] neighborBranches; int[][] neighborPaths; GetNeighborPaths(path, branch.index, out neighborBranches, out neighborPaths); return(new Node { parent = null, children = null, path = path, neighborBranches = neighborBranches, neighborPaths = neighborPaths, branch = branch, depth = depth, offset = Vector2.zero, gameObject = gameObject, mesh = null, meshFilter = meshFilter, meshRenderer = meshRenderer, meshRequest = null, meshRequestCancellation = null }); }
void DoUpdate() { MeshModifier meshModifier = displacementSettings.GetMeshModifier(); meshModifier.ModifyMaterial(material); Context.Constants constants = new Context.Constants { desiredScreenSpaceLength = desiredScreenSpaceLength, gameObject = gameObject, material = material, maxDepth = maxDepth, resolution = resolution * 2 - 1, // We can only use odd resolutions., meshModifier = meshModifier }; Context.Branch[] branches = Context.Branch.GetFromConstants(constants); Context.Depth[] depths = Context.Depth.GetFromConstants(constants); Context.Triangles[] triangles = Context.Triangles.GetFromConstants(constants); Node[] roots = new Node[6]; for (int i = 0; i < 6; i++) { roots[i] = Node.CreateRoot(constants, depths[0], branches[i]); } context = new Context { constants = constants, branches = branches, depths = depths, triangles = triangles, roots = roots }; Reconciler.Initialize(context); lastReconciliationTime = Time.time; }