2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 13:44:56 +00:00

Code style improvements

This commit is contained in:
Jack Andersen
2019-09-30 21:23:35 -10:00
parent 0b30fedef5
commit 8a73a8ee48
26 changed files with 719 additions and 833 deletions

View File

@@ -10,6 +10,7 @@ list(APPEND PY_SOURCES
hecl/sact/SACTSubtype.py
hecl/srea/__init__.py
hecl/swld/__init__.py
hecl/armature.py
hecl/mapa.py
hecl/mapu.py
hecl/frme.py

View File

@@ -1,11 +1,11 @@
# Node Grid Arranger Class
NODE_PADDING = 80
FRAME_NAMES = ['Textures','Output']
FRAME_WIDTHS = [400, 180]
FRAME_NAMES = ['Textures','Output','Blend']
FRAME_WIDTHS = [400, 180, 180]
TOTAL_WIDTH = 0.0
for width in FRAME_WIDTHS:
TOTAL_WIDTH += width + NODE_PADDING
FRAME_COLORS = [(0.6,0.48,0.44),(0.53,0.6,0.47)]
FRAME_COLORS = [(0.6,0.48,0.44),(0.53,0.6,0.47),(0.56,0.46,0.90)]
class Nodegrid:
def __init__(self, nodetree, cycles=False):

View File

@@ -9,7 +9,7 @@ bl_info = {
"category": "System"}
# Package import
from . import hmdl, sact, srea, swld, mapa, mapu, frme, path, Nodegrid, Patching
from . import hmdl, sact, srea, swld, armature, mapa, mapu, frme, path, Nodegrid, Patching
Nodegrid = Nodegrid.Nodegrid
parent_armature = sact.SACTSubtype.parent_armature
import bpy, os, sys, struct, math
@@ -20,6 +20,7 @@ hecl_typeS = [
('NONE', "None", "Active scene not using HECL", None),
('MESH', "Mesh", "Active scene represents an HMDL Mesh", hmdl.draw),
('CMESH', "Collision Mesh", "Active scene represents a Collision Mesh", None),
('ARMATURE', "Armature", "Active scene represents an Armature", armature.draw),
('ACTOR', "Actor", "Active scene represents a HECL Actor", sact.draw),
('AREA', "Area", "Active scene represents a HECL Area", srea.draw),
('WORLD', "World", "Active scene represents a HECL World", swld.draw),
@@ -141,9 +142,10 @@ from bpy.app.handlers import persistent
@persistent
def scene_loaded(dummy):
# Hide everything from an external library
for o in bpy.context.scene.objects:
if o.library:
o.hide_set(True)
if bpy.context.scene.hecl_type != 'FRAME':
for o in bpy.context.scene.objects:
if o.library or (o.data and o.data.library):
o.hide_set(True)
# Show PATH library objects as wireframes
if bpy.context.scene.hecl_type == 'PATH':
@@ -208,6 +210,7 @@ def register():
mapa.register()
mapu.register()
path.register()
armature.register()
bpy.utils.register_class(hecl_scene_panel)
bpy.utils.register_class(hecl_light_panel)
bpy.types.Scene.hecl_auto_select = bpy.props.BoolProperty(name='HECL Auto Select', default=True)

View File

@@ -0,0 +1,35 @@
import struct
def cook(writebuf, arm):
writebuf(struct.pack('I', len(arm.bones)))
for bone in arm.bones:
writebuf(struct.pack('I', len(bone.name)))
writebuf(bone.name.encode())
writebuf(struct.pack('fff', bone.head_local[0], bone.head_local[1], bone.head_local[2]))
if bone.parent:
writebuf(struct.pack('i', arm.bones.find(bone.parent.name)))
else:
writebuf(struct.pack('i', -1))
writebuf(struct.pack('I', len(bone.children)))
for child in bone.children:
writebuf(struct.pack('i', arm.bones.find(child.name)))
def draw(layout, context):
layout.prop_search(context.scene, 'hecl_arm_obj', context.scene, 'objects')
if not len(context.scene.hecl_arm_obj):
layout.label(text="Armature not specified", icon='ERROR')
elif context.scene.hecl_arm_obj not in context.scene.objects:
layout.label(text="'"+context.scene.hecl_arm_obj+"' not in scene", icon='ERROR')
else:
obj = context.scene.objects[context.scene.hecl_arm_obj]
if obj.type != 'ARMATURE':
layout.label(text="'"+context.scene.hecl_arm_obj+"' not an 'ARMATURE'", icon='ERROR')
import bpy
def register():
bpy.types.Scene.hecl_arm_obj = bpy.props.StringProperty(
name='HECL Armature Object',
description='Blender Armature Object to export during HECL\'s cook process')

View File

@@ -1,6 +1,12 @@
import struct, bpy, bmesh
from . import HMDLShader, HMDLMesh
BLEND_TYPES = {
'HECLAdditiveOutput': 2,
'HECLBlendOutput': 1,
'HECLOpaqueOutput': 0,
}
def write_out_material(writebuf, mat, mesh_obj):
writebuf(struct.pack('I', len(mat.name)))
writebuf(mat.name.encode())
@@ -20,12 +26,10 @@ def write_out_material(writebuf, mat, mesh_obj):
writebuf(prop[0].encode())
writebuf(struct.pack('i', prop[1]))
blend = 0
if mat.blend_method == 'BLEND':
blend = 1
elif mat.blend_method == 'ADD':
blend = 2
writebuf(struct.pack('I', blend))
blend_node = mat.node_tree.nodes['Blend']
if blend_node.node_tree.name not in BLEND_TYPES:
raise RuntimeError("HMDL *requires* one of the HMDL*Output group nodes for the 'Blend' node")
writebuf(struct.pack('I', BLEND_TYPES[blend_node.node_tree.name]))
# Takes a Blender 'Mesh' object (not the datablock)
# and performs a one-shot conversion process to HMDL
@@ -256,6 +260,7 @@ def draw(layout, context):
obj = context.scene.objects[context.scene.hecl_mesh_obj]
if obj.type != 'MESH':
layout.label(text="'"+context.scene.hecl_mesh_obj+"' not a 'MESH'", icon='ERROR')
layout.prop(obj.data, 'cskr_id')
layout.prop(obj.data, 'hecl_active_material')
layout.prop(obj.data, 'hecl_material_count')
@@ -297,6 +302,7 @@ def register():
bpy.types.Scene.hecl_actor_obj = bpy.props.StringProperty(
name='HECL Actor Object',
description='Blender Empty Object to export during HECL\'s cook process')
bpy.types.Mesh.cskr_id = bpy.props.StringProperty(name='Original CSKR ID')
bpy.types.Mesh.hecl_material_count = bpy.props.IntProperty(name='HECL Material Count', default=0, min=0)
bpy.types.Mesh.hecl_active_material = bpy.props.IntProperty(name='HECL Active Material', default=0, min=0, update=material_update)
bpy.utils.register_class(hecl_mesh_operator)

View File

@@ -52,6 +52,7 @@ def draw(layout, context):
else:
#layout.prop(linked_action, 'hecl_index', text="Index")
#layout.prop(linked_action, 'hecl_anim_props', text="Props")
layout.prop(linked_action, 'anim_id', text="ANIM ID")
layout.prop(linked_action, 'hecl_fps', text="Frame Rate")
row = layout.row()
row.prop(context.scene, 'hecl_auto_remap', text="60-fps Remap")

View File

@@ -1,4 +1,5 @@
from . import SACTSubtype, SACTAction, ANIM
from .. import armature
import bpy
import bpy.path
@@ -207,21 +208,14 @@ def _out_armatures(sact_data, writebuf):
writebuf(struct.pack('I', len(arm.name)))
writebuf(arm.name.encode())
writebuf(struct.pack('I', len(arm.bones)))
for bone in arm.bones:
writebuf(struct.pack('I', len(bone.name)))
writebuf(bone.name.encode())
if arm.library:
arm_path = bpy.path.abspath(arm.library.filepath)
writebuf(struct.pack('I', len(arm_path)))
writebuf(arm_path.encode())
else:
writebuf(struct.pack('I', 0))
writebuf(struct.pack('fff', bone.head_local[0], bone.head_local[1], bone.head_local[2]))
if bone.parent:
writebuf(struct.pack('i', arm.bones.find(bone.parent.name)))
else:
writebuf(struct.pack('i', -1))
writebuf(struct.pack('I', len(bone.children)))
for child in bone.children:
writebuf(struct.pack('i', arm.bones.find(child.name)))
armature.cook(writebuf, arm)
def _out_subtypes(sact_data, writebuf):
writebuf(struct.pack('I', len(sact_data.subtypes)))
@@ -232,9 +226,14 @@ def _out_subtypes(sact_data, writebuf):
mesh = None
if subtype.linked_mesh in bpy.data.objects:
mesh = bpy.data.objects[subtype.linked_mesh]
cskr_id = mesh.data.cskr_id
writebuf(struct.pack('I', len(cskr_id)))
writebuf(cskr_id.encode())
else:
writebuf(struct.pack('I', 0))
if mesh and mesh.library:
mesh_path = bpy.path.abspath(mesh.library.filepath)
if mesh and mesh.data.library:
mesh_path = bpy.path.abspath(mesh.data.library.filepath)
writebuf(struct.pack('I', len(mesh_path)))
writebuf(mesh_path.encode())
else:
@@ -257,9 +256,14 @@ def _out_subtypes(sact_data, writebuf):
mesh = None
if overlay.linked_mesh in bpy.data.objects:
mesh = bpy.data.objects[overlay.linked_mesh]
cskr_id = mesh.data.cskr_id
writebuf(struct.pack('I', len(cskr_id)))
writebuf(cskr_id.encode())
else:
writebuf(struct.pack('I', 0))
if mesh and mesh.library:
mesh_path = bpy.path.abspath(mesh.library.filepath)
if mesh and mesh.data.library:
mesh_path = bpy.path.abspath(mesh.data.library.filepath)
writebuf(struct.pack('I', len(mesh_path)))
writebuf(mesh_path.encode())
else:
@@ -274,9 +278,14 @@ def _out_attachments(sact_data, writebuf):
mesh = None
if attachment.linked_mesh in bpy.data.objects:
mesh = bpy.data.objects[attachment.linked_mesh]
cskr_id = mesh.data.cskr_id
writebuf(struct.pack('I', len(cskr_id)))
writebuf(cskr_id.encode())
else:
writebuf(struct.pack('I', 0))
if mesh and mesh.library:
mesh_path = bpy.path.abspath(mesh.library.filepath)
if mesh and mesh.data.library:
mesh_path = bpy.path.abspath(mesh.data.library.filepath)
writebuf(struct.pack('I', len(mesh_path)))
writebuf(mesh_path.encode())
else:
@@ -302,6 +311,9 @@ def _out_actions(sact_data, writebuf):
bact = None
if action.name in bpy.data.actions:
bact = bpy.data.actions[action.name]
anim_id = bact.anim_id
writebuf(struct.pack('I', len(anim_id)))
writebuf(anim_id.encode())
if not bact:
raise RuntimeError('action %s not found' % action.name)
@@ -334,6 +346,9 @@ def _out_action_no_subtypes(sact_data, writebuf, action_name):
bact = None
if action.name in bpy.data.actions:
bact = bpy.data.actions[action.name]
anim_id = bact.anim_id
writebuf(struct.pack('I', len(anim_id)))
writebuf(anim_id.encode())
if not bact:
raise RuntimeError('action %s not found' % action.name)
@@ -386,14 +401,6 @@ def cook_action_channels_only(writebuf, action_name):
# Output action without AABBs
_out_action_no_subtypes(sact_data, writebuf, action_name)
# Access actor's contained armature names
def get_armature_names(writebuf):
writebuf(struct.pack('I', len(bpy.data.armatures)))
for arm in bpy.data.armatures:
writebuf(struct.pack('I', len(arm.name)))
writebuf(arm.name.encode())
# Access actor's contained subtype names
def get_subtype_names(writebuf):
sact_data = bpy.context.scene.hecl_sact_data
@@ -402,6 +409,10 @@ def get_subtype_names(writebuf):
subtype = sact_data.subtypes[sub_idx]
writebuf(struct.pack('I', len(subtype.name)))
writebuf(subtype.name.encode())
obj = bpy.data.objects[subtype.linked_mesh]
cskr_id = obj.data.cskr_id
writebuf(struct.pack('I', len(cskr_id)))
writebuf(cskr_id.encode())
# Access subtype's contained overlay names
def get_subtype_overlay_names(writebuf, subtypeName):
@@ -413,6 +424,10 @@ def get_subtype_overlay_names(writebuf, subtypeName):
for overlay in subtype.overlays:
writebuf(struct.pack('I', len(overlay.name)))
writebuf(overlay.name.encode())
obj = bpy.data.objects[overlay.linked_mesh]
cskr_id = obj.data.cskr_id
writebuf(struct.pack('I', len(cskr_id)))
writebuf(cskr_id.encode())
return
writebuf(struct.pack('I', 0))
@@ -424,6 +439,10 @@ def get_attachment_names(writebuf):
attachment = sact_data.attachments[att_idx]
writebuf(struct.pack('I', len(attachment.name)))
writebuf(attachment.name.encode())
obj = bpy.data.objects[attachment.linked_mesh]
cskr_id = obj.data.cskr_id
writebuf(struct.pack('I', len(cskr_id)))
writebuf(cskr_id.encode())
# Access actor's contained action names
def get_action_names(writebuf):
@@ -433,6 +452,9 @@ def get_action_names(writebuf):
action = sact_data.actions[action_idx]
writebuf(struct.pack('I', len(action.name)))
writebuf(action.name.encode())
anim_id = bpy.data.actions[action.name].anim_id
writebuf(struct.pack('I', len(anim_id)))
writebuf(anim_id.encode())
# Panel draw
def draw(layout, context):
@@ -452,6 +474,7 @@ def register():
SACTAction.register()
bpy.utils.register_class(SACTData)
bpy.types.Scene.hecl_sact_data = bpy.props.PointerProperty(type=SACTData)
bpy.types.Action.anim_id = bpy.props.StringProperty(name='Original ANIM ID')
bpy.types.Action.hecl_fps = bpy.props.IntProperty(name='HECL Action FPS', default=30)
bpy.types.Action.hecl_additive = bpy.props.BoolProperty(name='HECL Additive Action', default=False)
bpy.types.Action.hecl_looping = bpy.props.BoolProperty(name='HECL Looping Action', default=False)

View File

@@ -55,17 +55,7 @@ class PathHasher:
def hashpath32(self, path):
writepipestr(path.encode())
read_str = readpipestr()
if len(read_str) >= 16:
hash = int(read_str[0:16], 16)
return (hash & 0xffffffff) ^ ((hash >> 32) & 0xffffffff)
return 0
def hashpath64(self, path):
writepipestr(path.encode())
read_str = readpipestr()
if len(read_str) >= 16:
return int(read_str[0:16], 16)
return 0
return int(read_str[0:8], 16)
# Ensure Blender 2.8 is being used
if bpy.app.version < (2, 80, 0):
@@ -226,21 +216,21 @@ def dataout_loop():
elif cmdargs[0] == 'MESHLIST':
meshCount = 0
for meshobj in bpy.data.objects:
if meshobj.type == 'MESH' and not meshobj.library:
if meshobj.type == 'MESH' and not meshobj.data.library:
meshCount += 1
writepipebuf(struct.pack('I', meshCount))
for meshobj in bpy.data.objects:
if meshobj.type == 'MESH' and not meshobj.library:
if meshobj.type == 'MESH' and not meshobj.data.library:
writepipestr(meshobj.name.encode())
elif cmdargs[0] == 'LIGHTLIST':
lightCount = 0
for obj in bpy.context.scene.objects:
if obj.type == 'LIGHT' and not obj.library:
if obj.type == 'LIGHT' and not obj.data.library:
lightCount += 1
writepipebuf(struct.pack('I', lightCount))
for obj in bpy.context.scene.objects:
if obj.type == 'LIGHT' and not obj.library:
if obj.type == 'LIGHT' and not obj.data.library:
writepipestr(obj.name.encode())
elif cmdargs[0] == 'MESHAABB':
@@ -256,6 +246,15 @@ def dataout_loop():
writepipestr(b'OK')
hecl.hmdl.cook(writepipebuf, bpy.data.objects[meshName])
elif cmdargs[0] == 'ARMATURECOMPILE':
armName = bpy.context.scene.hecl_arm_obj
if armName not in bpy.data.objects:
writepipestr(('armature %s not found' % armName).encode())
continue
writepipestr(b'OK')
hecl.armature.cook(writepipebuf, bpy.data.objects[armName].data)
elif cmdargs[0] == 'MESHCOMPILENAME':
meshName = cmdargs[1]
useLuv = int(cmdargs[2])
@@ -281,13 +280,13 @@ def dataout_loop():
writepipestr(b'OK')
colCount = 0
for obj in bpy.context.scene.objects:
if obj.type == 'MESH' and not obj.library:
if obj.type == 'MESH' and not obj.data.library:
colCount += 1
writepipebuf(struct.pack('I', colCount))
for obj in bpy.context.scene.objects:
if obj.type == 'MESH' and not obj.library:
if obj.type == 'MESH' and not obj.data.library:
hecl.hmdl.cookcol(writepipebuf, obj)
elif cmdargs[0] == 'MESHCOMPILEPATH':
@@ -384,10 +383,6 @@ def dataout_loop():
writepipestr(b'OK')
hecl.sact.cook_action_channels_only(writepipebuf, actionName)
elif cmdargs[0] == 'GETARMATURENAMES':
writepipestr(b'OK')
hecl.sact.get_armature_names(writepipebuf)
elif cmdargs[0] == 'GETSUBTYPENAMES':
writepipestr(b'OK')
hecl.sact.get_subtype_names(writepipebuf)