buildNodeHierarchy method
dynamic
buildNodeHierarchy(
- dynamic nodeId,
- dynamic parentObject,
- dynamic json,
- dynamic parser,
Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes @param {number} sceneIndex @return {Promise
Implementation
buildNodeHierarchy(nodeId, parentObject, json, parser) async {
Map<String, dynamic> nodeDef = json["nodes"][nodeId];
var node = await parser.getDependency('node', nodeId);
if (nodeDef["skin"] != null) {
// build skeleton here as well
var skinEntry;
var skin = await parser.getDependency('skin', nodeDef["skin"]);
skinEntry = skin;
var jointNodes = [];
for (var i = 0, il = skinEntry["joints"].length; i < il; i++) {
var _node = await parser.getDependency('node', skinEntry["joints"][i]);
jointNodes.add(_node);
}
node.traverse((mesh) {
if(mesh is SkinnedMesh) {
List<Bone> bones = [];
List<Matrix4> boneInverses = [];
for (var j = 0, jl = jointNodes.length; j < jl; j++) {
var jointNode = jointNodes[j];
if (jointNode != null) {
bones.add(jointNode);
var mat = new Matrix4();
if (skinEntry["inverseBindMatrices"] != null) {
mat.fromArray(skinEntry["inverseBindMatrices"].array, j * 16);
}
boneInverses.add(mat);
} else {
print(
'THREE.GLTFLoader: Joint "%s" could not be found. ${skinEntry["joints"][j]}');
}
}
mesh.bind(new Skeleton(bones, boneInverses),
mesh.matrixWorld);
}
});
}
// build node hierachy
parentObject.add(node);
if (nodeDef["children"] != null) {
var children = nodeDef["children"];
for (var i = 0, il = children.length; i < il; i++) {
var child = children[i];
await buildNodeHierarchy(child, node, json, parser);
}
}
}