|
@@ -233,13 +233,24 @@ var BABYLON;
|
|
|
if (!sampler) {
|
|
|
continue;
|
|
|
}
|
|
|
- var inputData = animation.parameters[sampler.input];
|
|
|
- var outputData = animation.parameters[sampler.output];
|
|
|
+ var inputData = null;
|
|
|
+ var outputData = null;
|
|
|
+ if (animation.parameters) {
|
|
|
+ inputData = animation.parameters[sampler.input];
|
|
|
+ outputData = animation.parameters[sampler.output];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ inputData = sampler.input;
|
|
|
+ outputData = sampler.output;
|
|
|
+ }
|
|
|
var bufferInput = BABYLON.GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
|
|
|
var bufferOutput = BABYLON.GLTFUtils.GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
|
|
|
var targetID = channel.target.id;
|
|
|
var targetNode = gltfRuntime.scene.getNodeByID(targetID);
|
|
|
if (targetNode === null) {
|
|
|
+ targetNode = gltfRuntime.scene.getNodeByName(targetID);
|
|
|
+ }
|
|
|
+ if (targetNode === null) {
|
|
|
BABYLON.Tools.Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
|
|
|
continue;
|
|
|
}
|
|
@@ -336,10 +347,10 @@ var BABYLON;
|
|
|
*/
|
|
|
var configureBoneTransformation = function (node) {
|
|
|
var mat = null;
|
|
|
- if (node.translation && node.rotation && node.scale) {
|
|
|
- var scale = BABYLON.Vector3.FromArray(node.scale);
|
|
|
- var rotation = BABYLON.Quaternion.FromArray(node.rotation);
|
|
|
- var position = BABYLON.Vector3.FromArray(node.translation);
|
|
|
+ if (node.translation || node.rotation || node.scale) {
|
|
|
+ var scale = BABYLON.Vector3.FromArray(node.scale || [1, 1, 1]);
|
|
|
+ var rotation = BABYLON.Quaternion.FromArray(node.rotation || [0, 0, 0, 1]);
|
|
|
+ var position = BABYLON.Vector3.FromArray(node.translation || [0, 0, 0]);
|
|
|
// Y is Up
|
|
|
if (GLTFFileLoader.MakeYUP) {
|
|
|
rotation = rotation.multiply(new BABYLON.Quaternion(-0.707107, 0, 0, 0.707107));
|
|
@@ -357,7 +368,7 @@ var BABYLON;
|
|
|
var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
|
|
|
// Try to find
|
|
|
for (var i = 0; i < newSkeleton.bones.length; i++) {
|
|
|
- if (newSkeleton.bones[i].id === jointName) {
|
|
|
+ if (newSkeleton.bones[i].name === jointName) {
|
|
|
return newSkeleton.bones[i];
|
|
|
}
|
|
|
}
|
|
@@ -549,7 +560,7 @@ var BABYLON;
|
|
|
var invertMesh = BABYLON.Matrix.Invert(mesh.getWorldMatrix());
|
|
|
mat = mat.multiply(mesh.getWorldMatrix());
|
|
|
}
|
|
|
- var bone = new BABYLON.Bone(node.name, newSkeleton, parentBone, mat);
|
|
|
+ var bone = new BABYLON.Bone(node.jointName, newSkeleton, parentBone, mat);
|
|
|
bone.id = id;
|
|
|
}
|
|
|
// Polish
|
|
@@ -900,8 +911,10 @@ var BABYLON;
|
|
|
newNode.parent = parent;
|
|
|
}
|
|
|
}
|
|
|
- for (var i = 0; i < node.children.length; i++) {
|
|
|
- traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
|
|
|
+ if (node.children) {
|
|
|
+ for (var i = 0; i < node.children.length; i++) {
|
|
|
+ traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
/**
|
|
@@ -910,8 +923,18 @@ var BABYLON;
|
|
|
var postLoad = function (gltfRuntime) {
|
|
|
// Nodes
|
|
|
var currentScene = gltfRuntime.currentScene;
|
|
|
- for (var i = 0; i < currentScene.nodes.length; i++) {
|
|
|
- traverseNodes(gltfRuntime, currentScene.nodes[i], null);
|
|
|
+ if (currentScene) {
|
|
|
+ for (var i = 0; i < currentScene.nodes.length; i++) {
|
|
|
+ traverseNodes(gltfRuntime, currentScene.nodes[i], null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ for (var thing in gltfRuntime.scenes) {
|
|
|
+ currentScene = gltfRuntime.scenes[thing];
|
|
|
+ for (var i = 0; i < currentScene.nodes.length; i++) {
|
|
|
+ traverseNodes(gltfRuntime, currentScene.nodes[i], null);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
// Set animations
|
|
|
loadAnimations(gltfRuntime);
|
|
@@ -924,6 +947,7 @@ var BABYLON;
|
|
|
* onBind shaderrs callback to set uniforms and matrices
|
|
|
*/
|
|
|
var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
|
|
|
+ var materialValues = material.values || technique.parameters;
|
|
|
for (var unif in unTreatedUniforms) {
|
|
|
var uniform = unTreatedUniforms[unif];
|
|
|
var type = uniform.type;
|
|
@@ -943,12 +967,12 @@ var BABYLON;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- var value = material.values[technique.uniforms[unif]];
|
|
|
+ var value = materialValues[technique.uniforms[unif]];
|
|
|
if (!value) {
|
|
|
continue;
|
|
|
}
|
|
|
if (type === BABYLON.EParameterType.SAMPLER_2D) {
|
|
|
- var texture = gltfRuntime.textures[value].babylonTexture;
|
|
|
+ var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
|
|
|
if (texture === null || texture === undefined) {
|
|
|
continue;
|
|
|
}
|
|
@@ -966,7 +990,7 @@ var BABYLON;
|
|
|
* Loads the appropriate textures
|
|
|
*/
|
|
|
var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
|
|
|
- var materialValues = material.values;
|
|
|
+ var materialValues = material.values || technique.parameters;
|
|
|
var techniqueUniforms = technique.uniforms;
|
|
|
/**
|
|
|
* Prepare values here (not matrices)
|
|
@@ -993,10 +1017,10 @@ var BABYLON;
|
|
|
};
|
|
|
// Texture (sampler2D)
|
|
|
if (type === BABYLON.EParameterType.SAMPLER_2D) {
|
|
|
- BABYLON.GLTFFileLoaderExtension.LoadTextureAsync(gltfRuntime, value, onLoadTexture(unif), function () { return onLoadTexture(null); });
|
|
|
+ BABYLON.GLTFFileLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
|
|
|
}
|
|
|
else {
|
|
|
- if (uniform.value && BABYLON.GLTFUtils.SetUniform(shaderMaterial, unif, value, type)) {
|
|
|
+ if (uniform.value && BABYLON.GLTFUtils.SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
|
|
|
// Static uniform
|
|
|
delete unTreatedUniforms[unif];
|
|
|
}
|
|
@@ -1076,8 +1100,8 @@ var BABYLON;
|
|
|
materials: {},
|
|
|
animations: {},
|
|
|
skins: {},
|
|
|
- currentScene: {},
|
|
|
extensionsUsed: [],
|
|
|
+ scenes: {},
|
|
|
buffersCount: 0,
|
|
|
shaderscount: 0,
|
|
|
scene: scene,
|
|
@@ -1140,6 +1164,9 @@ var BABYLON;
|
|
|
if (parsedData.skins) {
|
|
|
parseObject(parsedData.skins, "skins", gltfRuntime);
|
|
|
}
|
|
|
+ if (parsedData.scenes) {
|
|
|
+ gltfRuntime.scenes = parsedData.scenes;
|
|
|
+ }
|
|
|
if (parsedData.scene && parsedData.scenes) {
|
|
|
gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
|
|
|
}
|
|
@@ -1295,7 +1322,7 @@ var BABYLON;
|
|
|
attributes: attributes,
|
|
|
uniforms: uniforms,
|
|
|
samplers: samplers,
|
|
|
- needAlphaBlending: states.enable && states.enable.indexOf(3042) !== -1
|
|
|
+ needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
|
|
|
};
|
|
|
BABYLON.Effect.ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
|
|
|
BABYLON.Effect.ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
|
|
@@ -1303,7 +1330,7 @@ var BABYLON;
|
|
|
shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
|
|
|
shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
|
|
|
shaderMaterial.sideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
|
|
|
- if (states.functions) {
|
|
|
+ if (states && states.functions) {
|
|
|
var functions = states.functions;
|
|
|
if (functions.cullFace && functions.cullFace[0] !== BABYLON.ECullingType.BACK) {
|
|
|
shaderMaterial.backFaceCulling = false;
|
|
@@ -1490,8 +1517,20 @@ var BABYLON;
|
|
|
// Creates nodes before loading buffers and shaders
|
|
|
GLTFFileLoader.prototype._createNodes = function (gltfRuntime) {
|
|
|
var currentScene = gltfRuntime.currentScene;
|
|
|
- for (var i = 0; i < currentScene.nodes.length; i++) {
|
|
|
- traverseNodes(gltfRuntime, currentScene.nodes[i], null);
|
|
|
+ if (currentScene) {
|
|
|
+ // Only one scene even if multiple scenes are defined
|
|
|
+ for (var i = 0; i < currentScene.nodes.length; i++) {
|
|
|
+ traverseNodes(gltfRuntime, currentScene.nodes[i], null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // Load all scenes
|
|
|
+ for (var thing in gltfRuntime.scenes) {
|
|
|
+ currentScene = gltfRuntime.scenes[thing];
|
|
|
+ for (var i = 0; i < currentScene.nodes.length; i++) {
|
|
|
+ traverseNodes(gltfRuntime, currentScene.nodes[i], null);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
return GLTFFileLoader;
|