multiple textures on one cube
Blitz3D Forums/Blitz3D Programming/multiple textures on one cube
| ||
Ok Im creating a very simple slot machine game and i need to put a different texture(picture) on each side of the cube. Im kinda stuck and need a little help. Thanks, Michael |
| ||
Use brushes and assign whatever you want to each side of cube.. |
| ||
Thanks i knew it was an easy solution |
| ||
Well im still having one little problem i cant seem to get the texture on just one side of the cube it goes on to all sides when i just want it on one side. need a little more help. |
| ||
you have to get surface you want out of your cube with GETSURFACE command..and then you can apply your brushes on to it..for your cube you should have 6 surfaces so eg. Surf1=getsurface(cube,1) Surf2=getsurface(cube,2) Surf3=getsurface(cube,3) Surf4=getsurface(cube,4) Surf5=getsurface(cube,5) Surf6=getsurface(cube,6) then you can assign to each surface your already created brush.. |
| ||
Well... my cube doesnt already have 6 surfaces so i know that i need to create surfaces using the CREATESURFACE command but i not quite sure how to use this command to create a surface just on one side of the cube. ps. ive just started using blitz so im a little lost but thanks for all the help!! |
| ||
I said that cube is consist of 6 surfaces, just in purpose of explanation..in order to reach total number surfaces of your cube, or any other mesh, use CountSurfaces(cube), eg. Total_Surfaces=CountSurfaces(cube)..then you will know how many surfaces you actually have and then trough for...next loop access each of them and do your brush painting stuff.. |
| ||
yes I need to create more surfaces though so i can put a texture on each side. right now my cube has only 1 surface. |
| ||
I would recomend using a 3d modelling program to do this, but if you don't want to, you could use the following little program. I don't know if this is the best way to do this, because it is my first expirience making a mesh with code, but it seems to work ok.Graphics3D 640,480 camera=CreateCamera() PositionEntity camera,0,0,-5 tex1=CreateBrush(255,255,255) tex2=CreateBrush(255,255,0) tex3=CreateBrush(255,0,0) tex4=CreateBrush(0,0,255) tex5=CreateBrush(0,255,255) tex6=CreateBrush(255,0,255) cube=CreateMesh() surf1=CreateSurface(cube,tex1) surf2=CreateSurface(cube,tex2) surf3=CreateSurface(cube,tex3) surf4=CreateSurface(cube,tex4) surf5=CreateSurface(cube,tex5) surf6=CreateSurface(cube,tex6) AddVertex(surf1,1,1,1) AddVertex(surf1,1,-1,1) AddVertex(surf1,-1,-1,1) AddVertex(surf1,-1,1,1) AddTriangle(surf1,2,1,0) AddTriangle(surf1,3,2,0) AddVertex(surf2,1,1,-1) AddVertex(surf2,1,-1,-1) AddVertex(surf2,-1,-1,-1) AddVertex(surf2,-1,1,-1) AddTriangle(surf2,0,1,2) AddTriangle(surf2,0,2,3) AddVertex(surf3,1,1,1) AddVertex(surf3,1,-1,1) AddVertex(surf3,1,-1,-1) AddVertex(surf3,1,1,-1) AddTriangle(surf3,0,1,2) AddTriangle(surf3,0,2,3) AddVertex(surf4,-1,1,1) AddVertex(surf4,-1,-1,1) AddVertex(surf4,-1,-1,-1) AddVertex(surf4,-1,1,-1) AddTriangle(surf4,2,1,0) AddTriangle(surf4,3,2,0) AddVertex(surf5,1,-1,-1) AddVertex(surf5,-1,-1,-1) AddVertex(surf5,-1,-1,1) AddVertex(surf5,1,-1,1) AddTriangle(surf5,2,1,0) AddTriangle(surf5,3,2,0) AddVertex(surf6,1,1,-1) AddVertex(surf6,-1,1,-1) AddVertex(surf6,-1,1,1) AddVertex(surf6,1,1,1) AddTriangle(surf6,0,1,2) AddTriangle(surf6,0,2,3) While Not KeyDown(1) TurnEntity cube,1,1,1 UpdateWorld RenderWorld Flip Wend End I hope it helps! |
| ||
Thank You That was exactly what i need to know, how to create the vertex and triangles part. I greatly appriciated all the help!!! |
| ||
ok im still having a problem with this code. Graphics3D 640,480 camera=CreateCamera() PositionEntity camera,0,0,-5 tex1=LoadBrush("double bar.jpg") tex2=LoadBrush("double bar.jpg") tex3=LoadBrush("double bar.jpg") tex4=LoadBrush("double bar.jpg") tex5=LoadBrush("double bar.jpg") tex6=LoadBrush("double bar.jpg") cube=CreateMesh() surf1=CreateSurface(cube,tex1) surf2=CreateSurface(cube,tex2) surf3=CreateSurface(cube,tex3) surf4=CreateSurface(cube,tex4) surf5=CreateSurface(cube,tex5) surf6=CreateSurface(cube,tex6) AddVertex(surf1,1,1,1) AddVertex(surf1,1,-1,1) AddVertex(surf1,-1,-1,1) AddVertex(surf1,-1,1,1) AddTriangle(surf1,2,1,0) AddTriangle(surf1,3,2,0) AddVertex(surf2,1,1,-1) AddVertex(surf2,1,-1,-1) AddVertex(surf2,-1,-1,-1) AddVertex(surf2,-1,1,-1) AddTriangle(surf2,0,1,2) AddTriangle(surf2,0,2,3) AddVertex(surf3,1,1,1) AddVertex(surf3,1,-1,1) AddVertex(surf3,1,-1,-1) AddVertex(surf3,1,1,-1) AddTriangle(surf3,0,1,2) AddTriangle(surf3,0,2,3) AddVertex(surf4,-1,1,1) AddVertex(surf4,-1,-1,1) AddVertex(surf4,-1,-1,-1) AddVertex(surf4,-1,1,-1) AddTriangle(surf4,2,1,0) AddTriangle(surf4,3,2,0) AddVertex(surf5,1,-1,-1) AddVertex(surf5,-1,-1,-1) AddVertex(surf5,-1,-1,1) AddVertex(surf5,1,-1,1) AddTriangle(surf5,2,1,0) AddTriangle(surf5,3,2,0) AddVertex(surf6,1,1,-1) AddVertex(surf6,-1,1,-1) AddVertex(surf6,-1,1,1) AddVertex(surf6,1,1,1) AddTriangle(surf6,0,1,2) AddTriangle(surf6,0,2,3) While Not KeyDown( 1 ) TurnEntity cube,7,0,0 UpdateWorld RenderWorld count_surf=CountSurfaces(cube) Text 0,0,"This mesh has "+count_surf+" surface(s)" Flip Wend End When i run this the texture i want does not show up on the cube. its just grey. Could anyone tell me what is wrong. Thanks ps sorry i dont know how to put it in a code box. |
| ||
my opinion. much better to fire up 3D modeller and create cube in that with 6 different surfaces. try unwrap3d as well |
| ||
You are not specifying texture co-ordinates in the AddVertex commands.AddVertex(surf1,1,1,1,1,1) AddVertex(surf1,1,-1,1,1,0) AddVertex(surf1,-1,-1,1,0,0) AddVertex(surf1,-1,1,1,0,1)Bradford has the best idea, use a modelling package. Forum Codes Here http://www.blitzbasic.com/faq/faq_entry.php?id=2 |
| ||
I would definately encourage you to use a modeling program, but if you don't want to, here is the complete code:Graphics3D 640,480 camera=CreateCamera() PositionEntity camera,0,0,-5 CameraClsColor camera,100,100,100 tex=CreateTexture(256,256) SetBuffer TextureBuffer(tex) Color 200,150,75 Oval 1,1,254,254 SetBuffer BackBuffer() tex1=CreateBrush(255,255,255) tex2=CreateBrush(255,255,0) tex3=CreateBrush(255,0,0) tex4=CreateBrush(0,0,255) tex5=CreateBrush(0,255,255) tex6=CreateBrush(255,0,255) BrushTexture tex1,tex BrushTexture tex2,tex BrushTexture tex3,tex BrushTexture tex4,tex BrushTexture tex5,tex BrushTexture tex6,tex cube=CreateMesh() surf1=CreateSurface(cube,tex1) surf2=CreateSurface(cube,tex2) surf3=CreateSurface(cube,tex3) surf4=CreateSurface(cube,tex4) surf5=CreateSurface(cube,tex5) surf6=CreateSurface(cube,tex6) AddVertex(surf1,1,1,1,0,0) AddVertex(surf1,1,-1,1,0,1) AddVertex(surf1,-1,-1,1,1,1) AddVertex(surf1,-1,1,1,0,1) AddTriangle(surf1,2,1,0) AddTriangle(surf1,3,2,0) AddVertex(surf2,1,1,-1,0,1) AddVertex(surf2,1,-1,-1,1,1) AddVertex(surf2,-1,-1,-1,1,0) AddVertex(surf2,-1,1,-1,0,0) AddTriangle(surf2,0,1,2) AddTriangle(surf2,0,2,3) AddVertex(surf3,1,1,1,1,0) AddVertex(surf3,1,-1,1,1,1) AddVertex(surf3,1,-1,-1,0,1) AddVertex(surf3,1,1,-1,0,0) AddTriangle(surf3,0,1,2) AddTriangle(surf3,0,2,3) AddVertex(surf4,-1,1,1,1,0) AddVertex(surf4,-1,-1,1,1,1) AddVertex(surf4,-1,-1,-1,0,1) AddVertex(surf4,-1,1,-1,0,0) AddTriangle(surf4,2,1,0) AddTriangle(surf4,3,2,0) AddVertex(surf5,1,-1,-1,1,0) AddVertex(surf5,-1,-1,-1,0,0) AddVertex(surf5,-1,-1,1,0,1) AddVertex(surf5,1,-1,1,1,1) AddTriangle(surf5,2,1,0) AddTriangle(surf5,3,2,0) AddVertex(surf6,1,1,-1,1,1) AddVertex(surf6,-1,1,-1,0,1) AddVertex(surf6,-1,1,1,0,0) AddVertex(surf6,1,1,1,1,0) AddTriangle(surf6,0,1,2) AddTriangle(surf6,0,2,3) While Not KeyDown(1) TurnEntity cube,1,1,1 UpdateWorld RenderWorld Flip Wend End Hope it helps! |