Skip to content

Commit

Permalink
fix(examples): PointCloud Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Feb 26, 2025
1 parent 2577248 commit 60e9d9a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 49 deletions.
5 changes: 2 additions & 3 deletions examples/copc_3d_loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@
var layer;

function onLayerReady() {
var lookAt = new itowns.THREE.Vector3();
layer.root.bbox.getCenter(lookAt);
var lookAt = layer.root._position;
var coordLookAt = new itowns.Coordinates(view.referenceCrs).setFromVector3(lookAt);

var size = new itowns.THREE.Vector3();
layer.root.bbox.getSize(size);
layer.root._bbox.getSize(size);

view.controls.lookAtCoordinate({
coord: coordLookAt,
Expand Down
17 changes: 9 additions & 8 deletions examples/copc_simple_loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@
function onLayerReady(layer) {
const camera = view.camera.camera3D;

const lookAt = new itowns.THREE.Vector3();
const size = new itowns.THREE.Vector3();
layer.root.bbox.getSize(size);
layer.root.bbox.getCenter(lookAt);
const lookAt = layer.root._position;
lookAt.z = (layer.maxElevationRange + layer.minElevationRange) * 0.5;

camera.far = 2.0 * size.length();
const size = new itowns.THREE.Vector3();
layer.root._bbox.getSize(size);

controls.groundLevel = layer.root.bbox.min.z;
const position = layer.root.bbox.min.clone().add(
size.multiply({ x: 1, y: 1, z: size.x / size.z }),
controls.groundLevel = layer.minElevationRange;
var corner = new itowns.THREE.Vector3(...layer.source.header.min);
var position = corner.clone().add(
size.multiply({ x: 0, y: 0, z: (size.x / size.z) })
);

camera.far = 2.0 * size.length();
camera.position.copy(position);
camera.lookAt(lookAt);
camera.updateProjectionMatrix();
Expand Down
7 changes: 3 additions & 4 deletions examples/entwine_3d_loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@
var eptLayer, eptSource;

function onLayerReady() {
var lookAt = new itowns.THREE.Vector3();
eptLayer.root.bbox.getCenter(lookAt);
var coordLookAt = new itowns.Coordinates(view.referenceCrs, lookAt);
var lookAt = eptLayer.root._position;
var coordLookAt = new itowns.Coordinates(view.referenceCrs).setFromVector3(lookAt);

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

view.controls.lookAtCoordinate({
coord: coordLookAt,
Expand Down
75 changes: 41 additions & 34 deletions examples/entwine_simple_loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,48 @@
<script src="js/GUI/LoadingScreen.js"></script>
<script src="../dist/debug.js"></script>
<script type="text/javascript">
itowns.proj4.defs('EPSG:3946', '+proj=lcc +lat_0=46 +lon_0=3 +lat_1=45.25 +lat_2=46.75 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs');
// itowns.proj4.defs('EPSG:3946', '+proj=lcc +lat_0=46 +lon_0=3 +lat_1=45.25 +lat_2=46.75 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs');

var debugGui = new dat.GUI();
var viewerDiv = document.getElementById('viewerDiv');
viewerDiv.style.display = 'block';
var view = new itowns.View('EPSG:3946', viewerDiv);
view.mainLoop.gfxEngine.renderer.setClearColor(0xcccccc);

const controls = new itowns.PlanarControls(view);

var eptLayer, eptSource;

function dblClickHandler(event) {
var pick = view.pickObjectsAt(event, 5, eptLayer);

for (const p of pick) {
console.info('Selected point #' + p.index + ' in position (' +
p.object.position.x + ', ' +
p.object.position.y + ', ' +
p.object.position.z +
') - node ' + p.object.userData.node.id);
}
}

let view;
function setView(crs) {
view = new itowns.View(crs, viewerDiv);
controls = new itowns.PlanarControls(view);
view.mainLoop.gfxEngine.renderer.setClearColor(0xdddddd);

view.domElement.addEventListener('dblclick', dblClickHandler);
}

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

var lookAt = eptLayer.root._position;
lookAt.z = (eptLayer.maxElevationRange + eptLayer.minElevationRange) * 0.5;

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

controls.groundLevel = eptLayer.root.bbox.min.z;
var position = eptLayer.root.bbox.min.clone().add(
size.multiply({ x: 0, y: 0, z: size.x / size.z })
controls.groundLevel = eptLayer.minElevationRange;
var corner = new itowns.THREE.Vector3(...eptLayer.source.boundsConforming.slice(0, 3));
var position = corner.clone().add(
size.multiply({ x: 0, y: 0, z: (size.x / size.z) })
);

view.camera3D.position.copy(position);
Expand Down Expand Up @@ -87,37 +106,25 @@
function loadEPT(url, options) {
eptSource = new itowns.EntwinePointTileSource({ url });

if (eptLayer) {
debugGui.removeFolder(eptLayer.debugUI);
view.removeLayer('Entwine Point Tile');
view.notifyChange();
eptLayer.delete();
}

const config = {
source: eptSource,
crs: view.referenceCrs,
...options,
}
eptLayer = new itowns.EntwinePointTileLayer('Entwine Point Tile', config);

view.addLayer(eptLayer).then(onLayerReady);
eptSource.whenReady.then(() => {
setView(eptSource.crs);

eptLayer.whenReady
.then(() => debug.PointCloudDebug.initTools(view, eptLayer, debugGui));
if (eptLayer) {
debugGui.removeFolder(eptLayer.debugUI);
eptLayer.delete();
}

function dblClickHandler(event) {
var pick = view.pickObjectsAt(event, 5, eptLayer);
eptLayer = new itowns.EntwinePointTileLayer('Entwine Point Tile', config);

for (const p of pick) {
console.info('Selected point #' + p.index + ' in position (' +
p.object.position.x + ', ' +
p.object.position.y + ', ' +
p.object.position.z +
') - node ' + p.object.userData.node.id);
}
}
view.domElement.addEventListener('dblclick', dblClickHandler);
view.addLayer(eptLayer).then(onLayerReady);
eptLayer.whenReady
.then(() => debug.PointCloudDebug.initTools(view, eptLayer, debugGui));
})
}

function loadGrandLyon() {
Expand Down

0 comments on commit 60e9d9a

Please sign in to comment.