vagran / dxf-viewer

DXF 2D viewer written in JavaScript
Mozilla Public License 2.0
310 stars 97 forks source link

Raycaster #16

Open ferhat-aslan opened 1 year ago

ferhat-aslan commented 1 year ago

Hi, Dear Developer, I really loved your job. It is the fastest and most comprehensive dxfviewer. I am trying to implement Threejs.Raycaster. But I couldn't. I think The Vertices in buffer geometry do not contain z values. This is causing the error. I tried to add z value to vertices. But I could not. This is beyond my abilities. I hope you add the raycaster feature in the future. I would love to work with you on this. best regards, ferhat

vagran commented 1 year ago

Hello, What is the end result you are trying to achieve? If that is a DXF primitive picking, it is not so easy to implement. Using three.js built-in features might not be helpful, because the viewer batches many primitives in a big rendering batches (anything which can be drawn by a single draw call, usually same type and material), so it loses releation between rendering entities and source primitives. This is done to maximize rendering performance. The primitives picking could be done by introducing some addional vertex attributes with feature IDs, and utilizing some common picking techniques (like rendering twice, once in custom framebuffer to fill it with IDs and pick from, second time in displayed canvas). That sounds like next big feature, I would like to implement this, but unfortunately I cannot commit now anything about possible timeframe.

ferhat-aslan commented 1 year ago

Hi, Thank you very much your reply, I mean that selecting objects such as line and getting object ID or points. I added z values to vertices. by using geometry.setattributes(). But raycasting is not working real-time.(slow and not correct).Now I will try GPU picking. If you give some resources(links, articles) about method that you mentioned. I may work on that. Thanks in advance, best regards, Ferhat

vagran commented 1 year ago

What I mentioned is something like described here: https://webglfundamentals.org/webgl/lessons/webgl-picking.html Among with modifying rendering pipeline it also requires saving IDs of each primitive as vertex atribute. Since we have 2D-only viewer, probably the depth buffer can be used alternatively instead of separate redering pass, however I am not sure if WebGL guarantees it has enough bits per sample for storing IDs.

ferhat-aslan commented 1 year ago

Ok, Thank you very much everything. best regards,

dotoritos-kim commented 1 year ago

I hope this issue is resolved too.

jdh-invicara commented 1 year ago

I'd be very interested in any proof of concept work done on Raycasting for picking elements of the model.

KaivnD commented 1 year ago

+1

vagran commented 1 year ago

This feature is planned for the next major release. It requires significant architectural changes to the library, which will make it very different from its current state as just a dummy renderer.

KaivnD commented 1 year ago

check out this one three-cad-viewer he made a nested group class for scene structure, might be helpful.

dotoritos-kim commented 1 year ago

Hi, Thank you very much your reply, I mean that selecting objects such as line and getting object ID or points. I added z values to vertices. by using geometry.setattributes(). But raycasting is not working real-time.(slow and not correct).Now I will try GPU picking. If you give some resources(links, articles) about method that you mentioned. I may work on that. Thanks in advance, best regards, Ferhat

How did you do it? I would be grateful if you could explain it briefly.

feslan commented 1 year ago

Hi, Thank you very much your reply, I mean that selecting objects such as line and getting object ID or points. I added z values to vertices. by using geometry.setattributes(). But raycasting is not working real-time.(slow and not correct).Now I will try GPU picking. If you give some resources(links, articles) about method that you mentioned. I may work on that. Thanks in advance, best regards, Ferhat

How did you do it? I would be grateful if you could explain it briefly.

Hi,It's been a long time, I don't remember exactly, I added z(0) value to the 3rd element of the position attribute array with a for loop.then raycaster started working without error anymore. but not sensitive. and often showed incorrect values.