loadAnimations: function() { var animations = this._gltfJSON.animations; if (!animations) return; var accessors = this._gltfJSON.accessors; var nodeAnimationTypes = this._nodeAnimationTypes; var nodes = this._gltfJSON.nodes; var meshes = this._gltfJSON.meshes; var osgjsAnimations = []; for (var i = 0; i < animations.length; i++) { var channels = animations[i].channels; var samplers = animations[i].samplers; var osgjsChannels = []; for (var j = 0; j < channels.length; j++) { var channel = channels[j]; var sampler = samplers[channel.sampler]; var times = accessors[sampler.input].data.getElements(); var accessorValues = accessors[sampler.output]; var values = accessorValues.data.getElements(); // target.id is deprecated var target = channel.target; var createChannel = ReaderWriterGLTF.TYPE_CHANNEL_PATH[target.path][accessorValues.type]; var nodeIndex = target.node !== undefined ? target.node : target.id; var node = nodes[nodeIndex]; var channelName = target.path; var targetName = nodes[nodeIndex].osgjsNodeName; // needs to get the updateCallback name of the morph geometry if (channelName === 'weights') { // if morph target we need to split each channel into scalar for each target var mesh = meshes[node.mesh]; var nbTargets = mesh.primitives[0].targets.length; var nkKeys = times.length; for (var targetIndex = 0; targetIndex < nbTargets; targetIndex++) { var weights = new Float32Array(nkKeys); for (var v = 0; v < nkKeys; v++) { weights[v] = values[v * nbTargets + targetIndex]; } targetName = this._getMorphTargetName(mesh, targetIndex); osgjsChannels.push(createChannel(weights, times, targetName, targetIndex)); } } else { osgjsChannels.push(createChannel(values, times, targetName, channelName)); } if (!nodeAnimationTypes[nodeIndex]) nodeAnimationTypes[nodeIndex] = {}; nodeAnimationTypes[nodeIndex][channelName] = true; } var animationName = 'animation-' + i.toString(); osgjsAnimations.push(animationFactory.createAnimation(osgjsChannels, animationName)); } var animationManager = new BasicAnimationManager(); animationManager.init(osgjsAnimations); this._animationManager = animationManager; },
var createAnimationWithNegativeKey = function(name, target1, target2) { var a = createFloatKeyframes(-10); a.target = target1 || 'a'; a.name = 'rotateX'; var b = createFloatKeyframes(10); b.target = target2 || 'b'; b.name = 'rotateY'; return Animation.createAnimation([a, b], name); };
return P.all( arrayChannelsPromise ).then( function ( channels ) { return Animation.createAnimation( channels, jsonObj.Name ); } );
return P.all(channelsPromiseArray).then(function(channels) { return animation.createAnimation(channels, animName); });