Challenge accepted See the other thread: Animation performance drop by translation/rotation - #2 by Gijs
I hope I didn’t sound too critical before. BJS is awesome.
But this issue (“I translated meshes and the fps fell to 30fps”) is exactly the kind of thing that I’d have expected to work out of the box with no performance loss. This is a simple demo “load some objects and make them run circles”; I’m certain BJS can handle it and you’ll tell me “do this and it will get back to 60fps”.
This example hopefully makes a practical case of what could be easier for a simple demo:
- you need to
addAllToScene()
because it’s a container. But at the same time I need to do things like scaling with a container.meshes.forEach loop.container.scaling
would be pure syntactic sugar but helpful. - with instances I have to disable to original mesh. At least I read that somewhere, perhaps it was related only the RTT thread with overriden materials? I don’t know why I have to do that.
- freezing materials seems to be what you want 99% of the time, but it also required a foreach and an if.
instantiateModelsToScene
is great – it just works and I read that instancing objects was not a trivial thing to implement. But now I have to do a foreach to the rootNodes of a subkey just for a simple translation. A façade for translation/scaling/rotation, just like with the container, would be very practical.
This is a bit closer to what I’d like to write
BABYLON.SceneLoader.LoadAssetContainer(path, scene, (container) => {
container.scaling = new BABYLON.Vector3(0.1, 0.1, 0.1);
container.instanceToScene(
5,
(instance, i) => {
instance.position.x = i*2.0;
instance.entries.animationGroups.forEach((group) => { group.speedRatio = 1.0-i/10; } );
}
});
I can just work with the instance. I don’t have to understand if the main object is part of the scene or not, instanceToScene
takes care of that. If I want to do something that is less standard, such as setting the animation speed, then I fall to the current API, which is very reasonable. The animation loop could also have a façade for translation/etc, abstracting the for loop of rootNodes.
This is of course my two cents, and my personal experience as a developer using BJS and not a developer of BJS (yet ).