Bug with stringify mesh.rotationQuaternion

Hi there,

I lost couple days investigating an issue I had by updating my Babylon lib from v4.0.0.alpha32 to the last stable one. Which is v4.0.3 from now.

Long story short I have an editor which is using Babylon (of course).
This editor is used to make a map an eventually add 3D models in this map then when you save the map all data are exported in a file and in theses data I have model rotation (rotationQuaternion).

Then when I load the map I parse all theses data and somehow my rotationQuaternion data was parsed as string (so my bad) and not as number so I had some thing like that:

mesh.rotationQuaternion = {
“x”: “-07”,
“y”: “0”,
“z”: “0”,
w: “-0.7”

instead of having something like that:

mesh.rotationQuaternion = {
“x”: -07,
“y”: 0,
“z”: 0,
w: -0.7

And this issue make my model not appear with no error. So I don’t know if it’s really a bug. But is it possible in future Babylon version to check, in the Quaternion constructor if the parameters are number and if not converting them to number or throw an error?
So far I fixed it by fixing my parsing part to ensure having number type.

Hope I can save some debug time for those who will get into this issue.

Here a PB that shows the issue (just comment line 23 and uncomment line 24 to see the difference)


1 Like

It sounds like you need to start using typescript.

I do!
But somehow strings can be passed to Quaternion constructor this way

case “Quaternion”:
retval = new (Function.prototype.bind.apply(BABYLON.Quaternion, [null].concat(objectsParams)));

But the problem is, it was working this way in previous Babylon version this issue has appeared recently.

Hey, we cannot check at runtime because of performance reason. We want the math library to be as fast as it possible can so there is almost no check at all :frowning:

This is not a bug, this is the way it should be. but if you want to keep your code without major changes, you can always add scalineInPlace after every quaternion creation. something like this:

sphere.rotationQuaternion = new BABYLON.Quaternion("-0.1", "0", "0", "-0.7").scaleInPlace(1);


This will force the strings to convert to numbers. It is a hack, but sometimes it is better than changing the entire way you are working.

Oh, and move to typescript :smile:

First off thank you guys for your awswers.

As I said I don’t know if we can considering this issue as a bug. The bad thing about that is,
It was working before, I just updated babylon lib and my models have just disappeared with no error or warning.

I don’t know if something can be done in the Babylon lib without mess with the performance to at least emit an error.
But anyway now I’m fine. I fixed my parser to ensure sending number type to Quaternion constructor! :slight_smile:

PS: I do use typescript but I can still pass string in Quaternion constructor

1 Like

4.0.3 was a big improvement in performance so this should be why :slight_smile: