Skip to content

Commit

Permalink
Add a "force-rerender" event to notify react when the display needs t…
Browse files Browse the repository at this point in the history
…o be updated (#851)
  • Loading branch information
gkjohnson authored Dec 2, 2024
1 parent c482d87 commit 1f4a454
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions example/r3f/globe.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function App() {
const { apiToken, ortho } = useControls( levaParams );
return (
<Canvas
frameloop='demand'
camera={ {
position: [ 0, 0.5 * 1e7, 1.5 * 1e7 ],
} }
Expand Down
File renamed without changes.
17 changes: 15 additions & 2 deletions src/plugins/three/fade/TilesFadePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function onUpdateAfter() {
if ( fadingBefore !== 0 && fadingAfter !== 0 ) {

tiles.dispatchEvent( { type: 'fade-change' } );
tiles.dispatchEvent( { type: 'force-rerender' } );

}

Expand Down Expand Up @@ -240,8 +241,20 @@ export class TilesFadePlugin {
tiles.group.add( fadeGroup );

const fadeManager = this._fadeManager;
fadeManager.onFadeSetStart = () => tiles.dispatchEvent( { type: 'fade-start' } );
fadeManager.onFadeSetComplete = () => tiles.dispatchEvent( { type: 'fade-end' } );
fadeManager.onFadeSetStart = () => {

tiles.dispatchEvent( { type: 'fade-start' } );
tiles.dispatchEvent( { type: 'force-rerender' } );

};

fadeManager.onFadeSetComplete = () => {

tiles.dispatchEvent( { type: 'fade-end' } );
tiles.dispatchEvent( { type: 'force-rerender' } );

};

fadeManager.onFadeComplete = onFadeComplete.bind( this );

this.tiles = tiles;
Expand Down
1 change: 1 addition & 0 deletions src/r3f/components/TilesRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const TilesRenderer = forwardRef( function TilesRenderer( props, ref ) {

const tiles = new TilesRendererImpl( url );
tiles.addEventListener( 'load-content', () => invalidate() );
tiles.addEventListener( 'force-rerender', () => invalidate() );
setTiles( tiles );

return () => {
Expand Down

0 comments on commit 1f4a454

Please sign in to comment.