Skip to main content

WoodcutTreeBaker

A class in Root.Township, Alta.Woodcutting.

Client component on a woodcut tree that combines its damaged trunk pieces and attachments into baked meshes in the distance LOD group, and updates the baked vertex colours as pieces are chopped. Does nothing on headless servers.

Constructors​

MemberWhat it is
WoodcutTreeBaker()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

19 private and internal fields
MemberWhat it is
private AtlasDefinition[] attachmentDefinitionsAtlas definitions for attachment renderers.
private MeshFilter[] attachmentLodFiltersMesh filters for baked attachment LODs.
private MeshRenderer[] attachmentLodRenderersRenderers for baked attachment LODs.
private Mesh[] attachmentLodsBaked attachment meshes.
private HashSet<TreeAttachment> attachmentsAttachments currently included in the bake.
private List<WoodcutTree.MapNode> damagedNodes with changed colours that are baked into the damaged mesh.
private Mesh[] damagedLodBaked damaged-node meshes.
private MeshFilter[] damagedLodFilterMesh filters that show the damaged bake.
private MeshRenderer[] damagedLodRendererRenderers that show the damaged bake.
private List<int> damagedVertexOffsetStart vertex of each damaged node within the damaged mesh.
private DistanceLODGroup distanceLODGroupThe tree's distance LOD group that renderers are added to and removed from.
private bool isLeavesModifiedLeaves dirty flag.
private bool isLod0ModifiedSet while a LOD 0 rebake is scheduled.
private MeshFilter[] lodFiltersMesh filters for trunk LODs. Not used in this class.
private MeshRenderer[] lodRenderersRenderers for trunk LODs. Not used in this class.
private Mesh[] lodsTrunk LOD meshes. Cleaned up on destroy but never created in this class.
private HashSet<WoodcutTree.MapNode> nodesTree nodes found during the last setup.
private WoodcutTree treeThe woodcut tree being baked.
private AtlasDefinition[] trunkDefinitionsAtlas definitions for trunk renderers. Not used in this class.

Methods​

MemberWhat it is
void EditorInitialize()Editor use: hooks Setup to the tree's ready-for-bake event.
override void Initialize()On clients, hooks Setup to the tree's ready-for-bake and chopped events. The private overload walks a node tree and collects its renderers and attachments.
void RegenerateLeavesAtEndOfFrame()Empty.
void RegenerateLod0AtEndOfFrame()Schedules one RegenerateLod0 at the end of the frame if not already scheduled.
11 private and internal methods
MemberWhat it is
private void Clear(ref Mesh[] meshes)Cleans up an array of baked meshes and nulls it.
private IEnumerator DelayRegenerateLeaves() (iterator)Coroutine that regenerates leaves at the end of the frame. Not started anywhere.
private IEnumerator DelayRegenerateLod0() (iterator)Coroutine that rebakes the damaged LOD 0 mesh at the end of the frame.
private void Generate()Creates the baked meshes, bakes the damaged LOD 0 mesh and points the third attachment LOD at the second one's mesh.
private void Initialize(WoodcutTree.MapNode node, List<Renderer>[] renderersToModify)On clients, hooks Setup to the tree's ready-for-bake and chopped events. The private overload walks a node tree and collects its renderers and attachments.
private void NodeModified(ColorModelCore<NullColorModelPoint, NullColorModelPoint, NullColorModelPoint, WoodcutPointData> core)When a node's colours change, adds it to the damaged bake and schedules a rebake, or updates its colours in place if already baked.
private void OnDestroy()Cleans up all baked meshes.
private void RegenerateLeaves()Only clears the leaves modified flag; leaf rebaking is not done here.
private void RegenerateLod0(bool isGeneratingUndamaged)Bakes all damaged nodes into the damaged LOD mesh, hides their own first renderers and copies their colours in.
private void Remove(TreeAttachment attachment)Removes a broken or moved attachment from the baker and the LOD group.
private void Setup()Clears the previous bake, walks the tree from its root to rebuild LOD renderer lists, then calls Generate.