Coding UV space

Hi,

I’ve been learning about procedural geometry and so have a little script which makes a 6 sided box. I’m trying to set up the UVs for this with standard box mapping but I’m finding the documentation confusing. It seems you have an array of 2D vectors, one for the UV’s of each vertex. But I do not understand how you can have a single 2D vector represent the UV space of a vertex, when a vertex may be part of multiple UV spaces. In the case of this box primitive; each corner vertex is part of 3 different UV spaces.

Could someone make this a little clearer to me please?

Whenever a single vertex needs different values for one of it’s properties (uv in your case, but also normals, or colors, whatever), you will need to duplicate it for as many different values you need. In your case, you need 4 vertices for each side of the cube, not only for the uvs, but also for the normals to get a proper flat shaded shaded surface.

Hi thanks for the reply but I still don’t see how to code this up. Below is the some very simple code for creating 2 sides of a cube. The UV’s work for one surface but them smear along the other as you would expect with planar mapping. How do I update the code for box mapping so that I have the image displayed correctly twice, one on each side of the cube (Not a single image bent round the side)? Obviously you’ll have to drop a material on to check out the mapping. Thanks for any help.

var material : Material;
function Start ()
{
gameObject.AddComponent(“MeshFilter”);
gameObject.AddComponent(“MeshRenderer”);
var mesh : Mesh = GetComponent(MeshFilter).mesh;

mesh.Clear();
mesh.vertices = [Vector3(0,0,0), Vector3(0,1,0), Vector3(1, 1, 0), Vector3(1,0,0), Vector3(0, 0,-1), Vector3(0,1,-1)];
mesh.uv = [Vector2 (0, 0), Vector2 (0, 1), Vector2 (1, 1), Vector2(1,0), Vector2(0, 0), Vector2(0,1)];
mesh.triangles = [0, 2, 1, 0, 3, 2, 0, 1, 4, 1, 5, 4];

mesh.RecalculateNormals();

if (material)
renderer.material = material;
else
renderer.material.color = Color.white;
}

A vertex can’t be part of multiple UV spaces. A cube needs 24 vertices, 4 for each face.

–Eric