[Closed] mesh intersection = deletion
I’m sure this question has been asked before.
I simply just want to take a select of objects and run a script which would delete them based on whether or not they test true for colliding meshes (*not bounding boxes)
Example:Image
delete all blue boxes which intersect with ring.
Maybe do IntersectRayEX I believe, from each box upwards, and see if it hits any nodes (donut) and if it does, delete it.
This partially works but I’m not sure if it is the best way to go about doing so?
Thoughts everyone?
fn find_intersection z_node node_to_z =
(
local testRay = ray node_to_z.pos [0,0,-1]
local nodeMaxZ = z_node.max.z
testRay.pos.z = nodeMaxZ + 0.0001 * abs nodeMaxZ
intersectRay z_node testRay
)
for i in selection do
(
int_point = find_intersection $Circle001 i
if int_point != undefined then i.wirecolor = blue
)--end i loop
it might be a solution for only very specific cases. in real life the geometry intersection is very complicated thing. to make the calculation faster real-time engines use some tricks, i.e. get intersection bbox with bbox, bound primitive (box, sphere, cylinder, capsule) with a primitive, convex hulls intersection…
so this kind of task has to be simplified for getting enough accuracy.
if you need true intersection one of most popular technique is voxel (grid) method. to get progressive accuracy some techniques use the octree methods. there are some good octree c# free libraries in internet. try to find…
Yeah, I mixed it up, was thinking of intersectScene, but ya, your method works well.
I’m not sure how else you’d do it? Your method seems clean and fast.
with redraw off with undo off
(
delete objects
gc()
xcount = 24
ycount = 24
inipos = [0,0,0]
boxsize = 10.
spacing = 2.
nodes = #()
setCommandPanelTaskMode mode:#create
-- create scene:
-- create boxes:
for y=0 to ycount-1 do
(
for x=0 to xcount-1 do
(
b = box name:(formattedprint (y*xcount + x + 1) format:"04d") \
width:boxsize length:boxsize height:boxsize \
pos:(inipos + [x*(boxsize+spacing), y*(boxsize+spacing), 0]) \
wirecolor:yellow
append nodes b
)
)
-- create selection mesh:
rad = xcount*(boxsize + spacing)*0.4
selnode = Torus name:"sel_node" segs:24 sides:12 radius1:rad radius2:(0.7*boxsize) mapcoords:off \
pos:(inipos + [rad, rad, boxsize/2]*1.1) wirecolor:green
-- add volume select mofifier:
vsel = VolumeSelect volume:3 level:2 type:1
vsel.node = selnode
disablerefmsgs()
t1 = timestamp()
addmodifier nodes vsel
-- collect selected/intersected nodes:
selected = for n in nodes where n.mesh.selectedfaces.count > 0 collect n
-- delete modifier:
deletemodifier nodes vsel
selected.wirecolor = red
t2 = timestamp()
enablerefmsgs()
format ">> time:%
" (t2-t1)
format " nodes:% selected:%
" nodes.count selected.count
)
it was not boring for me…
Well It says the z direction right now.
I was wondering if it checks an object in all directions because it seems to be missing some object right now when i run it.
It surprisingly runs fast than i expected it to.
So is that the best way to test this scenario?
It seems to miss objects when i test it?
I have a feeling that you are looking for a method that is fast and accurate at the same time, if so you chasing a ghost.
Where could I find examplea to do so using bouding primitive it convex hulls. Is like to stick within maxscriot and not expand to c# for the time being thanks though for letting me know as that being an option.
Is doing a convex hull type of calculation something that would be a little more accurate and better?
My recent Shrink Wrap script I made can do convex hulls in a sense, which I didn’t plan in the first place.
You could do the same, which wouldn’t be necessarily 100% accurate, but is fast and should work for what u want. I just use MeshProjIntersect() for something like on your donut, and take a geosphere, and for each vert in the geo sphere, get the closest hit pos on the donut to make ur convex hull.
Then from there just do raycast like before at the convex hull?