utility vc_adjust "Adjust Vertex Colors"
(
local work_node = undefined
local gncpvv

fn filter_emesh p_n =
(
if classof p_n == Editable_Mesh and p_n.modifiers.count == 0 and (getnumcpvverts p_n)>0 then ok_return = true else ok_return = false
ok_return
)

group "About..."
(
label vcalabel01 "Adjust VC"
label vcalabel02 "Version 1.2 - 4/26/2000"
label vcalabel03 "(c)99-00 by Bobo's Rendert**ls"
label vcalabel04 "http://gfxcentral.com/bobo/"
)

group "EditableMesh"
(
pickbutton pick_node "Pick Mesh to Adjust" width:140 height:30 filter:filter_emesh align:#center tooltip:"Pick an EditableMesh with VC Info and NO Modifiers"
label node_info1 "Nothing Selected" align:#center
button emergency_restore "Restore Vertex Colors" width:140 height:20 align:#center tooltip:"Reset VCs to Original State"

)

group "Adjustment Options"
(
radiobuttons clamp_yes labels:#("Cycle","Clamp")
)

on pick_node picked obj do
(
work_node = obj
pick_node.text = work_node.name
emergency_array = #()
emergency_count = (getnumcpvverts work_node)
node_info1.text = emergency_count as string + " CV Total"

for i = 1 to emergency_count do
(
append emergency_array (vc = getvertcolor work_node i)
)
)

on emergency_restore pressed do
(
if work_node != undefined then
(
check_count = (getnumcpvverts work_node)
if check_count == emergency_count then
	(
	for i = 1 to emergency_count do
		(
		setvertcolor work_node i emergency_array[i] 
		)
	update work_node	
	)
)
)


group "Hue"
(
button hue_up "Hue UP" width:140
button hue_down "Hue DOWN" width:140
spinner hue_val "Increment" range:[0,255,1] type:#float
)

group "Sat"
(
button sat_up "Saturation UP" width:140
button sat_down "Saturation DOWN" width:140
spinner sat_val "Increment" range:[0,255,1] type:#float
)

group "Value"
(
button value_up "Value UP" width:140
button value_down "Value DOWN" width:140
spinner value_val "Increment" range:[0,255,1] type:#float

)

fn change_vc w_node mode c_value =
( 
gncpvv = getnumcpvverts w_node
(
for i = 1 to gncpvv do
(
vc = getvertcolor w_node i
case mode of
(
1: (
	vc_hue = vc.hue
	vc_hue+= c_value
	if vc_hue > 255 then 
		(
		if clamp_yes.state == 1 then 
			(
			vc_hue -= 255
			)
			else
			(
			vc_hue = 255
			)
		)
	vc.hue = vc_hue	
	)
2: (
	vc_hue = vc.hue
	vc_hue -= c_value
	if vc_hue < 0 then 
		(
		if clamp_yes.state == 1 then 
			(
			vc_hue += 255
			)
			else
			(
			vc_hue = 0
			)
		)
	vc.hue = vc_hue	
	)
3: (
	vc_saturation = vc.saturation
	vc_saturation += c_value
	if vc_saturation > 255 then 
		(
		if clamp_yes.state == 1 then 
			(
			vc_saturation -= 255
			)
			else
			(
			vc_saturation = 255
			)
		)
	vc.saturation = vc_saturation
	)
4: (
	vc_saturation = vc.saturation
	vc_saturation -= c_value
	if vc_saturation < 0 then 
		(
		if clamp_yes.state == 1 then 
			(
			vc_saturation += 255
			)
			else
			(
			vc_saturation = 0
			)
		)
	vc.saturation = vc_saturation
	)
5: (
	vc_value = vc.value
	vc_value += c_value
	if vc_value > 255 then 
		(
		if clamp_yes.state == 1 then 
			(
			vc_value -=255
			)
			else
			(
			vc_value = 255
			)
		)
	vc.value = vc_value
	)
6: (
	vc_value = vc.value
	vc_value -= c_value
	if vc_value < 0 then 
		(
		if clamp_yes.state == 1 then 
			(
			vc_value += 255
			)
			else
			(
			vc_value = 0
			)
		)
	vc.value = vc_value
	)
)--end case
setvertcolor w_node i vc
)
update w_node
)--end if

)--end fn



on hue_up pressed do
(
if work_node != undefined then
(
change_vc work_node 1 hue_val.value
)
)

on hue_down pressed do
(
if work_node != undefined then
(
change_vc work_node 2 hue_val.value
)
)

on sat_up pressed do
(
if work_node != undefined then
(
change_vc work_node 3 sat_val.value
)
)

on sat_down pressed do
(
if work_node != undefined then
(
change_vc work_node 4 sat_val.value
)
)


on value_up pressed do
(
if work_node != undefined then
(
change_vc work_node 5 value_val.value
)
)

on value_down pressed do
(
if work_node != undefined then
(
change_vc work_node 6 value_val.value
)
)

)--end util