Lightmap in b3d blues - JFK,Mark, Anyone?

Blitz3D Forums/Blitz3D Programming/Lightmap in b3d blues - JFK,Mark, Anyone?

D4NM4N(Posted 2005) [#1]
This is driving me mad :P
Does anyone know how 2 export a lightmap on set 1 in b3d using jfk's version of the exporter?

My problem seems to be, even though ive set all the relevent lightmap flags etc and specified coord1 UVs there doesnt seem to be a way of telling the secondary brush texture to use set 1. It allways apears using the set 0 coords. (see code below)

Also probably unrelated - what is entitybrush for, if i set it to a brush number i get a MAV

Here is the textures and brushes bit:
	b3dBeginChunk( "BB3D" )
		b3dWriteInt( 1 )	;version

		b3dBeginChunk( "TEXS" ) ; list all textures used by the mesh
		For i=1 To children
			b3dWriteString(c_tex_name$(i)) 	;texture file
			DebugLog c_tex_name$(i)
			b3dWriteInt( 9 )					;flags
			b3dWriteInt( 2 )					;blend
			b3dWriteFloat( 0 )					;x in tex 0 (hu?)
			b3dWriteFloat( 0 )					;y in tex 0
			b3dWriteFloat(1.000);tu );tex_uvscale(7-i) )					;x scale 1
			b3dWriteFloat(1.000);tex_uvscale(7-i) )					;y scale 1
			b3dWriteFloat(0 )					;rotation 0
			
		Next
		b3dWriteString(strip_path(lmname$)) 	;texture file
		DebugLog lmname$
		b3dWriteInt( 9 )					;flags
		b3dWriteInt( 2 )					;blend
		b3dWriteFloat( 0 )					;x in tex 0 (hu?)
		b3dWriteFloat( 0 )					;y in tex 0
		b3dWriteFloat(1.000);tu );tex_uvscale(7-i) )					;x scale 1
		b3dWriteFloat(1.000);tex_uvscale(7-i) )					;y scale 1
		b3dWriteFloat(0 )					;rotation 0
		
		b3dEndChunk()	;end of TEXS chunk

		
		b3dBeginChunk( "BRUS" ) ; describe all brushes used by the mesh
		b3dWriteInt( 2 )					;number of textures per brush ; (eg 2 with lightmap)
		For i=1 To children
			b3dWriteString( brushname$+" "+(i-1) )		;brushname
			b3dWriteFloat( 1 )					;red
			b3dWriteFloat( 1 )					;green
			b3dWriteFloat( 1 )					;blue
			b3dWriteFloat( 1 )					;alpha
			b3dWriteFloat( 0 )					;shininess
			b3dWriteInt( 1 )					;blendmode
			If i=children 
				b3dWriteInt( 2 )
			 Else 
				b3dWriteInt( 32+2 +lightmap_onoff)					;FX
			EndIf
			b3dWriteInt( i-1 )					;used texture index 
			b3dWriteInt( children )					;additional texture index (eg lightmap), but here we only use 1 (see above)
		Next
		b3dEndChunk()	;end of BRUS chunk


here is the mesh writing bit:
	n_surfs=CountSurfaces( mesh )
	
	b3dBeginChunk( "MESH" )
		b3dWriteInt( -1 )				;no 'entity' brush -1
		
		b3dBeginChunk( "VRTS" )
			b3dWriteInt( 3 )			;flags - 0=no normal/color
			b3dWriteInt( 2 )			;number of tex_coord sets (eg: 2 with lightmap)
			b3dWriteInt( 2 )			;coords per set (u,v,w?) 2 with uv, 3 with uvw
			
			For k=1 To n_surfs
				surf=GetSurface( mesh,k )
				n_verts=CountVertices( surf )-1
				
				For j=0 To n_verts
					b3dWriteFloat( VertexX( surf,j ) )
					b3dWriteFloat( VertexY( surf,j ) )
					b3dWriteFloat( VertexZ( surf,j ) )
					b3dWriteFloat( VertexNX( surf,j ) )
					b3dWriteFloat( VertexNY( surf,j ) )
					b3dWriteFloat( VertexNZ( surf,j ) )
					b3dWritefloat( VertexRed( surf,j )/255 )
					b3dWritefloat( VertexGreen( surf,j )/255 )
					b3dWritefloat( VertexBlue( surf,j )/255 )
					b3dWriteFloat( VertexAlpha( surf,j ) )
					b3dWriteFloat( VertexU#( surf,j,0 ) )
					b3dWriteFloat( VertexV#( surf,j,0 ) )
;					;b3dWriteFloat( VertexW#( surf,j,0 ) )
					b3dWriteFloat(VertexU#( surf,j,1 ) ) ; lightmap uv
					b3dWriteFloat(VertexV#( surf,j,1 ) ) ; lightmap uv
;					;b3dWriteFloat( VertexW#( surf,j,1 ) )
				Next
			Next
		b3dEndChunk()	;end of VRTS chunk
		
		first_vert=0
		For k=1 To n_surfs
			surf=GetSurface( mesh,k )
			n_tris=CountTriangles( surf )-1
			
			b3dBeginChunk( "TRIS" )
			
				;decide wether index for tex comes from child or surface
				If texindex=0
					b3dWriteInt( k-1 )			;brush for these triangles (surf -1 !!!)				
				Else
					b3dWriteInt( texindex-1 )		;brush for these triangles (surf -1 !!!)
				EndIf
				
				For j=0 To n_tris
					b3dWriteInt( first_vert+TriangleVertex( surf,j,0 ) )
					b3dWriteInt( first_vert+TriangleVertex( surf,j,1 ) )
					b3dWriteInt( first_vert+TriangleVertex( surf,j,2 ) )
				Next
				
			b3dEndChunk()	;end of TRIS chunk
			
			first_vert=first_vert+CountVertices( surf )
			
		Next
		
	b3dEndChunk()	;end of MESH chunk



Jeppe Nielsen(Posted 2005) [#2]
I think you will need to add 65536 to the flags value of your lightmap texture, this will indicate that the texture will use the second uv values, ala the TextureCoords command:

change:

b3dWriteInt( 9 )

to

b3dWriteInt( 9 + 65536 )

I think that is what is needed.


D4NM4N(Posted 2005) [#3]
Thanks, worked a treat!


IPete2(Posted 2005) [#4]
Don't you just love these forums - brilliant example f why it is called a community!

IPete2.


Tom(Posted 2005) [#5]
http://www.blitzbasic.com/sdkspecs/sdkspecs/b3dfile_specs.txt

I think Mark might have had a few beers when he wrote this one :)
The flags field value can conditional an additional flag value of '65536'. This is used to indicate that the texture uses secondary UV values, ala the TextureCoords command. Yes, I forgot about this one.