Skip to content

Commit

Permalink
feat(View): add getters for threejs renderer and camera
Browse files Browse the repository at this point in the history
Use `View.renderer` to get the threejs renderer of the view
Use `View.camera3D` to get the threejs camera of the view
  • Loading branch information
jailln committed Oct 11, 2023
1 parent c3bc003 commit 3900c11
Show file tree
Hide file tree
Showing 48 changed files with 183 additions and 196 deletions.
8 changes: 4 additions & 4 deletions examples/3dtiles_basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
var viewerDiv = document.getElementById('viewerDiv');

var view = new itowns.GlobeView(viewerDiv, placement);
view.camera.camera3D.near = 5;
view.camera3D.near = 5;
setupLoadingScreen(viewerDiv, view);

var menuGlobe = new GuiTools('menuDiv', view, 300);
Expand Down Expand Up @@ -84,9 +84,9 @@
debug.create3dTilesDebugUI(menuGlobe.gui, view, $3dTilesLayerDiscreteLOD, d);
debug.create3dTilesDebugUI(menuGlobe.gui, view, $3dTilesLayerRequestVolume, d);
d.zoom = function() {
view.camera.camera3D.position.set(1215013.9, -4736315.5, 4081597.5);
view.camera.camera3D.quaternion.set(0.9108514448729665, 0.13456816437801225, 0.1107206134840362, 0.3741416847378546);
view.notifyChange(view.camera.camera3D);
view.camera3D.position.set(1215013.9, -4736315.5, 4081597.5);
view.camera3D.quaternion.set(0.9108514448729665, 0.13456816437801225, 0.1107206134840362, 0.3741416847378546);
view.notifyChange(view.camera3D);
}
menuGlobe.gui.add(d, 'zoom').name('Go to point cloud');
</script>
Expand Down
16 changes: 8 additions & 8 deletions examples/3dtiles_pointcloud.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ul>
<li>Display your pointcloud</li>
<li>Use classification to assign colour to each points</li>
<li>Switch between mode on the left panel</li>
<li>Switch between mode on the left panel</li>
</ul>
</div>
<div id="viewerDiv"></div>
Expand All @@ -27,7 +27,7 @@
<script type="text/javascript">
/* global itowns,document,GuiTools*/


var placement = {
coord: new itowns.Coordinates('EPSG:4326', 3.695885, 43.397379, 0),

Expand All @@ -39,7 +39,7 @@
var viewerDiv = document.getElementById('viewerDiv');

var view = new itowns.GlobeView(viewerDiv, placement);
view.camera.camera3D.near = 5;
view.camera3D.near = 5;
setupLoadingScreen(viewerDiv, view);

var menuGlobe = new GuiTools('menuDiv', view, 300);
Expand Down Expand Up @@ -75,14 +75,14 @@
itowns.View.prototype.addLayer.call(view, $3dTilesLayerSetePC);
function switchMode(){
let pntsLayer = view.getLayerById("3d-tiles-sete");

if(pntsLayer){
pntsLayer = pntsLayer;
pntsLayer.pntsMode = pntsLayer.pntsMode == itowns.PNTS_MODE.COLOR ? itowns.PNTS_MODE.CLASSIFICATION : itowns.PNTS_MODE.COLOR;
view.notifyChange(view.camera.camera3D);
view.notifyChange(view.camera3D);
}
}

// Add the UI Debug
var d = new debug.Debug(view, menuGlobe.gui);
debug.createTileDebugUI(menuGlobe.gui, view, view.tileLayer, d);
Expand All @@ -93,9 +93,9 @@
}
menuGlobe.gui.add(d, 'switch').name('Mode Switch');







</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion examples/effects_postprocessing.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
var r = g.renderer;
r.setRenderTarget(g.fullSizeRenderTarget);
r.clear();
r.render(view.scene, view.camera.camera3D);
r.render(view.scene, view.camera3D);

