Texturing a Mesh? How?
Blitz3D Forums/Blitz3D Programming/Texturing a Mesh? How?
| ||
Why doesn't the following code texture a mesh?side = CreateMesh() sideTexture = LoadTexture("c:\blitz\bright.bmp") sideBrush = CreateBrush() BrushTexture(sideBrush, sideTexture) sideSurface = CreateSurface(side, sideBrush) AddVertex sideSurface,-1,-1,-1 AddVertex sideSurface, 1,-1,-1 AddVertex sideSurface, 1,-1, 1 AddVertex sideSurface,-1,-1, 1 AddTriangle sideSurface,0,1,2 AddTriangle sideSurface,0,2,3 ; Paint the mesh with the textured brush? PaintMesh(side, sideBrush) |
| ||
I forgot to add that "c:\blitz\bright.bmp" is a copy of the grass.bmp texture that comes with blitz. Also the mesh appears, but is a single solid greeny colour. Looks as though the first texture pixel is being used to fill the whole mesh. |
| ||
Try messing about with the entityfx command. Can't remember which flag it is tho. Think it might be the vertex colouring flag you need to use :) |
| ||
Hey, sorry. I see you aren't setting the UV co-ords when your adding a vertex. This must be done so the texture is layed out properly.v0=AddVertex sideSurface,-1,-1,-1,0,1 v1=AddVertex sideSurface, 1,-1,-1,1,1 v2=AddVertex sideSurface, 1,-1, 1,1,0 v3=AddVertex sideSurface,-1,-1, 1,0,0 AddTriangle sideSurface,v0,v1,v2 AddTriangle sideSurface,v0,v2,v3 try that :) |
| ||
Still no joy! |
| ||
Don't use the brush command. Try simply loading in the texture then applying it to the meshEntityTexture side,sideTexture Take out all references to the brush, and use vertex colouring. Also, mind and stick in the addvertex commands i put above. |
| ||
So we now have...side = CreateMesh() sideTexture = LoadTexture("c:\blitz\bright.bmp") sideSurface = CreateSurface(side) v0=AddVertex sideSurface,-1,-1,-1,0,1 v1=AddVertex sideSurface, 1,-1,-1,1,1 v2=AddVertex sideSurface, 1,-1, 1,1,0 v3=AddVertex sideSurface,-1,-1, 1,0,0 AddTriangle sideSurface,v0,v1,v2 AddTriangle sideSurface,v0,v2,v3 EntityTexture(side, sideTexture) Unfortunately it still doesn't work!!! Arhhh! Surely this should be easy... |
| ||
No brackets on EntityTexture. |
| ||
side = CreateMesh() sideTexture = LoadTexture("c:\blitz\bright.bmp") sideSurface = CreateSurface(side) v0=AddVertex sideSurface,-1,-1,0,0,1 v1=AddVertex sideSurface, 1,-1,0,1,1 v2=AddVertex sideSurface,-1, 1,0,1,0 v3=AddVertex sideSurface, 1, 1,0,0,0 AddTriangle sideSurface,v0,v1,v2 AddTriangle sideSurface,v0,v2,v3 EntityTexture side, sideTexture Try that? |
| ||
No difference! I'm fairly sure the brackets are optional on all commands. |
| ||
I'm at college right now so i can't test it. I'll see if i can find some mesh stuff on this site. |
| ||
side = CreateMesh() sideTexture = LoadTexture("c:\blitz\bright.bmp",1) sideSurface = CreateSurface(side) EntityFx side,4 v0=AddVertex sideSurface,-1,-1,0,0,0 v1=AddVertex sideSurface, 1,-1,0,1,0 v2=AddVertex sideSurface,-1, 1,0,0,1 v3=AddVertex sideSurface, 1, 1,0,1,1 AddTriangle sideSurface,v0,v1,v2 AddTriangle sideSurface,v0,v2,v3 EntityTexture side, sideTexture Does that work? What do you get? A green color? |
| ||
It doing what it always did: displaying a flat shaded green square. I'm guessing the green colour is coming from the texture (as no other colour is defined), so something must be wrong the the texture u/v. Maybe I'm not supplying them?!? |
| ||
That's what the to end values are on the end of add vertex. Did you try fiddling with the various options of the EntityFx flag? Also you could try UpdateNormals side After you create the triangle. |
| ||
Still no luck! Help!!! =-) |
| ||
Yeah come-on ppl, someone else step in here. I can't actually test anything! :D |
| ||
If I texture a cube created with the CreateCube() command it works, so there must be something that isn't setup correctly in my hand made mesh. I'm new to this so it might be something very obvious! |
| ||
I've got it! This code was missing: VertexTexCoords sideSurface, 0, 0, 1 VertexTexCoords sideSurface, 1, 1, 1 VertexTexCoords sideSurface, 2, 1, 0 VertexTexCoords sideSurface, 3, 0, 0 |
| ||
That's strange :S The addvertex command, lets you assign the texture co-ords. Oh well, glad you got it working :) |
| ||
Doh! I missed those extra parameters Ross. Thanks for the help. |
| ||
np! |