xeokit-sdk icon indicating copy to clipboard operation
xeokit-sdk copied to clipboard

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

Open xeolabs opened this issue 2 years ago • 3 comments

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?

xeolabs avatar Nov 20 '23 17:11 xeolabs

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

tmarti avatar Nov 24 '23 19:11 tmarti

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

We could:

  • keep the SceneModel.createTransform() method, so users can eager-create transformhierarchies,
  • change the SceneModelMesh.transform property into an accessor, that lazy-creates a SceneModelTransform if it doesn't already exist
  • make the SceneModel.transforms map private, since it won't be pre-populated any more, replace it with SceneModel.getTransform(id), which would lazy-create.

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:

  • To each VBO batching layer. add a data texture that contains dynamic transform matrices, then have the indexes into those DTX matrices in batched VBO arrays (1 integer per vertex in a VBO).

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

xeolabs avatar Nov 24 '23 22:11 xeolabs

Yes, DTX was designed with such things in mind 😊

tmarti avatar Nov 25 '23 09:11 tmarti