xeokit / xeokit-sdk

Open source JavaScript SDK for viewing high-detail, full-precision 3D BIM and AEC models in the Web browser.
https://xeokit.io
Other
714 stars 286 forks source link

Is possible to read geometry from VBOGeometry shapes? #1584

Closed campog424 closed 2 months ago

campog424 commented 2 months ago

Hi,

Before asking anything, here is some context:

This is an XY problem derived from a little experiment: having a model and a section, I want to calculate the points where the model and the section intersect:

Dibujito

I saw CrossSections and it was a good approach, but I need to go a little further and obtain the coordinates of the model's points so I can calculate where they intersect. I tried to get the geometry data but it seems that I'm loading the model's data as VBOGeometry, with the ups and downs of having the data in the GPU. Realizing that, I have considered using ReadableGeometry but I don't think it will be suitable for a real case scenario since I plan to test this on a big XKT and the memory footprint can be a bit too much to handle.

So, I am curious about how the SDK handles things like picking or working with the geometry when it works with VBOGeometry. Reading the code, I see that there are methods that take an array of positions and a decodeMatrix and they convert them to XYZ coordinates, but I don't really know how to do the same given access to the GL object and the view.

And now to the question:

Is it possible to read the stored geometry from the GPU? Is this more a WebGL problem or just the particular way that the SDK handles the XKTs?

paireks commented 2 months ago

Hey @campog424!

I discussed it with Lindsay in the past, cause I was also curious about the same thing, short answer is we probably cannot get these geometries back. Sections are done inside shaders meaning it only displays it differently, but we cannot get the "results" of it. All shaders are doing is drawing things on screen. Lindsay mentioned there are some hacky ways people make shaders return something, but these are more or less tricks.

One of the possible solutions for the future would be to experiment with WebGPU, as it offers some more functionalities that potentially could be used for section calculation. But it is topic for Xeokit v3.

To calculate and return actual coordinates of intersection we'd have to calculate such intersection using traditional JS code (or some library), calculating it on CPU. It may be slower though.

xeolabs commented 2 months ago

Hi @campog424, @paireks, although VBOGeometry only stores geometry GPU memory, we can obtain things like the World-space 3D position of a point picked on its surface by way of the picking shaders.

FYI it works like this:

I hope gives some insight..

campog424 commented 2 months ago

Thank you very much, @paireks @xeolabs

@xeolabs, could you help me a bit more with what you are proposing? I don't fully understand it, and I would appreciate it if you could provide some screenshots of how you would do the process. It would be perfect if you could do it with a simple object like a cube or something similar and show it.

To clarify my initial query, what I am trying to achieve is to represent in a 2D section what I see in the 3D section after making the section through a plane on the 3D object. I would like to be able to obtain the information of the edges and vertices of said section in order to represent it in a DXF file or similar.