Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduroure committed Sep 11, 2023
1 parent 5b3be38 commit 845e95f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
Binary file added tests/scenes/32_uvmap_indices.blend
Binary file not shown.
Binary file added tests/scenes/GlTF_logo.svg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 43 additions & 4 deletions tests/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ describe('Exporter', function() {
let ext = args.indexOf('--glb') === -1 ? '.gltf' : '.glb';
let outDirPath = path.resolve(OUT_PREFIX, 'scenes', outDirName);
let dstPath = path.resolve(outDirPath, `${scene}${ext}`);
blenderFileToGltf(blenderVersion, blenderPath, outDirPath, (error) => {
/*blenderFileToGltf(blenderVersion, blenderPath, outDirPath, (error) => {
if (error)
return done(error);
validateGltf(dstPath, done);
}, args);
// validateGltf(dstPath, done); // uncomment this and comment blenderFileToGltf to not re-export all files
}, args);*/
validateGltf(dstPath, done); // uncomment this and comment blenderFileToGltf to not re-export all files
});
});
});
Expand Down Expand Up @@ -1830,8 +1830,47 @@ describe('Exporter', function() {
assert.strictEqual(asset.accessors[sphere_rotation_sampler.input].count, 6);
assert.strictEqual(asset.accessors[sphere_rotation_sampler.input].count, 6);

});

it('exports Custom Attribute UVMaps', function() {
let gltfPath = path.resolve(outDirPath, '32_custom_uvmap_attribute.gltf');
const asset = JSON.parse(fs.readFileSync(gltfPath));

assert.strictEqual(asset.materials.length, 2);
const material_0 = asset.materials[asset.meshes.filter(a => a.name == "Cube.001")[0].primitives[0]["material"]]
const material_1 = asset.materials[asset.meshes.filter(a => a.name == "Cube.002")[0].primitives[0]["material"]]
assert.strictEqual(material_0.pbrMetallicRoughness["baseColorTexture"]["index"], 0);
assert.strictEqual(material_0.pbrMetallicRoughness["baseColorTexture"]["texCoord"], 5);
assert.strictEqual(material_1.pbrMetallicRoughness["baseColorTexture"]["index"], 0);
assert.strictEqual(material_1.pbrMetallicRoughness["baseColorTexture"]["texCoord"], 1);

});

it('exports UVMaps texcoord', function() {
let gltfPath = path.resolve(outDirPath, '32_uvmap_indices.gltf');
const asset = JSON.parse(fs.readFileSync(gltfPath));

assert.strictEqual(asset.images.length, 1);
assert.strictEqual(asset.meshes.length, 6);
assert.strictEqual(asset.materials.length, 6);

const material_0 = asset.materials[asset.meshes[asset.nodes.filter(a => a.name == "Cube")[0].mesh].primitives[0]["material"]]
const material_1 = asset.materials[asset.meshes[asset.nodes.filter(a => a.name == "Cube.003")[0].mesh].primitives[0]["material"]]
const material_2 = asset.materials[asset.meshes[asset.nodes.filter(a => a.name == "Cube.001")[0].mesh].primitives[0]["material"]]
const material_3 = asset.materials[asset.meshes[asset.nodes.filter(a => a.name == "Cube.002")[0].mesh].primitives[0]["material"]]
const material_4 = asset.materials[asset.meshes[asset.nodes.filter(a => a.name == "Plane")[0].mesh].primitives[0]["material"]]
const material_5 = asset.materials[asset.meshes[asset.nodes.filter(a => a.name == "Plane.001")[0].mesh].primitives[0]["material"]]


assert.ok(!("texCoord" in material_0.emissiveTexture));
assert.strictEqual(material_1.emissiveTexture["texCoord"], 1);
assert.strictEqual(material_2.emissiveTexture["texCoord"], 1);
assert.ok(!("texCoord" in material_3.emissiveTexture));
assert.strictEqual(material_4.pbrMetallicRoughness["baseColorTexture"]["texCoord"], 1);
assert.ok(!("texCoord" in material_5.pbrMetallicRoughness["baseColorTexture"]));

});

});
});
});
Expand Down Expand Up @@ -1863,7 +1902,7 @@ describe('Importer / Exporter (Roundtrip)', function() {
if (fs.existsSync(gltfOptionsPath)) {
options += ' ' + fs.readFileSync(gltfOptionsPath).toString().replace(/\r?\n|\r/g, '');
}
// return done(); // uncomment to not roundtrip all files
return done(); // uncomment to not roundtrip all files
blenderRoundtripGltf(blenderVersion, gltfSrcPath, outDirPath, (error) => {
if (error)
return done(error);
Expand Down

0 comments on commit 845e95f

Please sign in to comment.