[Closed] Vertex color sanity check
Okay. I am very confused. Honestly I have been working with MAXScript for a couple of weeks, and I have never worked with a similar tool ever before. I have some knowledge of 3DStudio, but none of computer graphics programming.
Now let me try to explain what I’m trying to do, because I’m affraid I’m heading the worng direction:
I have a huge function that calculates the colour for a given vertex (or face). I give this function the vertex’s (or face’s) normal as the input, and I get the colour to apply to that vertex (face) as the output of the function.
So, assuming this function works perfectly, is this the propper way to do this?
What I’m thinking is to apply this output colour to meshop.setMapVert, is that right? But only during this early stage. Later it would not be with simple colours but with any material so, is this Bobo-function working with the #alpha channel what I need?
Vertex colors are very confusing! So with acknowledging that lets have a look and see if I can help with this (because I’m also still learning all about vertex colors!).
Some pointers… vertex color vertices are not the same as mesh vertices. Vertexcolor vertices are the same as UVW vertices. The vertexcolors are stored in mapchannel 0 and behave the same as a normal UVW map (try to apply a UVWunwrap to an vertexedcolored object, select vertexcolors on the Unwrap and press reset, now check out the UVeditor, colors are represented as UVW (or point3) values). So that means there’s no direct relation between a mesh vertex and a vertex color vertex. That’s the real confusing part.
Only a face has a relation to a VC vertex each (tri)face has 3 UVW verts… with these you can do the manipulations.
First
You are applying the normal direction of a given face as vertex color to the vertexcolor vertices? Am I right?
in very short pseudocode
normal = getNormalFace object face1
mapVerts = getMapVertsFromFace object face1
for i in mapVerts do setMapVert object i normal
This will apply the face normal as color to the faces’ mapVerts.
Is that what you mean? And what do you want to do with this information, you want to apply the normals as vertex color? there should be easier ways… maybe…
-Johan
Hello again,
Well, actually no.
Suppose we have a function myFunction that gets one input parameter Nn, and returns a point3 color. The calculations of the function are irrelevant right now. Nn is the normal of a given vertex (or face). The output is the colour I want to apply to that vertex (or face).
So my code goes inside the Bob-function like:
[left]([/left]
theMesh = snapshotasmesh $ –get the TriMesh into memory
vchannel = 0 –define vcolor channel index
vert = 1 –this is the vertex to which I want to calculate a new colour
[left]–Nn contains the normal of this vector[/left]
– Get all faces using the vert as array
[left]– Actually I don’t need to go through the whole of this loop,[/left]
[left]– to get on correct mV is enough.[/left]
fArray = (meshop.getFacesUsingVert theMesh vert) as array
for f in fArray do – for each face,
(
–Get geometry face – vertex is either its first, second or third
[left]component [/left]
gF = getFace theMesh f
– Get map face (index corresponds with geometry face)
mF = meshop.getMapFace theMesh vchannel f
– Find order inside the mesh face – vertex (component) order will be the
[left]same in both[/left]
mV = case of
(
(gF.x == vert): mF.x
(gF.y == vert): mF.y
(gF.z == vert): mF.z
)
–apply the calculated colour to the vertex
[left]meshop.setMapVert theMesh vchannel mV (myFunction Nn)[/left]
)–end f loop
delete theMesh –release the mesh from memory
[left])–end script[/left]
[left]So, at this point, this function is enough for me! I’m at a point in which working with plain colours is all I need (I will post here my results as soon as I have them).[/left]
[left]But later, I need to use textures, so myFunction won’t be working with regular colours, and therefore it won’t be returning regular colours. So my question is, would this procedure still work for me then? Is there a way to get the RGB component of any material to apply it to a given vertex (or face)?[/left]
[left]Once again, thank you.[/left]
Ah ok, I see what you mean now. The same function could be a starting point to retreive colors from a texture. There’s no quickmethod to retreive information from a texture. If you want to get it from bitmaps, the thing you have to do is to figure out where the UVWmap (channel 1, 2 till n…) vertex is and where on the bitmap that is, then you have to get the pixel which corresponds to the UV coordinate with the bitmap functions.
It’s not a trivial thing, and I don’t really know how to get the values from procedural textures such as noise. I’d reckon you’d need to render the map to a bitmap and sample that. But that’s as far as I can take from the top of my head.
In the MXS manual there’s a tutorial about a object map painter which uses lot of these idea’s in a somewhat similar fashion. It has been written by Bobo and if you really want some expert advice, you should try to contact him also check out a tutorial he made: http://www.scriptspot.com/bobo/mxs5/pflow/pflow__inherit_UV.htm
Cheers,
-Johan
Hello to everyone who’s been following my posts here, specially JHN and Bobo.
After all my questions, I have finally completed the first stage of what I need to do.
Please watch it here:
So how does this work? I’m really not sure at all. The function which performs the main blending and masking was not written by me or for MAXScript and I don’t understand it. All I did was to translate it to MAXScript to achieve what I need to do.
Basically the idea is to make some sort of extension to the Top/Bottom material and make it a Top/Bottom/Left/Right/Front/Back material. Aditionally, the original function was very, very precise because it worked by pixel, I had to work by vertex so I lost a lot of precission.
Well, I don’t want to discuss this here anymore, I’ll open a new thread for this because my new questions go away from the main subject of this one, and I also want to get more attention.
Thank you again for all your help.