Skip to content

Commit

Permalink
Merge pull request #6351 from AnalyticalGraphicsInc/node-trs-default
Browse files Browse the repository at this point in the history
Add default translation, rotation, scale to node targeted for animation
  • Loading branch information
emackey authored Mar 20, 2018
2 parents c268786 + 697c6d9 commit 3f075ad
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Change Log
* Fixed model loading failure when containing unused materials. [6315](https://github.com/AnalyticalGraphicsInc/cesium/pull/6315)
* Fixed default value of `alphaCutoff` in glTF models. [#6346](https://github.com/AnalyticalGraphicsInc/cesium/pull/6346)
* Fixed rendering vector tiles when using `invertClassification`. [#6349](https://github.com/AnalyticalGraphicsInc/cesium/pull/6349)
* Fixed animation for glTF models with missing animation targets. [#6351](https://github.com/AnalyticalGraphicsInc/cesium/pull/6351)

### 1.43 - 2018-03-01

Expand Down
5 changes: 5 additions & 0 deletions Source/ThirdParty/GltfPipeline/ForEach.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ define([
ForEach.topLevel(gltf, 'animations', handler);
};

ForEach.animationChannel = function(animation, handler) {
var channels = animation.channels;
ForEach.object(channels, handler);
};

ForEach.animationSampler = function(animation, handler) {
var samplers = animation.samplers;
if (defined(samplers)) {
Expand Down
29 changes: 29 additions & 0 deletions Source/ThirdParty/GltfPipeline/addDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,34 @@ define([
}
}

function getAnimatedNodes(gltf) {
var nodes = {};
ForEach.animation(gltf, function(animation) {
ForEach.animationChannel(animation, function(channel) {
var target = channel.target;
var nodeId = target.node;
var path = target.path;
// Ignore animations that target 'weights'
if (path === 'translation' || path === 'rotation' || path === 'scale') {
nodes[nodeId] = true;
}
});
});
return nodes;
}

function addDefaultTransformToAnimatedNodes(gltf) {
var animatedNodes = getAnimatedNodes(gltf);
ForEach.node(gltf, function(node, id) {
if (defined(animatedNodes[id])) {
delete node.matrix;
node.translation = defaultValue(node.translation, [0.0, 0.0, 0.0]);
node.rotation = defaultValue(node.rotation, [0.0, 0.0, 0.0, 1.0]);
node.scale = defaultValue(node.scale, [1.0, 1.0, 1.0]);
}
});
}

var defaultMaterial = {
values : {
emission : [
Expand Down Expand Up @@ -479,6 +507,7 @@ define([
function addDefaults(gltf, options) {
options = defaultValue(options, {});
addDefaultsFromTemplate(gltf, gltfTemplate);
addDefaultTransformToAnimatedNodes(gltf);
addDefaultMaterial(gltf);
addDefaultTechnique(gltf);
addDefaultByteOffsets(gltf);
Expand Down

0 comments on commit 3f075ad

Please sign in to comment.