Description: This MouseTool is made to help place a node onto the surface of some geometry based upon mouse click location. it will place the node by its pivot point and orient its local z axis to the normal of the intersection. (Additional: Added a new Ability to click and drag to rotate around the Nodes Local Z axis) Hope its helpful to someone besides me. Heres the code... Enjoy
macroScript AlignToSurface
category:"ClaverTech"
toolTip:"AlignToSurface"
(
tool AlignToSurfaceTool
(
local somethin=undefined
local OrgPos=undefined
local OrgRot=undefined
local target_mesh=undefined
local StartDragging=0
local posy=undefined
local roty=undefined
local OrgViewY=undefined
fn g_filter o =
(
if o!=somethin then
(
superclassof o == Geometryclass
)
else
(
false
)
)
fn ResetStuff str=
(
somethin.pos = OrgPos
somethin.dir = OrgRot
)
fn DoMyStuff str=
(
local myRay=mapScreenToWorldRay viewPoint -- make a ray from active viewport
local tempRay=intersectRay target_mesh myRay --see if the ray hits the picked object
if tempRay!=undefined then --if we actually hit the picked object set to surface
(
somethin.pos = tempRay.pos
somethin.dir = tempRay.dir
)
else -- otherwise make it reset
(
ResetStuff now
)
str --functions need to return somethin right
)
on start do
(
--if something is selected
if $!=undefined then
(
somethin=$
OrgPos=somethin.pos --save original position
OrgRot=somethin.dir --save original rotation
target_mesh = pickObject message:"Pick Target Surface" forceListenerFocus:false filter:g_filter
)
else -- if nothing is selected
(
messageBox "Start this tool with an object selected"
#stop
)
)
on mouseAbort clicker do
( --reset position and rotation
ResetStuff now
)
on mousePoint clickno do
(
if (clickno == 1 and target_mesh!=undefined)then
(
DoMyStuff now -- function calls dont seem to work without a parameter
)
else
(
#stop --bail
)
)
on freeMove do
(
if target_mesh!=undefined then
(
DoMyStuff now --this way it actually shows it is workin
)
else
(
#stop --bail
)
)
on mouseMove clickno do
(
if StartDragging==0 then
(
posy = somethin.pos -- dont ask why i need this
roty = somethin.rotation -- dont ask why i need this
OrgViewY=viewPoint.y -- store click loc for later
StartDragging=1 -- make sure this dont happen again
)
somethin.rotation = roty -- dont ask why setting rotation moves the object
somethin.pos = posy -- but now we got to move it back... theres got to be a better way
local tempRot = eulerangles 0 0 0 -- make a blank euler
tempRot.z=((viewPoint.y-OrgViewY)/2) -- make it only rotate more or less by initial screen click loc
in coordsys local rotate somethin tempRot -- and finally rotate locally
--somethin.pos = posy
)
)
startTool AlignToSurfaceTool
)
Comments (10)
Comment policy
Thanks for the great stuff.
ClaverTech_AlignToSurface so relevant project now. It is so important for the gambling industry and new front-end development. I think that my casinosistersites site can provide good usability due to your script.
Any idea how to make it work in Max2019?
It works on 2017 as i tested. but it is not working in 2019. and after restarting the program, the option even disappears entirely.
Any idea how to make it work in Max2019?
Work fine...
Thank´s a lot...
Work fine en 3dsmax 2018.
Install Problems
Can't seem to get it to run on 3ds Max 2016, Windows 10.
In theory it installed, but does nothing - at least it shows up in the Customize User Interface
There may be an issue with a temp file it is trying to write to
C:\Users\\AppData\Local\Autodesk\3dsMax\2016 - 64bit\ENU\usermacros
Any suggestions?
Nevermind - works fine! (User error)
Tested using 3dsMax 9-32bit and worked.........
or something like this
on start do
if selection.count == 1 then
(
somethin=$
OrgPos=somethin.pos --save original position
OrgRot=somethin.dir --save original rotation
target_mesh = pickObject message:"Pick Target Surface" forceListenerFocus:false filter:g_filter
)
else if selection.count==0 then messageBox "Start this tool with an object selected" title: "Selection Error"
else messageBox "Please select one object only" title: "Selection Error"
there was some error when you select more than one object....
on start do
if selection.count == 1 then
(
bla...bla...bla
)
else messageBox "Please select one object only" title: "Selection Error"
that will help remove error when selection more than 1 object, unless you make it support for more than 2 object or even group.
What a great, and handy little script.
I owe you a PBR.
at the risk of repeating myself, best script to populate and reposition people and cars in architectural scene !!! Thanks
Hello
Thanks to your PBR dealer, it is the tool I needed !!!
If I want to add "toolMode.coordsys #local" for rotation, where do I need to add in your script ?
So I can rotate in local coord orientation of my objects .
Thanks !!! :-)))