xeokit / xeokit-sdk

Open source JavaScript SDK for viewing high-detail, full-precision 3D BIM and AEC models in the Web browser.
https://xeokit.io
Other
714 stars 286 forks source link

DISCUSSION: A way to automatically decide which objects should get dynamic transforms? #1249

Open xeolabs opened 10 months ago

xeolabs commented 10 months ago

I recently added the ability to create transform hierarchies on models in the SDK.

Specifically, this PR adds a new SceneModelTransform component, which can be used to define for each object in a SceneModel a transform that positions, scales and orients it. The transform can then be animated by dynamically updating its scale, position and rotation properties. These transforms can also be created in hierarchies, for complex transform animations.

When we load glTF or XKT into the SDK, we load them into a SceneModel. However, when we load glTF or XKT into a SceneModel it probably does not make sense to automatically create a SceneModelTransform for every object, since they each do represent an additional JavaScript object in memory, with its own properties (matrix, quaternion, rotation angles, scale factors, translation offset, etc).

Is there some heuristic we can use to decide when SceneModelTranslations should be created by XKTLoaderPlugin and GLTFLoaderPlugin?

Are there certain IFC types that should trigger the creation of these, ie. things that are likely to move, like IfcFurnishingElement?

Any sort of metadata that can hint at when they should be created?

Or maybe just have a loading option that either creates them for all objects, or no objects?

tmarti commented 9 months ago

Maybe, those transforms could be created in a lazy way when needed?

I mean, only initialize it the 1st time time the transform is modified

xeolabs commented 9 months ago

@tmarti yes I think that would work - SceneModelTransforms are decoupled enough that they can be created on-demand.

We could:

A SceneModelMesh with batched VBO geometry would not have a SceneModelTransform though, since we don't support dynamic transforms on batched VBO objects. That's because it's not efficient to store transform matrices in the batched VBO arrays (16 floats per vertex in a VBO).

Solution options for that could be:

For data textures, we're in luck, however, because all DTX objects always have updateable transform matrices ;)

tmarti commented 9 months ago

Yes, DTX was designed with such things in mind 😊