I got hung up on bugs in the 010 editor scripting system (ceil does not return ceil) so abandoned it and moved right back to my python script.
I took a peek at your code but not too deep yet.
I'm approaching this exactly as I did the flatfile webmap using the unpack function stepwise through the file as necessary bits of info are collected. I like the way python's unpack fucntion works better than php's though. Much more efficient.
This is what I have so far.... (still behind yours by a bit, but taking a different approach - once I get to the same stage yours is at, then a merge of some kind may be in order, but you know how it is with code... )
bl_addon_info= {
"name": "Import StarFleet Command Models",
"author": "Bonk",
"version": (0, 1),
"blender": (2, 5, 5),
"api": 31847,
"location": "File > Import > StarFleet Command Model (.mod)",
"description": "Imports a StarFleet Command model file.",
"warning": "",
"wiki_url": "http://www.dynaverse.net/wiki/index.php?title=Blender:SFC_Models",
"category": "Import/Export"}
import os
import io
import time
import struct
import chunk
import array
import bpy
import mathutils
# print (dir(bpy))
# print (list(bpy.data.objects))
def import_mod(filename,
context):
print (filename)
name, ext= os.path.splitext(os.path.basename(filename))
file= open(filename, 'rb')
# Header
try:
modHdrTag, \
modHdrFileSize, \
modHdrVersion, \
modHdrRadius, \
modHdrTotalLODs, \
modHdrLODHyst \
= struct.unpack("<4siIfif", file.read(24))
print ("modHdrTag: " + modHdrTag.decode("ascii"))
print ("modHdrFileSize: %d" % modHdrFileSize)
print ("modHdrVersion: %d" % modHdrVersion)
print ("modHdrRadius: %f" % modHdrRadius)
print ("modHdrTotalLODs: %d" % modHdrTotalLODs)
print ("modHdrLODHyst: %f " % modHdrLODHyst)
modHdrLODTrans \
= struct.unpack("<%df" % modHdrLODHyst, file.read(int(modHdrLODHyst)*4))
print ("modHdrLODTrans:")
print (modHdrLODTrans)
except:
print("Error parsing file header. Boo!")
file.close()
return
# Strings
modStrTag, \
modStrSize \
= struct.unpack("<4si", file.read(8))
print ("modStrTag: " + modStrTag.decode("ascii"))
print ("modStrSize: %d" % modStrSize)
modStrPool \
= struct.unpack("<%ds" % modStrSize, file.read(modStrSize))
print (modStrPool)
from bpy.props import *
class IMPORT_OT_mod(bpy.types.Operator):
'''Import MOD Operator.'''
bl_idname= "import.mod"
bl_label= "Import MOD"
bl_description= "Import a StarFleet Command model."
bl_options= {'REGISTER', 'UNDO'}
filepath= StringProperty(name="File Path", description="Filepath used for importing the model file", maxlen=1024, default="")
def execute(self, context):
import_mod(self.filepath,
context)
return {'FINISHED'}
def invoke(self, context, event):
wm= context.window_manager
wm.add_fileselect(self)
return {'RUNNING_MODAL'}
def menu_func(self, context):
self.layout.operator(IMPORT_OT_mod.bl_idname, text="StarFleet Command Model (.mod)")
def register():
bpy.types.INFO_MT_file_import.append(menu_func)
def unregister():
bpy.types.INFO_MT_file_import.remove(menu_func)
if __name__ == "__main__":
register()
Hmmm should we go for a
SyntaxHighligter install here? (<- I just used the url button marstone!
)
... anyway, I'm doing like I said, just printing it all to the console - I'm up to the same decision point as with my t hex editor template - how to handle the strings exactly... might just leave them as a byte blob for now and move on then make the decision when I need to use the strings. That makes sense.
Once I have parsed the file reliably into variables and data.. then I'll build a model with it (looking at the lwo scene importer as a starting seed).
Only thing that worries me about my current approach is I'm not sure that the chunk order is consistent in the mod files and I may have to separate each into its own procedure and iterate through them. Again, I find that out once I get there. (unless you know already).