Jump to content
  • Advertisement
Sign in to follow this  
Telamon

MaxScript Help Please! (very basic)

This topic is 4408 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've been learning MaxScript over the past two days and I'm thrilled that it is so great because it means that I don't have to touch the MAX SDK in order to write an exporter for our game. The first snag I ran into was exporting texture coords, since as I understand it max keeps per-face coords instead of per-vertex coords for textures (somewhat questionable design choice). I found a snippet of code from the internets that I think solves this. My real problem is that I don't know how to use functions inside of a MacroScript (I said it was basic)... I am erstwhile searching for example code on the net, but an initial search has proven fruitless. If someone could take a quick look at this, it would probably save me at least an hour. This is a working exporter for verts, normals and faces.
MacroScript ExportToRoblox category:"Roblox"
(
	fn GetGeometry o = (
	Superclassof o == Geometryclass and classof o != TargetObject )
	obj = pickobject filter:GetGeometry
	if isValidNode obj then
	(
		tmesh = snapshotAsMesh obj 
		out_name = GetSaveFileName()
		if out_name != undefined then
		(
			out_file = createfile out_name
			num_verts = tmesh.numverts 
			num_faces = tmesh.numfaces
			format "%,%\n" num_verts num_faces to:out_file
			for v = 1 to num_verts do
			format "%%," (getVert tmesh v) (getNormal tmesh v) to:out_file
			format "\n" to:out_file
			for f = 1 to num_faces do
			(
				face = getFace tmesh f
				format "%," face to:out_file
			)
			close out_file
			edit out_name
		)
	)
)
I want to add this function and call it from the line of code where I am writing the per-vertex info to the file:
	fn getUVCoordByVert theMesh mapChannel vertIndex = (
		local faces = (meshOp.getFacesUsingVert theMesh vertIndex) as array
		mapVertices = #()
		for theFace in faces do
		(
			theFaceDef = getFace theMesh theFace
			theMapFace = meshOp.getMapFace theMesh mapChannel theFace
			if theFaceDef.x == vertIndex then theMapVert = theMapFace.x as integer
			if theFaceDef.y == vertIndex then theMapVert = theMapFace.y as integer
			if theFaceDef.z == vertIndex then theMapVert = theMapFace.z as integer
			if findItem mapVertices theMapVert == 0 do append mapVertices theMapVert
		)
		return mapVertices
	)
The source of my confusion is that I don't know how the MacroScript decides what code to run. If I add a 2nd function inside the scope of the MacroScript clause, it doesn't work. Is the MaxScript interpreter 1-pass or multi-pass (i.e. do I need to have called functions appearing above callee functions in the source like in C, or is it like C# where it doesn't matter).

Share this post


Link to post
Share on other sites
Advertisement
I figured out the function scope thing, I was being obtuse before. Now I don't understand why I get a function undefined error on getUVCoordByVert.

Current exporter script:


MacroScript ExportToRoblox category:"Roblox"
(
fn GetGeometry o = (
Superclassof o == Geometryclass and classof o != TargetObject
)

fn getUVCoordByVert theMesh mapChannel vertIndex = (
local faces = (meshOp.getFacesUsingVert theMesh vertIndex) as array
mapVertices = #()
for theFace in faces do
(
theFaceDef = getFace theMesh theFace
theMapFace = meshOp.getMapFace theMesh mapChannel theFace
if theFaceDef.x == vertIndex then theMapVert = theMapFace.x as integer
if theFaceDef.y == vertIndex then theMapVert = theMapFace.y as integer
if theFaceDef.z == vertIndex then theMapVert = theMapFace.z as integer
if findItem mapVertices theMapVert == 0 do append mapVertices theMapVert
)
return mapVertices
)

obj = pickobject filter:GetGeometry
if isValidNode obj then
(
tmesh = snapshotAsMesh obj
out_name = GetSaveFileName()
if out_name != undefined then
(
out_file = createfile out_name
num_verts = tmesh.numverts
num_faces = tmesh.numfaces
format "%,%\n" num_verts num_faces to:out_file
for v = 1 to num_verts do
format "%%%," (getVert tmesh v) (getNormal tmesh v) (getUVCoordByVert tmesh 1 v) to:out_file
format "\n" to:out_file
for f = 1 to num_faces do
(
face = getFace tmesh f
format "%," face to:out_file
)
close out_file
edit out_name
)
)
)


Error:


-- Error occurred in V loop; filename: C:\Program Files\Autodesk\3dsMax8\UI\MacroScripts\Roblox-ExportToRoblox.mcr; position: 567
-- Frame:
-- V: 1
-- getUVCoordByVert: undefined
-- called in anonymous codeblock
-- Frame:
-- out_name: "C:\Documents and Settings\John Shedletsky\Desktop\girl.mesh"
-- num_verts: 190
-- GetGeometry: GetGeometry()
-- tmesh: TriMesh
-- out_file: <File:C:\Documents and Settings\John Shedletsky\Desktop\girl.mesh>
-- num_faces: 148
-- Obj: $Cylinder01
>> MAXScript MacroScript Error Exception: -- Type error: Call needs function or class, got: undefined <<

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!