Skip to content

Commit 3f075ad

Browse files
authored
Merge pull request #6351 from AnalyticalGraphicsInc/node-trs-default
Add default translation, rotation, scale to node targeted for animation
2 parents c268786 + 697c6d9 commit 3f075ad

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Change Log
3333
* Fixed model loading failure when containing unused materials. [6315](https://github.com/AnalyticalGraphicsInc/cesium/pull/6315)
3434
* Fixed default value of `alphaCutoff` in glTF models. [#6346](https://github.com/AnalyticalGraphicsInc/cesium/pull/6346)
3535
* Fixed rendering vector tiles when using `invertClassification`. [#6349](https://github.com/AnalyticalGraphicsInc/cesium/pull/6349)
36+
* Fixed animation for glTF models with missing animation targets. [#6351](https://github.com/AnalyticalGraphicsInc/cesium/pull/6351)
3637

3738
### 1.43 - 2018-03-01
3839

Source/ThirdParty/GltfPipeline/ForEach.js

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ define([
4949
ForEach.topLevel(gltf, 'animations', handler);
5050
};
5151

52+
ForEach.animationChannel = function(animation, handler) {
53+
var channels = animation.channels;
54+
ForEach.object(channels, handler);
55+
};
56+
5257
ForEach.animationSampler = function(animation, handler) {
5358
var samplers = animation.samplers;
5459
if (defined(samplers)) {

Source/ThirdParty/GltfPipeline/addDefaults.js

+29
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,34 @@ define([
214214
}
215215
}
216216

217+
function getAnimatedNodes(gltf) {
218+
var nodes = {};
219+
ForEach.animation(gltf, function(animation) {
220+
ForEach.animationChannel(animation, function(channel) {
221+
var target = channel.target;
222+
var nodeId = target.node;
223+
var path = target.path;
224+
// Ignore animations that target 'weights'
225+
if (path === 'translation' || path === 'rotation' || path === 'scale') {
226+
nodes[nodeId] = true;
227+
}
228+
});
229+
});
230+
return nodes;
231+
}
232+
233+
function addDefaultTransformToAnimatedNodes(gltf) {
234+
var animatedNodes = getAnimatedNodes(gltf);
235+
ForEach.node(gltf, function(node, id) {
236+
if (defined(animatedNodes[id])) {
237+
delete node.matrix;
238+
node.translation = defaultValue(node.translation, [0.0, 0.0, 0.0]);
239+
node.rotation = defaultValue(node.rotation, [0.0, 0.0, 0.0, 1.0]);
240+
node.scale = defaultValue(node.scale, [1.0, 1.0, 1.0]);
241+
}
242+
});
243+
}
244+
217245
var defaultMaterial = {
218246
values : {
219247
emission : [
@@ -479,6 +507,7 @@ define([
479507
function addDefaults(gltf, options) {
480508
options = defaultValue(options, {});
481509
addDefaultsFromTemplate(gltf, gltfTemplate);
510+
addDefaultTransformToAnimatedNodes(gltf);
482511
addDefaultMaterial(gltf);
483512
addDefaultTechnique(gltf);
484513
addDefaultByteOffsets(gltf);

0 commit comments

Comments
 (0)