[Closed] mesh intersection = deletion
It’s ok if it is a little rough. That sounds a possible solution or something to build off of.
Would there be a possible way to do primitive based calculations. Like box or sphere ? Like bounding box. Unless there is a convex solution.
I’m not sure if i see the benefit of doing the convex hull process that your mentioning verses what I’m doing right now
I messed with the voxel grid stuff.
I’m not getting any results from the hits?
I feel like this could possibly resolve what I’m after.
(
theSphere = selection as array
theGeoSphere = $Tube001
theObjectsHit = #() --init. an arrawy to collect face selection
rm = RayMeshGridIntersect () --create an instance of the Reference Target
rm.Initialize 1 --init. the voxel grid size to 10x10x10
rm.addNode theSphere --add the sphere to the grid
rm.buildGrid () --build the grid data (collecting faces into the grid voxels)
theGSMesh = snapshotasmesh theGeoSphere --grab the TriMesh of the Geosphere
for v = 1 to theGSMesh.numverts do --go through all verts of the Geosphere
(
thePos = getVert theGSMesh v --get the position of the vertex
theNormal = -(getNormal theGSMesh v) --get the normal of the vertex, reverse direction
theHitsCount = rm.intersectRay thePos theNormal false --intersect the ray with the sphere
if theHitsCount > 0 then --if have hit anything...
(
theIndex = rm.getClosestHit () --get the index of the closest hit by the ray
theFace = rm.getHitFace theIndex --get the face index corresponding to that indexed hit
append theObjectsHit theFace --add to the face array to select the face...
)
else
format "The Ray % Missed
" v
)
for obj in theObjectsHit do obj.wirecolor = blue
)
Both RayMeshGridIntersect and MeshProjIntersect only accept 1 mesh to build the voxel grid.
It looks like your trying to do the opposite, add the objects to hit as an array into it?
That’s why I was saying, ud want to either convert your torus to a Mesh or collapse other objects as snapshots into 1 mesh and put that into the voxel grid. It has to be a mesh that goes in.
So if you snapshotted ur Torus, put that in, set Gridsize to like 25 and built, then for each box pos , do the closestHit check in MeshProjIntersect to get the hit or not on the Torus, and if so, collect the box.
This is a function I setup to call for each vert pos in a mesh, using a global built MeshProjIntersect setup.
--GET Closest Hit
fn tTclosestPointOnSurf surf refPos =
(
tTShrinkHitTest.closestFace refPos doubleSided:true
closestPoint = tTShrinkHitTest.getHitPos()
closestFace = tTShrinkHitTest.GetHitFace()
return #(closestPoint,closestFace)
)
I’ve attached the script and file that I’m testing on.
It is registering objects that are not getting hit by the tube as “getting hit” resulting in changing their wirecolor to blue. What would be a solution to this? The voxel processing method?
My other thought, which would not be ideal in anyway would be to snapshot the mesh and break every polygon into a separate object and then skinwrap it to the original mesh and then do a bounding box collision test for each object in the scene versus each object that represented the tube.
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 t = 1 to 20 do
(
slidertime = t
for i in selection do
(
int_point = find_intersection $Tube001 i
if int_point != undefined then i.wirecolor = blue
)--end i loop
)
Such a clever idea. That works out great. It is exactly what I was after. I will mess around with it today and see what result I get and if it works in the long run of things for what my main goal is.
I didn’t know vol select could work like that.
Very cool.
Obviously this method isn’t the fastest method inside of max as of right now.
If one is to use a gizmo how do I then detect collision? Is it using the same method?
Could someone test this out and let me know what I’m missing.
For some reason it thinks the cubes within the middle of the torus are being selected by the mesh when in reality they are not intersecting it at all.
But as a result of this it is testing true when it shouldn’t be.
Just take the below script and run it. You’ll notice right away what is going wrong.
(
--//add key z
fn fnAnimate obj atTime =
(
obj.position.controller.Z_Position.controller = bezier_float ()
sKey = addNewKey obj.position.controller.Z_Position.controller atTime
endKey = addNewKey obj.position.controller.Z_Position.controller (atTime+3f)
endKey.value -= 40.0
)
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 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
)
)
subSample = 1 --subsample for fast moving objects
-- create selection mesh:
_objArr = nodes
_hitNodes = #()
collisionObj = Torus name:"sel_node" segs:24 sides:24 radius1:80 radius2:20 mapcoords:on pos:[150,-100,0] wirecolor:green
in coordsys local rotate collisionObj (EulerAngles 90 0 0)
with animate on (at time 30 (collisionObj.pos = [150,350,0]))
-- add volume select mofifier:
vsel = VolumeSelect level:1 type:1 method:0 volume:3 node:collisionObj --//Add volume select for "mesh intersection" testing
disablerefmsgs()
t1 = timestamp()
for t in animationrange.start to animationrange.end by subSample do --Go frame by frame and find the objects colliding with the actual mesh of the collisionObj, but only one time per object)
(
at time t
(
local _tmpArr = for obj in _objArr where (intersects collisionObj obj) collect obj
addmodifier _tmpArr vSel
for obj in _tmpArr where obj.mesh.selectedVerts.count > 0 do
(
append _hitNodes #(obj,t)
idx = findItem _objArr obj
if idx != 0 do deleteItem _objArr idx
)
deletemodifier _tmpArr vSel --// Delete VS modifier:
)
)
t2 = timestamp()
enablerefmsgs()
format ">> time:%
" (t2-t1)
)
for o in _hitNodes do
(
obj = o[1]
theTime = o[2]
obj.wirecolor = red
fnAnimate obj theTime
)
)