Skip to content

Commit

Permalink
Merge pull request #962 from vorth/camera-then-parts
Browse files Browse the repository at this point in the history
Scene animation now does camera first then parts
  • Loading branch information
vorth authored Jan 19, 2025
2 parents cf8b530 + b6de8ef commit a1ccae6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
15 changes: 10 additions & 5 deletions online/src/viewer/context/camera.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const CameraProvider = ( props ) =>

if ( duration <= 0 ) {
setCamera( goalCamera );
return;
return Promise.resolve();
}

cancelTweens();
Expand Down Expand Up @@ -257,7 +257,8 @@ const CameraProvider = ( props ) =>

const tweenRotate = new Tween( { t: 0 } );
tweens .add( tweenRotate );
tweenRotate
return new Promise( resolve => {
tweenRotate
.easing( Easing.Quadratic.InOut )
.to( { t: 1.0 }, duration )
.onUpdate( ({ t }) => {
Expand All @@ -266,11 +267,15 @@ const CameraProvider = ( props ) =>
const up = toVector( new Vector3(0,1,0) .applyQuaternion( sourceQuaternion ) );
const lookDir = toVector( new Vector3(0,0,-1) .applyQuaternion( sourceQuaternion ) );
setCamera( { up, lookDir } );
})
.onComplete( () => {
resolve();
});

// We don't want to do this sync, since the tween duration may expire before subsequent
// code in the caller finishes.
requestAnimationFrame( () => tweens .getAll() .map( tween => tween.start() ) );
// We don't want to do this sync, since the tween duration may expire before subsequent
// code in the caller finishes.
requestAnimationFrame( () => tweens .getAll() .map( tween => tween.start() ) );
});
}

const providerValue = {
Expand Down
9 changes: 5 additions & 4 deletions online/src/viewer/context/scene.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ const SceneProvider = ( props ) =>
createEffect( () => {
postRequest( selectScene( props.name ) )
.then( ( { payload: { scene } } ) => {
if ( scene.camera ) {
tweenCamera( scene.camera );
}
if ( scene.lighting ) {
const { backgroundColor } = scene.lighting;
setLighting( { ...state.lighting, backgroundColor } );
}
setScene( 'embedding', reconcile( scene.embedding ) );
setScene( 'polygons', scene.polygons );
updateShapes( scene.shapes );
if ( scene.camera ) {
tweenCamera( scene.camera )
.then( () => updateShapes( scene.shapes ) );
} else
updateShapes( scene.shapes );
});
});

Expand Down
9 changes: 5 additions & 4 deletions online/src/viewer/context/viewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ const ViewerProvider = ( props ) =>

subscribeFor( 'SCENE_RENDERED', ( { scene } ) => {
setWaiting( false );
if ( scene.camera ) {
tweenCamera( scene.camera );
}
if ( scene.lighting ) {
const { backgroundColor } = scene.lighting;
setLighting( { ...state.lighting, backgroundColor } );
}
setScene( 'embedding', reconcile( scene.embedding ) );
setScene( 'polygons', scene.polygons );
updateShapes( scene.shapes );
if ( scene.camera ) {
tweenCamera( scene.camera )
.then( () => updateShapes( scene.shapes ) );
} else
updateShapes( scene.shapes );
// logShapes();
} );

Expand Down

0 comments on commit a1ccae6

Please sign in to comment.