Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Aug 2, 2021
1 parent 04467c2 commit f1e8b8b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Blender MTL File: 'None'
# Material Count: 1

newmtl None
Ns 0
Ka 0.000000 0.000000 0.000000
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Blender v2.78 (sub 0) OBJ File: ''
# www.blender.org
mtllib box-incorrect-winding-order.mtl
o Cube_Cube.001
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
vn -1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 1.0000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
usemtl None
s off
f 1//1 3//1 2//1
f 4//2 7//2 3//2
f 8//3 5//3 7//3
f 6//4 1//4 5//4
f 7//5 1//5 3//5
f 4//6 6//6 8//6
f 2//1 4//1 3//1
f 4//2 8//2 7//2
f 8//3 6//3 5//3
f 6//4 2//4 1//4
f 7//5 5//5 1//5
f 4//6 2//6 6//6
24 changes: 24 additions & 0 deletions specs/lib/loadObjSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const objMissingAttributesPath = 'specs/data/box-missing-attributes/box-missing-
const objIncompletePositionsPath = 'specs/data/box-incomplete-attributes/box-incomplete-positions.obj';
const objIncompleteNormalsPath = 'specs/data/box-incomplete-attributes/box-incomplete-normals.obj';
const objIncompleteUvsPath = 'specs/data/box-incomplete-attributes/box-incomplete-uvs.obj';
const objIncorrectWindingOrderPath = 'specs/data/box-incorrect-winding-order/box-incorrect-winding-order.obj';
const objInvalidPath = 'invalid.obj';

function getMeshes(data) {
Expand Down Expand Up @@ -511,6 +512,29 @@ describe('loadObj', () => {
expect(primitive.uvs.length).toBe(0);
});

async function loadAndGetIndices(objPath, options) {
const data = await loadObj(objPath, options);
const primitive = getPrimitives(data)[0];
const indices = primitive.indices;
return new Uint16Array(indices.toUint16Buffer().buffer);
}

it('applies triangle winding order sanitization', async () => {
options.triangleWindingOrderSanitization = false;
const indicesIncorrect = await loadAndGetIndices(objIncorrectWindingOrderPath, options);

options.triangleWindingOrderSanitization = true;
const indicesCorrect = await loadAndGetIndices(objIncorrectWindingOrderPath, options);

expect(indicesIncorrect[0]).toBe(0);
expect(indicesIncorrect[2]).toBe(2);
expect(indicesIncorrect[1]).toBe(1);

expect(indicesCorrect[0]).toBe(0);
expect(indicesCorrect[2]).toBe(1);
expect(indicesCorrect[1]).toBe(2);
});

it('throws when position index is out of bounds', async () => {
let thrownError;
try {
Expand Down

0 comments on commit f1e8b8b

Please sign in to comment.