How to make 3D lasso tool

i need help with something , someone kindly guide me

now i am using stock webgl , and i decided to add three.js

the webgl i am using , allows me to import Stl or obj and draw on its surface

so what i need to do is to draw 3D lasso on its surface to select area here link of webgl i am using
please someone help me

Here is a demo I put together demonstrating how to implement a lasso tool with the three-mesh-bvh library I maintain. The code can be found in the selection.js file in example folder.

Depending on your use case performance may be good enough without an acceleration structure. Here’s a rough overview of the algorithm I used for finding the lasso selection for every triangle that intersects the lasso shape:

  1. Construct a list of screen space line segments that represent the lasso shape drawn by the user.
  2. For every triangle in the geometry check if any part is within the lasso. If it is then consider the triangle selected.

To determine whether a triangle intersects the lasso:

  1. Project the triangle vertices and edge segments into screen space.
  2. Check if any of the triangle vertices are within the lasso shape, which you can use the ray-crossing algorithm for. If any of the crossing numbers are different between the points or if any of the crossing counts are odd then the triangle intersects the lasso shape.
  3. Check if any of the triangle line segments intersect any of the lasso line segments. If they do then the triangle intersects the lasso shape.
  4. Otherwise the triangle has not been intersected.

Spatial index data structures can be used to quickly cull large sets of triangles by determining if parent bounds are entirely encapsulated by the lasso shape or do not intersect at all which can give a bit of a performance boost if needed.

5 Likes

thank you for help , may you kindly tell me how to apply it to sculptgl ? i have been trying but i am lost ,
and is there away to make selection by put dots or points on the 3D model and once they are connected they select the area ? and as well move the dots or points over the 3D models to adjust the selected area
@gkjohnson

may you kindly tell me how to apply it to sculptgl

I cannot – I’m unfamiliar with sculptgl. It doesn’t look to be based on three.js, either.

is there away to make selection by put dots or points on the 3D model and once they are connected they select the area ? and as well move the dots or points over the 3D models to adjust the selected area

Of course it’s possible to implement this but I doubt anyone already has this feature created in a ready to use way. These are complex features and it’s probably best to make head way on your own implementation and ask more specific questions if you get stuck.

1 Like

By this question chance, may you kindly tell me how to determine whether a point within the lasso selection area? Thanks

The code for the lasso project is available here:

But you can look up “ray crossing algorithm” for how to determine point containment for arbitrary points.

1 Like

I have learned and implemented the way your lasso, but the selected area is not matched to the point position in the scene…still struggling with this challenge. but the way to draw the line is great!

Hi, @gkjohnson
Please tell me, if I want to use lasso to select multiple models in the scene, instead of selecting triangle faces, how do I confirm which models are selected?

in the demo provided above you can use the option selectModel…
image

you’ll likely be able to analyse the codebase provided and determine which parameters are switched to achieve this…

3 Likes

ok, thanks

Hi, @Lawrence3DPK @gkjohnson
If the scene has multiple models, how to assign toScreenSpaceMatrix

can you provide more context to your question? the environment you’re working in and ideally a live example of your setup?

In fact, my main problem is to use the lasso or, the rectangular box, the circle to select the model, so I asked how to select the entire model before.
Then, there will be many models in my scene, and I want to use these tools to select them