Upgrading 4.0.3 stable version to 4.1.0-beta.27

Hi, guys.

I’ve got an error when I’m upgrading 4.0.3 stable version of babylonjs to 4.1.0-beta.27

This error is very strange and it seems a bug in beta version.

Here is the detail of the error that I’ve got.

TS2322: Type ‘import(“babylonjs/Maths/math”).Vector3’ is not assignable to type ‘import(“babylonjs/Maths/math.vector”).Vector3’.

I’ve checked where it is happening.
this.camera.position = new bjs.Vector3(0, 0, -250);

I think the error happens here.
I am not sure what is the best solution for solving this problem. I couldn’t find any discussion about such kind of problem here.

Any help will be appreciated!
Thank you

Hello and welcome!
This is because we decoupled the engine a bit more in 4.1

you have to import Vector3 from babylonjs/Maths/math.vector

1 Like

Hello Deltakosh

Thanks for your reply.
I’ll try with babylonjs/Maths/math.vector and let you know if I have more trouble.

Best Regards.

1 Like

Hi Deltakosh

It looks like the problem has solved. But there are too many errors while I am migrating.

I’ve got another errors regarding Physics engine.

  1. Argument of type ‘Mesh’ is not assignable to parameter of type ‘IPhysicsEnabledObject’
    With this code:

this.meshBase.physicsImpostor = new bjs.PhysicsImpostor(this.meshBase, bjs.PhysicsImpostor.SphereImpostor, { mass: 1, restitution: 0.5 }, this.scene.bjsScene);

Here, this.meshBase is a variable of BABYLON.Mesh type

  1. No overload matches this call.
    Overload 1 of 2, ‘(gravity: Vector3, plugin?: IPhysicsEnginePlugin): boolean’, gave the following error.
    Argument of type ‘import(“babylonjs/Maths/math.vector”).Vector3’ is not assignable to parameter of type ‘import(“babylonjs/Maths/math”).Vector3’.
    The types of ‘toQuaternion().equals’ are incompatible between these types.
    Type ‘(otherQuaternion: import(“babylonjs/types”).DeepImmutableObject<import(“babylonjs/Maths/math.vector”).Quaternion>) => boolean’ is not assignable to type ‘(otherQuaternion: import(“babylonjs/types”).DeepImmutableObject<import(“babylonjs/Maths/math”).Quaternion>) => boolean’.
    Types of parameters ‘otherQuaternion’ and ‘otherQuaternion’ are incompatible.
    Property ‘equalsWithEpsilon’ is missing in type ‘import(“babylonjs/types”).DeepImmutableObject<import(“babylonjs/Maths/math”).Quaternion>’ but required in type ‘import(“babylonjs/types”).DeepImmutableObject<import(“babylonjs/Maths/math.vector”).Quaternion>’.
    Overload 2 of 2, ‘(gravity: Vector3, plugin?: IPhysicsEnginePlugin): boolean’, gave the following error.
    Argument of type ‘CannonJSPlugin’ is not assignable to parameter of type ‘IPhysicsEnginePlugin’.
    Types of property ‘setGravity’ are incompatible.
    Type ‘(gravity: Vector3) => void’ is not assignable to type ‘{ (gravity: Vector3): void; (gravity: Vector3): void; }’.
    Types of parameters ‘gravity’ and ‘gravity’ are incompatible.
    Type ‘Vector3’ is missing the following properties from type ‘Vector3’: negateInPlace, negateToRef, crossts(2769)
    babylon.module.d.ts(3558, 9): ‘equalsWithEpsilon’ is declared here.

With code:
this.bjsScene.enablePhysics(this.bjsScene.gravity, new bjs.CannonJSPlugin(true, undefined, CANNON));

Here this.bjsScene is a variable of BABYLON.Scene type.

Is there any document I can refer for migration?
Please help me to solve this problems as well.

Thank you

Hey,

Let’s solve this :slight_smile:

Can you make sure you only import the newest babylon version and have removed all reference to the old one?

Also - what version of typescript are you using? might be an issue as well.

When I try referencing a mesh (or an abstractmesh) as an IPhysicsEnabledObject my compiler lets me do that without a problem, so there must be some incompatibilities in the project itself (which I hope are easy to find and fix)

2 Likes

Hello RaananW

I have solved the problem with importing @babylonjs/core, @babylonjs/gui, instead of using babylonjs npm package.

So it works fine for now. btw, I was used es6.

Thanks a lot for your help guys.

4 Likes

my mistake was mixing BABYLON.Types with types imported directly. ie:

    //this doesnt work
    import { Vector3 } from 'babylonjs';
    const light = new BABYLON.HemisphericLight("light", new Vector3(0, 10, -5), scene)
    //this does work
    import { HemisphericLight, Vector3 } from 'babylonjs';
    const light = new HemisphericLight("light", new Vector3(0, 10, -5), scene)