Skip to content

Commit

Permalink
Add throttling to terrain update
Browse files Browse the repository at this point in the history
  • Loading branch information
liberostelios committed Oct 20, 2020
1 parent e934e8d commit 51fc455
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dat.gui": "^0.7.7",
"debounce": "^1.2.0",
"jest": "^26.4.2",
"lodash": "^4.17.20",
"three": "^0.121.1",
"tweakpane": "^1.5.5",
"vue": "^2.6.11",
Expand Down
15 changes: 11 additions & 4 deletions src/components/ThreeViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
import { SSAOPass } from 'three/examples/jsm/postprocessing/SSAOPass.js';
import debounce from 'debounce';
import throttle from 'lodash/throttle';
const Tweakpane = require('tweakpane');
Expand Down Expand Up @@ -565,6 +567,14 @@ export default {
this.needsRerender = 1;
},
updateTerrain: throttle( function() {
const transform = this.tiles.root.cached.transform;
const sceneTransform = new Vector2( transform.elements[12], transform.elements[13] );
this.terrainTiles.update( sceneTransform, this.camera );
}, 200 ),
renderScene() {
requestAnimationFrame( this.renderScene );
Expand Down Expand Up @@ -597,11 +607,8 @@ export default {
this.tiles.update();
if ( this.tiles.root ) {
const transform = this.tiles.root.cached.transform;
const sceneTransform = new Vector2( transform.elements[12], transform.elements[13] );
this.terrainTiles.update( sceneTransform, this.camera );
this.updateTerrain();
}
Expand Down
4 changes: 2 additions & 2 deletions src/terrain-tiles/base/TilesRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export class TilesRenderer {

if ( ! this.activeTiles.includes( ti.getId() ) ) {

this.activeTiles.push( ti.getId() );

this.createTile( ti, sceneCenter );

}
Expand Down Expand Up @@ -103,8 +105,6 @@ export class TilesRenderer {
mesh.position.y = scenePosition.y;
mesh.updateMatrix();

this.activeTiles.push( tile.getId() );

}

}

0 comments on commit 51fc455

Please sign in to comment.