Notifications
Clear all

[Closed] Multiple Mapping Channels, do Faces Correspond?

I’m looking to export raw UVs from multiple mapping channels on the same object. Now I’m starting to think that I’m going to logic bomb myself.

Do the faces between different mapping channels correspond?

If I grab face 1 from mapping channel 1, is is the same face as face 1 from mapping channel 2?

If they do correspond, to the verts correspond as well?

I guess something like:

MC1.Face1 –> MC2.Face1

MC1.Face1.Vert1.x –> MC2.Face1.Vert1.x
MC1.Face1.Vert2.x –> MC2.Face1.Vert1.x

8 Replies

Faces do and verts don’t

Check out the topic “Understanding Texture Coordinates and Vertex Colors” in the MAXScript Reference. Just type in “Understanding” in the Index tab and you will find it…

In short, the faces always correspond, and the vertex indices of each face point to vertices that correspond, too, but the indices of vertices and texture vertices inside the vertex arrays and mapping vertex arrays do not. So if face 42 has its first mesh vertex pointing at vertex 123, and mapping channel 2 texture face 42 has its first mapping vertex index pointing at mapping vertex 321, you know that this mapping vertex is being used by mesh vertex 123. But mesh vertex 123 might be shared by multiple faces, and each corresponding mapping face might be using a different mapping vertex. If you unwrap a sphere, you will see that the pole mesh vertices use as many mapping vertices as there are faces sharing that mesh vertex, while vertices at the back seam usually have two mapping vertices to accomodate both U=0.0 and U=1.0 at the same time.

Okay, I’m gonna back up a bit and get a bit more explicit because it’s the indexing thing that is throwing me for a loop. That and I have a hard time coming to grips with how MaxScript handles certain things.

I’m working on a way to get mapping channels into Photoshop. Data sets of two different mapping channels in the same file. Once I get two channels exported, I can load them up into PS and let PS do the rastor acrobatics without having to open Max again (or keep it open).

So I have one object with multiple mapping channels.

What I can do is cycle through the faces and vertices for a given channel and output to a file.

Now, one of the limitations that I’m working with is how I export the UV data. I can’t use indexing – I have to resort to raw face to vert to UV data.

Chan1.Face1.Vert1.U
Chan1.Face1.Vert1.V
Chan1.Face1.Vert2.U
Chan1.Face1.Vert2.V

And so on for the channel.

What I’m having a hard time with is figuring out how to make sure that the other channel that I want to export corresponds to the first channel that I exported.

This is what I can’t do – and it truly vexes me to no end.

Is it as simple as running through the same cycle? If it’s not, how do I make them correspond?

This seems to answer to my question:

In short, the faces always correspond, and the vertex indices of each face point to vertices that correspond

If that is correct and I can run through the same cycle twice, then all should be well. If not, then I’m in a for a world of confusion.

~crosses fingers~

I haven’t used Photoshop lately (!!!), so I have no idea what you are exporting.
But in general, you do this (pseudo-code, don’t run!):

mapchannels = #(1,2)
for m in mapchannels do
(
for f = 1 to theMesh.numfaces do
(
theFace = getFace theMesh f –this is the face f
meshVert1 = theFace.x –this is the index of the first mesh vertex
meshVert2 = theFace.y
meshVert3 = theFace.z
meshVertPos1 = getVert theMesh meshVert1 –the POSITION of the 1st mesh vertex
meshVertPos2 = getVert theMesh meshVert2
meshVertPos3 = getVert theMesh meshVert3
theMapFace = meshop.getMapFace theMesh m f –the map face (Point3, 3 indices)
mapVert1 = theMapFace.x –the INDEX of the first map vertex, maps to first mesh vertex in face f
mapVert2 = theMapFace.y
mapVert3 = theMapFace.z
mapUVW1 = meshop.getMapVert theMesh m mapVert1 –the UVW value of the first map vert
mapUVW2 = meshop.getMapVert theMesh m mapVert2
mapUVW3 = meshop.getMapVert theMesh m mapVert3
)
)

