metaforce/hecl/blender/addon/__init__.py

106 lines
3.2 KiB
Python
Raw Normal View History

'''
Root HECL addon package for Blender
'''
bl_info = {
"name": "HECL",
"author": "Jack Andersen <jackoalan@gmail.com>",
"version": (1, 0),
"blender": (2, 69),
"tracker_url": "https://github.com/RetroView/hecl/issues/new",
"location": "Properties > Scene > HECL",
"description": "Enables blender to gather meshes, materials, and textures for hecl",
"category": "System"}
# Package import
2015-05-24 22:19:28 +00:00
from . import hmdl, sact
import bpy, os, sys
from bpy.app.handlers import persistent
# Appendable list allowing external addons to register additional resource types
2015-05-24 22:19:28 +00:00
hecl_typeS = [
('NONE', "None", "Active scene not using HECL", None, None),
2015-05-24 22:19:28 +00:00
('MESH', "Mesh", "Active scene represents an HMDL Mesh", hmdl.draw, hmdl.cook),
('ACTOR', "Actor", "Active scene represents a HECL Actor", sact.draw, sact.cook)]
# Main Scene Panel
class hecl_scene_panel(bpy.types.Panel):
bl_idname = "SCENE_PT_hecl"
bl_label = "HECL"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
@classmethod
def poll(cls, context):
return (context.scene is not None)
def draw(self, context):
layout = self.layout
type_row = layout.row(align=True)
2015-05-24 22:19:28 +00:00
type_row.prop_menu_enum(context.scene, 'hecl_type', text='Export Type')
2015-05-24 22:19:28 +00:00
for exp_type in hecl_typeS:
if exp_type[0] == context.scene.hecl_type and callable(exp_type[3]):
exp_type[3](self.layout, context)
break
2015-05-24 22:19:28 +00:00
# Blender-selected polymorphism cook
def do_cook(writebuf, platform_type, endian_char):
for tp in hecl_typeS:
if tp[0] == bpy.context.scene.hecl_type:
if callable(tp[4]):
2015-05-24 22:19:28 +00:00
return tp[4](writefd, platform_type, endian_char)
return False
# Blender export-type registration
def register_export_type_enum():
2015-05-24 22:19:28 +00:00
bpy.types.Scene.hecl_type = bpy.props.EnumProperty(items=
[tp[:3] for tp in hecl_typeS],
name="HECL Export Type",
description="Selects how active scene is exported by HECL")
# Function for external addons to register export types with HECL
def add_export_type(type_tuple):
type_tup = tuple(type_tuple)
2015-05-24 22:19:28 +00:00
for tp in hecl_typeS:
if tp[0] == type_tup[0]:
raise RuntimeError("Type already registered with HECL")
2015-05-24 22:19:28 +00:00
hecl_types.append(type_tup)
register_export_type_enum()
2015-05-24 22:19:28 +00:00
# Shell command receiver (from HECL driver)
def command(cmdline, writepipeline, writepipebuf):
if cmdline[0] == b'COOK':
resource_type = bpy.context.scene.hecl_type.encode()
writepipeline(resource_type)
ackbytes = readpipeline()
if ackbytes != b'ACK':
return
try:
result = do_cook(writepipebuf, cmdline[1].decode(), cmdline[2].decode())
if result == None or result == True:
writepipeline(b'SUCCESS')
else:
writepipeline(b'FAILURE')
except:
writepipeline(b'EXCEPTION')
# Registration
def register():
2015-05-24 22:19:28 +00:00
register_export_type_enum()
hmdl.register()
2015-05-24 22:19:28 +00:00
sact.register()
bpy.utils.register_class(hecl_scene_panel)
def unregister():
hmdl.unregister()
2015-05-24 22:19:28 +00:00
sact.unregister()
bpy.utils.unregister_class(hecl_scene_panel)
if __name__ == "__main__":
register()