Skip to content

Commit

Permalink
Merge pull request #155 from AnalyticalGraphicsInc/dont-optimize-with…
Browse files Browse the repository at this point in the history
…out-indices

Dont optimize without indices
  • Loading branch information
lilleyse committed Aug 10, 2016
2 parents 08c9e4e + f0ef96c commit 73c3bf2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/cacheOptimization.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ function cacheOptimization(gltf, cacheSize) {
var primitivesLength = primitives.length;
for (var i = 0; i < primitivesLength; i++) {
primitive = primitives[i];
geometry = gltfPrimitiveToCesiumGeometry(gltf, primitive);
GeometryPipeline.reorderForPostVertexCache(geometry, cacheSize);

cesiumGeometryToGltfPrimitive(gltf, primitive, geometry);
if (defined(primitive.indices)) {
geometry = gltfPrimitiveToCesiumGeometry(gltf, primitive);
GeometryPipeline.reorderForPostVertexCache(geometry, cacheSize);
cesiumGeometryToGltfPrimitive(gltf, primitive, geometry);
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions specs/lib/cacheOptimizationSpec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';
var Cesium = require('cesium');
var GeometryPipeline = Cesium.GeometryPipeline;

var addDefaults = require('../../lib/addDefaults');
var cacheOptimization = require('../../lib/cacheOptimization');
var readAccessor = require('../../lib/readAccessor');
Expand Down Expand Up @@ -59,4 +62,24 @@ describe('cacheOptimization', function() {
expect(positions).toEqual(unpackedOptimizedVertices);
}), done).toResolve();
});

it('doesn\'t run if a primitive has no indices', function() {
var gltf = {
meshes : {
mesh : {
primitives : [
{
attributes : {
POSITION : 'notImportant',
NORMAL : 'notImportantEither'
}
}
]
}
}
};
spyOn(GeometryPipeline, 'reorderForPostVertexCache');
cacheOptimization(gltf);
expect(GeometryPipeline.reorderForPostVertexCache).not.toHaveBeenCalled();
});
});

0 comments on commit 73c3bf2

Please sign in to comment.