Skip to content

Commit

Permalink
addDefaults fixes from unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcozzi committed Jan 10, 2016
1 parent bcb3077 commit 0fd4208
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/addDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -113,6 +114,7 @@ function imageDefaults(gltf) {
}
}

// TODO: move lightDefaults() for KHR_materials_common elsewhere?
function lightDefaults(gltf) {
if (!defined(gltf.extensions)) {
gltf.extensions = {};
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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];
Expand All @@ -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);
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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 = [];
}
}
}
Expand All @@ -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,
Expand Down Expand Up @@ -519,4 +523,4 @@ function addDefaults(gltf, stats) {
textureDefaults(gltf);

return gltf;
};
}

0 comments on commit 0fd4208

Please sign in to comment.