mediabounds Posted July 22, 2014 Share Posted July 22, 2014 I'm getting up-to-speed on developing with Babylon.js and I'm having a problem with physics simulations and initial rotation on a mesh: You'll notice that the box and the ball bounce off the air above the "ground." My expectation is that both the box and the ball would land on the surface of the ground. It works as expected if there is no initial rotation. The greater the rotation, the more obvious the problem. Here's how I'm rotating the ground:var ground = BABYLON.Mesh.CreateBox("ground", 10, scene);ground.rotate(BABYLON.Axis.Z, .3, BABYLON.Space.LOCAL);ground.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass:0, friction:0.5, restitution: 0.4});If it helps, here's all the code I'm using to create the scene:var createPrototypeScene = function(engine) {var scene = new BABYLON.Scene(engine);var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 10, -40), scene);var light0 = new BABYLON.DirectionalLight("Omni", new BABYLON.Vector3(-2, -5, 2), scene);var light1 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(2, -5, -2), scene);camera.setTarget(new BABYLON.Vector3(0, 0, 0));scene.enablePhysics(null, new BABYLON.CannonJSPlugin());// Create the groundvar ground = BABYLON.Mesh.CreateBox("ground", 10, scene);ground.rotate(BABYLON.Axis.Z, .3, BABYLON.Space.LOCAL);ground.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass:0, friction:0.5, restitution: 0.4});// Create the ballvar ball = BABYLON.Mesh.CreateSphere("ball", 16, 1, scene);ball.material = new BABYLON.StandardMaterial("ball", scene);ball.material.wireframe = true;ball.position = new BABYLON.Vector3(3, 20, 0);ball.setPhysicsState(BABYLON.PhysicsEngine.SphereImpostor, { mass: 5 });var box = BABYLON.Mesh.CreateBox("box", 3, scene);box.position = new BABYLON.Vector3(0, 15, 0);box.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass: 1});return scene;}Thanks! Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 23, 2014 Share Posted July 23, 2014 Hi MB, welcome to the forum. I have no solution, but I made a Run-able playground scene for this... at... http://www.babylonjs.com/playground/#1AAQUN Strange situation... easy to see it happen. *scratch scratch* The experts will have comments, soon, I suspect. Temechon 1 Quote Link to comment Share on other sites More sharing options...
Kilombo Posted July 23, 2014 Share Posted July 23, 2014 Quite strange really, I took wingnut example, and added another box and sphere 1 pixel bigger, then I parented them to the first ones, and the problem got a bit better. I think that maybe cannon.js creates something like a "invizible box" that makes the original one a bit larger but it gets unseen (just specullating of course).Where's the example: http://www.babylonjs.com/playground/#26L9IU#1 Quote Link to comment Share on other sites More sharing options...
Temechon Posted July 24, 2014 Share Posted July 24, 2014 I think this problem is linked to the physic body size calculation. In CannonJs (and in OimoJs), all registered mesh is linekd to a 'body' : an invisible object linked to the physic engine. Here is how the body size is processed with CannonJs : bbox = mesh.getBoundingInfo().boundingBox;var min = bbox.minimumWorld;var max = bbox.maximumWorld;var box = max.subtract(min).scale(0.5);This code does not take into account the rotation at all (the maximum point of a box is ok when the box is not rotated). Quote Link to comment Share on other sites More sharing options...
Temechon Posted July 24, 2014 Share Posted July 24, 2014 This problem is fixed in Oimo plugin with this : bbox = mesh.getBoundingInfo().boundingBox;var size = bbox.extends.scale(2).multiply(mesh.scaling); I don't know if this will fix the problem in CannonJs. Fixed in Oimo.js : http://pixelcodr.com/oimo3/ EDIT : Updated to take scaling into account. Dad72 1 Quote Link to comment Share on other sites More sharing options...
mediabounds Posted July 24, 2014 Author Share Posted July 24, 2014 I believe Temechon is right about the problem being the physics size calculation. If I go straight to the physics plugin and rotate it's body instead of the Babylon Mesh, it behaves correctly:http://www.babylonjs.com/playground/#1AAQUN#2 Quote Link to comment Share on other sites More sharing options...
Kilombo Posted July 24, 2014 Share Posted July 24, 2014 Temechon it's probably right Is the man of the physics engines , If he says so, probably he's right Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.