Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: Use more pointer semantics. #21504

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/webgl_geometry_terrain_raycast.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
let helper;

const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
const pointer = new THREE.Vector2();

init();
animate();

function init() {

container = document.getElementById( 'container' );
container.innerHTML = "";
container.innerHTML = '';

renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
Expand Down Expand Up @@ -103,7 +103,7 @@
helper = new THREE.Mesh( geometryHelper, new THREE.MeshNormalMaterial() );
scene.add( helper );

container.addEventListener( 'pointermove', onMouseMove );
container.addEventListener( 'pointermove', onPointerMove );

stats = new Stats();
container.appendChild( stats.dom );
Expand Down Expand Up @@ -232,11 +232,11 @@

}

function onMouseMove( event ) {
function onPointerMove( event ) {

mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 - 1;
mouse.y = - ( event.clientY / renderer.domElement.clientHeight ) * 2 + 1;
raycaster.setFromCamera( mouse, camera );
pointer.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 - 1;
pointer.y = - ( event.clientY / renderer.domElement.clientHeight ) * 2 + 1;
raycaster.setFromCamera( pointer, camera );

// See if the ray from the camera into the world hits one of our meshes
const intersects = raycaster.intersectObject( mesh );
Expand Down
16 changes: 7 additions & 9 deletions examples/webgl_interactive_buffergeometry.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

let camera, scene, renderer;

let raycaster, mouse;
let raycaster, pointer;

let mesh, line;

Expand Down Expand Up @@ -175,7 +175,7 @@

raycaster = new THREE.Raycaster();

mouse = new THREE.Vector2();
pointer = new THREE.Vector2();

geometry = new THREE.BufferGeometry();
geometry.setAttribute( 'position', new THREE.BufferAttribute( new Float32Array( 4 * 3 ), 3 ) );
Expand All @@ -200,7 +200,7 @@
//

window.addEventListener( 'resize', onWindowResize );
document.addEventListener( 'mousemove', onDocumentMouseMove );
document.addEventListener( 'pointermove', onPointerMove );

}

Expand All @@ -213,12 +213,10 @@

}

function onDocumentMouseMove( event ) {
function onPointerMove( event ) {

event.preventDefault();

mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
pointer.x = ( event.clientX / window.innerWidth ) * 2 - 1;
pointer.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

}

Expand All @@ -240,7 +238,7 @@
mesh.rotation.x = time * 0.15;
mesh.rotation.y = time * 0.25;

raycaster.setFromCamera( mouse, camera );
raycaster.setFromCamera( pointer, camera );

const intersects = raycaster.intersectObject( mesh );

Expand Down
14 changes: 6 additions & 8 deletions examples/webgl_interactive_cubes.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
let INTERSECTED;
let theta = 0;

const mouse = new THREE.Vector2();
const pointer = new THREE.Vector2();
const radius = 100;

init();
Expand Down Expand Up @@ -85,7 +85,7 @@
stats = new Stats();
container.appendChild( stats.dom );

document.addEventListener( 'mousemove', onDocumentMouseMove );
document.addEventListener( 'mousemove', onPointerMove );

//

Expand All @@ -102,12 +102,10 @@

}

