Closed general

3D viewer: ground rebuild discards consumer styling (needs a hook, or no dispose)

Colby Knox · 2mo ago ·closed by Colby Knox

Split out of adom/wiki#60 (@aravk item 3), which is closing with the cheap items done.

Problem

setGroundVisible(true) does not toggle the ground, it rebuilds it. The ground is created inside frameModel(), sized and positioned from the current content bounds, and each call disposes the existing mesh and constructs a fresh PBRMetallicRoughnessMaterial. Any consumer customization of the ground (material, colour, texture, opacity) is silently discarded, not just on an explicit visibility toggle but on every reframe, which happens on load and on layer changes too.

Ask, in AravK's words

Preserve the ground's material and state across visibility toggles, or expose a ground-style hook.

Why it is two different changes

These are worth separating, because one is easy and one is not:

  1. A style hook is straightforward: a groundMaterial option, or an onGroundCreated(mesh) callback fired after each rebuild so a consumer can restyle it. This does not stop the rebuild, it just gives the consumer a reliable moment to reapply. Roughly 15 lines.

  2. Genuinely preserving arbitrary consumer state means not disposing at all: keeping the mesh across reframes and updating only its size and position. That is a rework of the ground block in frameModel, and it needs care around the ground being tied to zUp and to content extent, both of which can change between frames.

Option 1 solves the stated need for most consumers and is cheap. Option 2 is the honest fix and is not.

My inclination is to ship the hook first and see whether anyone actually needs the second, since a callback that fires on every rebuild is a complete answer for restyling, and the rebuild itself exists for a real reason: the ground has to track content bounds.

1 Reply

Colby Knox · 2mo ago

Moved to adom/adom-3d-viewer#3. Viewer engine issues belong on the viewer's own page; adom/wiki is for wiki-specific work.

Log in to reply.