1

I have some project for child http://kinosura.kiev.ua/sova/ and i need to check faceIndex of all cubes in screen.

Now i use intersections array from mouse, but is working only when user pointer at the cube.

How to make ray or rays from camera to all object to check faceIndex ?

I try to make four rays to cubes but if i set cube.position as origin of like this: raycaster.setFromCamera( cube1.positoin , camera )

I get empty array of intersections.

I also try to set static 2d vector as origin (get coordinate from mouse) but i have relative renderer size and this coordinate all time change... its not work(

Thanks for answer anyway.

Gleb Dolzikov
  • 776
  • 8
  • 13
  • possible duplicate of [Determine if a mesh is visible on the viewport according to current camera](http://stackoverflow.com/questions/17624021/determine-if-a-mesh-is-visible-on-the-viewport-according-to-current-camera) – stdob-- Jul 04 '15 at 09:18

1 Answers1

1

I suggest that you try another approach It appears that your cubes do not cover one another, relative to the camera view. So use the surface normals, and compare them to the view direction to determine if they are facing the camera or facing away from the camera by a simple one-per-polygon dot product.

When you are creating your geometry, before adding it a THREE.Mesh call .generateFaceNormals() on it.

Instead of ray casting, iterate through all faces, grab the surface normal of the face, transform relative to the view (inverse transpose of the object's matrix), then dot(). might sound complicated, at first, but it's actually just a couple of steps and much faster than doing a lot of raycasts (which will probably include this anyway!)

bjorke
  • 3,295
  • 1
  • 16
  • 20