function onDocumentMouseMove( event ) {
function onPointerMove( event ) {

event.preventDefault();

mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
pointer.x = ( event.clientX / window.innerWidth ) * 2 - 1;
pointer.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

}

Expand Down Expand Up @@ -135,7 +133,7 @@

// find intersections

raycaster.setFromCamera( mouse, camera );
raycaster.setFromCamera( pointer, camera );

const intersects = raycaster.intersectObjects( scene.children );

Expand Down
16 changes: 7 additions & 9 deletions examples/webgl_interactive_cubes_gpu.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@

const pickingData = [];

const mouse = new THREE.Vector2();
const pointer = new THREE.Vector2();
const offset = new THREE.Vector3( 10, 10, 10 );

init();
animate();

function init() {

container = document.getElementById( "container" );
container = document.getElementById( 'container' );

camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 1000;
Expand Down Expand Up @@ -165,18 +165,16 @@
stats = new Stats();
container.appendChild( stats.dom );

renderer.domElement.addEventListener( 'pointermove', onMouseMove, false );
renderer.domElement.addEventListener( 'pointermove', onPointerMove );

}

//

function onMouseMove( e ) {
function onPointerMove( e ) {

e.preventDefault();

mouse.x = e.clientX;
mouse.y = e.clientY;
pointer.x = e.clientX;
pointer.y = e.clientY;

}

Expand All @@ -195,7 +193,7 @@

// set the view offset to represent just a single pixel under the mouse

camera.setViewOffset( renderer.domElement.width, renderer.domElement.height, mouse.x * window.devicePixelRatio | 0, mouse.y * window.devicePixelRatio | 0, 1, 1 );
camera.setViewOffset( renderer.domElement.width, renderer.domElement.height, pointer.x * window.devicePixelRatio | 0, pointer.y * window.devicePixelRatio | 0, 1, 1 );

// render the scene

Expand Down
14 changes: 6 additions & 8 deletions examples/webgl_interactive_cubes_ortho.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
let theta = 0;
let INTERSECTED;

const mouse = new THREE.Vector2();
const pointer = new THREE.Vector2();
const radius = 500;
const frustumSize = 1000;

Expand Down Expand Up @@ -87,7 +87,7 @@
stats = new Stats();
container.appendChild( stats.dom );

document.addEventListener( 'mousemove', onDocumentMouseMove );
document.addEventListener( 'pointermove', onPointerMove );

//

Expand All @@ -110,12 +110,10 @@

}

function onDocumentMouseMove( event ) {
function onPointerMove( event ) {

event.preventDefault();

mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
pointer.x = ( event.clientX / window.innerWidth ) * 2 - 1;
pointer.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

}

Expand Down Expand Up @@ -143,7 +141,7 @@

// find intersections

raycaster.setFromCamera( mouse, camera );
raycaster.setFromCamera( pointer, camera );

const intersects = raycaster.intersectObjects( scene.children );

Expand Down
14 changes: 6 additions & 8 deletions examples/webgl_interactive_lines.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
let container, stats;
let camera, scene, raycaster, renderer, parentTransform, sphereInter;

const mouse = new THREE.Vector2();
const pointer = new THREE.Vector2();
const radius = 100;
let theta = 0;

Expand Down Expand Up @@ -136,7 +136,7 @@
stats = new Stats();
container.appendChild( stats.dom );

document.addEventListener( 'mousemove', onDocumentMouseMove );
document.addEventListener( 'pointermove', onPointerMove );

//

Expand All @@ -153,12 +153,10 @@

}

function onDocumentMouseMove( event ) {
function onPointerMove( event ) {

event.preventDefault();

mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
pointer.x = ( event.clientX / window.innerWidth ) * 2 - 1;
pointer.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

}

Expand Down Expand Up @@ -186,7 +184,7 @@

// find intersections

raycaster.setFromCamera( mouse, camera );
raycaster.setFromCamera( pointer, camera );

const intersects = raycaster.intersectObjects( parentTransform.children, true );

Expand Down
16 changes: 7 additions & 9 deletions examples/webgl_interactive_points.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
const PARTICLE_SIZE = 20;

let raycaster, intersects;
let mouse, INTERSECTED;
let pointer, INTERSECTED;

init();
animate();
Expand Down Expand Up @@ -144,7 +144,7 @@
//

raycaster = new THREE.Raycaster();
mouse = new THREE.Vector2();
pointer = new THREE.Vector2();

//

Expand All @@ -154,16 +154,14 @@
//

window.addEventListener( 'resize', onWindowResize );
document.addEventListener( 'mousemove', onDocumentMouseMove );
document.addEventListener( 'pointermove', onPointerMove );

}

function onDocumentMouseMove( event ) {
function onPointerMove( event ) {

event.preventDefault();

mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
pointer.x = ( event.clientX / window.innerWidth ) * 2 - 1;
pointer.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

}

Expand Down Expand Up @@ -193,7 +191,7 @@
const geometry = particles.geometry;
const attributes = geometry.attributes;

raycaster.setFromCamera( mouse, camera );
raycaster.setFromCamera( pointer, camera );

intersects = raycaster.intersectObject( particles );

Expand Down
14 changes: 6 additions & 8 deletions examples/webgl_interactive_raycasting_points.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
let clock;
let toggle = 0;

const mouse = new THREE.Vector2();
const pointer = new THREE.Vector2();
const spheres = [];

const threshold = 0.1;
Expand Down Expand Up @@ -209,16 +209,14 @@
//

window.addEventListener( 'resize', onWindowResize );
document.addEventListener( 'mousemove', onDocumentMouseMove );
document.addEventListener( 'pointermove', onPointerMove );

}

function onDocumentMouseMove( event ) {
function onPointerMove( event ) {

event.preventDefault();

mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
pointer.x = ( event.clientX / window.innerWidth ) * 2 - 1;
pointer.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

}

Expand All @@ -245,7 +243,7 @@
camera.applyMatrix4( rotateY );
camera.updateMatrixWorld();

raycaster.setFromCamera( mouse, camera );
raycaster.setFromCamera( pointer, camera );

const intersections = raycaster.intersectObjects( pointclouds );
intersection = ( intersections.length ) > 0 ? intersections[ 0 ] : null;
Expand Down
Loading