Three.js raycaster.intersectObjects fails (returns no results)

Hello everyone,

i’ve got a new filesystem + database data-editor in 2D and 3D in the works.
it’s MIT-licensed. :slight_smile:

but i’ve got a problem here : NicerApp-WebOS-v6.y.z/NicerAppWebOS/logic.vividUserInterface/v6.y.z/3D/na3D.js at 9e4de165f077be0f5764b55e427f00fff7946efe · NicerEnterprises/NicerApp-WebOS-v6.y.z · GitHub - var intersects2 stays empty

the live demo is at NicerApp WebOS Unified Interface
and the latest sources are at GitHub - NicerEnterprises/NicerApp-WebOS-v6.y.z

i’ve spent the last 2.5 days completely stuck on this issue, and i’d love to receive some help.
i promise to credit the tip giver with a link back to this thread here.

  1. Consider using meaningful names in code - currently it’s pretty much impossible to understand or debug it. With names like t, s2 etc. it’s becoming hard to indicate the purpose of specific variables.
  2. In any code besides short and simple JS scripts, avoid using vars - especially in the way you’ve used them in places like this - this, and all other, vars are moved to the top of the current (usually function / class, not the closest if or { ) context and are very likely to collide at some point. Use const instead.
  3. As for the raycasting, try setting the second parameter of intersectObjects to true.

t.s2 contains all the Mesh objects, as a flat list. it’s linked to t.items; t.items[1].model === t.s2[1] and t.s2[1].it points back to t.items[1].

var t is the current js class object; an abbreviation of ‘this’.

and giving intersectObjects a 2nd param of ‘true’, doesn’t fix this problem :frowning:

Even with partial explanations of what s2 is, there’s still no way to debug this code. It’s unformatted and uses vars all over the place :smiling_face_with_tear:

If setting recursive parameter to true didn’t work - then anything could be at fault. Console.log value of the objects you’re trying to intersect and the ray - see if these values make sense (raycasting is independent of rendering and visibility - so as long as you pass a properly pointing ray and an array of valid Three.Mesh objects, it should work ok.)

(Side-note: If you’re working with classes of 2000+ lines, and now you mention you store arrays of circular dependencies, you pretty much are not allowed to not use typescript.)

hi again :slight_smile:

i’ve fixed the problem.

and ‘var’ has a limited scope conditions set, ‘const’ is readonly and way too strict for my liking…
i do work a lot with large classes, my universal web theme editor that comes with my software is atm 2610 lines long. i have a small bunch of files like that. around a dozen.

1 Like