[SOLVED] script to place points on a mesh surface - mouseTrack or customFunction?

[SOLVED] script to place points on a mesh surface - mouseTrack or customFunction?

ClaudioAlvaro
Contributor Contributor
453 Views
1 Reply
Message 1 of 2

[SOLVED] script to place points on a mesh surface - mouseTrack or customFunction?

ClaudioAlvaro
Contributor
Contributor
Hi,

I'm attempting to write a little script that will place markers (points) on the surface of a mesh. There are three things I want it to do, A) show a box aligning to the surface of the mesh as the cursor is moved around so the user knows exactly where the marker will be placed, B) create a new marker on the surface whenever the user clicks the left mouse button, and C) allow the user to right-click and exit the script at any time.

I first tried writing the code myself, but realised that mouse.buttonStates is unreliable (quad menu disrupts right-click to cancel).

Then after a little research I noticed there was a mouseTrack function. I can achieve my two latter goals with this function, however I'm unclear on how to push a box around the surface using mouseTrack without my script looking like a hack...
I thought of simply using mouseTrack as a means of getting mouse input and sticking to a custom script - again it seems like I'm missing something.

Anyone have any tips or suggestions on what would be the most efficient way of writing this script?

Note that I'm a novice scripter so if I missed something that is blatantly obvious please let me know.

CL Audio
---
3DSMax 2012 SP2
0 Likes
454 Views
1 Reply
Reply (1)
Message 2 of 2

ClaudioAlvaro
Contributor
Contributor
Thanks to a script from Paul Hormis, I was able to figure this one out. The solution was a mouse tool. Here's the code:

fn getScreenRayAtNode obj =
(
screenRay = mapScreenToWorldRay mouse.pos
finalRay = intersectRay obj screenRay
finalRay
)

fn placeMarkersOnSurface =
(
tool surfacePoints
(
local obj = getCurrentSelection()
local m = point size:60 centermarker:false axistripod:false cross:false box:true wirecolor:red
local pointArray = #()

on start do
(
if obj.count == 1 and obj != undefined then
(
obj = obj
)
else #stop
)

on freeMove do
(
local ir = getScreenRayAtNode obj

if ir != undefined then
(
m.pos = ir.pos
m.dir = ir.dir
redrawViews()
)
)

on mouseMove clickNo do
(
local ir = getScreenRayAtNode obj

if ir != undefined then
(
m.pos = ir.pos
m.dir = ir.dir
redrawViews()
)
)

on mousePoint clickNo do
(
local ir = getScreenRayAtNode obj

if ir != undefined then
(
local p = point pos:ir.pos dir:ir.dir size:40 centermarker:false axistripod:false cross:true box:false wirecolor:yellow
append pointArray p
m.pos = ir.pos
m.dir = ir.dir

redrawViews()
)
)

on mouseAbort clickNo do
(
#stop
)

on stop do
(
delete m
return pointArray
)
)

startTool surfacePoints

)


Needs more error checking but the basics are there.
---
3DSMax 2012 SP2
0 Likes