Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Script for swapping vertex paint channels

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
1132 Views, 1 Reply

Script for swapping vertex paint channels

Hello. I've got an issue with channels in vertex paint. The solution was to swap vertex color channel data with illum channel data. I'm wondering, if there's a script to do such thing for me as there're too many models with this issue. I would also appreciate any advice on how to do this script.
Thanks.

Labels (1)
1 REPLY 1
Message 2 of 2
denisT.MaxDoctor
in reply to: Anonymous

Here is all what you need to swap texture channels.

 

fn copyChannel node type:3 targetChannel: sourceChannel: clear:off = 
(
	if meshop.getMapSupport node.mesh targetChannel do
	(	
		if sourceChannel == #new do
		(
			ChannelInfo.AddChannel node
			sourceChannel = (meshop.getnummaps node.mesh) - 1
			node.modifiers[1].name = "add CH(" + sourceChannel as string + ")"
		)
		
		ChannelInfo.CopyChannel node type targetChannel
		ChannelInfo.PasteChannel node type sourceChannel
		node.modifiers[1].name = "copy CH(" + targetChannel as string + ")->" + "CH(" + sourceChannel as string + ")"

		if clear do 
		(
			ChannelInfo.ClearChannel node targetChannel
			node.modifiers[1].name = "clear CH(" + targetChannel as string + ")"
		)
		
		sourceChannel
	)
)

mapped fn swapChannels node ch_a ch_b collapse:off = 
(
	if iskindof node GeometryClass and not iskindof node Targetobject do  
	(
		-- suspendEditing() 

		tempChannel = copyChannel node targetChannel:ch_a sourceChannel:#new 
		copyChannel node targetChannel:ch_b sourceChannel:ch_a 
		copyChannel node targetChannel:tempChannel sourceChannel:ch_b clear:on
		if collapse do collapsestack node

		-- resumeEditing()
	)
)

/* 
--EXAMPLE 1 -- swap illum channel (-1) and vertex color channel (0) with no collapse for selected geometry nodes: 
(
	swapChannels $ -1 0 collapse:off
)
*/

/* 
--EXAMPLE 2 -- swap illum channel (-1) and vertex color channel (0) with collapse for all geometry node in scene: 
(
	swapChannels (geometry as array) -1 0 collapse:on
)
*/

in the swapChannels function "suspend" and "resume" editing are commented. You can use "suspend - resume" option for a final version, but it doesn't really make sense for multi nodes editing.

 

This is how to swap channels in the current scene. For multiple scenes you need to make a "batch" script. But before that, you must provide the rule for which nodes you need “channel swapping”. The script should use this rule to search for processing nodes.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report