re. the Stunt Car MAV - loading B3Ds

Blitz3D Forums/Blitz3D Programming/re. the Stunt Car MAV - loading B3Ds

I've upgraded to XP and running the game in the Blitz IDE I get the MAV that lots of others have been getting.

It's caused by the game loading a B3D file that the game editor produces, using the public B3D code (that I believe is either in the archives or comes in a demo program from Mark) that is shown below.

If I use a B3D exported from 3DSMax then it all works just fine, so the B3D code must be the cause of this problem.

Now, it works on Win2000, BUT I can get win2000 to MAV also if I move the .B3D file from the SCR folder root into a subfolder, but by messing with the lines that write the texture paths I can sometimes get it to work, but I don't understand *WHY* it works or doesn't work - I think it's looking for the textures relative to the B3D, but creating an identical directory structure in a different place still causes a MAV.

So, I think the MAV is being caused by some difference between XP and 2000 that means when Blitz loads the B3D file, for some reason it can't locate the textures.

Anyone got any ideas how I can fix this by modifying the .B3D saving code shown below?

Function FUNC_Export_Single_Mesh()

	FlushKeys

	;save world data first
	FUNC_Save(True)
	
	;create a single mesh
	singlemesh = CreateMesh()

	For s.TYPE_segment = Each TYPE_segment
		x# = EntityX#(s\mesh,1)
		y# = EntityY#(s\mesh,1)
		z# = EntityZ#(s\mesh,1)
		yaw# = EntityYaw#(s\mesh,1)
		PositionEntity s\mesh,0,0,0
		RotateEntity s\mesh,0,0,0
		RotateMesh s\mesh,0,yaw#,0
		PositionMesh s\mesh,x#,y#,z#
		AddMesh s\mesh , singlemesh
	Next

	PositionEntity singlemesh,0,20,0
	EntityColor singlemesh,255,0,0
	ScaleMesh singlemesh,10,10,10
	
	;compile a list of used textures
	DebugLog "Compiling texture list..."
	numsurfs = CountSurfaces(singlemesh)
	DebugLog "   "+numsurfs+" surfaces present in mesh."
	For i=1 To numsurfs
		 c_surf(i)= GetSurface(singlemesh,i)
		 c_brush(i)=GetSurfaceBrush( c_surf(i) )
		 c_tex(i)=GetBrushTexture( c_brush(i) )
		 c_tex_name$(i)=Lower$(TextureName$( c_tex(i))) ; Full (!) Texture Path
		 curdir$=Lower$(CurrentDir$()) 
		 c_tex_name$(i)= Replace$(c_tex_name$(i),curdir$,"") ;<<<<<<<<<<<<<<<<<<<

		;set texture path to the TEXTURES directory
		c_tex_name$(i)=Replace$(c_tex_name$(i),"track editor\segments","textures")

		 DebugLog "   Texture used : "+c_tex_name$(i)
		 If c_tex_name$(i)="" Then DebugLog "Error: Surface No."+i+" has no Texture"
		 If FileType(c_tex_name$(i))<>1 Then DebugLog "Warning: Surface No."+i+" uses nonexistant Texture ("+c_tex_name$(i)+")."
	Next

	FUNC_WriteBB3D( "exported_track.b3d",singlemesh)
	
	FreeEntity singlemesh	
	
	;clear and reload
	FUNC_Clear_World(False)
	FUNC_Load(True)
	
End Function




Function FUNC_WriteBB3D( f_name$,mesh )

	file=WriteFile( f_name$ )

	b3dSetFile( file )
	
	b3dBeginChunk( "BB3D" )
		b3dWriteInt( 1 )	;version

		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
		b3dEndChunk()	;end of TEXS chunk

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

			b3dEndChunk()	;end of BRUS chunk
		Next
		
		b3dBeginChunk( "NODE" )
			b3dWriteString( "entity_name_here!" )
			b3dWriteFloat( 0 )	;x_pos
			b3dWriteFloat( 0 )	;y_pos
			b3dWriteFloat( 0 )	;z_pos
			b3dWriteFloat( 1 )	;x_scale
			b3dWriteFloat( 1 )	;y_scale
			b3dWriteFloat( 1 )	;z_scale
			b3dWriteFloat( 1 )	;rot_w
			b3dWriteFloat( 0 )	;rot_x
			b3dWriteFloat( 0 )	;rot_y
			b3dWriteFloat( 0 )	;rot_z
			FUNC_WriteMESH( mesh )
		b3dEndChunk()	;end of NODE chunk
		
	b3dEndChunk()	;end of BB3D chunk
	
	CloseFile file
