diff --git a/specs/data/box-incorrect-winding-order/box-incorrect-winding-order.mtl b/specs/data/box-incorrect-winding-order/box-incorrect-winding-order.mtl new file mode 100644 index 00000000..70d3ba1d --- /dev/null +++ b/specs/data/box-incorrect-winding-order/box-incorrect-winding-order.mtl @@ -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 diff --git a/specs/data/box-incorrect-winding-order/box-incorrect-winding-order.obj b/specs/data/box-incorrect-winding-order/box-incorrect-winding-order.obj new file mode 100644 index 00000000..adad9117 --- /dev/null +++ b/specs/data/box-incorrect-winding-order/box-incorrect-winding-order.obj @@ -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 diff --git a/specs/lib/loadObjSpec.js b/specs/lib/loadObjSpec.js index 3a886282..0db5d32f 100644 --- a/specs/lib/loadObjSpec.js +++ b/specs/lib/loadObjSpec.js @@ -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) { @@ -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 {