Disclaimer
This is not a Cesium product.
(Despite that “Cesium Team” label)
It is a spare-time project, published as “Public Domain”, in the hope that people find it useful.
It is provided “as is”, without warranty of any kind.
But if it doesn’t work as expected, feel free to point it out…
The ModelInstanceCollection class in earlier CesiumJS versions allowed the user to create many instances of the same glTF asset, with different “instance matrices”. I think that this class was never part of the ‘public API’. But people used it nevertheless. During a refactoring as part of 1.96, this class was removed.
The request to restore the ModelInstanceCollection came up quickly after that. In the meantime, roughly 30 people have expressed their interest in this feature, often saying that it is “badly needed”, “really badly needed”, “desperately needed”, followed by the usual
's.
An initial PR to restore it was quickly closed. Another PR to restore it has received ~70 commits and >100 comments, but seems to be abandoned for now.
In a comment in the issue, I came up with a hypothetical idea:
Imagine a magic function that receives a blob with glTF data and a bunch of matrices, builds a blob containing I3DM data, and then loads that data using the I3dmLoader at runtime(!).
That sounds crazy. But I gave it a try, and created a ModelInstanceCollectionGenerator class that does exactly that. The usage of that class is as simple as it can be:
const matrices = createSomeMatrices();
const url = "../SampleData/models/CesiumAir/Cesium_Air.glb";
const model = await ModelInstanceCollectionGenerator.create(matrices, url);
viewer.scene.primitives.add(model);
That’s it.
As an example, here is the result of rendering 1000 planes, with different instance matrices, running smoothly and calmly at ~60 FPS:
More disclaimers…
Of course, this is not an ideal solution. There are many possible scenarios and use-cases for which this will not be sufficient! The class does generate I3DM data at runtime, meaning that it will not be possible to modify the instance transforms at runtime. Also, tasks like identifying the instances or associating them with metadata are not so easy to accomplish. But I think that there are many scenarios in which such a class can be useful, even if it is only a (somewhat obscure) workaround.
Here is a sandcastle that contains this class and shows the usage example that the screenshot was taken from:
https://sandcastle.cesium.com/index.html#c=1Rprc9u48a9gPNMplTCUbTlp6kfmFD9yuvGrlnzTJPZkIAqS0FCkCoK26Iz/e3cBggRfstrcfehMHIrA7mKx7wXoR2EsyQNnj0yQIxKyR3LMYp4svN/VmHO35av34yiUlIdM3G11Du7EXahxvNhnIfMmbJzMhvPo8UzQBYuvmRgyPwonQFKKhCkE/Ou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CAT9bXH3ZbndYd0sQwYHvh2Fbm4qzfb5yL79Q1+erNgfLdlUTDX3f/VpyqVu9D6h1b5x0exB9nbUYtoMBDBCZS3lkTOgtRcF+dy0LfZeLybnj5glwlU1I9zDiESmHH0AbBjf9RS4sCHkCeoNw3SUfQxSkI8IhsuMRdobrxxadAtstMkEZldmxYns9bsseVuHcYyDdgHnPuFQ7kulCYc0IJkoAWsdrrjBCpv6fkxxpPwsGtQDif8gfDJUcMXa/pbM5jBi4Yhf2J3Wx8OuwBfQsOzf+D76oGJAKpqAJnvfDjXg1AAHXbhtY4loygYU2FR/A8
6 Likes
Thank you so much for taking the time to create this tool and share it with everyone. It has solved a major pain point for many Cesium developers. While it is a workaround, it is incredibly practical, and your effort means a great deal to us. We truly appreciate it!
1 Like