// MAP CALLBACKS refresh() { const frustum = new THREE.Frustum(); frustum.setFromMatrix( new THREE.Matrix4().multiplyMatrices( this.camera.projectionMatrix, this.camera.matrixWorldInverse ) ); this.tileset.root.checkLoad(frustum, this._getCameraPosition()); }
// HELPERS _getCameraPosition() { if (!this.viewProjectionMatrix) { return new THREE.Vector3(); } const cam = new THREE.Camera(); const rootInverse = new THREE.Matrix4().getInverse(this.rootTransform); cam.projectionMatrix.elements = this.viewProjectionMatrix; cam.projectionMatrixInverse = new THREE.Matrix4().getInverse(cam.projectionMatrix); // add since three@0.103.0 const campos = new THREE.Vector3(0, 0, 0).unproject(cam).applyMatrix4(rootInverse); return campos; }
render(gl, viewProjectionMatrix) { this.viewProjectionMatrix = viewProjectionMatrix; const l = new THREE.Matrix4().fromArray(viewProjectionMatrix); this.renderer.state.reset(); // The root tile transform is applied to the camera while rendering // instead of to the root tile. This avoids precision errors. this.camera.projectionMatrix = l.multiply(this.rootTransform); this.renderer.render(this.scene, this.camera); if (this.loadStatus === 1) { // first render after root tile is loaded this.loadStatus = 2; const frustum = new THREE.Frustum(); frustum.setFromMatrix( new THREE.Matrix4().multiplyMatrices( this.camera.projectionMatrix, this.camera.matrixWorldInverse ) ); if (this.tileset) { this.tileset.update(frustum, this._getCameraPosition()); } } }