Jump to content

Loop animation - Animation (babylon 2.4.0 release)


Recommended Posts

Hi I create simple animation Elevator which goes up an down in loop.
When I load it from bayblon file it works OK.

But when I add physics impostor on the Elevator I get error. (new bayblon version 2.4.0. and 2.5.0-alpha)

Any idea what it could be a problem?

(In previos version 2.4.0-alpha animation with impostor worked OK but new version get me error look down)

Uncaught TypeError: Cannot read property 'x' of nullQuaternion.copy

@ cannon.js:4487t._updatePhysicsBodyTransformation

@ babylon.2.4.js:28t.generatePhysicsBody

@ babylon.2.4.js:28t.addImpostor

@ babylon.2.4.js:18t._init

@ babylon.2.4.js:18t.forceUpdate

@ babylon.2.4.js:18set

@ babylon.2.4.js:6i.setValue

@ babylon.2.4.js:17i.animate

@ babylon.2.4.js:17e._animate

@ babylon.2.4.js:17i._animate

@ babylon.2.4.js:10i.render

@ babylon.2.4.js:11(anonymous function)

@ Game.js:156o._renderLoop

@ babylon.2.4.js:4


Link to comment
Share on other sites

It sounds like your animation is trying to animate a rotation property that has been set to null.

When you use a physics imposter, rotationQuaternion is used and rotation is set to null (at least in 2.4). 

Edit: Actually it looks like the physics plugin is trying to set rotationQuaternion that has been set to null by the animation.


Link to comment
Share on other sites

Did someone ping?

Will it be possible to show a simple playground that reproduces it? This seems like a bug with the way we interact with cannon, but since you are using the minified babylon version, the line number doesn't actually mean anything :)

The bug happens when generating the physics body. Does this body have a parent? what kind of body is it? 

Link to comment
Share on other sites

RaanaW, I post simple model with animation :)

I set mesh impostor on Path, sphere impostor on Ball and mesh impostor on Elevator.
(When physics impostor was add to Elevator, upper error happend) 
If you put this babylon file in sandbox it works OK, but when we add physics on Elevator(animated object) Upper error happend.

I atthach model (bablon file)


Link to comment
Share on other sites

Hallo RaananW,

here is playground


