iTowns / itowns

A Three.js-based framework written in Javascript/WebGL for visualizing 3D geospatial data
http://www.itowns-project.org
Other
1.1k stars 298 forks source link

camera not moving in positionGlobe example #747

Closed mbredif closed 6 years ago

mbredif commented 6 years ago

The camera does not move when the click starts on a object3D that has been added directly to the scene.

Steps to Reproduce

  1. open http://www.itowns-project.org/itowns/examples/positionGlobe.html
  2. click and drag on the ground : the camera moves
  3. click and drag on the red cone : the camera does not move

Expected Behavior

the camera should move in 3.

Actual Behavior

the camera does not move in 3.

Possible Cause

My guess is that picking is not working with objects directly added to the threejs scene.

Possible Solutions :

in any case, this should be documented somewhere

peppsac commented 6 years ago

Here's another fix:

diff --git a/src/Core/Prefab/GlobeView.js b/src/Core/Prefab/GlobeView.js
index a19382da..9aff0ceb 100644
--- a/src/Core/Prefab/GlobeView.js
+++ b/src/Core/Prefab/GlobeView.js
@@ -366,7 +366,10 @@ GlobeView.prototype.selectNodeAt = function selectNodeAt(mouse) {
 GlobeView.prototype.readDepthBuffer = function readDepthBuffer(x, y, width, height) {
     const g = this.mainLoop.gfxEngine;
     const restore = this.wgs84TileLayer.level0Nodes.map(n => n.pushRenderState(RendererConstant.DEPTH));
-    const buffer = g.renderViewToBuffer(this, { x, y, width, height });
+    // only draw the objects of this layer
+    const buffer = g.renderViewToBuffer(
+        { camera: this.camera, scene: this.wgs84TileLayer.object3d },
+        { x, y, width, height });
     restore.forEach(r => r());
mbredif commented 6 years ago

Is it a hack or a general fix ? Is there any implications / side effects ?

peppsac commented 6 years ago

It's a fix to make sure we only render objects belonging to the globe layer (and the same fix should be implemented in PlanarView).