Hello Simone,
Below, is the code that I used.
The position is supposed to be slightly in front of Red or Blue boxes but, here what is displayed:
Instead of something like this:
I hope that the code is formatted correctly.
<!DOCTYPE html>
<html>
<body class="" topmargin="0" leftmargin="0">
<script type="importmap">
{
"imports": {
"three": "./three.js-master/build/three.module.js",
"three/addons/": "./three.js-master/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import {TrackballControls} from 'three/addons/controls/TrackballControls.js';
var intSceneWidth;
var intSceneHeight;
var intSceneDepth;
var intBoxWidth;
var intBoxHeight;
var intBoxDepth;
var center;
var camera;
var controls;
var scene;
var renderer;
var matRed;
var matGreen;
var matBlue;
var matWhite;
var matYellow;
var matFloor;
var geoFloor;
var mesFloor;
var geoBox;
var mesBox;
var posRedBox;
var posBlueBox;
intSceneWidth=220000;
intSceneHeight=280000;
intSceneDepth=250000;
intBoxWidth=10000;
intBoxHeight=10000;
intBoxDepth=30000;
renderer=new THREE.WebGLRenderer( { antialias: true });
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
scene=new THREE.Scene();
scene.background = new THREE.Color( 0x156289 );
camera=new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,1,intSceneDepth);
camera.near=500;
camera.far=700000;
camera.updateProjectionMatrix();
camera.position.set(0,0,intSceneDepth*2);
controls=new TrackballControls( camera, renderer.domElement,scene );
controls.maxDistance=700000;
controls.update();
matRed=new THREE.MeshBasicMaterial( { color: 0xff0000 } );
matGreen=new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
matBlue=new THREE.MeshBasicMaterial( { color: 0x0000ff } );
matWhite=new THREE.MeshBasicMaterial( { color: 0xffffff } );
matYellow=new THREE.MeshBasicMaterial( { color: 0xffff00 } );
matFloor=new THREE.MeshBasicMaterial( { color: 0x7f7f7f } );
center=new THREE.Vector3();
center.x=intSceneWidth/2;
center.y=intSceneHeight/2;
geoFloor=new THREE.BoxGeometry(intSceneWidth,intSceneHeight,150);
mesFloor=new THREE.Mesh( geoFloor, matFloor );
mesFloor.position.set(intSceneWidth/2,intSceneHeight/2,150/2);
mesFloor.position.sub(center);
scene.add(mesFloor);
geoBox=new THREE.BoxGeometry(intBoxWidth,intBoxHeight,intBoxDepth);
mesBox=new THREE.Mesh( geoBox, matWhite );
mesBox.position.set(intSceneWidth/2,intSceneHeight/2,intBoxDepth/2);
mesBox.position.sub(center);
scene.add(mesBox);
posRedBox=new THREE.Vector3(80000+intBoxWidth/2,0+intBoxHeight/2,intBoxDepth/2);
posRedBox.sub(center);
mesBox=new THREE.Mesh( geoBox, matRed );
mesBox.position.set(posRedBox.x,posRedBox.y,posRedBox.z);
scene.add(mesBox);
mesBox=new THREE.Mesh( geoBox, matYellow );
mesBox.position.set(75000+intBoxWidth/2,250000+intBoxHeight/2,intBoxDepth/2);
mesBox.position.sub(center);
scene.add(mesBox);
posBlueBox=new THREE.Vector3(0+intBoxWidth/2,42000+intBoxHeight/2,intBoxDepth/2);
posBlueBox.sub(center);
mesBox=new THREE.Mesh( geoBox, matBlue );
mesBox.position.set(posBlueBox.x,posBlueBox.y,posBlueBox.z);
scene.add(mesBox);
mesBox=new THREE.Mesh( geoBox, matGreen );
mesBox.position.set(210000+intBoxWidth/2,110000+intBoxHeight/2,intBoxDepth/2);
mesBox.position.sub(center);
scene.add(mesBox);
animate();
window.scene=scene;
window.SetCameraPositionRedBox=SetCameraPositionRedBox;
window.SetCameraPositionBlueBox=SetCameraPositionBlueBox;
window.camera=camera;
window.controls=controls;
window.addEventListener( 'resize', onWindowResize );
function animate()
{
requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );
}
function SetCameraPositionRedBox()
{
camera.position.set(posRedBox.x,posRedBox.y-35000,15000);
camera.updateProjectionMatrix();
controls.update();
}
function SetCameraPositionBlueBox()
{
camera.position.set(posBlueBox.x,posBlueBox.y-35000,15000);
camera.updateProjectionMatrix();
controls.update();
}
function onWindowResize()
{
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
</script>
<div style="position:absolute; top:0px; left:0px; color:#ffffff;">
<input type="button" style="white-space:normal; width:150px;" value="Set camera position Red box" onclick="SetCameraPositionRedBox();">
<input type="button" style="white-space:normal; width:150px;" value="Set camera position Blue box" onclick="SetCameraPositionBlueBox();">
</div>
</body>
</html>
Thanks