[Closed] vert>get tvert
Hi There,
I am writing an other exporter, and I need to export renderman uv map for objects.
I followed the guidlines in the help file, and worte this rough code, that it will find the vertex corresponding tvert. Its needed since renderman uv verts accepts only the same number of tverts as the verts.
There must be a much more simple to way to get it. This works more or less, I also get weird result (worry about that later) but I need a much faster version. Is there any other way? Thanks (see the comments to follow the code)
clearlistener()
t1 = timestamp()
facearr = #() -- facearray
texfacearr = #() -- texture face array
indexarr = #() --the face index array with contains only faces with the corresponding vertex (vindex)
vindex = 6 -- the vertex Index > goal find the corresponding texture vertex index.
-- GET THE FACE LIST
for i=1 to $.numfaces do (
facearr[i] = getface $ i
)
-- FILL THE FACE INDEX ARRAY, (only faces with the correspoding vertices)
for i=1 to facearr.count do (
if facearr[i][1] == vindex or facearr[i][2] == vindex or facearr[i][3] == vindex do append indexarr i
)
facearr = #() -- clean the face array.
-- GET THE FACE CORRESPONDING TEXTURE FACE ARRAY
for i=1 to indexarr.count do (
facearr[i] = getface $ indexarr[i]
texfacearr[i] = gettvFace $ indexarr[i]
)
-- FIND THAT FACE VERTEX INTEGER WHICH IS A PART OF ALL FACE ELEMENTS IN THE ARRAY, THAT WILL BE THE VERTEX CORRESPONDING TVERT INDEX
nr = #()
nr[1]= 0
nr[2]= 0
nr[3]= 0
-- LOST OF LOOPS.
for k=1 to 3 do (
for i=1 to texfacearr.count do (
for h=1 to 3 do (
if texfacearr[1][k] == texfacearr[i][h] do nr[k] = nr[k]+1
)
)
if nr[k]==texfacearr.count do (
tvertindex = texfacearr[1][k]
exit
)
if k == 3 do (
tvertindex = texfacearr[1][3]
)
)
facearr
texfacearr
tvertindex -- THIS IS THE INDEX OF TVERT
t2 = timestamp()
print (t2-t1)
I hate to say it, there’s no direct relation between a vertex and a texture vertex. You need to get the geo verts face in order to get the UV face and with the UV face you grab the UV vert. Because of the vert order in both UV and geo face being the same you can derive which UV vert corresponds with which geo vert.
Convoluted to say the least…
-Johan
Thats what the code does, as it explained in the maxscrip help. Now it is a lots of lines. I was wondering even known it is not the usual case, maybe somebody have meet with this problem before, and have a better solution.
The code finds the faces belongs, to the vertex, then finds, the same texture faces, and then checks the texture vertices from the faces whihc on is present in all of them, so that is obviously the corresponding vertex.
I will maybe talk to 3dsmax develpers on this case, maybe they will help at least to get correct result. THanks anyway, if you have shorter code, you are welcome to post.
now, meshop.defaultMapFaces fixes this trouble and makes it simple, nopw I got the uv coordinates out, however it does look like there is planar mapping over the meshes. Like the uv-s ar flattened or something.
I did an other shorter code, and it does the job, but there are seams, and problems.
Anybody could give me a hand to fix that? Note, this time I didnt use any uv reset (meshop.defaultMapFaces)
clearlistener()
x=0
vmesh = snapshotasmesh $
meshvert = 5
meshfaceusedbyvert = meshop.getFacesUsingVert vmesh meshvert
for i=1 to meshfaceusedbyvert.count do (
if meshfaceusedbyvert[i] == true do (
x=i
exit
)
)
textface = gettvface vmesh x
meshface = getface vmesh x
if meshface[1] == meshvert do tvertindex = 1
if meshface[2] == meshvert do tvertindex = 2
if meshface[3] == meshvert do tvertindex = 3
tvert = textface[tvertindex]
tvert = gettvert vmesh tvert
This is typically what happens when there’s just one tvert per vertex (like in the .3ds format), check out the topic Understanding Texture Coordinates and Vertex Colors in the maxscript reference for more information on texture vertices.
Martijn
Hej Martin, I know that, but the file format I am exporting to., striuctly forbid to have more than one texture coord for a vertex.
However, all other exporters seems to be fine with it. For example the cinema4d exporter exports perfectly. I have read and undesrtood that part, now I am trying to find a real soulution for it out of max. I know its possible.
Only Luxrender sensitive about it, any other renderer I worked so far didnt mind it to have more texture coords/verts.
I hope this all not a misunderstanding.
I throught I try to manually get those tverts closer to each other. Will see. If you have any other idea pls share.
I got an other info, that I should duplicate as many time those vertices which have more than one texture vertex assigned as many more tverts there.
I will try that.
Hi, Im also working on either this excact problem or one very very similar. Did you manage to sort out this?
There is a solution for you if the vertex order doesnt count…
This is based on face order, so this way is much easier.
The code is written by perpixel.
mverts = #()
mtverts = #()
mnverts = #()
mfaces = #()
tmesh = snapshotAsMesh obj
num_faces = tmesh.numfaces
for i = 1 to num_faces do
(
face = getFace tmesh i
v1 = (mverts.count + 1)
v2 = (mverts.count + 2)
v3 = (mverts.count + 3)
append mfaces [v1,v2,v3]
v1 = getVert tmesh face.x
v2 = getVert tmesh face.y
v3 = getVert tmesh face.z
append mverts v1
append mverts v2
append mverts v3
v1 = getnormal tmesh face.x
v2 = getnormal tmesh face.y
v3 = getnormal tmesh face.z
append mnverts v1
append mnverts v2
append mnverts v3
tvface = getTVFace tmesh i
v1 = getTVert tmesh tvface.x
v2 = getTVert tmesh tvface.y
v3 = getTVert tmesh tvface.z
append mtverts v1
append mtverts v2
append mtverts v3
)
for f in mfaces do
(
format "% % %
" (f.x as integer - 1) (f.y as integer - 1) (f.z as integer - 1) to:tmpLxs
)
writeline "]\"point P\" ["
for v in mverts do
(
format "% % %
" v.x v.y v.z to:tmpLxs
)
writeline "]\"normal N\" ["
for v in mnverts do
(
format "% % %
" v.x v.y v.z to:tmpLxs
)
writeline "]\"float uv\" ["
for v in mtverts do
(
vert = v
format "% %
" vert.x vert.y to:tmpLxs
)
writeline "]"
WriteLine "AttributeEnd
"
delete tmesh
)