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