Merge pull request #156 from AnalyticalGraphicsInc/vertex-count-fix-1.0

Fix objs with interleaved materials (1.0)
This commit is contained in:
Sean Lilley 2018-10-11 17:30:36 -04:00 committed by GitHub
commit f2cceaff0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 5 deletions

View File

@ -1,6 +1,10 @@
Change Log
==========
### 1.3.4 2018-10-11
* Fixed handling of objs with interleaved materials. [#156](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/156)
### 1.3.3 2018-09-19
* Fixed handling of objs with mismatching attribute layouts. [#154](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/154)

View File

@ -107,6 +107,11 @@ function loadObj(objPath, options) {
var vertexIndices = [];
function clearVertexCache() {
vertexCache = {};
vertexCacheCount = 0;
}
function getName(name) {
return (name === '' ? undefined : name);
}
@ -130,8 +135,7 @@ function loadObj(objPath, options) {
mesh.primitives.push(primitive);
// Clear the vertex cache for each new primitive
vertexCache = {};
vertexCacheCount = 0;
clearVertexCache();
vertexCount = 0;
}
@ -143,6 +147,8 @@ function loadObj(objPath, options) {
for (var i = 0; i < primitivesLength; ++i) {
if (primitives[i].material === material) {
primitive = primitives[i];
clearVertexCache();
vertexCount = primitive.positions.length / 3;
return;
}
}
@ -204,8 +210,7 @@ function loadObj(objPath, options) {
// may be some duplicate vertices.
vertexCacheCount++;
if (vertexCacheCount > vertexCacheLimit) {
vertexCacheCount = 0;
vertexCache = {};
clearVertexCache();
}
}
return index;

View File

@ -1,6 +1,6 @@
{
"name": "obj2gltf",
"version": "1.3.3",
"version": "1.3.4",
"description": "Convert OBJ model format to glTF",
"license": "Apache-2.0",
"contributors": [

View File

@ -254,6 +254,14 @@ describe('loadObj', function() {
expect(primitives[0].material).toBe('Red');
expect(primitives[1].material).toBe('Green');
expect(primitives[2].material).toBe('Blue');
var expectedIndices = [0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7];
var length = expectedIndices.length;
for (var i = 0; i < 3; ++i) {
for (var j = 0; j < length; ++j) {
expect(primitives[i].indices.get(j)).toBe(expectedIndices[j]);
}
}
}), done).toResolve();
});