Browse Source

Fix raycast display

Garrett Johnson 5 years ago
parent
commit
339c207832
4 changed files with 100 additions and 49 deletions
  1. 74 30
      example/bundle/example.e31bb0bc.js
  2. 1 1
      example/bundle/example.e31bb0bc.js.map
  3. 1 1
      example/bundle/index.js
  4. 24 17
      example/index.js

File diff suppressed because it is too large
+ 74 - 30
example/bundle/example.e31bb0bc.js


File diff suppressed because it is too large
+ 1 - 1
example/bundle/example.e31bb0bc.js.map


+ 1 - 1
example/bundle/index.js

@@ -212,7 +212,7 @@ var parent = module.bundle.parent;
 if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
   var hostname = "" || location.hostname;
   var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
-  var ws = new WebSocket(protocol + '://' + hostname + ':' + "61189" + '/');
+  var ws = new WebSocket(protocol + '://' + hostname + ':' + "52787" + '/');
 
   ws.onmessage = function (event) {
     checkedAssets = {};

+ 24 - 17
example/index.js

@@ -132,6 +132,7 @@ function init() {
 	const rayRing = new Mesh( new TorusBufferGeometry( 1.5, 0.2, 16, 100 ), rayIntersectMat );
 	rayIntersect.add( rayRing );
 	scene.add( rayIntersect );
+	rayIntersect.visible = false;
 
 	reinstantiateTiles();
 
@@ -188,23 +189,6 @@ function onMouseMove( e ) {
 
 	mouse.x = ( e.clientX / window.innerWidth ) * 2 - 1;
 	mouse.y = - ( e.clientY / window.innerHeight ) * 2 + 1;
-	raycaster.setFromCamera( mouse, camera );
-
-	const results = raycaster.intersectObject( tiles.group, true );
-	if ( results.length ) {
-
-		const closestHit = results[ 0 ];
-		const point = closestHit.point;
-		const normal = closestHit.face.normal;
-
-		rayIntersect.position.copy( point );
-		rayIntersect.lookAt(
-			point.x + normal.x,
-			point.y + normal.y,
-			point.z + normal.z
-		);
-
-	}
 
 }
 
@@ -236,6 +220,29 @@ function animate() {
 
 	}
 
+	raycaster.setFromCamera( mouse, camera );
+
+	const results = raycaster.intersectObject( tiles.group, true );
+	if ( results.length ) {
+
+		const closestHit = results[ 0 ];
+		const point = closestHit.point;
+		const normal = closestHit.face.normal;
+
+		rayIntersect.position.copy( point );
+		rayIntersect.lookAt(
+			point.x + normal.x,
+			point.y + normal.y,
+			point.z + normal.z
+		);
+		rayIntersect.visible = true;
+
+	} else {
+
+		rayIntersect.visible = false;
+
+	}
+
 	stats.begin();
 	render();
 	stats.end();