diff --git a/lib/addDefaults.js b/lib/addDefaults.js index 5022e152..07aa091e 100644 --- a/lib/addDefaults.js +++ b/lib/addDefaults.js @@ -44,7 +44,7 @@ function animationDefaults(gltf) { animation.samplers = {}; } - var samplers = animations.samplers; + var samplers = animation.samplers; for (var samplerName in samplers) { if (samplers.hasOwnProperty(samplerName)) { @@ -72,6 +72,7 @@ function assetDefaults(gltf) { profile.api = defaultValue(profile.api, 'WebGL'); profile.version = defaultValue(profile.version, '1.0.2'); + // glTF 0.8 backward compatibility if (defined(gltf.version)) { asset.version = defaultValue(asset.version, gltf.version); delete gltf.version; @@ -113,6 +114,7 @@ function imageDefaults(gltf) { } } +// TODO: move lightDefaults() for KHR_materials_common elsewhere? function lightDefaults(gltf) { if (!defined(gltf.extensions)) { gltf.extensions = {}; @@ -125,6 +127,7 @@ function lightDefaults(gltf) { var khrMaterialsCommon = extensions.KHR_materials_common; if (defined(gltf.lights)) { + // glTF 0.8 backward compatibility khrMaterialsCommon.lights = gltf.lights; delete gltf.lights; } @@ -198,6 +201,7 @@ function materialDefaults(gltf) { var material = materials[name]; var instanceTechnique = material.instanceTechnique; if (defined(instanceTechnique)) { + // glTF 0.8 backward compatibility material.technique = instanceTechnique.technique; material.values = instanceTechnique.values; @@ -255,7 +259,7 @@ function meshDefaults(gltf) { mesh.primitives = []; } - var primitives = mesh.primitives.length; + var primitives = mesh.primitives; var length = primitives.length; for (var i = 0; i < length; ++i) { var primitive = primitives[i]; @@ -266,7 +270,6 @@ function meshDefaults(gltf) { // Backwards compatibility for glTF 0.8. primitive was renamed to mode. var defaultMode = defaultValue(primitive.primitive, WebGLConstants.TRIANGLES); - primitive.mode = defaultValue(primitive.mode, defaultMode); } } @@ -291,6 +294,7 @@ function nodeDefaults(gltf) { } if (hasAxisAngle && defined(node.rotation)) { + // glTF 0.8 backward compatibility var rotation = node.rotation; Cartesian3.fromArray(rotation, 0, axis); Quaternion.fromAxisAngle(axis, rotation[3], quat); @@ -374,8 +378,8 @@ function sceneDefaults(gltf) { for (var name in scenes) { if (scenes.hasOwnProperty(name)) { var scene = scenes[name]; - if (!defined(scene.node)) { - scene.node = []; + if (!defined(scene.nodes)) { + scene.nodes = []; } } } @@ -396,7 +400,7 @@ function skinDefaults(gltf) { for (var name in skins) { if (skins.hasOwnProperty(name)) { var skin = skins[name]; - if (defined(skin.bindShapeMatrix)) { + if (!defined(skin.bindShapeMatrix)) { skin.bindShapeMatrix = [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, @@ -519,4 +523,4 @@ function addDefaults(gltf, stats) { textureDefaults(gltf); return gltf; -}; +}