-
Notifications
You must be signed in to change notification settings - Fork 229
Description
Hi Nathan,
Here is a draft: examples/raycasting-triangles.html
Please do not look at the code inside the html page, i've tried different options, copied & pasted some of your example, without cleaning anything... ok.
Here are the line that compute the triangle raycast. Not so much. I wrote it my style (no semicolon, leading blank line, no inline-if) because it's a draft, if there's a PR i will rewrite it in ogl actual style.
It's not exactly the same code than three.js which i do not really understand in the details, but we are trying to solve the same equation.
The one i use is O + k * D = A + ku * U + kv * V
For better performances, i prefer to dereference all the component (x, y, z) from the vector, and write directly dot and cross product rather than calling function (since calculations are not as dense as in the case of matrices). Generally speaking i do not think that seeking optimization in javascript is a primary goal, but here, since meshes can have thousands of triangles, i prefer to be careful.
If the code for raycast triangle seems ok, i still have bug with non-indexed geometry (sometimes hover produce flickering, triangles are not drawn under the mouse):
examples/raycasting-triangles.html?fox=true.
I do not have time yet to understand why. A first bug came from null triangle than can be provided in models, so i wrote a check first. For non-indexed geometries, every 3 vertices from the position attributes represent a triangle right?
Also, raycast may have some option (backface culling, distance max), actually i only return the closest triangles, but it may be useful to have all the triangles (in case of non-convex geometries). And also actually the test is made mesh by mesh, but may be done from any node (eg: scene) by walking through every child.
At last, is there actually a way to display debug lines / dot / vectors?
It could be useful to display pivot from any Transform, normal from raycast etc. What could be the best option to achieve that do you think?
Many questions. Not sure the current issue is really concerned. Should we move the discussion elsewhere?
Originally posted by @jniac in #38 (comment)
