DISCUSSION: A way to automatically decide which objects should get dynamic transforms?
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?
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 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.transformproperty into an accessor, that lazy-creates aSceneModelTransformif it doesn't already exist - make the
SceneModel.transformsmap private, since it won't be pre-populated any more, replace it withSceneModel.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 ;)
Yes, DTX was designed with such things in mind 😊