mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-23 08:34:14 -05:00
Handle face signature containing attributes that are missing
This commit is contained in:
parent
8fa5bf9d24
commit
f502b805b8
@ -189,7 +189,7 @@ function loadObj(objPath, options) {
|
||||
|
||||
function createVertex(p, u, n) {
|
||||
// Positions
|
||||
if (defined(p)) {
|
||||
if (defined(p) && (globalPositions.length > 0)) {
|
||||
const px = globalPositions.get(p * 3);
|
||||
const py = globalPositions.get(p * 3 + 1);
|
||||
const pz = globalPositions.get(p * 3 + 2);
|
||||
@ -199,7 +199,7 @@ function loadObj(objPath, options) {
|
||||
}
|
||||
|
||||
// Normals
|
||||
if (defined(n)) {
|
||||
if (defined(n) && (globalNormals.length > 0)) {
|
||||
const nx = globalNormals.get(n * 3);
|
||||
const ny = globalNormals.get(n * 3 + 1);
|
||||
const nz = globalNormals.get(n * 3 + 2);
|
||||
@ -209,7 +209,7 @@ function loadObj(objPath, options) {
|
||||
}
|
||||
|
||||
// UVs
|
||||
if (defined(u)) {
|
||||
if (defined(u) && (globalUvs.length > 0)) {
|
||||
const ux = globalUvs.get(u * 2);
|
||||
const uy = globalUvs.get(u * 2 + 1);
|
||||
primitive.uvs.push(ux);
|
||||
|
12
specs/data/box-missing-attributes/box-missing-attributes.mtl
Normal file
12
specs/data/box-missing-attributes/box-missing-attributes.mtl
Normal file
@ -0,0 +1,12 @@
|
||||
# Blender MTL File: 'box.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
20
specs/data/box-missing-attributes/box-missing-attributes.obj
Normal file
20
specs/data/box-missing-attributes/box-missing-attributes.obj
Normal file
@ -0,0 +1,20 @@
|
||||
# Blender v2.78 (sub 0) OBJ File: 'box.blend'
|
||||
# www.blender.org
|
||||
mtllib box-missing-attributes.mtl
|
||||
o Cube
|
||||
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
|
||||
usemtl Material
|
||||
s off
|
||||
f 1/1/1 2/2/1 4/3/1 3/4/1
|
||||
f 3/5/2 4/6/2 8/7/2 7/8/2
|
||||
f 7/9/3 8/10/3 6/11/3 5/12/3
|
||||
f 5/13/4 6/14/4 2/15/4 1/16/4
|
||||
f 3/5/5 7/17/5 5/18/5 1/16/5
|
||||
f 8/19/6 4/6/6 2/15/6 6/20/6
|
@ -40,6 +40,7 @@ const objInvalidContentsPath = 'specs/data/box/box.mtl';
|
||||
const objConcavePath = 'specs/data/concave/concave.obj';
|
||||
const objUnnormalizedPath = 'specs/data/box-unnormalized/box-unnormalized.obj';
|
||||
const objMixedAttributesPath = 'specs/data/box-mixed-attributes/box-mixed-attributes.obj';
|
||||
const objMissingAttributesPath = 'specs/data/box-missing-attributes/box-missing-attributes.obj';
|
||||
const objInvalidPath = 'invalid.obj';
|
||||
|
||||
function getMeshes(data) {
|
||||
@ -455,6 +456,14 @@ describe('loadObj', () => {
|
||||
expect(primitives[3].indices.length).toBe(6); // 2 faces
|
||||
});
|
||||
|
||||
it('does not add missing normals and uvs', async() => {
|
||||
const data = await loadObj(objMissingAttributesPath, options);
|
||||
const primitive = getPrimitives(data)[0];
|
||||
expect(primitive.positions.length).toBeGreaterThan(0);
|
||||
expect(primitive.normals.length).toBe(0);
|
||||
expect(primitive.uvs.length).toBe(0);
|
||||
});
|
||||
|
||||
it('throws when file has invalid contents', async () => {
|
||||
let thrownError;
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user