quad.material.uniforms.tDiffuse.value = g.fullSizeRenderTarget.texture;
quad.material.uniforms.tSize.value.set(
Expand Down
11 changes: 4 additions & 7 deletions examples/effects_stereo.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

view.render = function render() {
r.clear();
effect.render(view.scene, view.camera.camera3D);
effect.render(view.scene, view.camera3D);
};

view.notifyChange();
Expand All @@ -125,8 +125,7 @@
function enableAnaglyph() {
var _eff;
if (effect instanceof THREE.AnaglyphEffect) return;
_eff = new THREE.AnaglyphEffect(view.mainLoop.gfxEngine.renderer,
view.camera.camera3D);
_eff = new THREE.AnaglyphEffect(view.mainLoop.gfxEngine.renderer, view.camera3D);
enableEffect(_eff);
}

Expand All @@ -139,8 +138,7 @@
function enableParallax() {
var _eff;
if (effect instanceof THREE.ParallaxBarrierEffect) return;
_eff = new THREE.ParallaxBarrierEffect(view.mainLoop.gfxEngine.renderer,
view.camera.camera3D);
_eff = new THREE.ParallaxBarrierEffect(view.mainLoop.gfxEngine.renderer, view.camera3D);
enableEffect(_eff);
}

Expand All @@ -150,8 +148,7 @@
function enableStereo() {
var _eff;
if (effect instanceof THREE.StereoEffect) return;
_eff = new THREE.StereoEffect(view.mainLoop.gfxEngine.renderer,
view.camera.camera3D);
_eff = new THREE.StereoEffect(view.mainLoop.gfxEngine.renderer, view.camera3D);
enableEffect(_eff);
}

Expand Down
10 changes: 4 additions & 6 deletions examples/entwine_simple_loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,21 @@
var eptLayer, eptSource;

function onLayerReady() {
var camera = view.camera.camera3D;

var lookAt = new itowns.THREE.Vector3();
var size = new itowns.THREE.Vector3();
eptLayer.root.bbox.getSize(size);
eptLayer.root.bbox.getCenter(lookAt);

camera.far = 2.0 * size.length();
view.camera3D.far = 2.0 * size.length();

var position = eptLayer.root.bbox.min.clone().add(size.multiply({ x: 0, y: 0, z: size.x / size.z }));

camera.position.copy(position);
camera.lookAt(lookAt);
view.camera3D.position.copy(position);
view.camera3D.lookAt(lookAt);

controls.options.moveSpeed = size.length();

view.notifyChange(camera);
view.notifyChange(view.camera3D);
controls.reset();
}

Expand Down
9 changes: 3 additions & 6 deletions examples/itowns-potree.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@
// Controls and camera specific setting.
itownsViewer.controls.minDistanceCollision = 0.01;
itownsViewer.controls.minDistance = 20;
itownsViewer.camera.camera3D.near = 0.1;


view.camera3D.near = 0.1;

// ---------- TWEAK ITOWNS VIEWER TO SUPPORT POTREE VISUALIZATION : ----------

Expand All @@ -179,9 +177,8 @@
})

// Set Potree viewer camera as iTowns viewer camera.
const camera = itownsViewer.camera.camera3D;
camera.zoomTo = () => {};
potreeViewer.scene.cameraP = camera;
view.camera3D.zoomTo = () => {};
potreeViewer.scene.cameraP = view.camera3D;

