Texturing Mesh
Blitz3D Forums/Blitz3D Programming/Texturing Mesh| 
 | ||
| I'm creating a simple tile mesh - rather than CreateCube to save triangles: Function CreateTile() tile=CreateMesh(parent) tileSurface=CreateSurface(tile) v0=AddVertex(tileSurface,-1,0,-1) v1=AddVertex(tileSurface,-1,0,1) v2=AddVertex(tileSurface,1,0,1) v3=AddVertex(tileSurface,1,0,-1) AddTriangle(tileSurface,v0,v1,v2) AddTriangle(tileSurface,v2,v3,v0) UpdateNormals(tile) Return tile End Function This works great and saves me lots of triangles - however, I can't seem to texture the mesh. When I apply a texture with EntityTexture the mesh is black and the texture is not applied. When I switch back to using CreateCube and apply the same texture it works fine. Any ideas? | 
| 
 | ||
| Have you tried FlipMesh? I imagine the tile is facing away from the camera when first created. Just a note tile=CreateMesh(parent) There's no value for parent, so if you wanted a parent for the tile, you ought to pass in parent as a parameter on the function. | 
| 
 | ||
| Thanks for the reply Malice. Using FlipMesh makes the "tile" invisible - so I guess the mesh is facing the camera. Point noted about "parent". Thanks, Ian. | 
| 
 | ||
| This piece of code demonstrates the problem: 
Graphics3D 640,480,16,2
SetBuffer BackBuffer()
camera=CreateCamera()
RotateEntity camera,45,0,0
light=CreateLight()
RotateEntity light,45,0,0
aTile1 = CreateFlatTile()
aTile2 = CreateFlatTile()
aTile3 = CreateCube()
aTile4 = CreateCube()
PositionEntity aTile1,-2,-5,4
PositionEntity aTile2,2,-5,4
PositionEntity aTile3,-4,-5,4
PositionEntity aTile4,4,-5,4
EntityColor aTile1,255,0,0
EntityColor aTile3,255,0,0
tileTex = LoadTexture("texture\tile1.png",1)
EntityTexture aTile2, tileTex
EntityTexture aTile4, tileTex
Repeat
	RenderWorld
	UpdateWorld
	Flip
Until KeyHit(1)
End
Function CreateFlatTile()
	tile=CreateMesh()
	tileSurface=CreateSurface(tile)
	v0=AddVertex(tileSurface,-1,0,-1)
	v1=AddVertex(tileSurface,-1,0,1)
	v2=AddVertex(tileSurface,1,0,1)
	v3=AddVertex(tileSurface,1,0,-1)
	AddTriangle(tileSurface,v0,v1,v2)
	AddTriangle(tileSurface,v2,v3,v0)
	UpdateNormals(tile)
	Return tile
End Function
You'll need to provide your own texture. Thanks, Ian. | 
| 
 | ||
| You need to set UV coords for the vertices: | 
| 
 | ||
| Thanks for the reply Warner - that's great. The texture isn't quite right but you have set me off in the right direction. Thanks very much, Ian. | 
| 
 | ||
| Ow yes, that last line should be: 1.0, 0.0 | 
| 
 | ||
| ;-) hey no problem - your help is much appreciated.  Thanks again. |