11import * as THREE from 'three' ;
2+ import { Constants } from './Constants.js' ;
3+ import { LoadingSpinner } from './LoadingSpinner.js' ;
24import { OrbitControls } from './OrbitControls.js' ;
35import { PlyLoader } from './PlyLoader.js' ;
4- import { SplatLoader } from './SplatLoader.js' ;
5- import { LoadingSpinner } from './LoadingSpinner.js' ;
6- import { SceneHelper } from './SceneHelper.js' ;
76import { Raycaster } from './raycaster/Raycaster.js' ;
7+ import { SceneHelper } from './SceneHelper.js' ;
8+ import { SplatLoader } from './SplatLoader.js' ;
89import { SplatMesh } from './SplatMesh.js' ;
9- import { createSortWorker } from './worker/SortWorker.js' ;
10- import { Constants } from './Constants.js' ;
1110import { getCurrentTime } from './Util.js' ;
11+ import { createSortWorker } from './worker/SortWorker.js' ;
1212
1313const THREE_CAMERA_FOV = 50 ;
1414const MINIMUM_DISTANCE_TO_NEW_FOCAL_POINT = .75 ;
@@ -76,6 +76,12 @@ export class Viewer {
7676 this . mouseDownPosition = new THREE . Vector2 ( ) ;
7777 this . mouseDownTime = null ;
7878
79+ this . loadingSpinner = new LoadingSpinner ( ) ;
80+ this . loadingSpinner . hide ( ) ;
81+
82+ this . frameloop = 'demand' ; // 'demand' | 'always'
83+ this . viewerNeedsUpdate = true ;
84+
7985 this . initialized = false ;
8086 this . init ( ) ;
8187 }
@@ -125,11 +131,12 @@ export class Viewer {
125131 this . controls . maxPolarAngle = Math . PI * .75 ;
126132 this . controls . minPolarAngle = 0.1 ;
127133 this . controls . enableDamping = true ;
128- this . controls . dampingFactor = 0.05 ;
134+ this . controls . dampingFactor = 0.25 ;
129135 this . controls . target . copy ( this . initialCameraLookAt ) ;
130136 this . rootElement . addEventListener ( 'pointermove' , this . onMouseMove . bind ( this ) , false ) ;
131137 this . rootElement . addEventListener ( 'pointerdown' , this . onMouseDown . bind ( this ) , false ) ;
132138 this . rootElement . addEventListener ( 'pointerup' , this . onMouseUp . bind ( this ) , false ) ;
139+ this . controls . addEventListener ( 'change' , this . onControlsChange . bind ( this ) , false ) ;
133140 window . addEventListener ( 'keydown' , this . onKeyDown . bind ( this ) , false ) ;
134141 }
135142
@@ -170,6 +177,7 @@ export class Viewer {
170177 break ;
171178 case 'KeyC' :
172179 this . showMeshCursor = ! this . showMeshCursor ;
180+ this . invalidate ( ) ;
173181 break ;
174182 case 'KeyP' :
175183 this . showControlPlane = ! this . showControlPlane ;
@@ -189,6 +197,9 @@ export class Viewer {
189197
190198 onMouseMove ( mouse ) {
191199 this . mousePosition . set ( mouse . offsetX , mouse . offsetY ) ;
200+ if ( this . showMeshCursor ) {
201+ this . invalidate ( ) ;
202+ }
192203 }
193204
194205 onMouseDown ( ) {
@@ -228,6 +239,14 @@ export class Viewer {
228239
229240 } ( ) ;
230241
242+ onControlsChange ( ) {
243+ this . invalidate ( ) ;
244+ }
245+
246+ invalidate ( ) {
247+ this . viewerNeedsUpdate = true ;
248+ }
249+
231250 getRenderDimensions ( outDimensions ) {
232251 if ( this . rootElement ) {
233252 outDimensions . x = this . rootElement . offsetWidth ;
@@ -558,6 +577,7 @@ export class Viewer {
558577 this . updateSplatMeshUniforms ( ) ;
559578 }
560579 lastRendererSize . copy ( currentRendererSize ) ;
580+ this . invalidate ( ) ;
561581 }
562582 } ;
563583
@@ -568,7 +588,11 @@ export class Viewer {
568588 requestAnimationFrame ( this . selfDrivenUpdateFunc ) ;
569589 }
570590 this . update ( ) ;
571- this . render ( ) ;
591+
592+ if ( this . frameloop === 'always' || this . viewerNeedsUpdate ) {
593+ this . render ( ) ;
594+ this . viewerNeedsUpdate = false ;
595+ }
572596 }
573597
574598 update ( ) {
0 commit comments