Jump to content
  • Advertisement
Sign in to follow this  
CPPNick

Max script help

This topic is 2948 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need some help with this thing that I am making for a school project.

I need to get a map of edges out of max to use for collision detection in our game. This is what I have so far.



rollout new "Edgemap Exporter"
(
label lab "Export Edgemap"
button btn_export "Export"
on btn_export pressed do
(
out_name = getSaveFileName types: "Edge Map(*.emap) |*.emap|"
out_file = createfile out_name


edgemap = snapshotAsMesh selection[1]
--I need to get a list of the edges of the object here


--num_verts = edgemap.numEdges

--format "%\n" num_verts to:out_file

--vert1 = getVert tmesh num_verts
--vert2 = getVert tmesh 1

--format "% % % %\n" (vert1.x) (vert1.y) (vert2.x) (vert2.y) to:out_file

--for v = 2 to num_verts do
--(
--vert1 = getVert tmesh v - 1
--vert2 = getVert tmesh v
--format "% % % %\n" (vert1.x) (vert1.y) (vert2.x) (vert2.y) to:out_file
--)


close out_file
)
)
CreateDialog new




I have got the thing saving a file properly and everything, but I need a way to get a list of all the edges of a spline(with all corners).

can anyone point me in the right direction?

thanks for any help on this.

Share this post


Link to post
Share on other sites
Advertisement
getting closer!


rollout new "Edgemap Exporter"
(
label lab "Export Edgemap"
button btn_export "Export"

on btn_export pressed do
(
s = objects as array

theLines = for o in s where classof o == Line collect o
theCircles = for o in s where classof o == Circle collect o

nLines = theLines.count
nCirlces = theCircles.count

if(nLines != 0 or nCircles != 0) then
(
//-- out_name = getSaveFileName types: "Edge Map(*.emap) |*.emap|"
//-- out_file = createfile out_name


// -- make an array to hold all the line segments
// --segArray = #()

for aLine = 1 to nLines do
(
// -- for each spline in the Line object
thisSpline = theLines[aLine]

nSplines = numSplines thisSpline

for aSpline = 1 to nSplines do
(
nSegments = numSegments thisSpline aSpline

for aSeg = 1 to nSegments do
(
print "This is a segment!"
)
)
)

//-- if(nCircles != 0) then
//-- (
//-- format "%\n" nCirlces to:out_file
//-- for i = 1 to nCirlces do
//-- (
//-- Circle1 = theCircles
//-- format "% % %\n" (Circle1.center.x) (Circle1.center.y) (Circle1.radius) to:out_file
//-- )
//-- )

//-- close out_file
)
)
)
CreateDialog new






just cant figure out how to retrieve the vertices from the segment =/

Share this post


Link to post
Share on other sites
Phew!
done.

here is the code if anyone wants to take a look.


rollout new "Edgemap Exporter"
(
label lab "Export Edgemap"
button btn_export "Export"

on btn_export pressed do
(
s = objects as array

theLines = for o in s where classof o == Line collect o
theCircles = for o in s where classof o == Circle collect o

nLines = theLines.count
nCirlces = theCircles.count

if(nLines != 0 or nCircles != 0) then
(
out_name = getSaveFileName types: "Edge Map(*.emap) |*.emap|"
out_file = createfile out_name

-- make an array to hold all the line segments
segArray = #()

if(nLines > 0) then
(
for aLine = 1 to nLines do
(
-- for each spline in the Line object
thisLine = theLines[aLine]

nSplines = numSplines thisLine

for aSpline = 1 to nSplines do
(

nKnots = numKnots thisLine aSpline

if(isClosed thisLine aSpline) then
(
if(nKnots > 1) then
(
pt1 = getKnotPoint thisLine aSpline nKnots
pt2 = getKnotPoint thisLine aSpline 1

append segArray #(pt1, pt2)

if(nKnots > 2) then
(
for aKnot = 2 to nKnots do
(
pt1 = getKnotPoint thisLine aSpline (aKnot - 1)
pt2 = getKnotPoint thisLine aSpline aKnot

append segArray #(pt1, pt2)
)
)
)
)
else
(
if(nKnots > 1) then
(
for aKnot = 2 to nKnots do
(
pt1 = getKnotPoint thisLine aSpline (aKnot - 1)
pt2 = getKnotPoint thisLine aSpline aKnot

append segArray #(pt1, pt2)
)
)
)
)
)

format "%\n" segArray.count to:out_file
for thisSeg = 1 to segArray.count do
(
format "% % % %\n" (segArray[thisSeg][1].x) (segArray[thisSeg][1].y) (segArray[thisSeg][2].x) (segArray[thisSeg][2].y) to:out_file
)
)

if(nCircles != 0) then
(
format "%\n" nCirlces to:out_file
for i = 1 to nCirlces do
(
Circle1 = theCircles
format "% % %\n" (Circle1.center.x) (Circle1.center.y) (Circle1.radius) to:out_file
)
)
--
close out_file
)
)
)
CreateDialog new

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!