Home Technical Talk

help with uv channel cleanup script

polycounter lvl 19
Offline / Send Message
Justin Meisse polycounter lvl 19
I'm working on a script that removes unneaded map channels from selected meshes. Right now it's coded to remove UV channels 2-4, vertex alpha & illumination - later I'll see if I can have a UI that asks what channels you'd like to keep and have it detect how many channels each object has.


Now to the problem, I don't really know what I'm doing here - it runs fine on a single object but once multiple objects are selected it crashes. Shouldn't the do loop look at each mesh in the array individually? I know if I select a bunch of meshes and open the map channel info viewer it just groups them all together - so I wonder if the script has to cycle through each selected mesh unselecting the rest. (most of the script is stolen from Mark's max script for noobs thread)

(
(

local meshes = $

if meshes != undefined then (

for i in meshes do (

channelInfo.ClearChannel $ 4
channelInfo.ClearChannel $ 3
channelInfo.ClearChannel $ 2
channelInfo.ClearChannel $ -1
channelInfo.ClearChannel $ -2
maxOps.CollapseNode i off

)

)

else (

messagebox "Nothing selected." title: "Selection Failure"

)

)
)

Replies

  • cupsster
    Offline / Send Message
    cupsster polycounter lvl 11
    Try this:
    (
    	(
    		-- catch selection to array othervise original for loop will not work
    		local cleaningObjects = selection as array
    		if cleaningObjects != undefined then 
    		(
    			-- we want maximum performance from our script so we make sure we are in create mode
    			max create mode
    			-- notify that we are starting
    			print "Cleaning UV Channels..."
    			for o in cleaningObjects do (
    				channelInfo.ClearChannel o 4
    				channelInfo.ClearChannel o 3
    				channelInfo.ClearChannel o 2
    				channelInfo.ClearChannel o -1
    				channelInfo.ClearChannel o -2
    				maxOps.CollapseNode o off
    				print ("Cleaning "+o.name+" UV Channels: Done")
    			)
    			-- notify that we are finished
    			print "Operation finished."
    		)
    		else 
    		( 
    			messagebox "Nothing selected." title: "Selection Failure"
    		)
    		-- empty local to be sure
    		cleaningObjects = undefined
    	)
    )
    
  • Justin Meisse
    Offline / Send Message
    Justin Meisse polycounter lvl 19
    cool, looks like that works. I think I can grasp most of it, does the o mean object?

    Oh wow, seems like the script doesn't care if there is only a UV 2 - so I won't have to worry about making it check if the extra channels exist or not.

    this leads me to another question - how the heck to meshes seem to collect extra UV channels like flies on poop? Lots of this is outsourced stuff that has a bunch of UV channels, it adds up to about 2-4mb per max file - not a huge amount but it adds up when you have thousands of assets.
  • cupsster
    Offline / Send Message
    cupsster polycounter lvl 11
  • Mark Dygert
    cool, looks like that works. I think I can grasp most of it, does the o mean object?
    O is just a variable, you could use X or P or JANK if you wanted to. It means anytime you find this variable insert the thing this "for loop" is currently working on, in this case the things its working on are "CleaningObjects".

    this leads me to another question - how the heck to meshes seem to collect extra UV channels like flies on poop? Lots of this is outsourced stuff that has a bunch of UV channels, it adds up to about 2-4mb per max file - not a huge amount but it adds up when you have thousands of assets.
    Outsourced art... the shit you have do to get it running is amazing...
    They probably just click and drag the Map Channel slider and crank it up to some higher number to create a new UV channel and don't realize that if you jump from 1-9 it creates map channels for 2-8 also. In short, they're probably just retarded and not using 1-2 channels properly... FUN!
Sign In or Register to comment.