Out Parameters in Maxscript?

I’ve got my head in a bit of a bender at the moment. I’ve been putting together a function to do a bit of validation of lightmap UVs before exporting, but the Out Parameters (pointers?) aren’t behaving at all the way I’d expect them to.

Basically, the following code snippet works fine when evaluated as is, either in the script editor or in the listener window.


addmodifier $ (Unwrap_UVW())
uv = $.modifiers[#Unwrap_UVW]
uv.setMapChannel 2
DialogMonitorOps.Enabled = true
DialogMonitorOps.RegisterNotification confirmResetUV id:#pressUnwrapOK
uv.unwrap.reset()
DialogMonitorOps.unRegisterNotification id:#pressUnwrapOK
DialogMonitorOps.Enabled = false
uv.unwrap4.getArea #{1..(uv.numberPolygons())} &x &y &width &height &areaUVW &areaGeom
print x
print y
print width
print height
print areaUVW
print areaGeom

I get the expected values printed out in the listener console.
Stick that code block between parentheses, however (be that a simple block, or in a function), and I consistently get the following values returned:

1e+030
1e+030
-2e+030
-2e+030
0.0
0.0
0.0

For kicks, I’ve tried declaring x, y, width, etc prior to the function, inside the function prior to the getArea() call, but still get the same results.

I can’t for the life of me figure out why this is, and I haven’t been able to find any help via google. Anybody know why this might be happening? Am I missing something?

fn checkUVArea obj:(selection as array)[1] reset:true=
	(
		x = undefined
		y = undefined
		width = undefined
		height = undefined
		areaUVW = undefined
		areaGeom = undefined
		addmodifier obj (Unwrap_UVW())
		uv = obj.modifiers[#Unwrap_UVW]
		uv.setMapChannel 2
-- 		DialogMonitorOps.Enabled = true
-- 		DialogMonitorOps.RegisterNotification confirmResetUV id:#pressUnwrapOK
		if reset == true then
			(
				uv.unwrap.reset()
			)
-- 		DialogMonitorOps.unRegisterNotification id:#pressUnwrapOK
-- 		DialogMonitorOps.Enabled = false
		uv.unwrap4.getArea #{1..(uv.numberPolygons())} &x &y &width &height &areaUVW &areaGeom
		format "x = %
y = %
width = %
height = %
areaUVW = %
areaGeom = %
" (x as string) (y as string) (width as string) (height as string) (areaUVW as string) (areaGeom as string)
	)
checkUVArea obj:$sphere001
checkUVArea obj:$sphere001 reset:false

I dropped your code in the function as above, and with a sphere selected, get the following output:

checkUVArea()
--Reset = True
x = 1e+030
y = 1e+030
width = -2e+030
height = -2e+030
areaUVW = 0.0
areaGeom = 0.0
OK
--Reset = False
x = 0.0
y = 0.0
width = 1.0
height = 1.0
areaUVW = 3.11642
areaGeom = 10054.5
OK

Not sure why it worked, but it did. If I had to guess, I’d say it’s something to do with when the results of the uv.unwrap.reset() are applied

Yeah, that seems to be the case on my end as well, cheers for finding that. Well, not being able to reset the UVWs makes it less than useful for the purpose I’d envisioned :\ Still finding it completely bizarre that it works perfectly well outside a codeblock (with the reset).

I’m not too familiar with the methods of the unwrap modifier. What does resetting the UVWs accomplish?

In addition to the more obvious function of essentially reverting your UVs, Reset also is the only way of actually accessing different UV channels.

Basically, if you switch map channels (whether in script or via the UI), the only way you’re actually going to be able to access that channel’s UVs is by Resetting.

So I’d sorta shelved this for a bit, then as I was looking at an unrelated thread on polycount, I found some good info that the UnwrapUVW modifier has a bit of trouble actually refreshing itself sometimes while in a script, and that

forcecompleteredraw dodisabled:true

might help.

So I went ahead and stuck that right after

uv.unwrap.reset()

and I received the correct return info. Looks like I can get that lightmap unwrap validator done up for the environment asset exporter after all :smiley: