|
@@ -306,8 +306,9 @@ module BABYLON.GLTF2 {
|
|
switch (this._parent.coordinateSystemMode) {
|
|
switch (this._parent.coordinateSystemMode) {
|
|
case GLTFLoaderCoordinateSystemMode.AUTO: {
|
|
case GLTFLoaderCoordinateSystemMode.AUTO: {
|
|
if (!this._babylonScene.useRightHandedSystem) {
|
|
if (!this._babylonScene.useRightHandedSystem) {
|
|
- this._rootNode.babylonMesh.rotation = new Vector3(0, Math.PI, 0);
|
|
|
|
- this._rootNode.babylonMesh.scaling = new Vector3(1, 1, -1);
|
|
|
|
|
|
+ this._rootNode.rotation = [ 0, 1, 0, 0 ];
|
|
|
|
+ this._rootNode.scale = [ 1, 1, -1 ];
|
|
|
|
+ this._loadTransform(this._rootNode);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -386,7 +387,7 @@ module BABYLON.GLTF2 {
|
|
this._loadMesh("#/meshes/" + node.mesh, node, mesh);
|
|
this._loadMesh("#/meshes/" + node.mesh, node, mesh);
|
|
}
|
|
}
|
|
|
|
|
|
- node.babylonMesh.parent = node.parent ? node.parent.babylonMesh : null;
|
|
|
|
|
|
+ node.babylonMesh.parent = node.parent.babylonMesh;
|
|
|
|
|
|
node.babylonAnimationTargets = node.babylonAnimationTargets || [];
|
|
node.babylonAnimationTargets = node.babylonAnimationTargets || [];
|
|
node.babylonAnimationTargets.push(node.babylonMesh);
|
|
node.babylonAnimationTargets.push(node.babylonMesh);
|
|
@@ -397,7 +398,15 @@ module BABYLON.GLTF2 {
|
|
throw new Error(context + ": Failed to find skin " + node.skin);
|
|
throw new Error(context + ": Failed to find skin " + node.skin);
|
|
}
|
|
}
|
|
|
|
|
|
- node.babylonMesh.skeleton = this._loadSkin("#/skins/" + node.skin, skin);
|
|
|
|
|
|
+ this._loadSkinAsync("#/skins/" + node.skin, skin, () => {
|
|
|
|
+ node.babylonMesh.skeleton = skin.babylonSkeleton;
|
|
|
|
+ node.babylonMesh._refreshBoundingInfo(true);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ node.babylonMesh.parent = this._rootNode.babylonMesh;
|
|
|
|
+ node.babylonMesh.position = Vector3.Zero();
|
|
|
|
+ node.babylonMesh.rotationQuaternion = Quaternion.Identity();
|
|
|
|
+ node.babylonMesh.scaling = Vector3.One();
|
|
}
|
|
}
|
|
|
|
|
|
if (node.camera != null) {
|
|
if (node.camera != null) {
|
|
@@ -807,9 +816,10 @@ module BABYLON.GLTF2 {
|
|
node.babylonMesh.scaling = scaling;
|
|
node.babylonMesh.scaling = scaling;
|
|
}
|
|
}
|
|
|
|
|
|
- private _loadSkin(context: string, skin: IGLTFSkin): Skeleton {
|
|
|
|
|
|
+ private _loadSkinAsync(context: string, skin: IGLTFSkin, onSuccess: () => void): void {
|
|
if (skin.babylonSkeleton) {
|
|
if (skin.babylonSkeleton) {
|
|
- return skin.babylonSkeleton;
|
|
|
|
|
|
+ onSuccess();
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
const skeletonId = "skeleton" + skin.index;
|
|
const skeletonId = "skeleton" + skin.index;
|
|
@@ -817,6 +827,7 @@ module BABYLON.GLTF2 {
|
|
|
|
|
|
if (skin.inverseBindMatrices == null) {
|
|
if (skin.inverseBindMatrices == null) {
|
|
this._loadBones(context, skin, null);
|
|
this._loadBones(context, skin, null);
|
|
|
|
+ onSuccess();
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
const accessor = GLTFLoader._GetProperty(this._gltf.accessors, skin.inverseBindMatrices);
|
|
const accessor = GLTFLoader._GetProperty(this._gltf.accessors, skin.inverseBindMatrices);
|
|
@@ -826,18 +837,14 @@ module BABYLON.GLTF2 {
|
|
|
|
|
|
this._loadAccessorAsync("#/accessors/" + accessor.index, accessor, data => {
|
|
this._loadAccessorAsync("#/accessors/" + accessor.index, accessor, data => {
|
|
this._loadBones(context, skin, <Float32Array>data);
|
|
this._loadBones(context, skin, <Float32Array>data);
|
|
|
|
+ onSuccess();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
- return skin.babylonSkeleton;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private _createBone(node: IGLTFNode, skin: IGLTFSkin, parent: Nullable<Bone>, localMatrix: Matrix, baseMatrix: Matrix, index: number): Bone {
|
|
private _createBone(node: IGLTFNode, skin: IGLTFSkin, parent: Nullable<Bone>, localMatrix: Matrix, baseMatrix: Matrix, index: number): Bone {
|
|
const babylonBone = new Bone(node.name || "bone" + node.index, skin.babylonSkeleton, parent, localMatrix, null, baseMatrix, index);
|
|
const babylonBone = new Bone(node.name || "bone" + node.index, skin.babylonSkeleton, parent, localMatrix, null, baseMatrix, index);
|
|
|
|
|
|
- node.babylonBones = node.babylonBones || {};
|
|
|
|
- node.babylonBones[skin.index] = babylonBone;
|
|
|
|
-
|
|
|
|
node.babylonAnimationTargets = node.babylonAnimationTargets || [];
|
|
node.babylonAnimationTargets = node.babylonAnimationTargets || [];
|
|
node.babylonAnimationTargets.push(babylonBone);
|
|
node.babylonAnimationTargets.push(babylonBone);
|
|
|
|
|
|
@@ -871,7 +878,7 @@ module BABYLON.GLTF2 {
|
|
}
|
|
}
|
|
|
|
|
|
let babylonParentBone: Nullable<Bone> = null;
|
|
let babylonParentBone: Nullable<Bone> = null;
|
|
- if (node.index !== skin.skeleton && node.parent && node.parent !== this._rootNode) {
|
|
|
|
|
|
+ if (node.parent !== this._rootNode) {
|
|
babylonParentBone = this._loadBone(node.parent, skin, inverseBindMatrixData, babylonBones);
|
|
babylonParentBone = this._loadBone(node.parent, skin, inverseBindMatrixData, babylonBones);
|
|
baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
|
|
baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
|
|
}
|
|
}
|
|
@@ -890,7 +897,7 @@ module BABYLON.GLTF2 {
|
|
node.translation ? Vector3.FromArray(node.translation) : Vector3.Zero());
|
|
node.translation ? Vector3.FromArray(node.translation) : Vector3.Zero());
|
|
}
|
|
}
|
|
|
|
|
|
- private _traverseNodes(context: string, indices: number[], action: (node: IGLTFNode, parentNode: IGLTFNode) => boolean, parentNode: Nullable<IGLTFNode> = null): void {
|
|
|
|
|
|
+ private _traverseNodes(context: string, indices: number[], action: (node: IGLTFNode, parentNode: IGLTFNode) => boolean, parentNode: IGLTFNode): void {
|
|
for (const index of indices) {
|
|
for (const index of indices) {
|
|
const node = GLTFLoader._GetProperty(this._gltf.nodes, index);
|
|
const node = GLTFLoader._GetProperty(this._gltf.nodes, index);
|
|
if (!node) {
|
|
if (!node) {
|
|
@@ -901,7 +908,7 @@ module BABYLON.GLTF2 {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public _traverseNode(context: string, node: IGLTFNode, action: (node: IGLTFNode, parentNode: Nullable<IGLTFNode>) => boolean, parentNode: Nullable<IGLTFNode> = null): void {
|
|
|
|
|
|
+ public _traverseNode(context: string, node: IGLTFNode, action: (node: IGLTFNode, parentNode: IGLTFNode) => boolean, parentNode: IGLTFNode): void {
|
|
if (GLTFLoaderExtension.TraverseNode(this, context, node, action, parentNode)) {
|
|
if (GLTFLoaderExtension.TraverseNode(this, context, node, action, parentNode)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|