コード例 #1
0
        return P.all(animPromiseArray).then(function(animations) {
            var animationManager = new BasicAnimationManager();
            animationManager.init(animations);

            self._basicAnimationManager = animationManager;
            animationManager.playAnimation(animations[0].name);
        });
コード例 #2
0
    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;
    },