Notifications
Clear all

[Closed] Get Vertex Color

Hi, I´m trying to do a dome-light type script getting the lights color and position from from verts. My problem is that I can´t find a method get the color from a selected vertex. There is a getVertColor method, but the color number and the vertex number it is not the same. So if I have:
vert = getVert obj i
It is any way to get the color from “vert”.
Thanks

3 Replies

” vert = getVert obj i “
This will only get the position value of vertex ” i “, not the vertex color.

Maybe you can do something like this,

num_verts = getNumCPVVerts $

for i = 1 to num_verts do
(
vert_color = getVertColor $ i
print vert_color
)

And, you need to have color value on Vetex Color Channel “0”.
Means that you have to genertate Vertex Color for the geometry first before you get vertex color.

Hope this is what you are looking for.

Here is a bit hack to do that. I don’t think this is the best way but…

I don’t know why you have to add 1 to theMapV at the end (0 index based versus 1 :?!). And when you assign a target to the light you can’t assign a material to the source object!

(
	with undo off
	(
		objTransform = selection[1]
		if classof objTransform == Editable_Poly then
		(
			uvChannel = 0 --Usado por vertex Color			
			obj = selection[1].EditablePoly
			disableSceneRedraw()

			for vertexIndex=1 to obj.GetNumVertices() do --loop through all vertices
			(
				theFace = obj.GetVertexFace vertexIndex 1 --Primera cara que comparte ese vertice
				
				indexInFace = 1 --Aqui guardo en qué indice de la cara está nuestro vértice
				--Recorro la cara y descubro el vértice en qué indice está
				for faceVertex = 1 to (obj.GetFaceDegree theFace) do
				(
					theVertexIndex =  obj.GetFaceVertex theFace faceVertex 
					if theVertexIndex == vertexIndex then --Son iguales, guardo el índice
					(
						indexInFace = faceVertex 
					)
				)
				--Y ahora hago un lookup del indice UV de esa cara en el indice en el que está nuestro
				--vertice
				theMapV = obj.GetMapFaceVertex uvChannel theFace indexInFace
				kolorea = ((obj.getMapVertex uvChannel (theMapV+1))*255) as color
				vert = (obj.getVertex vertexIndex)*objTransform.transform --Coger el vértice en mundo
				argia = Directionallight rgb:kolorea pos:[vert.x,vert.y,vert.z] target:objTransform
				argia.wirecolor = kolorea
			)
			enableSceneRedraw()
		)
	)
)

Thank Geng.
Thank you Borja! That is what I’m looking for. Great work as always. I’m going to add a UI.
Thanks again.