In this case, your external loop has the mapping channels 1 and 2.
The internal loop goes through all mesh faces (which is the same count as the map faces).
For each face, get the mesh face. The INDICES of the 3 corners of the face point at the mesh vertex array. If you would call ‘getVert theMesh meshVert1’ you would get the world space position of that vertex.
Then you get the map face with the SAME INDEX as the mesh face. Its 3 corners point at 3 map vertices which have DIFFERENT indices than the mesh vertices, but correspond to them. Then you can call meshop.getMapVert() for each corner of the map face and you will get the 3 UV coordinates mapUVW1, mapUVW2 and mapUVW3 that correspond to the 3 mesh vertices meshVert1,meshVert2 and meshVert3. You can export these values, then it goes to the next face and so on.
So for each channel, you loop through all faces and get the 3 map vertices of each.

Once again, keep in mind that a mesh vertex referenced by multiple mesh faces will have as many map faces in a channel, each one potentially pointing at a different map vertex, so you can have any number of map vertices corresponding to a single mesh vertex.
(3DS DOS had a one-to-one correspondence between map vertices and mesh vertices and it was a pain.)

That is pretty close to what I have. I’m starting to think that my crazy idea will work without being getting too complicated with index acrobatics that confuse my poor little dyslexic brain.

I can draw triangles in Photoshop and even translate/interpolate rastor between two different triangles. Drawing a triangle is actually a bit more complicated than I thought. But I got it done. (The idea of a mini-mapping-channel-render engine in PS really cracks me up.)

Now it’s just a matter of getting the triangle UV data out of Max and into Photoshop. Hopefully I can keep things straight. If I end up with a bunch of dis-jointed rastor triangles all over the place, I just might… cry or something.

I’ll let y’all know.

Many thanks.

If you are drawing the UVs, all you need is the UV value multiplied by the image width minus one for the width and similar for the height, but subtracted from the height value (assuming the UVs are in the 0.0-1.0 range).
So if you have an image that is 1024×1024, a U value of 0.0 corresponds to pixel 0, a value of 1.0 corresponds to pixel 1023. Since the V coordinates’ 0 point is in the bottom left corner, but the first pixel is in the UPPER left corner, you have to subtract from the full height the V multiplied by the height. A vaue of 0.0 results in 1023 and a value of 1.0 results in pixel 0.
If you DO use values outside of the 0.0-1.0 range, you might need to use the MOD method to get your UVs in the range.

No worries about the Photoshop side of things. Been doing that kind of thing for a few years. But definitely thanks for your concern about the silly little things can cause extended sessions of hair pulling.

Minor Update

I can get the data out of Max. Have to use text because of bit flipping. Don’t really feel like dealing with bit flipping and then not bit flipping. Even though text files are mucho biggier, should allow other folks to easily create their own data sets with 3d progs other than Max.

And I can get the data into Photoshop. Turns out reading floats from a text file is a bit trickier than I first thought.

All that is left to do is run the data through my triangle scanner. And cross my fingers with the hope of corresponding UVs.

Hopefully this weekend I’ll have good news.

Holy nibble my toes – it works.

~does a happy dance~

Turns out that the face/verts of different mapping channel do correspond.

After exporting a couple of data sets out of Max, I can now do mapping channel work in completely in Photoshop. Want to paint a mask in this channel and then apply it to that channel sans Max? Not a problem.

I chucked around 7000 triangles into my scanner thingie and PS spits out uberness in well under 2 seconds. Not sure if PS will choke on higher tri counts due to using an int instead of an unsigned long int and limitations on the arrays that I’m using.

Other than type casting and array limitations, the only thing that I really have to worry about is transparency. The rest should be cake.

Once I get the PS clean-up almost done, I’ll probably be asking for help on cleaning up the Max Script.

The one thing that really makes me giggle about this is bringing mapping channels to folks that don’t have access to high-end 3d prog that uses them. I know a community that uses the same mesh and have to resort to old school trial-n-error for seams and such. I’m more than willing to toss out some data sets to make texture mapping a head and such easier. And you don’t even really need Photoshop – just a compliant host.

Back to my code monkey dance.