End Function








Function FUNC_WriteMESH( mesh )

	n_surfs=CountSurfaces( mesh )
	
	b3dBeginChunk( "MESH" )
		b3dWriteInt( -1 )				;no 'entity' brush -1
		
		b3dBeginChunk( "VRTS" )
			b3dWriteInt( 2 )			;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( VertexRed#( surf,j ) / 255.0 )
					b3dWriteFloat( VertexGreen#( surf,j ) / 255.0 )
					b3dWriteFloat( VertexBlue#( surf,j ) / 255.0 )
					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" )
				b3dWriteInt( k-1 )		;brush for these triangles (surf -1 !!!)
				
				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
	
End Function


Have you tried storing your textures in the same folder as the models and then setting the texture paths to "." (which is the current directory). Then, before loading, ChangeDir to the model/texture directory.

I have no idea if this'll work, tbh, as I'm not familiar with the B3D format - do all texture paths have to be absolute? Hmm, surely not - that'd be a nightmare. :P

Strange this is an XP/2000 specific problem, though.

[edit] If by some freak of nature this method does work, you could alternativey set all texture paths to "..\textures" (or whatever) if you wanted to keep the textures in a separate folder.

OK, I think I sorted it -

can you XP users who were getting MAVs please download this new file - http://www.jameskett.dsl.pipex.com/SCR_XP.zip

REMEMBER YOU NEED THE COMPLETE ORIGINAL SCR DEMO - www.jameskett.dsl.pipex.com/SCR_Demo.zip

it's a new EXE (SCR_winXP.exe) and a new DLL for mipmapping and a new track, so unzip it to the original SCR demo folder and overwrite EXPORTED_TRACK.b3d.

It should now work in normal (non-win98-compat) mode in XP, so please can you guys test it and let me know if it works. You'll all have a nice new track to play also!

thank you
James

Was I way off then, Vorderman? I guess no comment speaks a thousand words. lol.

Sorry, I didn't mean to ignore what you posted, but I was reading through the code and spotted that a small change I had made has screwed up the b3d file structure, so it was my fault and not the original code (posted in the archives by JFK) - it was writing out a blank line for loads of non-existant textures, rather than stopping after it had written out however many were actually used. Why this worked under Win2000 and not XP I don't know, but hopefully it's now sorted.

XP seems to catch some types of illegal memory accesses.

Blitz likes to MAV when you try and access e.g. past the end of an array, WritePixelFast'ing outside of the screen etc.

I remember an X file (fredborgs dotmybot demo) that would MAV on some machines and not others. It was fine after I imported/exported it thru Unwrap3D (I think).

This version works fine for me :) Both of the previous builds gave me a MAV... Woohoo!

Nice one Vord...

Great, that's really good to hear!

Thanks Daze.

All fix0red. w00t! :o)

Working here too now. No errors.
I like to huuuuge jump in the new track. I could almost fit in a cuppa coffee before I land.
Love it :)

Argh, dude! I can't play it!!

Seriously, I don't have a joypad and can't seem to select mouse control.

*whimper*

I was reading through the code and spotted that a small change I had made has screwed up the b3d file structure
That explains why I could not view the track in Blitz MediaViewer (enhanced). I kept getting a MAV.
Works perfectly now though:


OHH MY GOD! THATS HELLA FUN! Love it, top notch.
Physics are perfect, controls perfect, car perfect, views perfect. 10

This game is awesome so far. I think the physics feel a lot better than Track Mania, which I found a little disappointing. Hope you finish this and release it.

Argh, dude! I can't play it!!

Seriously, I don't have a joypad and can't seem to select mouse control.

*whimper*
I find it strange that so many games developers don't have joypad or joysticks. What are you people using to test your games?


This game is awesome so far. I think the physics feel a lot better than Track Mania, which I found a little disappointing. Hope you finish this and release it.



I agree with that 100%. Vorderman's done a kickass job :)

@Oddball: I'm not current interested in developing games that require the use of a joypad.

Joypad owners are in a minority. Perhaps M$ will make good on the promise of Xbox360 joypad compatability in Vista and things will change.