realbasic-games
[Top] [All Lists]

Re: UV settings

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: UV settings
From: "Joseph J. Strout" <joe at realsoftware dot com>
Date: Mon, 24 Oct 2005 08:18:19 -0600
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <9abc90404cec20e07a6dc74205677e14 at pyramiddesign dot us> <a0620070ebf80298f19cf at [10 dot 0 dot 1 dot 4]> <65176 dot 68 dot 38 dot 18 dot 235 dot 1130019764 dot squirrel at webmail dot pyramiddesign dot us>
At 3:22 PM -0700 10/22/05, joe at pyramiddesign dot us wrote:

 > You're only setting the UV coordinate for the first vertex (index 0).
 You need to set it for all four vertices to get anything sensible out.

I was wondering about that. So I set all four UV listings to the same U,V
values? I would assume so.

No, you should set each one to the U,V value you want associated with that vertex.

I see there is some general introduction needed here, so here's a stab at it:

Texture mapping works as follows: each Trimesh is attached to one Material, which may have a Texture (which is a Picture that you want applied to the mesh). Every vertex in the Trimesh maps to some location in that texture. The position in the texture that it maps to is the "U,V coordinate" of that vertex. Roughly speaking, the U is the X position within the texture, and the V is the Y position in the texture. Actually, U coordinates range from 0 (left side of picture) to 1 (right side of picture), and V coordinates also range from 0 (top of picture) to 1 (bottom of picture).

So, if you have a triangle that you want to map to the upper-left triangle of your texture, the UV coordinate of the upper-left vertex would be (0,0), the top-right vertex would have UV of (1,0), and the lower triangle would have a UV of (0,1).

Note that it is also possible to specify UV coordinates outside the 0-1 range; in this case, think of the texture as tiling an infinite plane. So if I were to set the U coordinate of one vertex to 0, and the U coordinate of the neighboring vertex to 5, the texture would repeat 5 times (along the horizontal or U axis) along that edge of the mesh.

A good way to get a feel for these things is to use the Trimesh Explorer demo project. You can create a Trimesh from a picture, which is a very simple case of two texture-mapped triangles. You can see how the UV coordinates relate to the vertices, which then define the triangles. You can also fiddle with the numbers interactively and see how it affects the appearance of the object.

You can also fiddle around in Meshwork, which uses the same concept of UV mapping per vertex (when in "pinned" texture-mapping mode).

HTH,
- Joe

--
Joe Strout                          REAL Software, Inc.

Vote for REALbasic (twice!) in the LinuxWorld Reader's Choice Awards:
http://linux.sys-con.com/general/readerschoice.htm
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>