question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Undefinend values in planeBufferGeometry causes raycaster to return empty

See original GitHub issue
Description of the problem

I create a planeBufferGeometry and fill it like so:

var positions = new Float32Array(grid.elevations.length * 3).fill(undefined);
for(stuff){
 positions[i * 3 + 0] = xpos ;
 positions[i * 3 + 1] = ypos;
 positions[i * 3 + 2] = (isNaN(zpos)) ? undefined : zpos;
}

var geometry = new THREE.PlaneBufferGeometry();
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
var terrainMesh = new THREE.Mesh(geometry, material);
terrainMesh.name = myMesh;
scene.add(terrainMesh)

then raycast using:

raycaster.setFromCamera(mouse, camera);
var intersects = raycaster.intersectObject(scene.getObjectByName('myMesh'));

intersects is always empty. If I do this: vertices[i * 3 + 2] = (isNaN(zpos)) ? -1: zpos;

I get a result;

Currently I’m thinking best work around is making a second planeBufferGeometry and assign the undefined values a -1. Then handle if(z = -1) . This position array can get rather large though and having another one is not ideal.

Three.js version
  • Dev
  • [ X] r84
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
makccommented, Jul 20, 2017

@kpetrow what I am saying is that if you are (obviously) not happy with what 3js puts into boundingSphere/Box, you could do this:

geometry.boundingSphere = new THREE.Sphere (yourCenter, yourRadius);
geometry.boundingBox = new THREE.Box3 (yourMin, yourMax);

instead of relying on geometry.computeBoundingSphere/Box calls. this will allow you to bypass the checks that you are saying are in the way of finding intersections, right?

0reactions
makccommented, Jul 20, 2017

Is there a better geometry type for surface data?

that might be BufferGeometry. if you are not happy with (0,0,0)-(0,0,0)-(0,0,0) triangles in PlaneBufferGeometry, you can create your own geometry avoiding the need to do something about triangles with missing data - by not creating these triangles in the 1st place.

Read more comments on GitHub >

github_iconTop Results From Across the Web

three.js - Raycaster.intersectObjects() not returning anything?
My Solution. The function below takes an empty array ( intersects ). It searches each child in scene for THREE Group objects and...
Read more >
three.js - Apple Open Source
isInteger = function ( value ) { return typeof value === 'number' ... target === null ) { throw new TypeError( 'Cannot convert...
Read more >
https://network.aia.org/HigherLogic/System/Downloa...
subVectors(b.center,this.origin);var d=a.dot(this.direction),e=a.dot(a)-d*d,g=b.radius*b.radius;if(e>g)return null;g=Math.sqrt(g-e);e=d-g;d+=g;return ...
Read more >
third_party/js/three.js/three.js - geovelo - Git at Google
value : function ( target ) {. 'use strict';. if ( target === undefined || target === null ) {. throw new TypeError(...
Read more >
JavaScript 3D library
ColorKeyframeTrack( trackName, times, values ); return new THREE.AnimationClip( null, duration, [ track ] ); }; ... function three.CompressedTexture ( mipmaps, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found