skybox function
BlitzMax Forums/MiniB3D Module/skybox function
| ||
im using this function which is the one i used in blitz3d to make a sky box.Function create_skybox(f$,r$, b$,l$, t$, bt$, sx, sy, sz)'front Right back Left top bottom scalex,y,z mesh = CreateMesh() 'front face brush = LoadBrush(f$,49) surface = CreateSurface(mesh,brush) AddVertex surface,-1,+1,-1,0,0 AddVertex surface,+1,+1,-1,1,0 AddVertex surface,+1,-1,-1,1,1 AddVertex surface,-1,-1,-1,0,1 AddTriangle surface,0,1,2 AddTriangle surface,0,2,3 FreeBrush brush 'Right face brush = LoadBrush(r$,49) surface = CreateSurface(mesh,brush) AddVertex surface,+1,+1,-1,0,0 AddVertex surface,+1,+1,+1,1,0 AddVertex surface,+1,-1,+1,1,1 AddVertex surface,+1,-1,-1,0,1 AddTriangle surface,0,1,2 AddTriangle surface,0,2,3 FreeBrush brush 'back face brush = LoadBrush(b$,49) surface = CreateSurface(mesh,brush) AddVertex surface,+1,+1,+1,0,0 AddVertex surface,-1,+1,+1,1,0 AddVertex surface,-1,-1,+1,1,1 AddVertex surface,+1,-1,+1,0,1 AddTriangle surface,0,1,2 AddTriangle surface,0,2,3 FreeBrush brush 'Left face brush = LoadBrush(l$,49) surface = CreateSurface(mesh,brush) AddVertex surface,-1,+1,+1,0,0 AddVertex surface,-1,+1,-1,1,0 AddVertex surface,-1,-1,-1,1,1 AddVertex surface,-1,-1,+1,0,1 AddTriangle surface,0,1,2 AddTriangle surface,0,2,3 FreeBrush brush 'top face brush = LoadBrush(t$,49) surface = CreateSurface(mesh,brush) AddVertex surface,-1,+1,+1,0,1 AddVertex surface,+1,+1,+1,0,0 AddVertex surface,+1,+1,-1,1,0 AddVertex surface,-1,+1,-1,1,1 AddTriangle surface,0,1,2 AddTriangle surface,0,2,3 FreeBrush brush 'bottom face brush = LoadBrush(bt$,49) surface = CreateSurface(mesh,brush) AddVertex surface,-1,-1,-1,1,0 AddVertex surface,+1,-1,-1,1,1 AddVertex surface,+1,-1,+1,0,1 AddVertex surface,-1,-1,+1,0,0 AddTriangle surface,0,1,2 AddTriangle surface,0,2,3 FreeBrush brush ScaleMesh mesh,sx,sy,sz FlipMesh mesh EntityFX mesh,1+4+8' make fullbright Return mesh End Function im calling it with skybox=create_skybox("media/starbox_front5.png","media/starbox_right1.png","media/starbox_back6.png","media/starbox_left2.png","media/starbox_top3.png","media/starbox_bottom4.png", 40, 40,40) the problem im getting is it loads the same texture to all 6 sides, but i can't see why? |
| ||
what about using variable names like "surface1, surface2, ....? |
| ||
Yeah that was my first though i tried that although there's no errors it makes no difference i was thinking it may have something to do with the freebrush command. Im lost here. |
| ||
Double post Last edited 2012 |
| ||
you are right, the different names are not necessary. I had a look on the skybox-code I always use in MiniB3D and it is nearly the same and it works:Function LoadSkyBox:TMesh( file$ ) Local m:TMesh = CreateMesh(), S:TSurface, B:TBrush 'front face b=LoadBrush( file$+"_FR.jpg",49 ) s=CreateSurface( m,b ) AddVertex s,-1,+1,-1,0,0 AddVertex s,+1,+1,-1,1,0 AddVertex s,+1,-1,-1,1,1 AddVertex s,-1,-1,-1,0,1 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'Right face b=LoadBrush( file$+"_LF.jpg",49 ) s=CreateSurface( m,b ) AddVertex s,+1,+1,-1,0,0 AddVertex s,+1,+1,+1,1,0 AddVertex s,+1,-1,+1,1,1 AddVertex s,+1,-1,-1,0,1 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'back face b=LoadBrush( file$+"_BK.jpg",49 ) s=CreateSurface( m,b ) AddVertex s,+1,+1,+1,0,0 AddVertex s,-1,+1,+1,1,0 AddVertex s,-1,-1,+1,1,1 AddVertex s,+1,-1,+1,0,1 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'Left face b=LoadBrush( file$+"_RT.jpg",49 ) s=CreateSurface( m,b ) AddVertex s,-1,+1,+1,0,0 AddVertex s,-1,+1,-1,1,0 AddVertex s,-1,-1,-1,1,1 AddVertex s,-1,-1,+1,0,1 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'top face b=LoadBrush( file$+"_UP.jpg",49 ) s=CreateSurface( m,b ) AddVertex s,-1,+1,+1,0,1 AddVertex s,+1,+1,+1,0,0 AddVertex s,+1,+1,-1,1,0 AddVertex s,-1,+1,-1,1,1 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'bottom face b=LoadBrush( file$+"_DN.jpg",49 ) s=CreateSurface( m,b ) AddVertex s,-1,-1,-1,1,0 AddVertex s,+1,-1,-1,1,1 AddVertex s,+1,-1,+1,0,1 AddVertex s,-1,-1,+1,0,0 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'End Rem ScaleMesh m,400,60,400 FlipMesh m EntityFX m,1 Return m End Function the only difference is the defining of the variables as local inside the function |
| ||
Thank god it was beginning to drive me mental! Thanks for your time |
| ||
The function doesnt have a return type |
| ||
Function LoadSkyBox:TMesh( file$ ) Local m:TMesh = CreateMesh(), S:TSurface, B:TBrush 'front face b=LoadBrush( file$+"front5.png",49 ) s=CreateSurface( m,b ) AddVertex s,-1,+1,-1,0,0 AddVertex s,+1,+1,-1,1,0 AddVertex s,+1,-1,-1,1,1 AddVertex s,-1,-1,-1,0,1 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'Right face b=LoadBrush( file$+"left2.png",49 ) s=CreateSurface( m,b ) AddVertex s,+1,+1,-1,0,0 AddVertex s,+1,+1,+1,1,0 AddVertex s,+1,-1,+1,1,1 AddVertex s,+1,-1,-1,0,1 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'back face b=LoadBrush( file$+"back6.png",49 ) s=CreateSurface( m,b ) AddVertex s,+1,+1,+1,0,0 AddVertex s,-1,+1,+1,1,0 AddVertex s,-1,-1,+1,1,1 AddVertex s,+1,-1,+1,0,1 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'Left face b=LoadBrush( file$+"right1.png",49 ) s=CreateSurface( m,b ) AddVertex s,-1,+1,+1,0,0 AddVertex s,-1,+1,-1,1,0 AddVertex s,-1,-1,-1,1,1 AddVertex s,-1,-1,+1,0,1 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'top face b=LoadBrush( file$+"top3.png",49 ) s=CreateSurface( m,b ) AddVertex s,-1,+1,+1,0,1 AddVertex s,+1,+1,+1,0,0 AddVertex s,+1,+1,-1,1,0 AddVertex s,-1,+1,-1,1,1 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'bottom face b=LoadBrush( file$+"bottom4.png",49 ) s=CreateSurface( m,b ) AddVertex s,-1,-1,-1,1,0 AddVertex s,+1,-1,-1,1,1 AddVertex s,+1,-1,+1,0,1 AddVertex s,-1,-1,+1,0,0 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b 'End Rem ScaleMesh m,40,40,40 FlipMesh m EntityFX m,1 Return m End Function calling it with skybox=loadskybox("media/starbox_") Same result skybox with 6 sides the same The function doesnt have a return type sorry being thick, can you explain. do you mean the original or midimasters version? |
| ||
He meant your original B3D one - it won't work if you copy it exactly as it is and run it through mB3D. - In Blitz3D the handles of textures, meshes etc. are integer values. - In BMax you can have new types of values - in this case, TMesh. If want to return a miniB3D TMesh, you need to declare this type in your function as well: LoadSkyBox:TMesh() |
| ||
please send us also the code, which is calling the function from loading to displaying. which image is shown? the last one? Do you use "SuperStrict"? Check the filename: b=LoadBrush( file$+"left2.png",49 ) Print "Filename=" + file$+"left2.png"+"!" local TestImg:TImage=LoadImage(file$+"left2.png") If TestImg=NULL then PRINT "Image not found" check, if it is working by commenting out some sides of the function. what happens, if you comment out one side. is it white? 'Right face b=LoadBrush( file$+"xxxxleft2.png",49 ) s=CreateSurface( m,b ) AddVertex s,+1,+1,-1,0,0 AddVertex s,+1,+1,+1,1,0 AddVertex s,+1,-1,+1,1,1 AddVertex s,+1,-1,-1,0,1 AddTriangle s,0,1,2 AddTriangle s,0,2,3 FreeBrush b this is how I call the function: Sky:TMesh=LoadSkyBox(ImagePfad + "Sky") |