ScriptSpot

Forum topic · General Scripting

Vertex Color Swapper

By airbrush · 2024-03-22

Description

Hi, Does anyone know of a script that will swap vertex colors?
I used one years ago, but can't seem to find it.

I would need to do for example:
swap what is currently blue to green, green to red, or dropdown combinations to pick from...blue to red etc.

I need to swap all current colors..currently i have meshes with Black being base color, Red, Green, Blue.

thx

Comments (2)

airbrush · 2024-03-25

thanks, will give it a try.

.

miauu · 2024-03-23

Try this one:


(	
	global rol_swapVertsColors
	try(destroyDialog rol_swapVertsColors)catch()
	rollout rol_swapVertsColors "miauu"
	(
		local poGetVertsByColor = polyop.getVertsByColor
		local poSetVertColor = polyop.setVertColor
		
		colorpicker clr_01 "Color 1" color:red alpha:true fieldWidth:50 height:20 modal:true
		colorpicker clr_02 "Color 2" color:blue alpha:true fieldWidth:50 height:20 modal:true
		button btn_swap "SWAP" width:110 height:30 align:#center
		
		on btn_swap pressed do
		(
			if (selObjsArr = selection as array).count != 0 then
			(
				clr1 = clr_01.color
				clr2 = clr_02.color
				for o in selObjsArr where classOf o == Editable_Poly do
				(
					verts01BA = poGetVertsByColor o clr1 0.1 0.1 0.1 channel:0
					verts02BA = poGetVertsByColor o clr2 0.1 0.1 0.1 channel:0
					
					if not verts01BA.isEmpty and not verts02BA.isEmpty do
					(
						poSetVertColor o 0 verts01BA clr2
						poSetVertColor o 0 verts02BA clr1
					)
				)
			)
			else
				messagebox "Select some Editable poly objects"
		)
	)
	createdialog rol_swapVertsColors width:120
)