From 5664abc9f175b7857ce557761a45f4b524db10ea Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Wed, 10 Aug 2016 10:57:27 -0400 Subject: [PATCH 1/4] Don't cache optimize primitives without indices --- lib/cacheOptimization.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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); + } } } } From de307b7a2beaa6c6cf6e01e1844496d2d484f850 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Wed, 10 Aug 2016 11:02:43 -0400 Subject: [PATCH 2/4] Added test case --- specs/lib/cacheOptimizationSpec.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/specs/lib/cacheOptimizationSpec.js b/specs/lib/cacheOptimizationSpec.js index d944638f..74216c00 100644 --- a/specs/lib/cacheOptimizationSpec.js +++ b/specs/lib/cacheOptimizationSpec.js @@ -59,4 +59,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' + } + } + ] + } + } + }; + expect(function() { + cacheOptimization(gltf); + }).not.toThrowRuntimeError(); + }); }); From b0a78f29bce3741df2ba24b7ae7a6707a449475f Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Wed, 10 Aug 2016 11:15:39 -0400 Subject: [PATCH 3/4] Test fails without change now --- specs/lib/cacheOptimizationSpec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/specs/lib/cacheOptimizationSpec.js b/specs/lib/cacheOptimizationSpec.js index 74216c00..61302c2c 100644 --- a/specs/lib/cacheOptimizationSpec.js +++ b/specs/lib/cacheOptimizationSpec.js @@ -75,8 +75,6 @@ describe('cacheOptimization', function() { } } }; - expect(function() { - cacheOptimization(gltf); - }).not.toThrowRuntimeError(); + cacheOptimization(gltf); }); }); From f0ef96c2c68d0ba8c516bebdcfa3875a59332df9 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Wed, 10 Aug 2016 12:48:40 -0400 Subject: [PATCH 4/4] Add spy and expect --- specs/lib/cacheOptimizationSpec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/specs/lib/cacheOptimizationSpec.js b/specs/lib/cacheOptimizationSpec.js index 61302c2c..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'); @@ -75,6 +78,8 @@ describe('cacheOptimization', function() { } } }; + spyOn(GeometryPipeline, 'reorderForPostVertexCache'); cacheOptimization(gltf); + expect(GeometryPipeline.reorderForPostVertexCache).not.toHaveBeenCalled(); }); });