instantiateModelsToScene and the missing cameras

Dear fellow scholars

Once again I find myself humbling seeking the wisdom of the great ones.

I’ve been doing some experiments with importing cameras that are set up specifically for a mesh authored in blender.

Historically I’ve been loading assets into asset containers and instancing them when I need them which has worked well up to this point, however, I realized that instantiateModelsToScene doesn’t bring cameras and their transform nodes with them :skull::skull::skull:

Hypothetically, if I need to add a GLB to the scene again, including the cameras and their parents…what would be the best approach?

I did try and clone the original cameras and their transform nodes but again, I am tarnished and I don’t really now if cloning and re-parenting should work…

I thought I was getting hit by a camera rotation export bug but that wasn’t the case, this is just me not being able to create the cameras with instantiateModelsToScene

Humbly, a tarnished potato :potato:

1 Like

Hello Tarnished potato!

You can still do something like:

assetContainer.addToScene(e => e instanceof Camera);

And that should just add the cameras.

1 Like

Thank you @Deltakosh , will that net me a clone or the originals, is there a way to instance the container + cameras to scene in a repeatable way?

camera cannot be instantiated but they can be cloned for sure.

you can even manually do it with something like:

assetContainers.cameras.forEach(c => {
   c.clone("new name");
1 Like

Fabulous. I’m still learning so please forgive my misunderstanding, I did trawl the forum and from what I read, the conversion for right to left-handed-ness, blender → Babylon is a transform applied to the root mesh.

I made the mistake of reparenting something like pirate JC’s tutorial with the cannons, all hell broke loose and I’m pretty sure it was the transform being applied to root thing.

I can see my cameras have transform node parents, am I right in thinking if I can clone that whole chain and pop them in the cloned root node it will all work as it should do? I did try cloning the cameras without the transforms and their parent being the root and it didn’t work out so well. They ended up under the floor :sweat_smile:

I would rather suggest to unparent the cameras from the transform node and reset them to the BJS system/coordinates before cloning. Else, for a matter of consistency I should say, another option would be to have your entire scene use the right handed system.

scene.useRightHandedSystem = true;

Legendary advice, I think I need to avoid the right-handed system option for consistency, is there a formal sort of way to reset the coordinates to the BJS system or is that just trial and error? Again sorry for the noddy question and thanks for the rapid reply.

No, not at all (noobish). This thing with left vs right handed systems is a mess for everyone.
I believe when you set you camera to use ‘parent = null’, it should null the camera and you should be good to go using the BJS coordinates.

Rocking, tell you what today can be an experiment in blender camera cloning, I’ll have a play and if I’m struggling, I’ll do a playground and maybe Kofi bibe my way to more help. Thanks @mawa

OK. Though, may be it’s ‘camera.setParent = null’. I’m never sure which one to use. Best to try both.

I’m closer for sure, do you know what would flip a camera horizontally? It’s like they see everything backwards, what was on the left is now on the right even some materials feel inverted.

I’m afraid this is still the left vs right handed system. Materials can be a problem. Any scaling at -1 on Z in your model? I think there is a way to ‘normalize’ materials in case this happens. Just can’t recall it right now. May be just do a quick search on ‘normalize’ or I can quickly call someone in that for sure knows much better than I do (I tend to avoid this kind of things at modelling level but this issue I know is very common).

Edit: @sebavan @Evgeni_Popov , could you kindly have a quick look and reply for this? Would be very appreciated. Thx,

You know, I had a feeling it was the L-R thing somewhere, I’m sure it’s to do with the GLTF conversion being a applied to the root mesh, so by virtual of a camera being cloned, it won’t have the right transformation because it doesn’t have the correct parent.

So! I grabbed the cameras, cloned and on cloning reparented them to the correct transformation node, so now everything is in the right place.

I’m thinking, this whole thing started because I wasn’t getting cameras using instantiateModelsToScene, is it possible that the root node (I think it’s the container in blender) does have the gltf R->L fix applied, and the cameras don’t or have been fixed (some magic I don’t understand), and by reparenting them, although notionally it’s working, it’s taking the camera back from L to R?

So Export mesh and cameras via blender GLTF plugin
→ Plugin does magic transformation on root mesh to convert from right handed to left handed.
→ Load .GLB into container
→ Cameras somehow get separated and converted to Left handed and are now independent of the root transform.
→ I add use instanciateModeslToScene
→ Cameras are not included on instanciate.
→ I find the cameras, clone and reparent them to the original transform nodes
→ Now the cameras are essentially being converted from L back to R ?

Yes, except this root node is not from blender. It’s created in BJS to cope with the issue of right vs left handed.

Yes, the magic is the idea. :magic_wand: But the magic is not yet entirely here for all use cases.

That’s the part I’m not sure of. I’ll let one of the big brains :grinning: from the BJS team answer this one.

@mawa I’ve for sure potato’ed my way through this, and I can see that -1 on the z, so we’re on the money, found this super interesting prop on the camera, ignoreParentScaling, setting it to true obviously ignores that scaling confirms everything, so we’re good.

I’d love to know the correct way of dealing with this If this wasn’t it, but thank you so much for the hints along the way. My understanding continues to grow.


Oh, what a nice find you got there. :heart_eyes: I bookmarked it already. I would have thought ‘setParent’ would do the same but didn’t have a chance to test it as of just now.

From my (small) experience with BJS, the ‘correct way’ is the way that works for you. The one you can master and maintain. This is probably the thing I like most with BJS. There is (nearly) never just one way to do things :smiley:

1 Like


1 Like