[Maxscript] Remove dead verts in vertex color channel

Hey all,

There is a function in maxscript that gives you the dead vertices of the mesh.
Is there a way I can delete the dead vertices of the vertex color channel?

Cheers,
Robbert

If you mean isolated vertex, then try this <EditablePoly>.deleteIsoVerts()

No, but thanks for the reply :slight_smile:

I attached an image to make myself more clear.

What I would do, since I already have the maxscript is just copy the vert data onto a new modifier, per vert. I assume that would get rid of the dead verts. What method are you using to apply your vert colours in the first place? Do you realise that a vert can have a different vert colour for each tri it is attached to? Let me run and grab my scripts for some examples.

The below struct, on initiation gets the selections vertex colours, including sub-vert colours.


struct MinMaxValues
	(
		LowestAVGValue,
		HighestAVGValue,
		HighestValue,
		LowestValue,
		Colours,
		fn FindValues =
			(
				if Colours == undefined then Colours = for i = 1 to (getNumCPVVerts $) collect (getVertColor $ i)
				HighestAVGValue = 0
				LowestAVGValue = 255
				AllColours = #()
				for c in Colours do
					(
						append AllColours c.r
							append AllColours c.g
							append AllColours c.b
						CurrentAvgValue = AverageRGB c
						if CurrentAvgValue > HighestAVGValue then HighestAVGValue = CurrentAvgValue
						if CurrentAvgValue < LowestAVGValue then LowestAVGValue = CurrentAvgValue
					)
				HighestValue = amax AllColours
				LowestValue = amin AllColours
				--format "
 Low; % High; %
" (LowestValue as string) (HighestValue as string)
				"Values Set on initialisation"
			),
		SetValues = FindValues()
	)
OriginalValues = MinMaxValues()

The below Function changes the vertex colours, although, as it’s well into Friday night and this was originally intended for use in a broader tool, it may not function quite the way you’d like without some modification.


fn UpdateVertColours ColoursArray NewName:"WWVertexColorBake" = 
	(
		--if NewName == unsupplied then NewName = "WWVertexColorBake"
		if $.modifiers.count > 0 then if (substring $.modifiers[1].name 1 8) == (substring NewName 1 8) then deleteModifier $ 1
		maxOps.cloneNodes $ cloneType:#copy newNodes:&NewObj
		maxOps.CollapseNode NewObj[1] true
		NewObj[1].name = "WWVertexColorBake"--Should assign options as name
		for i = 1 to (getNumCPVVerts NewObj[1]) do setVertColor NewObj[1] i ColoursArray[i]
		ChannelInfo.CopyChannel NewObj[1] 3 0
		ChannelInfo.PasteChannel $ 3 0
		delete NewObj[1]
		$.modifiers[1].name = NewName--"WWVertexColorBake"
	)

To call the above function (after producing your struct) you’d call something along the lines of:


select obj--Your object
OriginalValues = MinMaxValues()
UpdateVertColours = OriginalValues.Colours

End result should be a layer on top of your current object with your desired colours, but I honestly have no idea if this will get rid of your dead verts issue. It just seems like it probably should, particularly if you add a clear vert colour channel line after you clone the reference object.

It’s all pretty hacky and has plenty of scope for improvement, but that’s thanks largely to the version of MAX I was using and the need for the tool (eg. 5 minutes ago).

Yes, I am aware that the mesh vertices are not the same as the map vertices.
I am not using a modifier for editing the vert colours.
I am mostly using the polyop.setmapvert and the update function for editing the vert colours.

Thanks for your reply!

Have you tried this <EditablePoly>.DeleteIsoMapVerts()

Thanks Akira, that is just what I needed. :slight_smile: