Strange...

Blitz3D Forums/Blitz3D Programming/Strange...

I am writing a landscape app that exports to b3d, when I load the b3d model into blitz it looks perfect alpha blended land layers, sky ect all looks fine, but the loaded model says it has no children and only one surface! (the sky)

If I free the entity the sky disappears but the landscape doesn't, any ideas what I've done wrong? (I'll post b3d file if needed)

BTW I did load it with LoadAnimMesh()

Thanks in advance.

B3D model and textures was here, but now I've removed the link ;)

Bump

Has ne1 come across this problem before?

Fascinating !

Looks like you have exported two objects in one somehow.

Blitz only recognises the sky(in an animmesh) - hence the sky moves when you tell it to, and vanishes when you tell it to - but the landscape does not. The landscape is not even being added to the entity system(though it is added to the rendersystem), hence it being orphaned, uncontrollable and visible.

Loading as a normal mesh(or into UU3D), it loads the other way round... and plays with the landscape nicely, but seems to be ignoring the sky !

Your mesh also crashes blitz a little bit...

I suggest you look very carefully at your exporter with intense suspicion. If the mesh was saved correctly it would collapse into one (on LoadMesh) with no problems.

You may get better results exporting two totally seperate objects(seperate files works), or one object with multiple surfaces than experimenting with object children.

Yeah it's very odd!

There are actualy three meshs to the landscape, so all three are being orphaned, but I can't get why this is happening.

Here's the exporter functions... (if anyones interested)
Function WriteBB3DLandscape( f_name$ )

	file=WriteFile( f_name$ )

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

		b3dBeginChunk( "TEXS" )
		tcount = -1
		For OptimizedMesh.OptimizedMesh = Each OptimizedMesh
			tcount = tcount + 1
			For LandscapeLayer.LandscapeLayer = Each LandscapeLayer
				If LandscapeLayer\TextureID = OptimizedMesh\TextureID
					Current.LandscapeLayer = LandscapeLayer.LandscapeLayer
					LandscapeLayer.LandscapeLayer = Last LandscapeLayer
				EndIf
			Next
			b3dWriteString("LayerTexture_"+OptimizedMesh\TexCount+".bmp")   ;texture file name
	 		b3dWriteInt(1)								;blitz3D TextureFLags default=1
			b3dWriteInt(2)          					;TextureBlend: default=2
			b3dWriteFloat(Current\TexturePositionU#)	;x position of texture: Default=0
			b3dWriteFloat(Current\TexturePositionV#)    ;y position of texture: default=0
			b3dWriteFloat(1.0/Current\TextureScaleU#)	;x scale of texture: Default=1
			b3dWriteFloat(1.0/Current\TextureScaleV#)   ;y scale of texture: default=1
			b3dWriteFloat(0)        					;rotation of texture (in radians): default=0	
		Next
		If SkyActive = 1
			tcount = tcount + 1
			skybrush = tcount
			b3dWriteString("Sky.bmp")				;texture file name
	 		b3dWriteInt(1)			 				;blitz3D TextureFLags default=1
			b3dWriteInt(2)           				;TextureBlend: default=2
			b3dWriteFloat(0)		 				;x position of texture: default=0
			b3dWriteFloat(0)         				;y position of texture: default=0
			b3dWriteFloat(1.0/SkyTextureScaleU#)	;x scale of texture: default=1
			b3dWriteFloat(1.0/SkyTextureScaleV#)    ;y scale of texture: default=1
			b3dWriteFloat(0)        				;rotation of texture (in radians): default=0	
		EndIf
		If LightMapTexture <> 0
			tcount = tcount + 1
			lightmapbrush = tcount
			b3dWriteString("LightMap.bmp")				;texture file name
	 		b3dWriteInt(1)			 				;blitz3D TextureFLags default=1
			b3dWriteInt(2)           				;TextureBlend: default=2
			b3dWriteFloat(0.02)		 				;x position of texture: default=0
			b3dWriteFloat(0.02)         			;y position of texture: default=0
			b3dWriteFloat(1.0/-1.065)				;x scale of texture: default=1
			b3dWriteFloat(1.0/-1.065)    			;y scale of texture: default=1
			b3dWriteFloat(0)        				;rotation of texture (in radians): default=0	
		EndIf
		b3dEndChunk()								; ends of TEXS chunk
		
		b3dBeginChunk( "BRUS" )
			If LightMapTexture <> 0
				b3dWriteint( 2 )					; textures per brush (with lightmap)
			Else
				b3dWriteInt( 1 )					;0 textures per brush
			EndIf
			For OptimizedMesh.OptimizedMesh = Each OptimizedMesh
				b3dWriteString( "LayerBrush_"+OptimizedMesh\TexCount )		;name
				b3dWriteFloat( 1 )					;red
				b3dWriteFloat( 1 )					;green
				b3dWriteFloat( 1 )					;blue
				b3dWriteFloat( 1 )					;alpha
				b3dWriteFloat( 0 )					;shininess
				b3dWriteInt( 1 )					;blend
				If OptimizedMesh.OptimizedMesh = First OptimizedMesh
					b3dWriteInt( 2 )
				Else
					b3dWriteInt( 32 + 2 )					;FX
				EndIf
  				b3dWriteInt( OptimizedMesh\TexCount-1 )   	;textures used in brush			
				If LightMapTexture <> 0
					b3dWriteInt( lightmapbrush )			; lightmap
				EndIf
			Next
			If SkyActive = 1
				b3dWriteString( "SkyBrush")			;name
				b3dWriteFloat( 1 )					;red
				b3dWriteFloat( 1 )					;green
				b3dWriteFloat( 1 )					;blue
				b3dWriteFloat( 1 )					;alpha
				b3dWriteFloat( 0 )					;shininess
				b3dWriteInt( 1 )					;blend
				b3dWriteInt( 2 )					;fx
  				b3dWriteInt( skybrush )   			;textures used in brush	
				If LightMapTexture <> 0
					b3dWriteInt( -1 )				; no texture?
				EndIf
			EndIf
		b3dEndChunk()	;end of BRUS chunk

		count = 0
		For OptimizedMesh.OptimizedMesh = Each OptimizedMesh
			mesh = OptimizedMesh\MeshID
			name$ = "LandscapeLayer"+count : count=count+1
			b3dBeginChunk( "NODE" )
				b3dWriteString( name$ )
				b3dWriteFloat( EntityX(mesh) )		;x_pos
				b3dWriteFloat( EntityY(mesh) )		;y_pos
				b3dWriteFloat( EntityZ(mesh) )		;z_pos
				b3dWriteFloat( EntityScaleX(mesh) )	;x_scale
				b3dWriteFloat( EntityScaleY(mesh) )	;y_scale
				b3dWriteFloat( EntityScaleZ(mesh) )	;z_scale
				b3dWriteFloat( 1 )	                ;rot_w    ?- what the #£!& -?
 				b3dWriteFloat( EntityPitch(mesh) )	;rot_x
				b3dWriteFloat( EntityYaw(mesh) )	;rot_y
				b3dWriteFloat( EntityRoll(mesh) )	;rot_z
				WriteMESH( mesh,OptimizedMesh.OptimizedMesh )
			b3dEndChunk()	;end of NODE chunk
		Next
		If SkyActive = 1
			mesh = SkyID
			name$ = "Sky" : count=count+1
			b3dBeginChunk( "NODE" )
				b3dWriteString( name$ )
				b3dWriteFloat( 0 )					;x_pos
				b3dWriteFloat( 0 )					;y_pos
				b3dWriteFloat( 0 )					;z_pos
				b3dWriteFloat( EntityScaleX(mesh) )	;x_scale
				b3dWriteFloat( EntityScaleY(mesh) )	;y_scale
				b3dWriteFloat( EntityScaleZ(mesh) )	;z_scale
				b3dWriteFloat( 1 )	                ;rot_w    ?- what the #£!& -?
 				b3dWriteFloat( EntityPitch(mesh) )	;rot_x
				b3dWriteFloat( EntityYaw(mesh) )	;rot_y
				b3dWriteFloat( EntityRoll(mesh) )	;rot_z
				WriteSkyMESH(mesh,skybrush)
			b3dEndChunk()	;end of NODE chunk
		EndIf
		
	b3dEndChunk()	;end of BB3D chunk
	
	CloseFile file
End Function





Function WriteMESH( mesh,OptimizedMesh.OptimizedMesh )

	n_surfs=CountSurfaces( mesh )
	
	b3dBeginChunk( "MESH" )
		b3dWriteInt( -1 )				;no 'entity' brush
		
		b3dBeginChunk( "VRTS" )
			b3dWriteInt( 3 )			;flags - 0=no normal/color
			b3dWriteInt( 1 )			;0 tex_coord sets
			b3dWriteInt( 2 )			;0 coords per set
			
			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 ) )
					b3dWriteFloat( VertexGreen( surf,j ) )
					b3dWriteFloat( VertexBlue( surf,j ) )
					b3dWriteFloat( VertexAlpha( surf,j ) )
					b3dWriteFloat( VertexU( surf,j ) )
					b3dWriteFloat( VertexV( surf,j ) )
				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( OptimizedMesh\TexCount-1 )		;brush for these triangles
				
				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









Function WriteSkyMESH(mesh,brush )

	n_surfs=CountSurfaces( mesh )
	
	b3dBeginChunk( "MESH" )
		b3dWriteInt( -1 )				;no 'entity' brush
		
		b3dBeginChunk( "VRTS" )
			b3dWriteInt( 0 )			;flags - 0=no normal/color
			b3dWriteInt( 1 )			;0 tex_coord sets
			b3dWriteInt( 2 )			;0 coords per set
			
			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 ) )
					;b3dWriteFloat( VertexGreen( surf,j ) )
					;b3dWriteFloat( VertexBlue( surf,j ) )
					;b3dWriteFloat( VertexAlpha( surf,j ) )
					b3dWriteFloat( VertexU( surf,j ) )
					b3dWriteFloat( VertexV( surf,j ) )
				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( brush )		;brush for these triangles
				
				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


Ok, I see what you are doing.

You are setting up the nodes as siblings, rather than children, in other words multiple root nodes, which I don't seem to remember blitz supporting.

If you write a "root" node, then have everything as children to that node, you may have better success. You'll still need to run findchild on the sky to move it seperately.

Thanks Braneloc, now I get it...
NODE
   MESH
   NODE
      MESH
   ENDNODE
ENDNODE

Instead of
NODE
   MESH
ENDNODE
NODE
   MESH
ENDNODE

Works a treat! :)