// TODO : should be moved to Label2DRenderer constructor
itownsViewer.mainLoop.gfxEngine.label2dRenderer.domElement.style.pointerEvents = 'none';
Expand Down
7 changes: 3 additions & 4 deletions examples/js/OrientedImageHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,12 @@ function setupViewCameraLookingAtObject(camera, coord, objectToLookAt) {
// eslint-disable-next-line no-unused-vars
function setupViewCameraDecomposing(view, camera) {
let upWorld;
const viewCamera = view.camera.camera3D;
camera.matrixWorld.decompose(viewCamera.position, viewCamera.quaternion, viewCamera.scale);
camera.matrixWorld.decompose(view.camera3D.position, view.camera3D.quaternion, view.camera3D.scale);

// setup up vector
upWorld = camera.localToWorld(camera.up.clone());
upWorld = viewCamera.position.clone().sub(upWorld);
viewCamera.up.copy(upWorld);
upWorld = view.camera3D.position.clone().sub(upWorld);
view.camera3D.up.copy(upWorld);
}

// add a camera helper to debug camera position..
Expand Down
2 changes: 1 addition & 1 deletion examples/js/plugins/DragNDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const DragNDrop = (function _() {
}

// Move the camera
itowns.CameraUtils.transformCameraToLookAtTarget(_view, _view.camera.camera3D, extent);
itowns.CameraUtils.transformCameraToLookAtTarget(_view, _view.camera3D, extent);
});
};

Expand Down
10 changes: 4 additions & 6 deletions examples/laz_dragndrop.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,21 @@
view.scene.add(points);
points.updateMatrixWorld(true);

var camera = view.camera.camera3D;

var lookAt = new itowns.THREE.Vector3();
var size = new itowns.THREE.Vector3();
geometry.boundingBox.getSize(size);
geometry.boundingBox.getCenter(lookAt);

camera.far = Math.max(2.0 * size.length(), camera.far);
view.camera3D.far = Math.max(2.0 * size.length(), camera.far);

var position = geometry.boundingBox.min.clone().add(size.multiply({ x: 0, y: 0, z: size.x / size.z }));

camera.position.copy(position);
camera.lookAt(lookAt);
view.camera3D.position.copy(position);
view.camera3D.lookAt(lookAt);

controls.options.moveSpeed = size.length();

view.notifyChange(camera);
view.notifyChange(view.camera3D);
controls.reset();
});
};
Expand Down
2 changes: 1 addition & 1 deletion examples/misc_camera_animation.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

function travel() {
return itowns.CameraUtils
.sequenceAnimationsToLookAtTarget(view, view.camera.camera3D, pathTravel);
.sequenceAnimationsToLookAtTarget(view, view.camera3D, pathTravel);
}


Expand Down
8 changes: 4 additions & 4 deletions examples/misc_camera_traveling.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
// Retrieve current camera transform options
const cameraTransformOptions = itowns.CameraUtils.getTransformCameraLookingAtTarget(
view,
view.camera.camera3D,
view.camera3D,
);
// Change default easing parameter for animation speed
// (see https://sole.github.io/tween.js/examples/03_graphs.html)
Expand All @@ -101,7 +101,7 @@
// Create a CameraHelper (https://threejs.org/docs/index.html?q=Camera#api/en/helpers/CameraHelper) at
// the current position of the camera. The camera is copied, and the copy's `far` is lowered. This
// renders shorter axes on the displayed CameraHelper.
const copyCamera = view.camera.camera3D.clone();
const copyCamera = view.camera3D.clone();
copyCamera.far = 50;
const helper = new itowns.THREE.CameraHelper(copyCamera);
helper.updateWorldMatrix(true, false);
Expand All @@ -114,12 +114,12 @@
travelOn = true;
return itowns.CameraUtils.sequenceAnimationsToLookAtTarget(
view,
view.camera.camera3D,
view.camera3D,
travelSteps,
).then(() => { travelOn = false; });
}

itowns.CameraUtils.stop(view, view.camera.camera3D); // If travel is on, interrupt it
itowns.CameraUtils.stop(view, view.camera3D); // If travel is on, interrupt it
}

