CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 03-14-2006, 02:25 PM   #1
PEN
R&D/Technical Director
 
PEN's Avatar
portfolio
Paul Neale
PEN Productions
Canada
 
Join Date: Jun 2002
Posts: 7,416
Hit test viewport grid?

Is there a method for hit testing the viewport grid? Not a grid object but the grid plane that you would build an object on? I don't want to use mouse tools, I'm thinking more along the lines of intersectRay or rayMeshGridIntersect. I just can't sort you how to get either to just get the viewport grid. Any one have a solution to this? I know that I could put a temporary grid object in there but I would rather not.
__________________
Paul Neale
http://paulneale.com
 
Old 03-14-2006, 08:21 PM   #2
JHaywood
Know-it-All
 
JHaywood's Avatar
portfolio
James Haywood
Senior Technical Artist
Bungie Studios
Seattle, USA
 
Join Date: Jun 2005
Posts: 395
I could be way off, but since you always know where the viewport grid is, do you even need to test for it? What exactly are you trying to do?
__________________
Website
Blog
 
Old 03-14-2006, 08:53 PM   #3
PEN
R&D/Technical Director
 
PEN's Avatar
portfolio
Paul Neale
PEN Productions
Canada
 
Join Date: Jun 2002
Posts: 7,416
Based on your mouse position on screen I want the position on the grid. Without using the built in tools.
__________________
Paul Neale
http://paulneale.com
 
Old 03-15-2006, 12:47 AM   #4
JHaywood
Know-it-All
 
JHaywood's Avatar
portfolio
James Haywood
Senior Technical Artist
Bungie Studios
Seattle, USA
 
Join Date: Jun 2005
Posts: 395
Ah, I see. Well, it's going to take a smarter man than I to help you with that one.
__________________
Website
Blog
 
Old 03-15-2006, 01:24 AM   #5
magicm
Maxscript Generator
 
magicm's Avatar
CGSociety Member
portfolio
Martijn van Herk
VFX Technical Director
Freelance
Rotterdam, Netherlands
 
Join Date: Jun 2002
Posts: 1,139
This script will place a point helper on the home grid (or a user grid when it's activated) at the current mouse position. Not entirely without built-in tools but it works

point pos:((gw.getPointOnCP mouse.pos) * (getCPTM()))

Cheers,
Martijn
 
Old 03-15-2006, 12:08 PM   #6
PEN
R&D/Technical Director
 
PEN's Avatar
portfolio
Paul Neale
PEN Productions
Canada
 
Join Date: Jun 2002
Posts: 7,416
That is what I'm looking for I only just started digging into what pointOnCp does. Perfect, I think that I might be back on track.
__________________
Paul Neale
http://paulneale.com
 
Old 03-15-2006, 06:37 PM   #7
PEN
R&D/Technical Director
 
PEN's Avatar
portfolio
Paul Neale
PEN Productions
Canada
 
Join Date: Jun 2002
Posts: 7,416
And here is a hit test for an object if any one is interested. It returns the ray of the face that it hits.

Code:
fn hitTest = ( theRay=mapScreenToWorldRay mouse.pos hitRay=intersectRay $ theRay )
__________________
Paul Neale
http://paulneale.com
 
Old 03-15-2006, 06:44 PM   #8
PEN
R&D/Technical Director
 
PEN's Avatar
portfolio
Paul Neale
PEN Productions
Canada
 
Join Date: Jun 2002
Posts: 7,416
Or a more complete one.

Code:
fn hitTest = ( theRay=mapScreenToWorldRay mouse.pos for x in objects do ( hitRay=intersectRay x theRay if hitRay!=undefined then ( return hitRay ) ) undefined )
__________________
Paul Neale
http://paulneale.com
 
Old 03-15-2006, 08:16 PM   #9
stuh505
Lord of the posts
 
stuh505's Avatar
portfolio
Stu H
USA
 
Join Date: Jan 2005
Posts: 2,012
Thanks PEN, added this to my little collection of script notes
 
Old 03-15-2006, 08:47 PM   #10
PEN
R&D/Technical Director
 
PEN's Avatar
portfolio
Paul Neale
PEN Productions
Canada
 
Join Date: Jun 2002
Posts: 7,416
Here is the latest, this one will get the closest face to you, the last would only return the first object that it hit. Returns undefined if it does hit anything and if it does it returns a ray.

Code:
fn hitTest = ( theRay=mapScreenToWorldRay mouse.pos dist=undefined theHit=undefined for x in objects do ( hitRay=intersectRay x theRay if hitRay!=undefined then ( tempDist=distance hitRay.pos theRay.pos if dist==undefined or tempDist<dist then ( dist=tempDist theHit=hitRay ) ) ) theHit )
__________________
Paul Neale
http://paulneale.com
 
Old 03-15-2006, 11:53 PM   #11
magicm
Maxscript Generator
 
magicm's Avatar
CGSociety Member
portfolio
Martijn van Herk
VFX Technical Director
Freelance
Rotterdam, Netherlands
 
Join Date: Jun 2002
Posts: 1,139
I haven't tested this, but these changes might make it a liiitle bit quicker:

Code:
for x in geometry do
Code:
dist = 1e+008 --> if tempDist < dist then
This way the dist variable doesn't need to be tested for undefined for each iteration.


Don't think it'll make much difference but it might be worth trying.

Cheers,
Martijn
 
Old 03-16-2006, 12:02 PM   #12
PEN
R&D/Technical Director
 
PEN's Avatar
portfolio
Paul Neale
PEN Productions
Canada
 
Join Date: Jun 2002
Posts: 7,416
Thanks Martijn, for dist I had that originaly but changed if for some reason. Maybe I will do a speed test on that and see what it does for me. As for just looping through geo well I didn't catch that at all, thanks that will make it much faster if used in a big scene.
__________________
Paul Neale
http://paulneale.com
 
Old 03-16-2006, 02:08 PM   #13
Rivendale
Right here
 
Rivendale's Avatar
portfolio
Carl-Mikael Lagnecrantz
CG artist
Stockholm, Sweden
 
Join Date: Apr 2002
Posts: 1,338

Hey, here is the way I do it to get a position on the grid:

Code:
pixelpos = mouse.pos gw.mapCPToWorld (mapScreenToCP pixelpos)


CML
__________________
PolyBoost Tools for 3ds max
 
Old 03-16-2006, 03:19 PM   #14
PEN
R&D/Technical Director
 
PEN's Avatar
portfolio
Paul Neale
PEN Productions
Canada
 
Join Date: Jun 2002
Posts: 7,416
Good to know that there is another way. I think that I might go with thePainterInterface now anyway as it looks like it solves one of the main problems. If I use any of the built in mouseTools functions then I don't have accress so everying thing else as I'm painting. If I write it all using mouse, gw and viewport tools then I run into the problem that the I'm always in selection mode and that just isn't clean. So thePainterInterface deals with every thing as far as I can tell so far.
__________________
Paul Neale
http://paulneale.com
 
Old 03-16-2006, 03:19 PM   #15
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 01:07 AM.


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