I'm only talking about the vertex normals.
Here's the code (you can be shure that the functions ChunkEnd, Chunkbegin, WriteStringC are working correctly)
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 texcount ;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 texcount 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 surfacecount=CountSurfaces(mesh) For k=1 To surfacecount surf=GetSurface(mesh,k ) vertexcount=CountVertices( surf )-1 For j=0 To vertexcount 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,VertexNX#(surf,j)) ;NormalX WriteFloat(file,VertexNY#(surf,j)) ;NormalY WriteFloat(file,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 surfacecount=CountSurfaces(mesh) For k=1 To surfacecount surf=GetSurface( mesh,k ) triscount=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 triscount 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)