Hi Topper/others.
Take a look at this thing, Topper…
https://www.babylonjs-playground.com/#HH1U5#89
It is a little animation demo that I once created. It makes heavy-use of the powerful but many-parameter’d BABYLON.Animation.CreateAndStartAnimation
call. I love that thing. It is a “derive-the-keyframes-with-math” type-of animation tool.
Note: Anims that DO use keyframes, also derive their steps… with “programmer-marshalled” math. Deriving animation steps… is often called “interpolation” and sometimes “LERP” (linear interpolation).
Notice HOW I “added” these 8 animation funcs (spin, spinTo, move, moveTo, scale, scaleTo, color, colorTo) …to the scene. They are sometimes called “over-loads” or “over-loading”. They are added to the “factory” that makes BJS mesh… BEFORE we begin making mesh. We asked the factory to PREPARE to produce “custom mesh”, and the factory said “Gladly”.
(some say that overloading is not a healthy/wise thing, for various reasons, but I still do it and so can you)
Those 8 animators… are ‘method’ overloads. You can also do ‘property’ overloads… like seen in line 54.
The NAME of the added/overloaded property or method… is important. For FULL POWER… use “custom” property and function names which ARE NOT already ‘members’ of the default BJS Mesh class.
Take careful note of lines 56-59, where I TRIED to force all factory-made mesh.isPickable
to FALSE. If you look at JS console output, we can see that… fail. The factory set mesh.isPickable
to ITS preference, no matter what we wanted.
In this case, perhaps wait-for scene isReady, and THEN take over the world, like this:
scene.onReadyObservable.add( function() {
for (mesh of scene.meshes) { mesh.isPickable = false }
});
That way, we modify factory-made meshes… AFTER their construction. All these methods can be used on all “nodes”… including Nodes, TransformNodes, Cameras, Lights, and Mesh. Also available on many non-node BJS objects.
Ok, I hope this gets your idea-juices flowing. scene.onReadyObservable
can be very useful/powerful for adding post-construction overloads, and lots of other things.
Sometimes programmers do the very first scene.render(), FIRST THING, inside scene.onReadyObservable
. I think this makes mesh.boundingInfo() “flesh-out”, so that its many measuring tools will be accurate. It also first-renders any GUI controls/widgets that the scene might use, and fleshes-out their GUI currentMeasure and measureForChildren (and similar) properties. (in case you need to do some accurate measurements and last-moment tweaks to your GUI).
Lots of things wait for the first-render… before they “flesh-out”, and you might need things fleshed-out (rendered at least once) before you can do the custom/personal measurements and tweaks you wish to do.
All in all, scene.onReadyObservable
is your personal place to doFinalStuffBeforeGO().
We COULD have added my 8 animation functions to each/select mesh… within onReadyObservable, if wanted (probably wiser). But, I wanted to show you both ways, so you have all the tools you need to blow up the planet. I hope I have been helpful. Party On!