how to define UV for the following situation?
Blitz3D Forums/Blitz3D Programming/how to define UV for the following situation?| 
 | ||
| hi i made a simple ramp with 6 vertex and 8 tris, but didn't found a way to define uv's for them. I redifine the ramp with 12 vertex and 8 tris. Redefining the same vertex with different uv to better suit a texture. is there a more intelligent, tricky aproach? following is a sample code. 
Graphics3D 800,600
Cam = CreateCamera()
PositionEntity Cam, 0,0,-5
Light = CreateLight()
Mesh1 = CreateRamp1()
Mesh2 = CreateRamp2()
MoveEntity Mesh1,-2,0,0
MoveEntity Mesh2, 2,0,0
EntityTexture Mesh1, CreateTexture1()
EntityTexture Mesh2, CreateTexture1()
While Not KeyHit(1)
	RenderWorld
	TurnEntity Mesh1,1, 1, 0
	TurnEntity Mesh2,1, 1, 0
	Flip
Wend
Function CreateRamp1()
	;first version 6 Verts, 8 Tris
	
	Local Mesh, Surface, VertexA,VertexB, VertexC, VertexD, VertexE, VertexF
	Local Triangle1, Triangle2, Triangle3, Triangle4
	Local Triangle5, Triangle6, Triangle7, Triangle8
	
	Mesh=CreateMesh()
	Surface=CreateSurface(Mesh)
	
	VertexA = AddVertex (Surface	, 1	, -1,  1, 0, 1)
	VertexB = AddVertex (Surface	, 1	, -1, -1, 1, 1)
	VertexC = AddVertex (Surface	,-1	, -1, -1, 0, 1)
	VertexD = AddVertex (Surface	,-1	, -1,  1, 1, 1)
	VertexE = AddVertex (Surface	, 1	,  1,  1, 1, 0)
	VertexF = AddVertex (Surface	,-1	,  1,  1, 0, 0)
	
	;    E
	;    /\
	;  F/| \
	;  |\|  \
	;  | \ A \ B
	;  | |\___\
	;  |/  \  /
	;  |____\/
	;  D     C
	
	Triangle1=AddTriangle(Surface,VertexA,VertexC,VertexB)
	Triangle2=AddTriangle(Surface,VertexA,VertexD,VertexC)	
	Triangle3=AddTriangle(Surface,VertexA,VertexB,VertexE)
	Triangle4=AddTriangle(Surface,VertexA,VertexE,VertexF)
	Triangle5=AddTriangle(Surface,VertexF,VertexE,VertexB)
	Triangle6=AddTriangle(Surface,VertexF,VertexB,VertexC)
	Triangle7=AddTriangle(Surface,VertexF,VertexC,VertexD)
	Triangle8=AddTriangle(Surface,VertexF,VertexD,VertexA)
	
	UpdateNormals Mesh
	
	Return Mesh
	
End Function
Function CreateRamp2()
	;Second version, 12 Verts, 8 tris
	Local Mesh, Surface, VertexA,VertexB, VertexC, VertexD, VertexE, VertexF
	Local Triangle1, Triangle2, Triangle3, Triangle4
	Local Triangle5, Triangle6, Triangle7, Triangle8
	
	Mesh=CreateMesh()
	Surface=CreateSurface(Mesh)
	
	VertexA = AddVertex (Surface	, 1	, -1,  1, 0, 0)
	VertexB = AddVertex (Surface	, 1	, -1, -1, 1, 0)
	VertexC = AddVertex (Surface	,-1	, -1, -1, 1, 1)
	VertexD = AddVertex (Surface	,-1	, -1,  1, 0, 1)
	VertexE = AddVertex (Surface	, 1	,  1,  1, 1, 0)
	VertexF = AddVertex (Surface	,-1	,  1,  1, 1, 1)
	;    E
	;    /\
	;  F/| \
	;  |\|  \
	;  | \ A \ B
	;  | |\___\
	;  |/  \  /
	;  |____\/
	;  D     C
	
	Triangle1=AddTriangle(Surface,VertexA,VertexC,VertexB)
	Triangle2=AddTriangle(Surface,VertexA,VertexD,VertexC)
	Triangle3=AddTriangle(Surface,VertexA,VertexE,VertexF)
	Triangle4=AddTriangle(Surface,VertexA,VertexF,VertexD)
	
		
	VertexF = AddVertex (Surface	,-1	,  1,  1, 0, 0)
	VertexE = AddVertex (Surface	, 1	,  1,  1, 1, 0)
	VertexC = AddVertex (Surface	,-1	, -1, -1, 0, 1)
	VertexB = AddVertex (Surface	, 1	, -1, -1, 1, 1)
	VertexA = AddVertex (Surface	, 1	, -1,  1, 0, 0)
	VertexD = AddVertex (Surface	,-1	, -1,  1, 1, 0)
	
	Triangle1=AddTriangle(Surface,VertexF,VertexB,VertexC)
	Triangle2=AddTriangle(Surface,VertexF,VertexE,VertexB)
	Triangle3=AddTriangle(Surface,VertexF,VertexC,VertexD)
	Triangle4=AddTriangle(Surface,VertexA,VertexB,VertexE)
	
	
	
	UpdateNormals Mesh
	
	Return Mesh
	
End Function
Function CreateTexture1()
	For i = 0 To 256/32+1
	For j = 0 To 256/32+1
		c = (i + j) Mod 2 * 255
		Color c, c, c
		Rect i * 32, j * 32, 32, 32
	Next
	Next
	
	tex = CreateTexture(256, 256, 1+8)
	CopyRect 0, 0, 256, 256, 0, 0, BackBuffer(), TextureBuffer(tex)
	Color 255,255,255
	
    Return tex
	
End Function
thank's in advance Juan | 
| 
 | ||
| For that, you'll need a little trigonometry; I'm cream-crackered right now, so I can't just work the math out for you, but basically, you need Sin()[b] and [b]Cos() to accurately map the UV of the vertices on the ramp's slope. Have a look at the Sin()/Cos() example in the help docs, that should get you going. | 
| 
 | ||
| Starfox's unweld function (second function in the code I quote in the post linked below) might be of use to you? http://www.blitzbasic.com/Community/posts.php?topic=92901#1064448 | 
| 
 | ||
| hi, thank's i just ask about a simple way of defining uv for this shape, if a simple one exist. i thought that there were no need for a uv mapping software, probably one knows a way of do it simply. Reordering the tris definition may be or some thing not so obvious at first. in the second Ramp definition i manually unweld part of the shape, duplicating vertex and so, reaching the posibility of define diferent uv coords for different vertex placed in the same point of the 3d space. i just thought that being the shape so simple, there would be a simple way for doing it and i was overcomplicating the thing! Juan |