From e2851abdf696016d80479ed95793ef99399fbe1b Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Mon, 19 Mar 2018 19:30:10 -0400 Subject: [PATCH 1/3] Add default TRS to node targeted by animation --- Source/ThirdParty/GltfPipeline/ForEach.js | 5 ++++ Source/ThirdParty/GltfPipeline/addDefaults.js | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Source/ThirdParty/GltfPipeline/ForEach.js b/Source/ThirdParty/GltfPipeline/ForEach.js index 7c20fc07e679..1894f5a896b1 100644 --- a/Source/ThirdParty/GltfPipeline/ForEach.js +++ b/Source/ThirdParty/GltfPipeline/ForEach.js @@ -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)) { diff --git a/Source/ThirdParty/GltfPipeline/addDefaults.js b/Source/ThirdParty/GltfPipeline/addDefaults.js index af0102cba4ae..00372b8a6668 100644 --- a/Source/ThirdParty/GltfPipeline/addDefaults.js +++ b/Source/ThirdParty/GltfPipeline/addDefaults.js @@ -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 node = target.node; + var path = target.path; + // Ignore animations that target 'weights' + if (path === 'translation' || path === 'rotation' || path === 'scale') { + nodes[node] = 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 : [ @@ -479,6 +507,7 @@ define([ function addDefaults(gltf, options) { options = defaultValue(options, {}); addDefaultsFromTemplate(gltf, gltfTemplate); + addDefaultTransformToAnimatedNodes(gltf); addDefaultMaterial(gltf); addDefaultTechnique(gltf); addDefaultByteOffsets(gltf); From af119b1b09136688069faf17bacd6af065131389 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Mon, 19 Mar 2018 19:38:42 -0400 Subject: [PATCH 2/3] Updated CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 4dca69d8ef9c..1b896fd7a9f2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,6 +27,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 From 697c6d9fcd5441debcacb35298613b0830a44c48 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 20 Mar 2018 09:39:28 -0400 Subject: [PATCH 3/3] Rename node to nodeId --- Source/ThirdParty/GltfPipeline/addDefaults.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/ThirdParty/GltfPipeline/addDefaults.js b/Source/ThirdParty/GltfPipeline/addDefaults.js index 00372b8a6668..51f46acb4b54 100644 --- a/Source/ThirdParty/GltfPipeline/addDefaults.js +++ b/Source/ThirdParty/GltfPipeline/addDefaults.js @@ -219,11 +219,11 @@ define([ ForEach.animation(gltf, function(animation) { ForEach.animationChannel(animation, function(channel) { var target = channel.target; - var node = target.node; + var nodeId = target.node; var path = target.path; // Ignore animations that target 'weights' if (path === 'translation' || path === 'rotation' || path === 'scale') { - nodes[node] = true; + nodes[nodeId] = true; } }); });