Jump to content

Bin Exporter


anamous

Recommended Posts

As a way of exporting arbitary animated meshes to Maya/Max etc., I think that the realflow mesh BIN format isn't bad. However, I'm stuck on getting a simple python SOP to export it. Could be something obviously wrong.

this is the format description

(Begin of file)
[unsigned int]                      ; ID code = 0xDADADADA
[unsigned int]                      ; version = 4
[unsigned int]                      ; geometry chunk code = 0xCCCCCCCC (*)
[int]                               ; number of vertices
      loop for [number of vertices]
        [float]                     ; X coordinate
        [float]                     ; Y coordinate
        [float]                     ; Z coordinate
      endloop
[int]                               ; number of faces
      loop for [number of faces]
        [int]                       ; vertex index
        [int]                       ; vertex index
        [int]                       ; vertex index
      endloop

[unsigned int] ; code = 0xDEDEDEDE (end of file mark)
(End of file)

Here's my quick and dirty shot at an exporter:

# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()

formatID  = 0xDADADADA
formatVer = 4
formatGeo = 0xCCCCCCCC
formatEnd = 0xDEDEDEDE

import struct
from math import floor

filename = hou.Node.evalParm(hou.pwd(), "binFile")

f = open(filename, 'wb')

f.write(struct.pack('I',formatID))
f.write(struct.pack('I',formatVer))
f.write(struct.pack('I',formatGeo))

np = len(geo.points())

f.write(struct.pack('I',np))

# write vertices

for fac in geo.prims():
    verts = fac.vertices()
    for vert in verts:
        pt = vert.point()
        f.write(struct.pack('f',pt.position()[0]))
        f.write(struct.pack('f',pt.position()[1]))
        f.write(struct.pack('f',pt.position()[2]))

nf = len(geo.prims())

f.write(struct.pack('I',nf))

# write faces

for fac in geo.prims():
    vrts = fac.vertices()
    f.write(struct.pack('i',vrts[0].number()))
    f.write(struct.pack('i',vrts[1].number()))
    f.write(struct.pack('i',vrts[2].number()))

f.write(struct.pack('I',formatEnd))
f.close()

It's writing a file alright, but it doesn't seem to be a correct file.. Any ideas? And yes, it expects triangles as input geometry.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...