MP3D Engine Alpha 33

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hello,

@G_Nom not now, but i work on it

Question about the im/export of mesh. Here comes my first try. I have made in the mp3d Forum a new thread:
http://www.morty-productions.de/gamedev ... hp?tid=193

Demo 1 shows how to make a direct x mesh with direct x functions
Demo 2 shows how load a directx mesh and get all information you needed to make an exportfuntion
Demo 3 shows how make a empty directx mesh and how to set vertex and triangles "manually" you needed to make a importfuntion

I think the first step could be to create a b3d export from demo 2.

We can talk in my forum about questions and code/structures/informations requests. I will allways have a look on it there...

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

Hi, @mpz. First off, I would like to say thank you so kindly for the upgrade!

Secondly, I would like to mention that I have made a very feeble ATTEMPT to create a Save_B3D() inside of CodeSnipes.pb.

It probably doesn't work, but it is a start. I need you to look this over and correct where I messed up so it DOES work.

Put this above Load_B3D():

Code: Select all

Procedure MP_SaveB3D( FileName.s, meshcolor=255 ) ; B3D Dateien saven

  Color.l = $FFFFFF  
  If FileName.s
    If Writefile(0, FileName)
      chunk_id.s = "    "
      WriteData(0, @chunk_id.s, 4)
      
      chunk_len = WriteLong(0, 0)
      Version = WriteLong(0, 1)

      While Eof(0) = 0           ; sich wiederholende Schleife bis das Ende der Datei ("end of file") erreicht ist
          
          WriteData(0, @chunk_id.s, 4)
          WriteLong(0, chunk_len)
          
          If chunk_id
            
              WriteString(0, "TEXS") ;Main Chunk
              
              While chunk_len > 4
                
                start = Loc(0)
                
                x_pos.f = EntityX(#B3DMesh)
                y_pos.f = EntityY(#B3DMesh)
                
                sizeX.f = (EntityBoundingBox(#B3DMesh, #PB_Entity_MinBoundingBoxX | #PB_Entity_WorldBoundingBox) - EntityX(#B3DMesh) / EntityBoundingBox(#B3DMesh, #PB_Entity_MinBoundingBoxX | #PB_Entity_LocalBoundingBox)
                sizeY.f = (EntityBoundingBox(#B3DMesh, #PB_Entity_MinBoundingBoxY | #PB_Entity_WorldBoundingBox) - EntityY(#B3DMesh) / EntityBoundingBox(#B3DMesh, #PB_Entity_MinBoundingBoxY | #PB_Entity_LocalBoundingBox)
               ;sizeZ.f = (EntityBoundingBox(#B3DMesh, #PB_Entity_MinBoundingBoxZ | #PB_Entity_WorldBoundingBox) - EntityZ(#B3DMesh) / EntityBoundingBox(#B3DMesh, #PB_Entity_MinBoundingBoxZ | #PB_Entity_LocalBoundingBox)
                
                rot.f = EntityYaw(#B3DMesh, #PB_Local)
                
                WriteString(0, chunk_id)
                
                WriteLong(0, flags)
                
                WriteFloat(0, x_pos.f)
                WriteFloat(0, y_pos.f)
                
                WriteFloat(0, sizeX.f)
                WriteFloat(0, sizeY.f)
                
                chunk_len + start - Loc(0)
                ;Debug "< Textur = <"+Texturname + "> = "+Str(chunk_len )
                
                ;Write Textures to B3D model
                WriteString(0, "BRUS")
            
              Wend
              
            EndIf
            
            n_texs = WriteLong(0, texcount)
            chunk_len - 12
              
            If chunk_id
            
              While chunk_len > 0
                start = Loc(0)
                WriteString(0, tname.s)
                
                WriteFloat(0, MP_Red(meshcolor))
                WriteFloat(0, MP_Green(meshcolor))
                WriteFloat(0, MP_Blue(meshcolor))
                
                WriteLong(0, BLEND_HERE)
                
                WriteLong(0, FX_HERE)
                
                For k=0 To n_texs-1
                  WriteLong(0, tex_id)
                Next
                chunk_len + start - Loc(0)
                ;Debug "< BRUS = <"+tname+"> = "+Str(chunk_len )
                
              Wend
              
            EndIf
            
            If chunk_id
              
              WriteString(0, "VRTS")
              
              WriteLong(0, VERT_FLAGS_HERE)
              
              WriteLong(0, tc_sets)
              WriteLong(0, tc_sizes)
              
              chunk_len - 12
              sz=12+tc_sets*tc_size*4
              If flags & 1 = 1
                sz+12
              EndIf
              qty_Vertex =chunk_len/sz
              ;Debug "< Vertex = "+Str(qty+Vertex)
              
              *VBuffer = AllocateMemory(SizeOf(MyVertex)*qty_Vertex)
              *PtrV.MyVertex = *VBuffer
              If qty_Vertex*sz = chunk_len ;b3dChunkSize()
              
				       ;read all verts in chunk
				       While chunk_len > 0 ; b3dChunkSize()
			                      
                 start = Loc(0)
                 
                 WriteFloat(0, *PtrV\x)
                 WriteFloat(0, *PtrV\y)
                 WriteFloat(0, *PtrV\z)

                 If flags & 1 = 1
					         WriteFloat(0, *PtrV\nx)
					         WriteFloat(0, *PtrV\ny)
					         WriteFloat(0, *PtrV\nz)
		             Else
			             *PtrV\nx = *PtrV\x
                   *PtrV\ny = *PtrV\y
                   *PtrV\nz = *PtrV\z
      	         EndIf
      	                    
      	         If flags & 2 = 2
      	           
      	           ;*PtrV\Color = MP_ARGB(ReadFloat(0),ReadFloat(0),ReadFloat(0),ReadFloat(0))
      	           
      	           WriteFloat(0, r.f*255)
      	           WriteFloat(0, g.f*255)
      	           WriteFloat(0, b.f*255)
      	           WriteFloat(0, a.f*255)
						                    
                   *PtrV\Color = (((Int(r) & $FF) << 24) | ((Int(g) & $FF) << 16) | ((Int(b) & $FF) << 8) | (Int(a) & $FF))

                 Else
                   
                   *PtrV\Color = Color                             
                   
				         EndIf

                 ;read tex coords...
				         For j=1 To tc_sets*tc_size
						       wert.f = ReadFloat(0)
                   If j = 1 : *PtrV\u = wert : EndIf ;Single Textur = u1
                   If j = 2 : *PtrV\v = wert : EndIf ;Single Textur = v1
                   ;If j = 3 : *PtrV\u = wert : EndIf ; j > 2 = multitexture u2,v2,u3... but the problem here is Ogre
				         Next
				          *PtrV + SizeOf(MyVertex) 
				          chunk_len + start - Loc(0)
				       Wend
			       Else
				       ProcedureReturn #False ; "***** Illegal number of vertices *****"
			       EndIf
			       
			     EndIf
			     
			     WriteString(0, "TRIS")
			     WriteLong(0, brush_id)
			     chunk_len-4
			     sz=12
			     qty_Triangle=chunk_len/sz
			     *IBuffer=AllocateMemory(SizeOf(FTriangle)*qty_Triangle)
           *PtrF.FTriangle=*IBuffer 
			     If qty_Triangle*sz=chunk_len
				     While chunk_len > 0
				       start = Loc(0)
					     WriteLong(0, *PtrF\f1)
					     WriteLong(0, *PtrF\f2)
					     WriteLong(0, *PtrF\f3)
					     *PtrF + SizeOf(FTriangle) 
					     chunk_len + start - Loc(0)
					   Wend
			     Else
			       ProcedureReturn #False ; "***** Illegal number of triangles *****"
			     EndIf
			     
			     WriteString(0, "MESH")
			     WriteLong(0, brush_id)
			     ;Debug "Brush ID "+Str(brush_id)
			     
           WriteString(0, "NODE")
           start = Loc(0)
           
           WriteString(0, name.s)
           
           WriteFloat(0, x_pos.f)
           WriteFloat(0, y_pos.f)
           WriteFloat(0, z_pos.f)
           
           WriteFloat(0, x_scl.f)
           WriteFloat(0, y_scl.f)
           WriteFloat(0, z_scl.f)
           
           WriteFloat(0, x_rot.f)
           WriteFloat(0, y_rot.f)
           WriteFloat(0, z_rot.f)
           
           chunk_len + start - Loc(0)
           
           ;Debug "< NODE = <"+name+"> = "+Str(chunk_len )
           
           For x = 1 To chunk_len
             WriteByte(0, 0)
           Next
           
      Wend

      AddElement(Mesh())
      Mesh()\Meshscale\Sx = 1
      Mesh()\Meshscale\Sy = 1
      Mesh()\Meshscale\Sz = 1
      Mesh()\kind = 1
      Mesh()\ZEnable = 1
               
      AddElement(Mesh()\Texture())
      D3DXMatrixTranslation(Mesh()\MeshPosition,0,0,0)      

         
      D3DXCreateMeshFVF (qty_Triangle,qty_Vertex,#D3DXMESH_MANAGED |#D3DXMESH_32BIT , #D3DFVF_VertexFormat,*D3DDevice, @Mesh()\Mesh) 

      *pVert=#Null 

      *pVBuf.IDIRECT3DVERTEXBUFFER9;
   
      Mesh()\Mesh\GetVertexBuffer(@*pVBuf)
  
      *pVBuf\Lock( 0, 0, @*pVert, 0 ) 
 
      CopyMemory(*VBuffer,*pVert,qty_Vertex * SizeOf(MyVertex))      
           
      *pVBuf\Unlock() 
      *pVBuf\Release() 

      FreeMemory(*VBuffer)
    
      *pInd=#Null 

      Mesh()\Mesh\LockIndexBuffer(#D3DLOCK_DISCARD,@*pInd) 

      CopyMemory(*IBuffer,*pInd,qty_Triangle * SizeOf(FTriangle)) 
   
      Mesh()\Mesh\UnlockIndexBuffer(); 
      FreeMemory(*IBuffer)
               
      D3DXMatrixTranslation(Mesh()\MeshPosition,0,0,0)
         
      AddElement (TextureM())
      Texturname.s = GetFilePart(Texturname.s)
               
      If Texturname.s
        Mesh()\Texture() = @TextureM()
        TextureM()\pTextureFilename = Texturname.s 
        If D3DXCreateTextureFromFileA(*D3DDevice, GetPathPart(FileName.s)+ TextureM()\pTextureFilename, @TextureM()) = #D3D_OK
          *D3DDevice\SetSamplerState(0, #D3DSAMP_MINFILTER, #D3DTEXF_LINEAR)
          *D3DDevice\SetSamplerState(0, #D3DSAMP_MAGFILTER, #D3DTEXF_LINEAR)
        EndIf
      EndIf

      Mesh()\Material\Ambient\r = 1
      Mesh()\Material\Ambient\g = 1
      Mesh()\Material\Ambient\b = 1
      Mesh()\Material\Diffuse\r = 1
      Mesh()\Material\Diffuse\g = 1
      Mesh()\Material\Diffuse\b = 1
      Mesh()\Material\Specular\r = 1
      Mesh()\Material\Specular\g = 1
      Mesh()\Material\Specular\b = 1
      
    EndIf
    CloseFile(0)
  EndIf
  error = 20

EndProcedure
I HOPE I did it right, but I doubt it.

O, btw, the variables that still need defined are as follows:
RED_HERE
GREEN_HERE
BLUE_HERE
BLEND_HERE
FX_HERE

And finally...

VERT_FLAGS_HERE
Thanks once again, @mpz!

Lets finish this ONCE & FOR ALL!

Mythros
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi,

multitexturing with directx and the import and export is not any longer a problem. I found a little bug in the engine and have made a new demo file for multitexuring. I think i can actualise the Mesh_in_Out.zip file with these demos an unbuged lib in this evening...

Greetings Michael

to create submesh for meshs you need these part of a code

Code: Select all

*MyMesh\Mesh\LockAttributeBuffer(#D3DLOCK_DISCARD,@*id)

*pointerAt.long = *id

*pointerAt\l = 0 : *pointerAt + 4 ; submesh 0
*pointerAt\l = 0 : *pointerAt + 4 ; submesh 0
*pointerAt\l = 1 : *pointerAt + 4 ; submesh 1
*pointerAt\l = 1 : *pointerAt + 4 ; submesh 1

*MyMesh\Mesh\UnlockAttributeBuffer();
Working on - MP3D Library - PB 5.73 version ready for download
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi,

the Mesh_in_Out.zip is actualized. Please use the new libs (includet theMesh_in_Out.zip file). Demo2 shows more information about a mesh. Now a "level.x" Multitexture directx mesh included. Demo 4 shows how to create a multitexture mesh...

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

Thanks a lot Michael!!
:D
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

Hi, @mpz. First I would like to say, this is an AMAZING job you have done! KUDOS to YOU! :)

Secondly, I would like if you could possibly test and tell me what I'm doing wrong with my Save_B3D() function above.

I KNOW I need to improve it, but I can't do anything until I have more feedback :)

Thanks again, @mpz!

Mythros
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi Mythros,

to make an exporter it is better to have an look to the developer of them, www.blitzbasic.com . Here you find a files descritiona and a sample kit:;
www.blitzbasic.com/sdkspecs/sdkspecs/b3dfile_utils.zip

I think these example is more easier to translate in PB.

Greetings Michael

Code: Select all

  
Function WriteBB3D( f_name$,mesh )

	file=WriteFile( f_name$ )

	b3dSetFile( file )
	
	b3dBeginChunk( "BB3D" )
		b3dWriteInt( 1 )	;version
		
		b3dBeginChunk( "BRUS" )
			b3dWriteInt( 0 )					;0 textures per brush
			b3dWriteString( "Shiny Red" )		;name
			b3dWriteFloat( 1 )					;red
			b3dWriteFloat( 0 )					;green
			b3dWriteFloat( 0 )					;blue
			b3dWriteFloat( 1 )					;alpha
			b3dWriteFloat( .75 )				;shininess
			b3dWriteInt( 1 )					;blend
			b3dWriteInt( 0 )					;FX
		b3dEndChunk()	;end of BRUS chunk
		
		b3dBeginChunk( "NODE" )
			b3dWriteString( "entity_name_here!" )
			b3dWriteFloat( 0 )	;x_pos
			b3dWriteFloat( 0 )	;y_pos
			b3dWriteFloat( 0 )	;y_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
			WriteMESH( mesh )
		b3dEndChunk()	;end of NODE chunk
		
	b3dEndChunk()	;end of BB3D chunk
	
	CloseFile file
End Function

Function WriteMESH( mesh )

	n_surfs=CountSurfaces( mesh )
	
	b3dBeginChunk( "MESH" )
		b3dWriteInt( -1 )				;no 'entity' brush
		
		b3dBeginChunk( "VRTS" )
			b3dWriteInt( 0 )			;flags - 0=no normal/color
			b3dWriteInt( 0 )			;0 tex_coord sets
			b3dWriteInt( 0 )			;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 ) )
				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( 0 )		;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
Working on - MP3D Library - PB 5.73 version ready for download
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hello,

i am ready with 6 demos for import an export of meshs. I will actualize the Mesh_in_Out.zip file a little bit later. The multitexturing export from *.x to b3d is ready, i have translated the WriteBB3D( f_name$,mesh ) function with texture support to mp3d. Now i am working on the multitexturing import of a b3d file...

Greetings
Michael
Working on - MP3D Library - PB 5.73 version ready for download
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

This works for all animated B3D files? :D
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi Mythos,

Question: "This works for all animated B3D files?"

No, i don´t have a b3d animation function im mp3d integrated, but i have written a "Convert_b3d_3ds_x_anim_to_directx_anim.exe" program. This will come into the "Mesh_in_Out.zip" file. With the converted file you can use the directx animation function of mp3d...

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

@mpz: KUDOS TO YOU! =D This would solve SO many problems I'm having with my Anim B3D function.
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hello,

new Mesh_in_Out.zip with 6 Demos and an anim b3d/3ds converter to create and anim directx meshs in my mp3d forum.

32) function changed: MP_EntityGetTexture(mesh[,n]) ; new parameter n, used for multitexturing meshs
33) function changed: MP_LoadMesh(File.s) ; load multitexturing b3d files, light maps are not included for now ( i am working on it)
34) new function added: MP_SaveB3DMesh( File.s,Mesh ) ; saved multitexturing b3d files, light maps are not included for now ( i am working on it)
35) new program will be included: Convert_b3d_3ds_x_anim_to_directx_anim.exe to covert anim meshs to anim directx mp3d meshs (Blitz3d exe file)

MP_LoadMesh(File.s) can load multitexturing b3d files but the function "light maps" are not included for now ( i am working on it)

P.S.: The Blitz3d code is include in the Mesh_in_Out.zip, the filerquester i have made myself, the converter file got from the Blitz3d forum...

Greetings Michael
Last edited by mpz on Fri Nov 22, 2013 8:42 pm, edited 1 time in total.
Working on - MP3D Library - PB 5.73 version ready for download
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

Hi, mpz! OMGOMGOMG! I LOVE this! Although, I would like to know one thing. Can you release the source for the B3D translator program so I can both use it for my B3D program and convert it to PB for other people to use?

I think it would benefit the community greatly!

Thanks again, MPZ

Mythros
User avatar
N_Gnom
User
User
Posts: 76
Joined: Fri Sep 13, 2013 3:20 pm
Location: Germany

Re: MP3D Engine Alpha 32

Post by N_Gnom »

function 33.) can you add in future that we can add several normal/bump maps and so on to every material?
So we should read the several surfaces/materials and add a normal/bump map and so on.

But for now...many thanks.Will test it tomorrow.
Aleks_Longard
User
User
Posts: 64
Joined: Mon Dec 24, 2012 9:07 am
Location: Ukraine

Re: MP3D Engine Alpha 32

Post by Aleks_Longard »

Hi Michael
You will make the team for 3d sound?
And please add the function to get the volume and pan, for example:
mp_soundgetpan ()
mp_soundgetvolume ()

Very thanks for you best library!
Sory my bad english
Post Reply