I have a teapot object and then…
raycaster = new THREE.Raycaster();
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
control = new THREE.TransformControls( camera, renderer.domElement );
control.addEventListener( 'change', render );
scene.add( control );
renderer.domElement.addEventListener( 'mousedown', clickEvent );
function clickEvent( event ) {
var elem = renderer.domElement,
boundingRect = elem.getBoundingClientRect(),
x = (event.clientX - boundingRect.left) * (elem.width / boundingRect.width),
y = (event.clientY - boundingRect.top) * (elem.height / boundingRect.height);
//1st view
var view = tripleViews[1];
camera = view.camera;
var WIDTH = Math.floor(windowWidth * view.width);
var HEIGHT = Math.floor(windowHeight * view.height);
mouse.x = ( x / WIDTH ) * 2 - 1;
mouse.y = - ( y / HEIGHT ) * 2 + 1;
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( scene.children );
if ( intersects.length > 0 ) {
if ( INTERSECTED != intersects[ 0 ].object ) {
INTERSECTED = intersects[ 0 ].object;
if ( control.object === undefined || control.object !== INTERSECTED ) {
control.attach( INTERSECTED );
}
}
}
render();
}
the transform controls only work in the 2nd viewport. Here are the configurations for my viewport.
var tripleViews = [
{
left: 0,
bottom: 0,
width: 0.33,
height: 1.0,
background: new THREE.Color( 0.8, 0.9, 1.0 ),
eye: [ 0, 300, 1200 ],
up: [ 0, 1, 0 ],
fov: 70,
updateCamera: function ( camera, scene, mouseX ) {
// camera.position.x += mouseX * 0.05;
// camera.position.x = Math.max( Math.min( camera.position.x, 2000 ), - 2000 );
camera.lookAt( scene.position );
// background: new THREE.Color( 0.2, 0.9, 1.0 );
}
},
{
left: 0.33,
bottom: 0,
width: 0.34,
height: 1,
background: new THREE.Color( 1.0, 0.8, 0.9 ),
eye: [ 0, 1800, 0 ],
up: [1, 0, 0 ],
fov: 45,
updateCamera: function ( camera, scene, mouseX ) {
//camera.position.x -= mouseX * 0.05;
//camera.position.x = Math.max( Math.min( camera.position.x, 2000 ), - 2000 );
camera.lookAt( camera.position.clone().setY( 0 ) );
}
},
{
left: 0.66,
bottom: 0,
width: 0.34,
height: 1,
background: new THREE.Color( 0.7, 0.897, 0.5),
eye: [ 1400, 800, 0 ],
up: [ 0, 1, 0 ],
fov: 60,
updateCamera: function ( camera, scene, mouseX ) {
// camera.position.y -= mouseX * 0.05;
/// camera.position.y = Math.max( Math.min( camera.position.y, 1600 ), - 1600 );
camera.lookAt( scene.position );
}
}
];
I also just want to use the world coordinates. Please help!