how do i make a texture stretch over a mesh?

i am working on a project where i have some code that generates a ribbon-type object, on this ribbon I want to render various textures … when i just want one long continuous texture (that is stretched) everything is ok, but when i want to use a texture with some text one it is unreadable.

This is what I’m trying to achieve: (See a short Quicktime of it in motion here)
http://www.okdeluxe.co.uk/_files/unity_ribbon/text_ribbon.mov

I am new to generating meshes from code so I may be doing something funny (or not doing enough). See Unity screenshot below.

Here’s a snippet of the Unity code I am using to generate the mesh with:

	// clear mesh to start with
	mesh.Clear();
	
	// vertices
	var mVertices = new Array();
	
	mVertices.Push(leftArr[0]);
	mVertices.Push(rightArr[0]);
	
	for(i=1; i<numSegs; i++){
		mVertices.Push(leftArr[i]);
		mVertices.Push(rightArr[i]);
		
		mVertices.Push(leftArr[i]);
		mVertices.Push(rightArr[i]);
	}
	
	mVertices.Push(leftArr[numSegs]);
	mVertices.Push(rightArr[numSegs]);
	
	//draw the mesh
	mesh.vertices = mVertices.ToBuiltin(Vector3);
	
	
	// UVs
	var mUV = new Array();
	for(i=0; i<numSegs; i++){
		mUV.Push(Vector2 (0, 1)); 
		mUV.Push(Vector2 (1, 1)); 
		mUV.Push(Vector2 (0, 0)); 
		mUV.Push(Vector2 (1, 0));
	}
	mesh.uv = mUV.ToBuiltin(Vector2);
	
	
	// normals
	var mNormals = new Array();
	for(i=0; i<numSegs; i++){
		mNormals.Push(Vector3(0, 1, 0)); 
		mNormals.Push(Vector3(0, 1, 0));
		mNormals.Push(Vector3(0, 1, 0)); 
		mNormals.Push(Vector3(0, 1, 0));
	}
	mesh.normals = mNormals.ToBuiltin(Vector3);
	
	
	// triangles
	var mTriangles = new Array();
	for(i=0; i<numSegs*4; i+=4){
		mTriangles.Push(i); mTriangles.Push(i+1); mTriangles.Push(i+2);
		mTriangles.Push(i+3); mTriangles.Push(i+2); mTriangles.Push(i+1);
		mTriangles.Push(i+2); mTriangles.Push(i+1); mTriangles.Push(i);	
		mTriangles.Push(i+1); mTriangles.Push(i+2); mTriangles.Push(i+3);	
	}
	mesh.triangles = mTriangles;

I’m stuck! Any pointers/ideas/help would be greatly appreciated :slight_smile:

Thanks,
Mikkel

www.okdeluxe.co.uk


54263--1969--$wanted_texture_effect_749.png

Your texture’s UV’s right now are going from 0 to 1 on every pair of triangles, creating the tiling. You need to change those values so that it smoothly moves from 0 to 1 along the length of the whole strip.

Ah, got it. Thanks :slight_smile:

Corrected the UV coordinates and swapped the order a bit.

var segWidth : float = 1.0/numSegs;
var mUV = new Array(); 
for(i=0; i<numSegs; i++){
    mUV.Push(Vector2 (1, i*segWidth)); 				//1,0
    mUV.Push(Vector2 (0, i*segWidth)); 				//0,0
    mUV.Push(Vector2 (1, i*segWidth + segWidth)); 	//1,1
    mUV.Push(Vector2 (0, i*segWidth + segWidth)); 	//0,1
}
mesh.uv = mUV.ToBuiltin(Vector2);

Cheers,
Mikkel