// Listens for user input :
Expand Down
4 changes: 2 additions & 2 deletions examples/misc_compare_25d_3d.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
// eslint-disable-next-line no-console
console.info('Globe initialized');
Promise.all(promises).then(function init() {
var planarCamera = planarView.camera.camera3D;
var globeCamera = view.camera.camera3D;
var planarCamera = planarView.camera3D;
var globeCamera = view.camera3D;
var params;
menuGlobe.addImageryLayersGUI(view.getLayers(function filterColor(l) { return l.isColorLayer; }));
menuGlobe.addElevationLayersGUI(view.getLayers(function filterElevation(l) { return l.isElevationLayer; }));
Expand Down
4 changes: 2 additions & 2 deletions examples/misc_georeferenced_images.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@
setupViewCameraDecomposing(view, camera);

// open view camera FOV of 10° to see landscape around the picture.
view.camera.camera3D.fov += 10;
view.camera.camera3D.updateProjectionMatrix();
view.camera3D.fov += 10;
view.camera3D.updateProjectionMatrix();

// uncomment to debug camera
// addCameraHelper(view, camera);
Expand Down
8 changes: 4 additions & 4 deletions examples/potree_25d_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@
view.domElement.addEventListener('dblclick', dblClickHandler);

function placeCamera(position, lookAt) {
view.camera.camera3D.position.copy(position);
view.camera.camera3D.lookAt(lookAt);
view.camera3D.position.copy(position);
view.camera3D.lookAt(lookAt);
// create controls
controls = new itowns.FirstPersonControls(view, { focusOnClick: true });
debugGui.add(controls.options, 'moveSpeed', 1, 100).name('Movement speed');

view.notifyChange(view.camera.camera3D);
view.notifyChange(view.camera3D);
}

// add potreeLayer to scene
Expand All @@ -104,7 +104,7 @@

debug.PotreeDebug.initTools(view, potreeLayer, debugGui);

view.camera.camera3D.far = 2.0 * size.length();
view.camera3D.far = 2.0 * size.length();

ratio = size.x / size.z;
position = potreeLayer.root.bbox.min.clone().add(
Expand Down
2 changes: 1 addition & 1 deletion examples/source_stream_wfs_3d.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
var i;
var mesh;
if (meshes.length) {
view.notifyChange(view.camera.camera3D, true);
view.notifyChange(view.camera3D, true);
}
for (i = 0; i < meshes.length; i++) {
mesh = meshes[i];
Expand Down
10 changes: 5 additions & 5 deletions examples/view_immersive.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
});

// limit camera far, to increase performance
view.camera.camera3D.far = 10000;
view.camera.camera3D.near = 0.1;
view.camera3D.far = 10000;
view.camera3D.near = 0.1;

// open camera fov
view.camera.camera3D.fov = 75;
view.camera.camera3D.updateProjectionMatrix();
view.camera3D.fov = 75;
view.camera3D.updateProjectionMatrix();

// disable atmosphere
view.getLayerById('atmosphere').visible = false;
Expand Down Expand Up @@ -175,7 +175,7 @@

// set camera to current panoramic
view.controls.setCameraToCurrentPosition();
view.notifyChange(view.camera.camera3D);
view.notifyChange(view.camera3D);

});

Expand Down
10 changes: 5 additions & 5 deletions examples/view_multi_25d.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@

// Since PlanarView doesn't create default controls, we manipulate directly three.js camera
// Position the camera at south-west corner
view.camera.camera3D.position.set(3, 2, 3);
view.camera.camera3D.updateMatrixWorld(true);
view.camera.camera3D.lookAt(new itowns.THREE.Vector3(0, 0, 0));
view.camera3D.position.set(3, 2, 3);
view.camera3D.updateMatrixWorld(true);
view.camera3D.lookAt(new itowns.THREE.Vector3(0, 0, 0));

controls = new itowns.THREE.OrbitControls(view.camera.camera3D, viewerDiv);
controls = new itowns.THREE.OrbitControls(view.camera3D, viewerDiv);
controls.minDistance = 1;
controls.addEventListener('change', function _() { view.notifyChange(view.camera.camera3D); });
controls.addEventListener('change', function _() { view.notifyChange(view.camera3D); });

// Request redraw
view.notifyChange();
Expand Down
Loading

0 comments on commit 3900c11

Please sign in to comment.