Recently, using the PhysicsImpostor.CylinderImpostor type when creating a new BABYLON.PhysicsImpostor on a (Cylinder Shaped) Mesh causes a Javascript error. Other PhysicsImpostor types like BoxImpostor seem to work fine though on the same mesh. Apparantly some variable or property seems not to be defined any more compared to previous builds.
Here’s the code to reproduce it in the playground:
///////////////
var width = 8;
var depth = 16;
scene.gravity = new BABYLON.Vector3(0, -9.81/4, 0);
scene.collisionsEnabled = true;
scene.enablePhysics(new BABYLON.Vector3(0, -9.81/4, 0)); // , new BABYLON.OimoJSPlugin());
var mesh =
BABYLON.MeshBuilder.CreateCylinder(
"CylinderMesh",
{
diameter: Math.max(width, depth),
height: Math.min(width, depth),
tessellation: 4 * (Math.max(Math.round(Math.max(width, depth)/6.4), 1)),
},
scene);
mesh.receiveShadows = false;
mesh.freezeWorldMatrix();
mesh.checkCollisions = true;
mesh.physicsImpostor =
new BABYLON.PhysicsImpostor(
mesh,
//BABYLON.PhysicsImpostor.BoxImpostor, // box impostor works
BABYLON.PhysicsImpostor.CylinderImpostor, // broken, error: a is undefined
/*
TypeError: "a is undefined"
_createShape https://preview.babylonjs.com/babylon.js:16:1505567
generatePhysicsBody https://preview.babylonjs.com/babylon.js:16:1501452
addImpostor https://preview.babylonjs.com/babylon.js:16:1498721
_init https://preview.babylonjs.com/babylon.js:16:481951
e https://preview.babylonjs.com/babylon.js:16:480506
*/
{
mass: 0,
friction: 0.5*2, // 1.0 = friction of rubber on concrete
restitution: 0.7/2, // 0.37 = restitution of tungsten/aluminum
},
scene);
/*
Similar error but then in my own web app:
TypeError: Cannot read property 'radiusTop' of undefined
at e._createShape (babylon.js:16)
at e.generatePhysicsBody (babylon.js:16)
at e.addImpostor (babylon.js:16)
at e._init (babylon.js:16)
at new e (babylon.js:16)
at new BABYLON.PhysicsImpostor
*/
///////////////
If you don’t enable physics on the scene, the code works fine also with CylinderImpostor type (but then you don’t have physics, so that doesn’t really solve the bug )