RayMeshGridIntersect returning weird values

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 03 March 2013   #1
RayMeshGridIntersect returning weird values


t=$sphere001
if myRMGI !=undefined then free myRGMI
for o in selection do
(
v1 = normalize((getknotpoint o 1 2)-(getknotpoint o 1 1))
			(	
id=1				
				myRMGI = raymeshgridintersect()
						myRMGI.initialize 10
					-- the raymeshgridinterface doesn't care if the added nodes aren't editable meshes
					-- as long as the nodes evaluate to an editable mesh
						myRMGI.addnode t
						myRMGI.buildgrid()
						-- test for intersection with target
						hcount = myRMGI.intersectray t.pos v1 true --false means don't check backfaces	
						ir = intersectray t (ray t.pos v1)
						print hcount
						-- get the closest hit
						if hcount > 0 then
						(
							for hit = 1 to hcount do
							(
										--local firsthit = rm.getClosestHit ()
										hitface = myRMGI.gethitface hit
										hitnorm = myRMGI.getHitNormal hit
										 hitdist = myRMGI.getHitDist hit
										hitPos = myRMGI.getHitBary hit
										p=point pos:hitpos
										format "%\n" #(t,hitface,hitnorm,hitdist,hitPos)
									
							)
						)
			)
		)


Create a sphere at 0,0,0
draw a couple of lines that intersect it

run this code. The returned values are not what I expected nor can I make any sense out of them. What am I missing here?

Thanks!
__________________
www.davetyner.com
 
Old 03 March 2013   #2
Looks like I have a fundamental misunderstanding of raymesh intersect. I am trying to find the intersection of a spline to a mesh, i think raymeshintersect only works with two meshes.
__________________
www.davetyner.com
 
Old 03 March 2013   #3
hitPos = myRMGI.getHitBary hit


does not return the hit position it returns the barycentric position within the hit face based on the face verts

to get the ray hit position, compute it from the initial ray and hit distance

Quote: Looks like I have a fundamental misunderstanding of raymesh intersect. I am trying to find the intersection of a spline to a mesh, i think raymeshintersect only works with two meshes.


it works with rays, segments, spheres and boxes against a single mesh.

Last edited by Klunk : 03 March 2013 at 07:22 PM.
 
Old 03 March 2013   #4
Problem in your case is you need to use the knot pos as your ray position not the t.pos. Currently you are searching from the Teapot position looking down the spline, when you need to be looking down the spline from knot to knot.

-Eric
__________________
"The Evil Monkey hiding in your closet."
 
Old 03 March 2013   #5
Originally Posted by PiXeL_MoNKeY: Problem in your case is you need to use the knot pos as your ray position not the t.pos. Currently you are searching from the Teapot position looking down the spline, when you need to be looking down the spline from knot to knot.

-Eric


YEP! Thank you Eric and Klunk! It's working great now. I am aware of the redundantly redundant placement of the dummy.



for h in objects where superclassof h == helper do delete h
d = dummy pos:(getknotpoint $Line001 1 1)

if myRMGI !=undefined then free myRGMI


v1 = normalize((getknotpoint $Line001 1 2)-(getknotpoint $Line001 1 1))

t = $sphere001
			(	
id=1				
				myRMGI = raymeshgridintersect()
						myRMGI.initialize 10
						myRMGI.addnode t
						myRMGI.buildgrid()
						hcount = myRMGI.intersectray d.pos v1 true --false means don't check backfaces	
						if hcount > 0 then
						(
							for hit = 1 to hcount do
							(
										--local firsthit = rm.getClosestHit ()
										hitface = myRMGI.gethitface hit
										hitnorm = myRMGI.getHitNormal hit
										 hitdist = myRMGI.getHitDist hit
										
										hitPos = d.pos+(v1)*hitdist
										p=point pos:hitpos
										format "%\n" #(hitface,hitnorm,hitdist,hitPos)
									
							)
						)
			)
__________________
www.davetyner.com
 
Old 03 March 2013   #6
I take that back. raymeshgridintersect is blowing my memory out. I am sending it about 700 splines to check against a target and my memory usage skyrockets when it enters the function.

skyrockets = 2.2GB usage to 24GB usage in a few seconds.
__________________
www.davetyner.com
 
Old 03 March 2013   #7
you are probably doing something wrong.... i use raymeshgridintersect on 100,000+ poly terrain within a viewport redraw call back to project into the terrain so you can track the terrain in walkthrough mode. Runs at about 300 fps so after a minute or so thats approx 20,000 ray tests against the voxel grid and I don't get any memory spikes.
 
Old 03 March 2013   #8
It looks like the problem was caused by not clearing the array returned by the function.

I did two things and there is no more issue. I declared the array of hits as a global array, and cleared the array with arr=#() after each return. <---(my hunch is that was it)

Now there is no more issue.
__________________
www.davetyner.com
 
Old 03 March 2013   #9
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:01 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.