Notifications
Clear all

[Closed] Map Channel Help

I’m trying to make a script that will create a second UV channel with the Pack UV’s function applied. It works until it’s within a function, in which case I get a system exception error.

Works:

 
-- copies map channel 1 to 2
channelInfo.CopyChannel $ 3 1
channelInfo.PasteChannel $ 3 2
 
-- pack uv's
modPanel.addModToSelection (Unwrap_UVW ()) ui:on
$.unwrap_uvw.unwrap.setMapChannel 2
$.unwrap_uvw.pack 1 0.002 true true true
 
maxOps.CollapseNode $ on
messageBox "Second UV channel created!" title:"Map Channel 2"

[size=2]Doesn’t work:[/size]

 
fn run =
(
-- copies map channel 1 to 2
channelInfo.CopyChannel $ 3 1
channelInfo.PasteChannel $ 3 2
 
-- pack uv's
modPanel.addModToSelection (Unwrap_UVW ()) ui:on
$.unwrap_uvw.unwrap.setMapChannel 2
$.unwrap_uvw.pack 1 0.002 true true true
 
maxOps.CollapseNode $ on
messageBox "Second UV channel created!" title:"Map Channel 2"
)
 
run()

Why is this happening?

5 Replies

I can get the Pack UV’s working on map channel 1. So if I do some channel swapping I can get it on channel 2.

 
fn run =
(
maxOps.CollapseNode $ off
channelInfo.CopyChannel $ 3 1
channelInfo.PasteChannel $ 3 3
 
-- pack uv's
modPanel.addModToSelection (Unwrap_UVW ()) ui:on
$.unwrap_uvw.pack 0 0.002 on on on
 
channelInfo.CopyChannel $ 3 1
channelInfo.PasteChannel $ 3 2
channelInfo.CopyChannel $ 3 3
channelInfo.PasteChannel $ 3 1
channelInfo.ClearChannel $ 3
 
maxOps.CollapseNode $ off
messageBox "Second UV channel created!" title:"Map Channel 2"
)
run()

Surely there’s a better way than this.

The unwrap modifier is a bit temperamental.
When I use it -and to avoid the bugs- I put max alway in modify mode

max modify mode

Another really stange thing that cause crashes: if you have severals objects selected and you work only on one object through his modifier unwrap, sometimes that cause crashes !!! In order to avoid this I select alway only the object on I work.

sel=getCurrentSelection() -- copy the selection
for obj in sel do
(
	select obj
	-- code
	-- obj.modifiers[1].unwrap.dosomething
)
select sel -- get back the original selection

Another thing : with certain functions as weld, break, the modifier do nothing if the windows isn’t open !!! :banghead:
I use : obj.modifiers[1].unwrap.edit()

example with weld function:

obj=selection[1]
select obj
max modify mode
addModifier obj (Unwrap_UVW ())
nv=obj.modifiers[1].unwrap.NumberVertices()
obj.modifiers[1].unwrap.edit()
obj.modifiers[1].unwrap.setWeldThreshold 0.001
obj.modifiers[1].unwrap.selectVertices #{1..nv}
obj.modifiers[1].unwrap.weldSelected()
obj.modifiers[1].unwrap.selectVertices #{}
max create mode

It’s an ugly solution but I don’t know it of the other one …

hope this helps

here is probably what you are tring to make

fromChannel=1
toChannel=3

max modify mode
sel=for obj in selection where validModifier obj (Unwrap_UVW ()) collect obj
for obj in sel do
	(
	select obj
	channelInfo.CopyChannel obj 3 fromChannel
	channelInfo.PasteChannel obj 3 toChannel
	addModifier obj (Unwrap_UVW ())
	obj.modifiers[1].name="Unwrap Pack ch"+(toChannel as string)
	objUnwrap=obj.modifiers[1].unwrap
	objUnwrap2=obj.modifiers[1].unwrap2
	objUnwrap.setMapChannel toChannel
	objUnwrap2.setTVSubObjectMode 3
	objUnwrap2.setTVElementMode true
	objUnwrap2.selectFaces #{1..obj.numfaces}
	objUnwrap2.pack 0 0.002 true true true
	objUnwrap2.selectFaces #{}
	)
select sel
max create mode

But in this case every object has one Pack different.
Is it really what you wish ? To create a lightmap for instance, I prefer to have the same ligntmap for all the objects.

If you want only one pack for several objects then you can use my script “multiObjectsUnwrap”.
Just make the copy of UVs before and edit the appropriate channel.
I have just added the function “copy channel” in the interface.
http://users.skynet.be/arketip/maxscript/multiObjectsUnwrap.mcr

Thanks prettyPixel, this is exactly what I’m after!

This will be used to generate lightmaps for a simulation that contains hundreds of objects. The lightmaps are used to create the shading and shadows for all of them. If something is under a light at night, for example, it’s going to need a different light map.

A problem that has come up is that if a model has multiple ids the method above doesn’t work that well. For example, a car has two maps, one for the wheels and one for the main body. Running the script combines the two giving the wheels more texture space than it needs.

I guess there’s still the auto unwrap. It just means that there is no one setting fits all.

1 Reply
(@prettypixel)
Joined: 1 year ago

Posts: 0

Yes I know the problem. But by changing the size of yours Uvs before, it is not a problem.
You can use the real size of the object or more easy: by multiplying the UVs size from the bitmap size (if you use bitmaps). I prefer the second solution because the UVs size have the same importance than the bitmapsize. So An big object with a little texture (for instance a background picture) will have a good size in the UVs. Just use “pack” after that.

An another problem with the “auto unwrap”: It is not easy to know the space between the clusters. But It is an another story…