Notifications
Clear all

[Closed] Getting vertices' position and uv – no correlation?

Hi.

I want to generate an list of vertices for my custom format exporter. I have to store the vertices’ position and texture coordinates (single channel).

I’ve tried it this way:

ePoly = $ -- I assume we've selected the Editable Poly object
pos = #()
uvs = #()
local verticesCount = polyOp.getNumVerts ePoly

for v = 1 to verticesCount do  ( 
    append vertices (polyOp.getVert ePoly v) 
    local mapVertex = polyop.getMapVert ePoly channelIndex v --channelIndex = 1
    append uvs mapVertex
)

The problem is, uvs and pos values for same rows are not corresponding. When I import such model in my engine, I see that textures coordinates are wrong (but not random). Like I would shuffle the uvs arrays – there is none relation between indices in pos and uvs arrays, but the single values looks ok.

The Editable Poly mesh I am working on has Unwrap UVW and all other modifiers collapsed to single Editable Poly before the script runs.

14 Replies

The geometry vertices and UV vertices does not necessarily needs to be the same. In fact, most of the times there will be more UV vertices than geometry vertices.

Here are two functions to gather both of them:

(
	fn GetNodeVerts node =
	(
		local getvert = polyop.getvert
		local verts = for j = 1 to node.numverts collect getvert node j
		return verts
	)

	fn GetNodeTVerts node channel =
	(
		local getmapvert = polyop.getmapvert
		local tverts = for j = 1 to (polyop.getnummapverts node channel) collect getmapvert node channel j
		return tverts
	)	
	
	verts = GetNodeVerts $
	tverts = GetNodeTVerts $ 1
	
	format "verts:% tverts:%
" verts.count tverts.count
)

The following simple examples will show how the UV vertices can be completely different than the geometry vertices:

(
	node = converttomesh (box mapcoords:on isselected:on)
	unwrap = unwrap_uvw()
	modpanel.addmodtoselection unwrap ui:on
	unwrap.edit()
	
	messagebox ("NumTVerts: " + (node.numtverts as string))
)
(
	node = converttomesh (box isselected:on)
	uvw = uvwmap maptype:5
	unwrap = unwrap_uvw()
	modpanel.addmodtoselection uvw
	modpanel.addmodtoselection unwrap ui:on
	unwrap.edit()
	
	messagebox ("NumTVerts: " + (node.numtverts as string))
)

PolyTools3D – Thank you very much

I understand now why and how they are not related.

Is there a way to combine them somehow? Without the loop through faces (expensive search for duplicates)?

Only the indices of the mesh faces and the UV faces are the same. The UV verts and edges can be much more than the mesh verts and edges.

4 Replies
(@polytools3d)
Joined: 11 months ago

Posts: 0

For editable meshes the UV edges cannot be more than the mesh edges as every face has 3 edges.
For vertices, the UV vertices can be as much as 3 times the amount of geometry faces.

For editable polys it is different.

(@miauu)
Joined: 11 months ago

Posts: 0

You are right.
My thoughts was for editable poly objects, because I use them more often than editable mesh.

(@denist)
Joined: 11 months ago

Posts: 0

there is no such thing as mesh uv edge, as well as no methods to work with uv edges

(@polytools3d)
Joined: 11 months ago

Posts: 0

So what is a UV face, a group of 3 or more vertices?
Don’t two points define a segment in space, and so what we call edge in this case?
Don’t we have open edges in UV mapping?
What is a UV Cluster or UV Shell?

The fact that there are no methods exposed to directly work with them does no mean they are not there.

If you are talking about how Max handles them, then yes, there is no storage of the UV Edges, but you can build your own structure (as the Unwrap UVW modifier does) and then work with them.

If you don’t want to see them, then there are no edges, but if you believe in them you will see.

It’s all relative, and using the same line of thought I could say there are no edges in a geometry neither. Or have you seen any edge stored in an .OBJ?

I am not sure to understand what you mean by “combine”.

Geometry vertices and UV vertices must be treated separately, as they store completely different information.

Every UV channel is indeed a separated geometry, but we are used to visualize them different than how we visualize objects, and so it might be confusing, but they have their own rules.

I see. About “combining” them: in DirectX I populate vertex buffer with vertices. And each of them has its position (3 floats) and uv coordinates (2 floats). I’ve forgot that 3ds max has a bit more complex interpretation for texture coordinates.

Thank you for clarifications, now I know the “why & how”

Geometry and UV vertices, both have 3 float components, [x,y,z] for geometry and [u,v,w] for UV vertices, which turns out to be pretty much the same as [x,y,z], just different naming.

If you don’t need the W component of the UV vertices (generally not used), you can strip that one out and just have [u,v].

That would give you the same result as what you need to use in DirectX.

[b]

Is there a way to combine them somehow? Without the loop through faces (expensive search for duplicates)?

[/b]yes if you only ever need position and uv coord a simpler method is possible, but as soon as you add normals (every vert can have multiple normals just as every vert can have multiple UV’s) the same with vertex color, vertex illumination, vertex alpha, UV channel 2, UV channel 3 etc etc Each of these can “break” the mesh and in different places and trying to get the simple version to work in these cases can be a tad tricky. IIRC one top studio had a limit on the output number verts as a percentage of the input vert count and if it exceeded it the export would fail so the artist would have to correct the model (stitch up some uv seams for example). If speed is that essential then SDK is the way to go for this sort of thing.

there is an edge thing in mesh geometry (editable mesh, trimesh). there is edge in unwrap modifier.

in map data there are no edges. so it’s hard to say how many of them. one thing i can say for sure that the number of map edges can’t be smaller than the number of not isolated map verts minus 1, and larger than the number of map faces.

1 Reply
(@polytools3d)
Joined: 11 months ago

Posts: 0

It’s no so hard. We can calculate them.

I suppose the reason why they are not stored is because there is no need to constantly visualize them, and so it would be a waste of resources.

I don’t know how all other 3d software out there handle this, but I would think some of them do store the UV edges for fast editing purposes.

The edges are implicitly stored in the faces structure (for both, geometry and UVs) and so they can be retrieved from there.

I know what the maximum could be, which is obviously the number of geometry triangles by 3.
But the minimum would depend on how you decide to store them, by face, by cluster, welded verts, etc.