View Full Version : Get Vertex Color

04 April 2008, 10:48 AM
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".

04 April 2008, 10:42 AM
" 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.

04 April 2008, 08:11 PM
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

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
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

04 April 2008, 08:28 AM
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.

CGTalk Moderation
04 April 2008, 08:28 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.