Scalar depreciated?


I was trying to figure out how to replace Scalar.Lerp in my code, but after looking at the docs and this warning Im still at a loss as to what is replacing Scalar?

There was the change - Complete migration of `Scalar` to functions (#15373) · BabylonJS/Babylon.js@58a5dc1 · GitHub
Scalar.Lerp is now just Lerp

1 Like

Hmm it seems that the scalar functions are not yet exposed?

They are (or they should be). In ES6 I mean. In UMD I think we are still sticking with Scalar class (unless I’m mistaken @RaananW ?)

1 Like

Correct, the Scalar standalone functions are only available in ES6. In UMD you will need to use the Scalar class.

Maybe we shouldn’t have deprecated it. Or exported the functions to the global namespace?

maybe not deprecate it then?

1 Like

I had issues exporting them in ES6, hmm hmm! Could be my issue as well, but I think I checked from source that they were not exposed. I think I have to double check

They are exported directly from the scalar.functions.js file, and need to be imported from there. If that doesn’t work I would really love to know that.

Ah seems that this works fine:
import { Clamp } from '@babylonjs/core/Maths/math.scalar.functions'

I was just confused, since @babylonjs/core doesn’t expose these functions, or I think so at least? So my vs code intellisense didn’t pick it up :slight_smile:

it is not recommended to import from @babylonjs/core, as this will result in importing the entire framework (due to side effects). we are working on a proper fix, but it will take some time until it is delivered.

Do you mean that in the future the base @babylonjs/core should not be used as it is, but include individual exact classes like import { Vector3 } from '@babylonjs/core/Maths/math.vector' ?

Yes, this is the right way to go. This will reduce your package size.

I can see that, I wonder if one can configure vs code to use exact imports like that :thinking: The default seems to be still the whole package.

Also in last project I did use the exact imports, but some parts still needed some side effect imports, and since I’m using many Babylonjs functionalities, the bundle size was not improved that much. Will it in the future though? :eyes:

We are planning to restructure the files to allow better side effects handling. When we start working on that we will keep the community updated, of course.

Oh, and yes, if you use a lot of features, your package will be large :slight_smile: but you can reduce that using dynamic imports, for example. You are in full control of what you are importing and when.

1 Like