Thanks. Well, SaveB3D doesn't LOAD anything, it will only save a Mesh.
If you want to load a lightmapped Mesh and then save it with the SaveB3D Function, you first need to track down the Lightmap Texture as well. THis may be pretty easy, use the command GetBrushTexture with the second, optinal INDEX parameter.
I think this would be:
lightmaptex=GetBrushTexture(brush,1) ; use 0 or 1, 1 for LIghtmap, AFAIK
lima_texfile$=texturename$(lightmaptex)
Now that you know the texture file that is used for the lightmap as a second texture layer on each brush, you can modify the SaveB3D Function easily, have a look at the comments, and these lines:
You see, in the TEX chunk all textures are inserted. Basicly the TEX chunk lists all teyxtures that may be used by the mesh. The Function assumes that each surface has exactly one texture, so it only counts up to the number of surfaces and inserts the surface-brushes texture info for each surface.
You may add an additional texture info block for the Lightmap. You may do this as the first block, or as the last block (pre or past the For loop), but it must be inside the TEX chunk. Something like:
(please note: use the right blend mode, "addition" or something)
Now heres a number of BRUS chunk, each one defines a Brush. Some people use only one BRUS chunk and include all Bsushes inside, but they need to use the same number of Texture Layers for each Brush, even when Layers can be deactivated by using -1 as index, if I remember right. However, this Function uses a method that defines a BRUS chunk for each Brush, this way each Brush can have its individual number of Textures. If you have added the lightmap info block in the TEX chunk after the For loop, you could do it this way:
Now the mesh still needs to know what to do with the lightmap, so you need to save the second UV Coords, in the Function it's already there, only remarked, so you only have to activate these two lines in the function WriteMESH( mesh ):
;;b3dWriteFloat( VertexU#( surf,j,1 ) ) ; lightmap uv
;;b3dWriteFloat( VertexV#( surf,j,1 ) ) ; lightmap uv
plus chanche this line:
b3dWriteInt( 1 );number of tex_coord sets
to
b3dWriteInt( 2 );number of tex_coord sets
Now you should be pretty close to a working Mesh exporter that works with lightmaps- Additionally you learned something about the format.
If you want to load a lightmapped Mesh and then save it with the SaveB3D Function, you first need to track down the Lightmap Texture as well. THis may be pretty easy, use the command GetBrushTexture with the second, optinal INDEX parameter.
I think this would be:
lightmaptex=GetBrushTexture(brush,1) ; use 0 or 1, 1 for LIghtmap, AFAIK
lima_texfile$=texturename$(lightmaptex)
Now that you know the texture file that is used for the lightmap as a second texture layer on each brush, you can modify the SaveB3D Function easily, have a look at the comments, and these lines:
b3dBeginChunk( "TEXS" ) ; list all textures used by the mesh For i=1 To c_surfs b3dWriteString( c_tex_name$(i) ) ;texture file b3dWriteInt( 1 );flags b3dWriteInt( 2 );blend b3dWriteFloat( 0 );x in tex 0 (hu?) b3dWriteFloat( 0 );y in tex 0 b3dWriteFloat( 1 );x scale 1 b3dWriteFloat( 1 );y scale 1 b3dWriteFloat( 0 );rotation 0 Next
You see, in the TEX chunk all textures are inserted. Basicly the TEX chunk lists all teyxtures that may be used by the mesh. The Function assumes that each surface has exactly one texture, so it only counts up to the number of surfaces and inserts the surface-brushes texture info for each surface.
You may add an additional texture info block for the Lightmap. You may do this as the first block, or as the last block (pre or past the For loop), but it must be inside the TEX chunk. Something like:
b3dWriteString( lima_file$ ) ;texture file b3dWriteInt( 1 );flags b3dWriteInt( 2 );blend - uh right now I don't remember exactly what blendmode needs to be used, but probably you have to try some modes b3dWriteFloat( 0 );x in tex 0 b3dWriteFloat( 0 );y in tex 0 b3dWriteFloat( 1 );x scale 1 b3dWriteFloat( 1 );y scale 1 b3dWriteFloat( 0 );rotation 0
(please note: use the right blend mode, "addition" or something)
Now heres a number of BRUS chunk, each one defines a Brush. Some people use only one BRUS chunk and include all Bsushes inside, but they need to use the same number of Texture Layers for each Brush, even when Layers can be deactivated by using -1 as index, if I remember right. However, this Function uses a method that defines a BRUS chunk for each Brush, this way each Brush can have its individual number of Textures. If you have added the lightmap info block in the TEX chunk after the For loop, you could do it this way:
For i=1 To c_surfs b3dBeginChunk( "BRUS" ) ; describe all brushes used by the mesh b3dWriteInt( 2 );number of textures per brush b3dWriteString( "brush"+(i-1) );brushname b3dWriteFloat( 1 );red b3dWriteFloat( 1 );green b3dWriteFloat( 1 );blue b3dWriteFloat( 1 );alpha b3dWriteFloat( 0 );shininess b3dWriteInt( 1 );blendmode b3dWriteInt( 1 );FX >>> lightmapped meshes usually are FX 1 b3dWriteInt( i-1 );used "material" texture index b3dWriteInt( c_surfs ); index of the lightmap b3dEndChunk();end of BRUS chunk Next
Now the mesh still needs to know what to do with the lightmap, so you need to save the second UV Coords, in the Function it's already there, only remarked, so you only have to activate these two lines in the function WriteMESH( mesh ):
;;b3dWriteFloat( VertexU#( surf,j,1 ) ) ; lightmap uv
;;b3dWriteFloat( VertexV#( surf,j,1 ) ) ; lightmap uv
plus chanche this line:
b3dWriteInt( 1 );number of tex_coord sets
to
b3dWriteInt( 2 );number of tex_coord sets
Now you should be pretty close to a working Mesh exporter that works with lightmaps- Additionally you learned something about the format.