Shumberg Posted January 13, 2016 Share Posted January 13, 2016 Hello all. I am trying to get a simple manual bones animation test working, and I think I have all the pieces going, but I see no deformation. The basic idea is I have a mesh which stands about 250 units tall, and I am trying to make a very simple 'spine' (2 bones) generate a smoothish z-bend, using very simple height-based weighting on a pair of bones: //// The mesh data is being brought in from a microservice - the basic mesh data is fine; //// My weighting looks reasonable. var obj = new BABYLON.Mesh(objName, scene); obj.position = BABYLON.Vector3.Zero(); obj.setVerticesData(BABYLON.VertexBuffer.PositionKind, data[objName].model.P, false, 3); obj.setVerticesData(BABYLON.VertexBuffer.NormalKind, data[objName].model.N, false, 3); obj.setVerticesData(BABYLON.VertexBuffer.UVKind, data[objName].model.uv, false, 2); obj.setIndices(data[objName].model.indices); var tmpAttr = [] for (var i = 0; i < data[objName].model.P.length; i+=3) { var nHt = Math.abs(data[objName].model.P[i+1]) / 250.0; tmpAttr.push(1.0 - nHt); tmpAttr.push(nHt); tmpAttr.push(0.0); tmpAttr.push(0.0); } obj.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, tmpAttr, false, 4); tmpAttr = []; for (var i = 0; i < data[objName].model.P.length; i+=3) { tmpAttr.push(0.0); tmpAttr.push(1.0); tmpAttr.push(0.0); tmpAttr.push(0.0); } obj.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, tmpAttr, false, 4); //// ...elided stuff... var skel = new BABYLON.Skeleton(objName + "Skeleton", objName + "Skeleton", scene); var par = null; var nBones = 2; var mat = new BABYLON.Matrix.FromValues(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); console.log(mat); for (var i = 0; i < nBones; i++) { var bone = new BABYLON.Bone(objName + "Bone" + i, skel, par, mat); var boneAnim = new BABYLON.Animation("Bone" + i + "Animation", "matrix", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); var keys = []; keys.push({frame: 0, value: mat}); keys.push({frame: 30, value: mat}); boneAnim.setKeys(keys); bone.animations.push(boneAnim); par = bone; mat = BABYLON.Matrix.FromValues(1.0, 0.0, 0.0, 0.0, 0.0, 0.7, -0.7, 125.0 * (i + 1), 0.0, 0.7, 0.7, 0.0, 0.0, 0.0, 0.0, 1.0); } obj.skeleton = skel; objCopy.skeleton = skel; console.log(skel); scene.beginAnimation(skel, 0, 30, true); The basic (static) display of my geometric data is working fine - I just see no deformation (i.e., my rather boring/static animation (looking for a 45 deg z bend halfway up the character)). I am using a custom ShaderMaterial, so I also tried adding "matricesWeights" and "matricesIndices" to the attributes list in the material constructor (I believe the deformations are being handled in a magic geometry shader (??)), but that didn't work either. Most of the bones examples are more oriented towards having the char/rig imported from a DCC app - I couldn't find any "from scratch" examples. Thanks in advance, Chris 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.