Skip to content

Commit

Permalink
shows coordinates, but not correct, but be should have checked normal…
Browse files Browse the repository at this point in the history
…ization
  • Loading branch information
Zvyozdo4ka committed Sep 15, 2021
1 parent 25f6812 commit ab78a1d
Showing 1 changed file with 52 additions and 35 deletions.
87 changes: 52 additions & 35 deletions extract point.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import * as THREE from './three.js-dev/build/three.module.js';

//import {Vector3} from './three.js-dev/src/math/Vector3.js';

import Stats from './three.js-dev/examples/jsm/libs/stats.module.js';
import { GUI } from './three.js-dev/examples/jsm/libs/dat.gui.module.js';

Expand All @@ -32,12 +34,16 @@
let group;
let raycaster;
let line;
let toggle = 0;
let clock;

var intersection = {
intersects: false,
point: new THREE.Vector3(),
normal: new THREE.Vector3()
};
let p= new THREE.Vector3();
let n;

console.log("normal", intersection.normal);

Expand Down Expand Up @@ -84,6 +90,8 @@

function init() {

clock = new THREE.Clock();

renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
Expand All @@ -94,12 +102,12 @@

scene = new THREE.Scene();

camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 120;
camera = new THREE.PerspectiveCamera( 10, window.innerWidth / window.innerHeight, 1, 3000 );
camera.position.z = 500;

const controls = new OrbitControls( camera, renderer.domElement );
controls.minDistance = 50;
controls.maxDistance = 200;
controls.maxDistance = 1000;

scene.add( new THREE.AmbientLight( 0x443333 ) );

Expand Down Expand Up @@ -137,25 +145,25 @@

} );

window.addEventListener( 'pointerdown', function () {

moved = false;
console.log("down");

} );

window.addEventListener( 'pointerup', function ( event ) {
console.log("up");

if ( moved === false ) {

checkIntersection( event.clientX, event.clientY );

if ( intersection.intersects ) shoot();

}

} );
// window.addEventListener( 'pointerdown', function () {
//
// moved = false;
// console.log("down");
//
// } );
//
// window.addEventListener( 'pointerup', function ( event ) {
// console.log("up");
//
// if ( moved === false ) {
//
// checkIntersection( event.clientX, event.clientY );
//
// if ( intersection.intersects ) shoot();
//
// }
//
// } );

window.addEventListener( 'pointermove', onPointerMove );

Expand All @@ -182,20 +190,25 @@
raycaster.setFromCamera( mouse, camera );
raycaster.intersectObject( group, false, intersects );

console.log("intersects", intersects);
console.log("raycaster", raycaster);
const intersections = raycaster.intersectObjects( group );
intersection.intersects = ( intersections.length ) > 0 ? intersections[ 0 ] : null;

if ( (intersects.length > 0) && toggle > 0.02 ) {

if ( intersects.length ===1 ) {
toggle = 0;

const p = intersects[ 0 ].point;
mouseHelper.position.copy( p );
intersection.point.copy( p );
console.log("p", p);
p = intersects[ 0 ].point;
console.log("p", p);

console.log("4", intersection.normal);
console.log("mouse", mouseHelper.position);
console.log("p", p);
console.log("mouse", mouseHelper.position);
mouseHelper.position.copy( p );
console.log("mouse", mouseHelper.position);

const n = intersects[ 0 ].face.normal.clone();
intersection.point = p;
console.log(intersection);

n = intersects[ 0 ].face.normal.clone();
n.transformDirection( group.matrixWorld );
n.multiplyScalar( 10 );
n.add( intersects[ 0 ].point );
Expand All @@ -208,6 +221,8 @@
positions.setXYZ( 1, n.x, n.y, n.z );
positions.needsUpdate = true;

console.log(intersection);

console.log("{x:", intersection.point.x,", y:", intersection.point.y, ",z:", intersection.point.z, "}");

intersection.intersects = true;
Expand All @@ -223,6 +238,8 @@
normal: new THREE.Vector3()
};
intersects.length = 0;
toggle += clock.getDelta();
// p=0;

}

Expand All @@ -246,7 +263,7 @@
function shoot() {

position.copy( intersection.point );
orientation.copy( mouseHelper.rotation );
//orientation.copy( mouseHelper.rotation );

if ( params.rotate ) orientation.z = Math.random() * 2 * Math.PI;

Expand Down Expand Up @@ -364,8 +381,8 @@

//group.position.y = 2;
// group.position.z = -9;
group.rotation.x = - Math.PI*1;
group.rotation.y = - Math.PI*2;
// group.rotation.x = - Math.PI*1;
// group.rotation.y = - Math.PI*2;

scene.add( group );
group.scale.set(10, 10, 10);
Expand Down

0 comments on commit ab78a1d

Please sign in to comment.