Hi, I'm currently working on a Mesh Editor. I already had a problem with it (yesterday). I'm using a new mesh format (a b3d exporter will come later) and writing it's files with the b3dutils (it's chunk based as .b3d) but when I want to load the saved data, all objects are on 0,0,0! Here is my saving code:
b3dSetFile(WriteFile(save_filename$+".cem"))
b3dBeginChunk("CEM1")
b3dWriteInt(1) ; Version
b3dEndChunk()
For ac_prim = Each primitive
If ac_prim\pr_type = 1 Then b3dBeginChunk("CUBE")
If ac_prim\pr_type = 2 Then b3dBeginChunk("SPHE")
If ac_prim\pr_type = 3 Then b3dBeginChunk("CYLI")
If ac_prim\pr_type = 4 Then b3dBeginChunk("CONE")
b3dWriteFloat(MeshWidth#(ac_prim\entity)) ;Width
b3dWriteFloat(MeshHeight#(ac_prim\entity));Height
b3dWriteFloat(MeshDepth#(ac_prim\entity)) ;Depth
b3dWriteFloat(ac_prim\cred#) ;Red
b3dWriteFloat(ac_prim\cgreen#) ;green
b3dWriteFloat(ac_prim\cblue#) ;Blue
b3dWriteFloat(EntityX#(ac_prim\entity)) ;X
b3dWriteFloat(EntityY#(ac_prim\entity)) ;Y
b3dWriteFloat(EntityZ#(ac_prim\entity)) ;Z
b3dWriteString(ac_prim\texture$) ;texture
b3dWriteString(ac_prim\name$) ;obj name
b3dEndChunk()
Next
CloseFile b3dfile
My (unfinished) loading code:
b3dSetFile(ReadFile(load_filename$+".cem"))
b3dReadChunk()
load_version = b3dReadInt()
If load_version > 1 Then
CloseFile b3d_file
RuntimeError "Invalid CEM version: "+load_version
EndIf
b3dExitChunk()
While Not Eof(b3d_file)
ent_type$ = b3dReadChunk()
ac_prim.primitive = New primitive
If ent_type$ = "CUBE" Then
ac_prim\pr_type = 1
ac_prim\entity = CreateCube()
EndIf
If ent_type$ = "SPHE" Then
ac_prim\pr_type = 2
ac_prim\entity = CreateSphere()
EndIf
If ent_type$ = "CYLI" Then
ac_prim\pr_type = 3
ac_prim\entity = CreateCylinder()
EndIf
If ent_type$ = "CONE" Then
ac_prim\pr_type = 4
ac_prim\entity = CreateCone()
EndIf
If ent_type$ <> "CUBE" And ent_type <> "SPHE" And ent_type <> "CYLI" And ent_type <> "CUBE" Then
CloseFile b3d_file
RuntimeError "Invalid CEM primitive: "+ent_type$
EndIf
ScaleMesh ac_prim\entity,0.5,0.5,0.5
ScaleMesh ac_prim\entity,b3dReadFloat(),b3dReadFloat(),b3dReadFloat()
ac_prim\cred# = b3dReadFloat()
ac_prim\cgreen# = b3dReadFloat()
ac_prim\cblue# = b3dReadFloat()
EntityColor ac_prim\entity,ac_prim\cred#,ac_prim\cgreen#,ac_prim\cblue#
PositionEntity ac_prim\entity,b3dReadFloat(),b3dReadFloat(),b3dReadFloat()
b3dExitChunk()
Wend
CloseFile b3d_file
Type primitive:
Type primitive
Field entity
Field name$
Field pr_type
Field texture$
Field cred#
Field cgreen#
Field cblue#
End Type I'll add more date to primitive later.
|