ScriptSpot

Forum topic · General Scripting

Getting Correct UVW info

By rosuto · 2012-07-13

Description

Im currently fighting with 3dmax to give me the correct information regarding UVW maps. If I have 6 UVW unwraps listed in the modifiers window, all on different channels, and my current selection is editable mesh; 3d max will tell me that only 2 uvw channels exist when I use meshop.getNumMaps geometry[1]. Its not till I click the very top modifier, does it actually give me the correct number of UVW channels. So I tried to do the following work around, but I find it quite time consuming as it takes around 2 seconds to process for each object. I have also tried collapseStack, but that took the same amount of time and I would prefer to not collapse the modifiers list. Is there a faster way to get the information I need?


if (geometry[f].modifiers.count) != 0 then (
  i=1
  do (
    if (geometry[f].modifiers[i].enabled and ((classOf geometry[f].modifiers[i]) == Unwrap_UVW or (classOf geometry[f].modifiers[i])== VertexPaint)) then (
      modpanel.setCurrentObject geometry[f].modifiers[i]
      found = true
    )
    i+= 1
  ) while (found == false and i <= geometry[f].modifiers.count)
)
if (meshop.getMapSupport geometry[f] 0) then (vertColor = 1)
for i=1 to meshop.getNumMaps geometry[f] do (
  if (meshop.getMapSupport geometry[f] i) then (
    textNum += 1
    append mapVerts (meshop.getNumMapVerts geometry[f] i)
  )
)
Comments (5)

Same issue

rosuto · 2012-07-13

Lets say my modifiers box looks like

Unwrap UVW (channel 4)
Unwrap UVW (channel 3)
Unwrap UVW (channel 2)
Unwrap UVW (channel 1)
Editable Mesh

So if I click on editable mesh and run the code, it will tell me the there is only 1 map channel. If I click on Unwrap UVW with channel 2, it will tell me that there is 2 map channels.

Now if I switch it up so the order is

Unwrap UVW (channel 4)
Unwrap UVW (channel 1)
Unwrap UVW (channel 2)
Unwrap UVW (channel 3)
Editable Mesh

It will spit 1 for editable mesh, 3 for unwrap uvw channels 1, 2, and 3. And finally 4 for channel 4. So what ever is the highest channel from where I clicked and down, is what it will spit out. I would like it to give me 4 no matter where I clicked or what the order is.

solution2

barigazy · 2012-07-14

This work with multiple selection, UnwrapUVW and UVWMap modifiers


if selection.count != 0 do
(
	local cnt = 1
	for obj in selection where isKindOf obj GeometryClass and not isKindOf obj TargetObject do
	(
		local Channels = #{}
		if obj.modifiers.count != 0 do
		(
			for m in 1 to obj.modifiers.count do
			(
				case classof obj.modifiers[m] of (
					(Unwrap_UVW): append Channels (obj.modifiers[m].getMapChannel())
					(Uvwmap): append Channels obj.modifiers[m].mapChannel
				)
			)
		)
		if Channels.numberset != 0 do 
		(
			format "object%: % ; mapchannel:%\n" cnt obj.name Channels.count
			cnt+=1
		)
	)
)


Try the code and let me know if it works

Works

rosuto · 2012-07-14

I like it. Much faster than what I have right now.

Thanks.

barigazy · 2012-07-14

Yep, because you need only mapchannel value from mods and not mesh faceID's. Reordering of modifiers don't affect final result.
Glad you like it.
Cheers!

solution

barigazy · 2012-07-13

A test this code on 3 Cylinder:
Cylinder001 have 6 UVWmap mods with different channels, Cylinder002 have 2 UVWmap etc....

gnm = meshop.getNumMaps
for obj in selection do
(
local objmesh = snapshotasmesh obj
format "object:% mapchannels:%\n" obj.name ((gnm objmesh)-1)
)
--result
--object:Cylinder001 mapchannels:5
--object:Cylinder003 mapchannels:2
--object:Cylinder002 mapchannels:3