Skip to content

Commit

Permalink
Merge pull request #3224 from AnalyticalGraphicsInc/skinned-model-fix
Browse files Browse the repository at this point in the history
Skinned model fix
  • Loading branch information
pjcozzi committed Nov 20, 2015
2 parents 80db8d7 + b1c4131 commit 06be660
Show file tree
Hide file tree
Showing 5 changed files with 829 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Change Log
* Added 'Video' Sandcastle showcase to demonstrate video materials.
* Added `createOpenStreetMapImageryProvider` function to replace the `OpenStreetMapImageryProvider` class. This function returns a constructed `UrlTemplateImageryProvider`.
* Fixed an issue with tile selection when below the surface of the ellipsoid. [#3170](https://github.com/AnalyticalGraphicsInc/cesium/issues/3170)
* Fixed an issue with loading skeletons for skinned glTF models. [#3224](https://github.com/AnalyticalGraphicsInc/cesium/pull/3224)

### 1.15 - 2015-11-02

Expand Down
14 changes: 8 additions & 6 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1712,16 +1712,17 @@ define([
return attributeLocations;
}

function searchForest(forest, jointName) {
function searchForest(forest, jointName, nodes) {
var length = forest.length;
for (var i = 0; i < length; ++i) {
var stack = [forest[i]]; // Push root node of tree

while (stack.length > 0) {
var n = stack.pop();
var id = stack.pop();
var n = nodes[id];

if (n.jointName === jointName) {
return n;
return id;
}

var children = n.children;
Expand Down Expand Up @@ -1755,19 +1756,20 @@ define([

// 1. Find nodes with the names in node.skeletons (the node's skeletons)
// 2. These nodes form the root nodes of the forest to search for each joint in skin.jointNames. This search uses jointName, not the node's name.

// 3. Search for the joint name among the gltf node hierarchy instead of the runtime node hierarchy. Child links aren't set up yet for runtime nodes.
var forest = [];
var gltfSkeletons = node.skeletons;
var skeletonsLength = gltfSkeletons.length;
for (var k = 0; k < skeletonsLength; ++k) {
forest.push(runtimeNodes[gltfSkeletons[k]]);
forest.push(gltfSkeletons[k]);
}

var gltfJointNames = skins[node.skin].jointNames;
var jointNamesLength = gltfJointNames.length;
for (var i = 0; i < jointNamesLength; ++i) {
var jointName = gltfJointNames[i];
skinnedNode.joints.push(searchForest(forest, jointName));
var jointNode = runtimeNodes[searchForest(forest, jointName, nodes)];
skinnedNode.joints.push(jointNode);
}
}
}
Expand Down
Loading

0 comments on commit 06be660

Please sign in to comment.