Gugis Posted September 13, 2015 Share Posted September 13, 2015 I'm trying to create bone animation programatically which will be used for interpolation between two animations.My code:var bone = skeleton.bones[0];var bone_animation = bone.animations[0];var current_frame = Math.round(bone_animation.currentFrame);if(!current_frame) current_frame = 0;var animationArm = new BABYLON.Animation("myAnimation", "_matrix", 30, BABYLON.Animation.ANIMATIONTYPE_MATRIX);animationArm.setKeys([ {frame: 0, value: bone_animation._keys[current_frame].value}, {frame: 30, value: bone_animation._keys[100].value}]);bone.animations.push(animationArm);animationArm.animate(0, 0, 30, true, 1);And i get this error: Uncaught TypeError: Cannot set property '_matrix' of undefinedCan someone tell me what i'm doing wrong. Or give some tips how interpollation between two skeletal animations can be achieved. Thanks Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 14, 2015 Share Posted September 14, 2015 Hello! can you try with this:var bone = skeleton.bones[0];var bone_animation = bone.animations[0];var current_frame = Math.round(bone_animation.currentFrame);if(!current_frame) current_frame = 0;var animationArm = new BABYLON.Animation("myAnimation", "_matrix", 30, BABYLON.Animation.ANIMATIONTYPE_MATRIX);animationArm.setKeys([ {frame: 0, value: bone_animation._keys[current_frame].value}, {frame: 30, value: bone_animation._keys[100].value}]);bone.animations.push(animationArm);scene.beginAnimation(bone, 0, 30, true); Quote Link to comment Share on other sites More sharing options...
Gugis Posted September 14, 2015 Author Share Posted September 14, 2015 Hi Deltakosh No error, but nothing happens. I guess problem is that bone has two animations (first is original skeletal animation and second is created programatically) and beginAnimation function tries to play them both. I need to find solution how to ignore the first one animation. Well maybe I'm wrong, that's just my speculations. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 14, 2015 Share Posted September 14, 2015 Can you share your code on the playground? Quote Link to comment Share on other sites More sharing options...
Gugis Posted September 14, 2015 Author Share Posted September 14, 2015 I couldn't load my scene in playground so i uploaded my code here: http://mmo.impressive.lt/ I track bone matrix via console.log() inside render function and you can see that matrix data is not changing. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 14, 2015 Share Posted September 14, 2015 can you reference babylon.max.js (the unminified version) ? Quote Link to comment Share on other sites More sharing options...
Gugis Posted September 14, 2015 Author Share Posted September 14, 2015 can you reference babylon.max.js (the unminified version) ?Sure. Done. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 14, 2015 Share Posted September 14, 2015 Can you add more keys in your animation ? By default matrices are not interpolated Quote Link to comment Share on other sites More sharing options...
Gugis Posted September 15, 2015 Author Share Posted September 15, 2015 Can you add more keys in your animation ? By default matrices are not interpolatedWow. It works!!!! Thank you I don't know if I am doing this right, but at least something is working My code looks like that now: var player = scene.getMeshByName('player'); var bone = get_bone_by_name(player.skeleton, 'LeftShoulder'); var bone_animation = bone.animations[0]; var current_frame = Math.round(bone_animation.currentFrame); if(!current_frame) current_frame = 0; var animationArm = new BABYLON.Animation("myAnimation", "_matrix", 30, BABYLON.Animation.ANIMATIONTYPE_MATRIX); var steps = new Float32Array(16); // Generate single step values for(var n in bone_animation._keys[current_frame].value.m) { var s_val = bone_animation._keys[current_frame].value.m[n]; var e_val = bone_animation._keys[90].value.m[n]; var val = (e_val - s_val) / 30; steps[n] = val; } // Generate keys var keys = []; for(var i = 0; i <= 30; i++){ var arr = new Float32Array(16); for(var n in steps) { arr[n] = bone_animation._keys[current_frame].value.m[n] + (i * steps[n]); } var obj = new BABYLON.Matrix(); obj.m = arr; var key = {frame: i, value: obj}; keys.push(key); } animationArm.setKeys(keys); bone.animations.push(animationArm); scene.beginAnimation(bone, 0, 30, false, 1, function(){ // Remove interpolation animation bone.animations.pop(); // Continue looped animation scene.beginAnimation(bone, 90, 105, true); }); Wingnut 1 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.