DPM Scene (deepMesh 3D file format)

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

DPM Scene (deepMesh 3D file format)

Postby D.J.Peters » Jun 05, 2011 23:21

only usefull for users of deepMesh

"DeepMesh.bi"

Code: Select all

' *.dpm deepMesh 3D scene class
#define DEBUG
#ifdef DEBUG
# define DPRINT(msg) open err for output as #99:print #99,msg:close 99#
#else
# define DPRINT(msg) :
#endif

#macro ReadChunk(n)
  get #hFile,,n##_count
  dprint("read " & #n & " " & n##_count.value & " times")
  if n##_count.value>0 then
    p##n##s=new P##n[n##_count.value]
    for i as integer=0 to n##_count.value-1
      dprint("read " & #n & " [" & i & "]")
      p##n##s[i]=new DPM_##n
      p##n##s[i]->read hFile
    next
  end if
#endmacro

#macro WriteChunk(n)
  put #hFile,,n##_count
  dprint("write " & #n & " " & n##_count.value & " times")
  if n##_count.value>0 then
    for i as integer=0 to n##_count.value-1
      dprint("write " & #n & " [" & i & "]")
      p##n##s[i]->write hFile
    next
  end if
#endmacro

#macro AddChunk(n)
  p##n##s=reallocate(p##n##s,sizeof(p##n) *(n##_count.value+1))
  p##n##s[n##_count.value] = new DPM_##n
  function = p##n##s[n##_count.value]
  n##_count.value+=1
#endmacro

type DPM_FLAG
  declare sub read (hFile as integer)
  declare sub write(hFile as integer)
  enum values
    Disabled
    Enabled
  end enum
  as values value
end type
sub DPM_FLAG.read(hFile as integer)
  get #hFile,,value
  #ifdef DEBUG
  if value=enabled then
    dprint("DPM_FLAG.read   enabled ")
  else
    dprint("DPM_FLAG.read   disabled")
  end if
  #endif
end sub
sub DPM_FLAG.write(hFile as integer)
  #ifdef DEBUG
  if value=enabled then
    dprint("DPM_FLAG.write   enabled ")
  else
    dprint("DPM_FLAG.write   disabled")
  end if
  #endif
  put #hFile,,value
end sub

type DPM_INT
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as integer value
end type
sub DPM_INT.read(hFile as integer)
  get #hFile,,value
  dprint("DPM_INT.read    " & value)
end sub
sub DPM_INT.write(hFile as integer)
  dprint("DPM_INT.write    " & value)
  put #hFile,,value
end sub
type DPM_UINT
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as uinteger value
end type
sub DPM_UINT.read(hFile as integer)
  get #hFile,,value
  dprint("COLOR.read      &H" & hex(value,0))
end sub
sub DPM_UINT.write(hFile as integer)
  dprint("COLOR.write      &H" & hex(value,0))
  put #hFile,,value
end sub
type DPM_FLOAT
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as single value
end type
sub DPM_FLOAT.read(hFile as integer)
  get #hFile,,value
  dprint("DPM_FLOAT.read  " & value)
end sub
sub DPM_FLOAT.write(hFile as integer)
  dprint("DPM_FLOAT.write  " & value)
  put #hFile,,value
end sub

type DPM_STRING
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  declare sub set(strValue as string)
  as integer     nChars
  as zstring ptr pChars
end type
sub DPM_STRING.read(hFile as integer)
  get #hFile,,nChars
  pChars = callocate(nChars+1)
  if nChars>0 then
    get #hFile,,*cptr(ubyte ptr,pChars),nChars
  dprint("DPM_STRING.read " & *pChars)
  end if
end sub
sub DPM_STRING.write(hFile as integer)
  put #hFile,,nChars
  if nChars>0 then
    dprint("DPM_STRING.write " & *pChars)
    put #hFile,,*cptr(ubyte ptr,pChars),nChars
  end if
end sub
sub DPM_STRING.set(strValue as string)
  if pChars<>0 then deallocate pChars
  nChars=len(strValue)
  pChars=callocate(nChars+1)
  if nChars>0 then
    for i as integer=0 to nChars-1
      pChars[i]=strValue[i]
    next
  end if
end sub
 
type DPM_FLOAT2
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as DPM_FLOAT u,v
end type
sub DPM_FLOAT2.read(hFile as integer)
  dprint("FLOAT2.read uv  ")
  u.read hFile
  v.read hFile
end sub
sub DPM_FLOAT2.write(hFile as integer)
  dprint("FLOAT2.write uv  ")
  u.write hFile
  v.write hFile
end sub

type DPM_FLOAT3
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as DPM_FLOAT x,y,z
end type
sub DPM_FLOAT3.read(hFile as integer)
  dprint("FLOAT3.read xyz ")
  x.read hFile
  y.read hFile
  z.read hFile
end sub
sub DPM_FLOAT3.write(hFile as integer)
  dprint("FLOAT3.write xyz ")
  x.write hFile
  y.write hFile
  z.write hFile
end sub

type DPM_TEXTURE
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as DPM_STRING tex_filename       ' Texture filename
  as DPM_INT    tex_wrap           ' Irrlicht enum EMF_TEXTURE_WRAP
end type
type  PTEXTURE as DPM_TEXTURE ptr
type PPTEXTURE as PTEXTURE ptr
sub DPM_TEXTURE.read(hFile as integer)
  dprint("DPM_TEXTURE.read")
  tex_filename.read hFile
  tex_wrap.read     hFile
end sub
sub DPM_TEXTURE.write(hFile as integer)
  dprint("DPM_TEXTURE.write")
  tex_filename.write hFile
  tex_wrap.write     hFile
end sub

type DPM_MATERIAL
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as DPM_INT   material_index
  as DPM_INT   material_type        ' Irrlicht enum E_MATERIAL_TYPE
  as DPM_FLAG  flag_wireframe       ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_pointcloud      ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_gouraud         ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_lighting        ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_zbuffer         ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_zwrite          ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_backface_cull   ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_frontface_cull  ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_bilinear        ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_trilinear       ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_anisotropic     ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_fog             ' 0=Disable, 1=Enable
  as DPM_FLAG  flag_normalize       ' 0=Disable, 1=Enable
  as DPM_INT   texwrap              ' Irrlicht enum E_TEXTURE_CLAMP
  as DPM_FLAG  flag_antialias       ' 0=Disable, 1=Enable
  as DPM_INT   colormask            ' Colormask bits
  as DPM_INT   colormaterial        ' Irrlicht enum E_COLOR_MATERIAL
  as DPM_UINT  color_ambient        ' ARGB Hexadecimal
  as DPM_UINT  color_diffuse        ' ARGB Hexadecimal
  as DPM_UINT  color_emissive       ' ARGB Hexadecimal
  as DPM_UINT  color_specular       ' ARGB Hexadecimal
  as DPM_FLOAT shininess            ' 0.0 - 128.0
  as DPM_FLOAT thickness            ' Line thickness
  as DPM_TEXTURE Textures(3)
end type
type  PMATERIAL as DPM_MATERIAL ptr
type PPMATERIAL as PMATERIAL ptr
sub DPM_MATERIAL.read(hFile as integer)
  dprint("DPM_MATERIAL.read")
  dprint("index")
  material_index.read      hFile
  dprint("type")
  material_type.read       hFile
  dprint("wireframe")
  flag_wireframe.read      hFile
  dprint("pointcloud")
  flag_pointcloud.read     hFile
  dprint("gouraud")
  flag_gouraud.read        hFile
  dprint("lighting")
  flag_lighting.read       hFile
  dprint("zbuffer")
  flag_zbuffer.read        hFile
  dprint("zwrite")
  flag_zwrite.read         hFile
  dprint("backface")
  flag_backface_cull.read  hFile
  dprint("frontface")
  flag_frontface_cull.read hFile
  dprint("bilinear")
  flag_bilinear.read       hFile
  dprint("trilinear")
  flag_trilinear.read      hFile
  dprint("anisotropic")
  flag_anisotropic.read    hFile
  dprint("fog")
  flag_fog.read            hFile
  dprint("normalize")
  flag_normalize.read      hFile
  dprint("texwrap")
  texwrap.read             hFile
  dprint("antialias")
  flag_antialias.read      hFile
  dprint("colormask")
  colormask.read           hFile
  dprint("colormaterial")
  colormaterial.read       hFile
  dprint("ambient")
  color_ambient.read       hFile
  dprint("diffuse")
  color_diffuse.read       hFile
  dprint("emissive")
  color_emissive.read      hFile
  dprint("specular")
  color_specular.read      hFile
  dprint("shininess")
  shininess.read           hFile
  dprint("thickness")
  thickness.read           hFile
  for i as integer=0 to 3
    Textures(i).read       hFile
  next
end sub
sub DPM_MATERIAL.write(hFile as integer)
  dprint("DPM_MATERIAL.write")
  dprint("index")
  material_index.write      hFile
  dprint("type")
  material_type.write       hFile
  dprint("wireframe")
  flag_wireframe.write      hFile
  dprint("pointcloud")
  flag_pointcloud.write     hFile
  dprint("gouraud")
  flag_gouraud.write        hFile
  dprint("lighting")
  flag_lighting.write       hFile
  dprint("zbuffer")
  flag_zbuffer.write        hFile
  dprint("zwrite")
  flag_zwrite.write         hFile
  dprint("backface_cull")
  flag_backface_cull.write  hFile
  dprint("frontface_cull")
  flag_frontface_cull.write hFile
  dprint("bilinear")
  flag_bilinear.write       hFile
  dprint("trilinear")
  flag_trilinear.write      hFile
  dprint("anisotropic")
  flag_anisotropic.write    hFile
  dprint("fog")
  flag_fog.write            hFile
  dprint("normalize")
  flag_normalize.write      hFile
  dprint("texwrap")
  texwrap.write             hFile
  dprint("antialias")
  flag_antialias.write      hFile
  dprint("colormask")
  colormask.write           hFile
  dprint("colormaterial")
  colormaterial.write       hFile
  dprint("ambient")
  color_ambient.write       hFile
  dprint("diffuse")
  color_diffuse.write       hFile
  dprint("emissive")
  color_emissive.write      hFile
  dprint("color_specular")
  color_specular.write      hFile
  dprint("shininess")
  shininess.write           hFile
  dprint("thickness")
  thickness.write           hFile
  for i as integer=0 to 3
    Textures(i).write       hFile
  next
end sub

type DPM_VERTEX
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  declare sub set(px as single,py as single,pz as single, _
                  nx as single=0,ny as single=1,nz as single=0, _
                  u0 as single=0,v0 as single=0, _
                  u1 as single=0,v1 as single=0, _
                  color as uinteger=&HFFFFFFFF)
  as DPM_FLOAT3 position           ' x,y,z vertex position
  as DPM_FLOAT3 normal             ' x,y,z vertex normal
  as DPM_FLOAT2 UV0                ' u,v texture coord set 0
  as DPM_FLOAT2 UV1                ' u,v texture coord set 1
  as DPM_UINT   color              ' ARGB Hexadecimal vertex color
end type
type  PVERTEX as DPM_VERTEX ptr
type PPVERTEX as PVERTEX ptr
sub DPM_VERTEX.read(hFile as integer)
  position.read hFile
  normal.read   hFile
  uv0.read      hFile
  uv1.read      hFile
  color.read    hFile
end sub
sub DPM_VERTEX.write(hFile as integer)
  position.write hFile
  normal.write   hFile
  uv0.write      hFile
  uv1.write      hFile
  color.write    hFile
end sub
sub DPM_VERTEX.set(px as single,py as single,pz as single, _
                   nx as single,ny as single,nz as single, _
                   u0 as single,v0 as single, _
                   u1 as single,v1 as single, _
                   color as uinteger)
  position.x.value=px
  position.y.value=py
  position.z.value=pz
  normal.x.value=nx
  normal.y.value=ny
  normal.z.value=nz
  uv0.u.value=u0
  uv0.v.value=v0
  uv1.u.value=u1
  uv1.v.value=v1
  this.color.value=color
end sub


type DPM_TRIANGLE
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as DPM_INT tv0                   ' Triangle vertex 0
  as DPM_INT tv1                   ' Triangle vertex 1
  as DPM_INT tv2                   ' Triangle vertex 2
end type
type  PTRIANGLE as DPM_TRIANGLE ptr
type PPTRIANGLE as PTRIANGLE ptr
sub DPM_TRIANGLE.read(hFile as integer)
  tv0.read hFile
  tv1.read hFile
  tv2.read hFile
end sub
sub DPM_TRIANGLE.write(hFile as integer)
  tv0.write hFile
  tv1.write hFile
  tv2.write hFile
end sub
type DPM_MESHBUFFER
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  declare function AddVertex( _
  px as single,py as single,pz as single, _
  nx as single=0,ny as single=1,nz as single=0, _
  u0 as single=0,v0 as single=0, _
  u1 as single=0,v1 as single=0, colour as uinteger=&HFF000000) as PVERTEX
  declare function AddTriangle(v0 as integer=0, _
                               v1 as integer=0, _
                               v2 as integer=0) as PTRIANGLE
  as DPM_INT     material_index    ' Material applied to this buffer
  as DPM_INT     vertex_count      ' Number of vertices to read
  as PPVERTEX    pVertexs
  as DPM_INT     triangle_count    ' Number of triangles to read
  as PPTRIANGLE  pTriangles
end type
type PMESHBUFFER as DPM_MESHBUFFER ptr
type PPMESHBUFFER as PMESHBUFFER ptr
sub DPM_MESHBUFFER.read(hFile as integer)
  dprint("material_index")
  material_index.read hFile
  ReadChunk(vertex)
  ReadChunk(triangle)
end sub
sub DPM_MESHBUFFER.write(hFile as integer)
  dprint("material_index")
  material_index.write hFile
  WriteChunk(vertex)
  WriteChunk(triangle)
end sub
function DPM_MESHBUFFER.AddVertex( _
  px as single,py as single,pz as single, _
  nx as single,ny as single,nz as single, _
  u0 as single,v0 as single, _
  u1 as single,v1 as single, colour as uinteger) as PVERTEX
  AddChunk(Vertex)
  pVertexs[vertex_count.value-1]->set( _
  px,py,pz,nx,ny,nz,u0,v0,u1,v1,colour)
end function
function DPM_MESHBUFFER.AddTriangle(v0 as integer, _
                                    v1 as integer, _
                                    v2 as integer) as PTRIANGLE
  AddChunk(Triangle)
  with *pTriangles[triangle_count.value-1]
    .tv0.value=v0
    .tv1.value=v1
    .tv2.value=v2
  end with
end function

type DPM_MESH
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  declare function AddMeshbuffer(byval meshname as string="") as PMESHBUFFER
  as DPM_STRING  mesh_name         ' Name of mesh
  as DPM_STRING  mesh_parent       ' Name of parent
  as DPM_FLOAT3  Position          ' x,y,z in local space
  as DPM_FLOAT3  Rotation          ' pitch,yaw,roll in local degrees
  as DPM_INT     meshbuffer_count      ' Number of meshbuffers to read
  as PPMESHBUFFER pMeshBuffers
end type
type PMESH as DPM_MESH ptr
type PPMESH as PMESH ptr
sub DPM_MESH.read(hFile as integer)
  mesh_name.read   hFile
  mesh_parent.read hFile
  position.read    hFile
  rotation.read    hFile
  ReadChunk(meshbuffer)
end sub
sub DPM_MESH.write(hFile as integer)
  mesh_name.write   hFile
  mesh_parent.write hFile
  position.write    hFile
  rotation.write    hFile
  WriteChunk(meshbuffer)
end sub
function DPM_MESH.AddMeshbuffer(byval meshname as string) as PMESHBUFFER
  AddChunk(Meshbuffer)

end function

type DPM_BONE
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as DPM_STRING  bone_name         ' Name of bone
  as DPM_STRING  bone_parent       ' Name of parent bone
  as DPM_FLOAT3  position          ' x,y,z in local space
  as DPM_FLOAT3  rotation          ' pitch,yaw,roll in local degrees
end type
type  PBONE as DPM_BONE ptr
type PPBONE as PBONE ptr
sub DPM_BONE.read(hFile as integer)
  bone_name.read   hFile
  bone_parent.read hFile
  position.read    hFile
  rotation.read    hFile
end sub
sub DPM_BONE.write(hFile as integer)
  bone_name.write   hFile
  bone_parent.write hFile
  position.write    hFile
  rotation.write    hFile
end sub
type DPM_WEIGHT
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as DPM_STRING  bone_name         ' Name of bone
  as DPM_STRING  mesh_name         ' Name of mesh
  as DPM_INT     meshbuffer        ' Meshbuffer index
  as DPM_INT     vertex            ' Vertex index
  as DPM_FLOAT   weight            ' Weight (0.0 - 1.0)
  as DPM_FLOAT3  position          ' x,y,z Transformed vertex position
end type
type  PWEIGHT as DPM_WEIGHT ptr
type PPWEIGHT as PWEIGHT ptr
sub DPM_WEIGHT.read(hFile as integer)
  bone_name.read  hFile
  mesh_name.read  hFile
  meshbuffer.read hFile
  vertex.read     hFile
  weight.read     hFile
  position.read   hFile
end sub
sub DPM_WEIGHT.write(hFile as integer)
  bone_name.write  hFile
  mesh_name.write  hFile
  meshbuffer.write hFile
  vertex.write     hFile
  weight.write     hFile
  position.write   hFile
end sub
type DPM_KEYFRAME
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as DPM_STRING  limb_name         ' Name of bone or mesh
  as DPM_INT     frame             ' Keyframe index
  as DPM_FLOAT3  position          ' x,y,z in local space
  as DPM_FLOAT3  rotation          ' pitch,yaw,roll in local degrees
end type
type  PKEYFRAME as DPM_KEYFRAME ptr
type PPKEYFRAME as PKEYFRAME ptr
sub DPM_KEYFRAME.read(hFile as integer)
  limb_name.read hFile
  frame.read     hFile
  position.read  hFile
  rotation.read  hFile
end sub
sub DPM_KEYFRAME.write(hFile as integer)
  limb_name.write hFile
  frame.write     hFile
  position.write  hFile
  rotation.write  hFile
end sub
type DPM_LIGHT
  declare sub read(hFile as integer)
  declare sub write(hFile as integer)
  as DPM_STRING  light_name        ' Name of light
  as DPM_INT     light_type        ' (0=point, 1=spot, 2=directional)
  as DPM_UINT    color             ' RGB Hexadecimal color
  as DPM_FLOAT   range             ' Light radius/range
  as DPM_FLOAT   inner_cone        ' Inner cone-angle
  as DPM_FLOAT   outer_cone        ' Outer cone-angle
  as DPM_FLOAT   atten_const       ' Constant attenuation factor
  as DPM_FLOAT   atten_linear      ' Linear attenuation factor
  as DPM_FLOAT   atten_quad        ' Quadratic attenuation factor
  as DPM_FLOAT   falloff           ' attenuation falloff
  as DPM_FLOAT3  position          ' x,y,z in global space
  as DPM_FLOAT3  rotation          ' pitch,yaw,roll in degrees
end type
type  PLIGHT as DPM_LIGHT ptr
type PPLIGHT as PLIGHT ptr
sub DPM_LIGHT.read(hFile as integer)
  light_name.read   hFile
  light_type.read   hFile
  color.read        hFile
  range.read        hFile
  inner_cone.read   hFile
  outer_cone.read   hFile
  atten_const.read  hFile
  atten_linear.read hFile
  atten_quad.read   hFile
  falloff.read      hFile
  position.read     hFile
  rotation.read     hFile
end sub
sub DPM_LIGHT.write(hFile as integer)
  light_name.write   hFile
  light_type.write   hFile
  color.write        hFile
  range.write        hFile
  inner_cone.write   hFile
  outer_cone.write   hFile
  atten_const.write  hFile
  atten_linear.write hFile
  atten_quad.write   hFile
  falloff.write      hFile
  position.write     hFile
  rotation.write     hFile
end sub
type DPM_SCENE
  declare function Load(FileName as string) as integer
  declare function Save(FileName as string) as integer
  declare function AddMaterial as PMATERIAL
  declare function AddMesh(meshname as string="") as PMESH
  declare function AddBone     as PBONE
  declare function AddWeight   as PWEIGHT
  declare function AddKeyframe as PKEYFRAME
  declare function AddLight    as PLIGHT
 
  as DPM_STRING formatID           ' "IDM100"
  as DPM_STRING editorID           ' Name of editor, e.g: "deepMesh v1.0"
  as DPM_INT    material_count     ' Number of materials to read
  as PPMATERIAL pMaterials
  as DPM_INT    mesh_count         ' Number of meshes to read
  as PPMESH     pMeshs
  as DPM_INT    bone_count         ' Number of bones to read
  as PPBONE     pBones
  as DPM_INT    weight_count       ' Number of weights to read
  as PPWEIGHT   pWeights
  as DPM_INT    keyframe_count     ' Number of keyframes to read
  as PPKEYFRAME pKeyFrames
  as DPM_UINT   ambient_light      ' RGB Hexadecimal color
  as DPM_INT    light_count        ' Number of lights to read
  as PPLIGHT    pLights
end type

function DPM_SCENE.AddMaterial as PMATERIAL
  AddChunk(Material)
  ' set default values
  dim as PMATERIAL pMat = pMaterials[material_count.value-1]
  with *pMat
  .material_index.value  = material_count.value-1
  .material_type.value  = 0
  .flag_wireframe.value      = 0
  .flag_pointcloud.value     = 0
  .flag_gouraud.value        = 1
  .flag_lighting.value       = 1
  .flag_zbuffer.value        = 1
  .flag_zwrite.value         = 1
  .flag_backface_cull.value  = 1
  .flag_frontface_cull.value = 0
  .flag_bilinear.value       = 1
  .flag_trilinear.value      = 0
  .flag_anisotropic.value    = 0
  .flag_fog.value            = 1
  .flag_normalize.value      = 1
  .texwrap.value             = 0
  .flag_antialias.value      = 1
  .colormask.value           = 1
  .colormaterial.value       = 0
  .color_ambient.value       = &HFFFFFFFF
  .color_diffuse.value       = &HFFFFFFFF
  .color_emissive.value      = &HFF000000
  .color_specular.value      = &HFFFFFFFF
  .shininess.value           = 0.0
  .thickness.value           = 1.0
  end with
end function
function DPM_SCENE.AddMesh(meshname as string) as PMESH
  AddChunk(Mesh)
  if meshname="" then meshname = "mesh" & trim(str(mesh_count.value-1))
  pMeshs[mesh_count.value-1]->mesh_name.set(meshname)
end function
function DPM_SCENE.AddBone as PBONE
  AddChunk(Bone)
end function
function DPM_SCENE.AddWeight as PWEIGHT
  AddChunk(Weight)
end function
function DPM_SCENE.AddKeyframe as PKEYFRAME
  AddChunk(Keyframe)
end function
function DPM_SCENE.AddLight as PLIGHT
  AddChunk(Light)
end function

function DPM_SCENE.Load(FileName as string) as integer
  dim as integer hFile = FreeFile()
  if open(FileName,for binary,access read,as #hFile) then
    return 0
  end if
  formatID.read hFile
  if *formatID.pChars<>"IDM100" then
    close #hFile
    return 0
  end if

  editorID.read hFile

  ReadChunk(material)
  ReadChunk(mesh)
  ReadChunk(bone)
  ReadChunk(weight)
  ReadChunk(keyframe)
  dprint("ambient_light")
  ambient_light.read hFile
  ReadChunk(light)

  close #hfile
  return -1
end function

function DPM_SCENE.Save(FileName as string) as integer
  dim as integer hFile = FreeFile()
  if open(FileName,for binary,access write,as #hFile) then
    return 0
  end if
 
  if formatID.pChars=0 then
    formatID.Set("IDM100")
  end if
  formatID.write hFile
 
  if editorID.pChars=0 then
    editorID.Set("Innesoft deepMesh DEMO v1.2 (140511)")
  end if
  editorID.write hFile

  WriteChunk(material)
  WriteChunk(mesh)
  WriteChunk(bone)
  WriteChunk(weight)
  WriteChunk(keyframe)
  ambient_light.write hFile
  WriteChunk(light)

  close #hFile
  return -1
end function

create and load a DPM_SCENE

Code: Select all

#include "DeepMesh.bi"

'
' main
'
dim as DPM_SCENE Scene

chdir exepath

if not Scene.Load("box01.dpm") then
  print "error: load dpm file !"
  beep:sleep:end
end if
sleep

create and save a DPM_SCENE

Code: Select all

#include "DeepMesh.bi"

'
' main
'
dim as DPM_SCENE Scene

Scene.AddMaterial()

var Mesh = Scene.AddMesh("mesh01")

var Meshbuffer = Mesh->AddMeshbuffer()
Meshbuffer->AddVertex(-1, 1, 0,  0,0,1)
Meshbuffer->AddVertex( 1, 1, 0,  0,0,1)
Meshbuffer->AddVertex( 1,-1, 0,  0,0,1)
Meshbuffer->AddVertex(-1,-1, 0,  0,0,1)

Meshbuffer->AddTriangle(0,1,2)
Meshbuffer->AddTriangle(0,2,3)

if not Scene.Save("tri01.dpm") then
  print "error: save dpm file !"
  beep:sleep:end
end if
sleep
Last edited by D.J.Peters on Jun 07, 2011 0:40, edited 6 times in total.
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Postby kiyotewolf » Jun 06, 2011 7:17

How about converting TO a *.DPM format and then using your loader?



:M
D.J.Peters
Posts: 7852
Joined: May 28, 2005 3:28

Postby D.J.Peters » Jun 07, 2011 0:52

kiyotewolf wrote:How about converting TO a *.DPM format and then using your loader?
you can import some formats in deepmesh

deepMesh (.dpm), Sequence (.seq), Irrlicht Mesh (.irrmesh)
3DStudio (.3ds), Direct3D9 (.x), Blitz3D (.b3d)
Collada (.dae), Cartography Shop (.csm), DeleD (.dmf)
Wavefront (.obj), Milkshape (.ms3d), My3D (.my3d)
OCT (.oct), Ogre3D (.mesh), Pulsar LMTools (.lmts)
Quake3 Map (.bsp), Quake2 Model (.md2), Doom3 Model (.md5)
Stanford Triangle (.ply), Stereolithography (.stl), Studiomdl Data (.smd)
Gelo2009 (.a3d)

Or do you mean create a *.dpm file from your own raw 3d format ?
in this case it works now

Joshy
own 3d model to the deepmesh scene format *.dpm

Code: Select all

#include "DeepMesh.bi"
dim as DPM_SCENE Scene

Scene.AddMaterial()

var Mesh = Scene.AddMesh("mesh01")

var Meshbuffer = Mesh->AddMeshbuffer()
Meshbuffer->AddVertex(-1, 1, 0,  0,0,1)
Meshbuffer->AddVertex( 1, 1, 0,  0,0,1)
Meshbuffer->AddVertex( 1,-1, 0,  0,0,1)
Meshbuffer->AddVertex(-1,-1, 0,  0,0,1)

Meshbuffer->AddTriangle(0,1,2)
Meshbuffer->AddTriangle(0,2,3)

if not Scene.Save("tri02.dpm") then
  print "error: save dpm file !"
  beep:sleep:end
end if
sleep

Return to “Tips and Tricks”

Who is online

Users browsing this forum: MSN [Bot] and 1 guest