diff --git a/lib/cacheOptimization.js b/lib/cacheOptimization.js index 943d1e6a..5dbea7f0 100644 --- a/lib/cacheOptimization.js +++ b/lib/cacheOptimization.js @@ -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); + } } } } diff --git a/specs/lib/cacheOptimizationSpec.js b/specs/lib/cacheOptimizationSpec.js index d944638f..6110fbea 100644 --- a/specs/lib/cacheOptimizationSpec.js +++ b/specs/lib/cacheOptimizationSpec.js @@ -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'); @@ -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(); + }); });