(so if we oncomment "mesh.setPhysicsState(BABYLON.PhysicsEngine.MeshImpostor, { mass: 0, friction: 0.5, restitution: 0 });" for Elevator than this error happends.

This is model file https://dl.dropboxusercontent.com/u/20766916/RollShadowAnimation.babylon, maybe is a problem indside .babylon file, but it works ok until we add physics to Elevator.

Can anybody check, or help me what should I do to work elevator physics in this case.

and code for playground (if link doesn work)

var createScene = function () {

    // This creates a basic Babylon Scene object (non-mesh)
    var scene = new BABYLON.Scene(engine);

    // This creates and positions a free camera (non-mesh)
    var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);

    // This targets the camera to scene origin

    // This attaches the camera to the canvas
    camera.attachControl(canvas, true);

    // This creates a light, aiming 0,1,0 - to the sky (non-mesh)
    var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);

    // Default intensity is 1. Let's dim the light a small amount
    light.intensity = 0.7;
	var gravityVector = new BABYLON.Vector3(0, -10, 0);
	var physicsPlugin = new BABYLON.CannonJSPlugin();
	scene.enablePhysics(gravityVector, physicsPlugin);

    BABYLON.SceneLoader.ImportMesh("", "https://dl.dropboxusercontent.com/u/20766916/", "RollShadowAnimation.babylon", scene, function (meshes) {
                	for (var a = 0; a < meshes.length; a++) {
                		var mesh = meshes[a];
                		console.log( mesh.id );
                		mesh.checkCollisions = true;	                    
	                    if (mesh.id.substring(0, 4) == "Path") {
	                    	console.log( mesh.id +" set Wall physics boxImpostor ");
	                    	//m.physicsImpostor = new BABYLON.PhysicsImpostor( wall, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0, friction : 0.5, restitution : 0 }, scene);
	                    	//mesh.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, move:false});
	                    	mesh.setPhysicsState(BABYLON.PhysicsEngine.MeshImpostor, { mass: 0, friction: 0.5, restitution: 0 });
						if (mesh.id.substring(0, 4) == "Ball") {
	                    	console.log( mesh.id +" set Wall physics boxImpostor ");
	                    	mesh.setPhysicsState(BABYLON.PhysicsEngine.SphereImpostor, { mass: 1, friction: 0.5, restitution: 0 });	                    	
						if (mesh.id.substring(0, 8) == "Elevator") {
	                    	//mesh.setPhysicsState(BABYLON.PhysicsEngine.MeshImpostor, { mass: 0, friction: 0.5, restitution: 0 });

    return scene;



Link to comment
Share on other sites

Ok, checked again.

You are animating the scale of the object. A change in scale requires a force update of the physics impostor (Rigid bodies mean - no change in the shape of the object). It should actually work, but will be very slow.

You are also animating the rotation, but the rotation required is a quaternion (you are animating the euler rotation). You will have to start working with quaternions in order for that to work correctly.

Somewhere along the way, the quaternion rotation is nulled (haven't found yet where), but this way it will anyhow not do what you want it to do :)

Recommendation - animate the rotationQuaternion and position, try to avoid animating the scale as much as you can.


Link to comment
Share on other sites

Ok, I admint I'm beginer.

But it is logicaly that quaternion means rotation (in this case with anitmaition).

But for me is strange that I did not use scaling or rotation in this animation. There is just location use. from fram 1 to 100 up for z=4unit, and forrm 100 1 z=-4unit.

I do Ctrl-A (scale rotate) on Elevator before I do animation.



Link to comment
Share on other sites

Your only problem is the scaling, actually. This won't work really. Creating a new impostor (mesh impostor) every frame will be very heavy on your CPU.

Rotation should actually work, but again, when working with physics it is better to use the quaternion. because internally, the rotation is converted to a quaternion and being reset. Which might also cause a little problem with the animations.

Link to comment
Share on other sites

ok I DON'T SEE WHERE IS A PROBLEM IN .babylon file? 

RaananW, can you show me where exactly is problem. (Where in .babylon file which I attach is a problem, Where is scaling animation).

Scaling values for animation frames is always 1 (for x,y,z) 





{"frame":200,"values":[0,0,0]}],"loopBehavior":1,"name":"rotation animation","property":"rotation"},{"dataType":1,"framePerSecond":24,"keys":[

{"frame":200,"values":[0,0,0]}],"loopBehavior":1,"name":"position animation","property":"position"},{"dataType":1,"framePerSecond":24,"keys":[

{"frame":200,"values":[1,1,1]}],"loopBehavior":1,"name":"scaling animation","property":"scaling





I also try to create new animation with quaternion mode, but I cannot export to .babylon file.

Export error in blender (Exporter (Babylon.js ver 5.0.2)

location: <unknown location>:-1

location: <unknown location>:-1
Traceback (most recent call last):
  File "/home/aaa/.config/blender/2.77/scripts/addons/babylon-js/__init__.py", line 81, in execute
    exporter.execute(context, self.filepath)
  File "/home/aaa/.config/blender/2.77/scripts/addons/babylon-js/json_exporter.py", line 99, in execute
    mesh = Mesh(object, scene, nextStartFace, forcedParent, nameID, self)
  File "/home/aaa/.config/blender/2.77/scripts/addons/babylon-js/mesh.py", line 39, in __init__
    self.define_animations(object, True, True, True)  #Should animations be done when forcedParent
  File "/home/aaa/.config/blender/2.77/scripts/addons/babylon-js/f_curve_animatable.py", line 43, in define_animations
    hasData = rotAnimation.append_range(object, animationRange)
  File "/home/aaa/.config/blender/2.77/scripts/addons/babylon-js/animation.py", line 110, in append_range
  File "/home/aaa/.config/blender/2.77/scripts/addons/babylon-js/animation.py", line 165, in get_attr
    return post_rotate_quaternion(getattr(object, self.attrInBlender), self.xOffset)
  File "/home/aaa/.config/blender/2.77/scripts/addons/babylon-js/package_level.py", line 184, in post_rotate_quaternion
    post = mathutils.Euler((angle, 0.0, 0.0)).to_matrix()
NameError: name 'mathutils' is not defined


if I switch back to XYZ Euler. It exports fine. Animation works fine, but if I add physics error as I write.

Can anybody check where EXCATLY IS A PROBLEM IN .BABYLON (Babylon file have no scaling no rotation in animation) (JSON) FILE.
Playground have no rotation no scaling for Elevator.


Link to comment
Share on other sites

@ian frustrating isn't it when you seem to be totally stuck on a simple issue. We have all been there.

Even if applying a rotation of 0 and a scaling of 1 a rotation and a scaling are applied, ie mesh.rotation = new BABYLON.Vector3(0, 0, 0) may result in no rotation and mesh.scaling = new BABYLON.Vector3(1, 1, 1) may result in no change of scale but in the code the rotation and scaling calculations are still carried out, so @RaananW is correct in reading the the data below to say a rotation and a scaling are been applied.

My knowledge of physics engines is non existent as is my knowledge of what happens if you manually edit a .babylon fileso perhaps you are best totally ignoring this advice, but then it is  worth a try.

Now for the trial and probable error advice - what happens if you manually edit the .babylon file and delete     "rotation":[0,0,0],"scaling":[1,1,1],  from the elevator?

1 hour ago, ian said:



Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...