@@ -93,10 +93,16 @@ function render() {
9393
9494 cesiumViewer . update ( ) ;
9595
96+ updateThreeStats ( ) ;
97+ updateCesiumStats ( ) ;
98+
99+ }
100+
101+ function updateThreeStats ( ) {
102+
96103 let shallowTilesLoaded , loadedGeometryTiles , allLoadedTiles ;
97104 let textureBytes , geometryBytes ;
98105
99- // update three stats
100106 loadedGeometryTiles = 0 ;
101107 textureBytes = 0 ;
102108 geometryBytes = 0 ;
@@ -155,6 +161,8 @@ function render() {
155161
156162 } ) ;
157163
164+ const { loadStart, loadEnd } = threeViewer ;
165+ const loadDelta = loadEnd - loadStart ;
158166 clearStats ( threeStats ) ;
159167 writeStats ( threeStats , 'visible tiles' , threeViewer . tiles . visibleTiles . size ) ;
160168 writeStats ( threeStats , 'loaded tiles' , allLoadedTiles ) ;
@@ -164,8 +172,17 @@ function render() {
164172 writeStats ( threeStats , 'total memory' , ( threeViewer . tiles . lruCache . cachedBytes * 1e-6 ) . toFixed ( 3 ) + ' MB' ) ;
165173 writeStats ( threeStats , 'geometry memory' , ( geometryBytes * 1e-6 ) . toFixed ( 3 ) + ' MB' ) ;
166174 writeStats ( threeStats , 'texture memory' , ( textureBytes * 1e-6 ) . toFixed ( 3 ) + ' MB' ) ;
175+ writeStats ( threeStats , 'load start' , loadStart . toFixed ( 0 ) + ' ms' ) ;
176+ writeStats ( threeStats , 'load end' , ( loadDelta < 0 ? '--' : loadEnd . toFixed ( 0 ) + ' ms' ) ) ;
177+ writeStats ( threeStats , 'load delta' , ( loadDelta < 0 ? '--' : loadDelta . toFixed ( 0 ) + ' ms' ) ) ;
178+ writeStats ( threeStats , 'load load time' , threeViewer . totalLoadTime . toFixed ( 0 ) + ' ms' ) ;
167179
168- // update cesium stats
180+ }
181+
182+ function updateCesiumStats ( ) {
183+
184+ let shallowTilesLoaded , allLoadedTiles ;
185+ let textureBytes , geometryBytes ;
169186
170187 shallowTilesLoaded = 0 ;
171188 traverse ( cesiumViewer . root , t => {
@@ -204,6 +221,8 @@ function render() {
204221
205222 } ) ;
206223
224+ const { loadStart, loadEnd } = cesiumViewer ;
225+ const loadDelta = loadEnd - loadStart ;
207226 clearStats ( cesiumStats ) ;
208227 writeStats ( cesiumStats , 'visible tiles' , cesiumViewer . tiles . statistics . selected ) ;
209228 writeStats ( cesiumStats , 'loaded tiles' , allLoadedTiles ) ;
@@ -213,6 +232,10 @@ function render() {
213232 writeStats ( cesiumStats , 'total memory' , ( cesiumViewer . tiles . totalMemoryUsageInBytes * 1e-6 ) . toFixed ( 3 ) + ' MB' ) ;
214233 writeStats ( cesiumStats , 'geometry memory' , ( geometryBytes * 1e-6 ) . toFixed ( 3 ) + ' MB' ) ;
215234 writeStats ( cesiumStats , 'texture memory' , ( textureBytes * 1e-6 ) . toFixed ( 3 ) + ' MB' ) ;
235+ writeStats ( cesiumStats , 'load start' , loadStart . toFixed ( 0 ) + ' ms' ) ;
236+ writeStats ( cesiumStats , 'load end' , ( loadDelta < 0 ? '--' : loadEnd . toFixed ( 0 ) + ' ms' ) ) ;
237+ writeStats ( cesiumStats , 'load delta' , ( loadDelta < 0 ? '--' : loadDelta . toFixed ( 0 ) + ' ms' ) ) ;
238+ writeStats ( cesiumStats , 'load load time' , cesiumViewer . totalLoadTime . toFixed ( 0 ) + ' ms' ) ;
216239
217240}
218241
@@ -320,6 +343,25 @@ async function initThree() {
320343
321344 } ) ;
322345
346+ let start = 0 ;
347+ tiles . addEventListener ( 'tiles-load-start' , e => {
348+
349+ start = performance . now ( ) ;
350+ if ( performance . now ( ) - threeViewer . loadEnd > 100 ) {
351+
352+ threeViewer . loadStart = start ;
353+
354+ }
355+
356+ } ) ;
357+
358+ tiles . addEventListener ( 'tiles-load-end' , e => {
359+
360+ threeViewer . loadEnd = performance . now ( ) ;
361+ threeViewer . totalLoadTime += performance . now ( ) - start ;
362+
363+ } ) ;
364+
323365 scene . add ( tiles . group ) ;
324366
325367 // lights
@@ -359,6 +401,9 @@ async function initThree() {
359401 window . addEventListener ( 'resize' , onWindowResize , false ) ;
360402
361403 threeViewer = {
404+ totalLoadTime : 0 ,
405+ loadStart : 0 ,
406+ loadEnd : 0 ,
362407 tiles,
363408 camera,
364409 renderer,
@@ -447,7 +492,35 @@ async function initCesium() {
447492 // height,
448493 // } );
449494
495+ let loading = false ;
496+ let start = 0 ;
497+ tileset . loadProgress . addEventListener ( ( pending , processing ) => {
498+
499+ const total = pending + processing ;
500+ if ( total !== 0 && ! loading ) {
501+
502+ loading = true ;
503+ start = performance . now ( ) ;
504+ if ( start - threeViewer . loadEnd > 100 ) {
505+
506+ cesiumViewer . loadStart = start ;
507+
508+ }
509+
510+ } else if ( total === 0 && loading ) {
511+
512+ loading = false ;
513+ cesiumViewer . loadEnd = performance . now ( ) ;
514+ cesiumViewer . totalLoadTime += performance . now ( ) - start ;
515+
516+ }
517+
518+ } ) ;
519+
450520 cesiumViewer = {
521+ totalLoadTime : 0 ,
522+ loadStart : 0 ,
523+ loadEnd : 0 ,
451524 tiles : tileset ,
452525 viewer,
453526 camera,
0 commit comments