*.B3D doesn't work with masked textures!
Blitz3D Forums/Blitz3D Programming/*.B3D doesn't work with masked textures!
| ||
I don't know what to do. I wrote a function to export something to .b3d .In this file format there is the flag for masking a texture, but the problem is that every surface can only be textured through a brush. But the Texture makes some nonsens with the brush-color depending to the blend-values I tried for the texture and the brush (e.g. everything but the black areas were transparent, funny...) .I have tried all combinations with the blend-values, but couldn't achieve a masked texture appearing. Has anybody already experiences with that? Is this a bug or my fault? |
| ||
For people who have the know-how of b3d-files, here's the code: (you can be shure that the functions ChunkEnd, Chunkbegin, WriteStringC are working correctly)Dim ChunkStart(100) :Global chunkebene=0 function ExportIt(mesh) ;I call this function name$="sample.b3d" file=WriteFile(name$) If file=0 Then Return ChunkBegin(file,"BB3D") WriteInt(file,1) ;version ChunkBegin(file,"TEXS") ;-----Textures------------- For i=1 To texanz ;there are about 3 textures WriteStringC(file,texname$(i)) ;name (a field of texturenames) masked=4+1 WriteInt(file,masked) ;flags (alpha..) WriteInt(file,1) ;blend 1 WriteFloat(file,0) ;X ;def:0 WriteFloat(file,0) ;Y WriteFloat(file,1) ;X Scale ;def:1 WriteFloat(file,1) ;Y Scale WriteFloat(file,0) ;Rotation Next ChunkEnd(file) ;-----Textures end--------- ChunkBegin(file,"BRUS") ;+++++Brush++++++++++++++++ WriteInt(file,1) ;1 textures per brush WriteStringC(file,"Default") ;Dname WriteFloat(file,1) ;Dred WriteFloat(file,0.3) ;Dgreen WriteFloat(file,0.3) ;Dblue WriteFloat(file,1) ;Dalpha WriteFloat(file,0) ;Dshininess WriteInt(file,0) ;Dblend WriteInt(file,0) ;DFX WriteInt(file,-1) ;DTextureNr (-1=no?) For i=1 To texanz WriteStringC(file,"Brush"+i) ;name WriteFloat(file,0) ;red WriteFloat(file,0) ;green WriteFloat(file,0) ;blue WriteFloat(file,1) ;alpha WriteFloat(file,0) ;shininess WriteInt(file,0) ;blend WriteInt(file,0) ;FX WriteInt(file,i-1) ;TextureNr (from 0) End If Next ChunkEnd(file) ;End of BRUS chunk ChunkBegin(file,"NODE" ) ;+++++Entities+++++++++++++ WriteStringC(file,"TheEntity") ;name WriteFloat(file,0) ;x WriteFloat(file,0) ;y WriteFloat(file,0) ;z WriteFloat(file,1) ;x_scale WriteFloat(file,1) ;y_scale WriteFloat(file,1) ;z_scale WriteFloat(file,1) ;rot_w WriteFloat(file,0) ;rot_x WriteFloat(file,0) ;rot_y WriteFloat(file,0) ;rot_z ChunkBegin(file,"MESH") ;+++++Meshes+++++++++++++++ WriteInt(file,-1) ;no 'entity' brush ChunkBegin(file,"VRTS" ) ;+++++Vertexes+++++++++++++ WriteInt(file,1 ) ;flags - 0=no 1=with normals / 2=with color WriteInt(file,1 ) ;1 tex_coord sets WriteInt(file,2 ) ;2 coords per set surfaceanz=CountSurfaces(mesh) For k=1 To surfaceanz surf=GetSurface(mesh,k ) vertexanz=CountVertices( surf )-1 For j=0 To vertexanz TFormPoint VertexX(surf,j),VertexY(surf,j),VertexZ(surf,j),stone(i),0 WriteFloat(file,TFormedX() ) ;X WriteFloat(file,TFormedY() ) ;Y WriteFloat(file,TFormedZ() ) ;Z WriteFloat(file,-1);VertexNX#(surf,j)) ;NormalX WriteFloat(file,0);VertexNY#(surf,j)) ;NormalY WriteFloat(file,0);VertexNZ#(surf,j)) ;NormalZ WriteFloat(file,VertexU( surf,j ) );TextureU WriteFloat(file,VertexV( surf,j ) );TextureV Next Next ChunkEnd(file) ;-----Vertexes end--------- first_vert=0 surfaceanz=CountSurfaces(mesh) For k=1 To surfaceanz surf=GetSurface( mesh,k ) trisanz=CountTriangles( surf )-1 ChunkBegin(file,"TRIS" ) ;++++++Tris++++++++++++++++ WriteInt(file,SurfaceTexNr(k) ) ;The Textur Nr corresponds to the brush number (they go from 1 to texquantity) For j=0 To trisanz WriteInt(file,first_vert+TriangleVertex( surf,j,0 ) ) WriteInt(file,first_vert+TriangleVertex( surf,j,1 ) ) WriteInt(file,first_vert+TriangleVertex( surf,j,2 ) ) Next ChunkEnd(file) ;-----Tris end------------ first_vert=first_vert+CountVertices( surf ) Next ChunkEnd(file) ;-----Mesh end------------ ChunkEnd(file) ;-----Entity end---------- ChunkEnd(file) ;-----BB3D end------------ CloseFile file End Function ;*********************************** Function ChunkBegin(file,tag$) chunkebene=chunkebene+1 For k=1 To 4 WriteByte(file,Asc(Mid$( tag$,k,1 ))) Next WriteInt(file,0) ChunkStart(ChunkEbene)=FilePos(file) End Function ;********************************** Function ChunkEnd(file) aha=ChunkStart(ChunkEbene) n=FilePos(file) SeekFile file,ChunkStart(ChunkEbene)-4 WriteInt(file,n-ChunkStart(ChunkEbene)) SeekFile file,n ChunkEbene=ChunkEbene-1 End Function ;********************************* Function WriteStringC(file,t$) For k=1 To Len( t$ ) ch=Asc(Mid$(t$,k,1)) WriteByte(file,ch) If ch=0 Return Next WriteByte(file,0) End Function ;I've shortened the code a bit for you, so there could be some typing errors. The Exportfunktion does it's stuff very well, it even exports the right textures and right coordinates, except the problem, that masking doesn't work and that Vertex Normals don't work with Textured Surfaces. ;(To write this I used Marks makeb3d.bb) |
| ||
Add this to the top of your codeConst FLAG_COLOR = 1 Const FLAG_ALPHA = 2 Const FLAG_MASKED = 4 Const FLAG_MIPMAP = 8 ;etc... For the rest of the different texture flags Then change this line: WriteInt(file,masked) ;flags (alpha..)To this: WriteInt(file,FLAG_COLOR Or FLAG_MASKED)And add whatever other flags you want by using 'Or'... That should do the trick, Fredborg |
| ||
Sorry, this trick doesn't change anything. |
| ||
Ohh, hadn't properly checked the code :) Your Blend settings are not correct, and texture and brush indexes start at 0 not 1...This works:Graphics3D 640,480,0,2 Dim ChunkStart(100) :Global chunkebene=0 cube = CreateSphere(16) Global tex$ = "RuinT00.tga" ;<--- Replace with whatever ExportIt(cube) Function ExportIt(mesh) ;I call this function name$="sample.b3d" file=WriteFile(name$) If file=0 Then Return ChunkBegin(file,"BB3D") WriteInt(file,1) ;version ChunkBegin(file,"TEXS") ;-----Textures------------- WriteStringC(file,tex$) ;name (a field of texturenames) masked=4+1 WriteInt(file,masked) ;flags (alpha..) WriteInt(file,2) ;<------- This WAS wrong, 2 is the default Blend of a Texture WriteFloat(file,0) ;X ;def:0 WriteFloat(file,0) ;Y WriteFloat(file,1) ;X Scale ;def:1 WriteFloat(file,1) ;Y Scale WriteFloat(file,0) ;Rotation ChunkEnd(file) ;-----Textures end--------- ChunkBegin(file,"BRUS") ;+++++Brush++++++++++++++++ WriteInt(file,1) ;1 textures per brush WriteStringC(file,"Default") ;Dname WriteFloat(file,1) ;Dred WriteFloat(file,1) ;Dgreen WriteFloat(file,1) ;Dblue WriteFloat(file,1) ;Dalpha WriteFloat(file,0) ;Dshininess WriteInt(file,1) ;Dblend <---- 1 is the Default Blend of a Brush WriteInt(file,0) ;DFX WriteInt(file,0) ;DTextureNr <---- Starts from 0 NOT 1 ChunkEnd(file) ;End of BRUS chunk ChunkBegin(file,"NODE" ) ;+++++Entities+++++++++++++ WriteStringC(file,"TheEntity") ;name WriteFloat(file,0) ;x WriteFloat(file,0) ;y WriteFloat(file,0) ;z WriteFloat(file,1) ;x_scale WriteFloat(file,1) ;y_scale WriteFloat(file,1) ;z_scale WriteFloat(file,1) ;rot_w WriteFloat(file,0) ;rot_x WriteFloat(file,0) ;rot_y WriteFloat(file,0) ;rot_z ChunkBegin(file,"MESH") ;+++++Meshes+++++++++++++++ WriteInt(file,-1) ;no 'entity' brush ChunkBegin(file,"VRTS" ) ;+++++Vertexes+++++++++++++ WriteInt(file,1 ) ;flags - 0=no 1=with normals / 2=with color WriteInt(file,1 ) ;1 tex_coord sets WriteInt(file,2 ) ;2 coords per set surfaceanz=CountSurfaces(mesh) For k=1 To surfaceanz surf=GetSurface(mesh,k ) vertexanz=CountVertices( surf )-1 For j=0 To vertexanz TFormPoint VertexX(surf,j),VertexY(surf,j),VertexZ(surf,j),0,0 WriteFloat(file,TFormedX() ) ;X WriteFloat(file,TFormedY() ) ;Y WriteFloat(file,TFormedZ() ) ;Z WriteFloat(file,VertexNX#(surf,j)) ;<---- This was wrong WriteFloat(file,VertexNY#(surf,j)) ;<---- This was wrong WriteFloat(file,VertexNZ#(surf,j)) ;<---- This was wrong WriteFloat(file,VertexU( surf,j ) );TextureU WriteFloat(file,VertexV( surf,j ) );TextureV Next Next ChunkEnd(file) ;-----Vertexes end--------- first_vert=0 surfaceanz=CountSurfaces(mesh) For k=1 To surfaceanz surf=GetSurface( mesh,k ) trisanz=CountTriangles( surf )-1 ChunkBegin(file,"TRIS" ) ;++++++Tris++++++++++++++++ WriteInt(file,0 ) ;<---- Brush for this surface. Starts from 0 NOT 1 For j=0 To trisanz WriteInt(file,first_vert+TriangleVertex( surf,j,0 ) ) WriteInt(file,first_vert+TriangleVertex( surf,j,1 ) ) WriteInt(file,first_vert+TriangleVertex( surf,j,2 ) ) Next ChunkEnd(file) ;-----Tris end------------ first_vert=first_vert+CountVertices( surf ) Next ChunkEnd(file) ;-----Mesh end------------ ChunkEnd(file) ;-----Entity end---------- ChunkEnd(file) ;-----BB3D end------------ CloseFile file End FunctionThe remaining functions are correct. Fredborg |