Skip to content

Commit

Permalink
Started working on #36
Browse files Browse the repository at this point in the history
  • Loading branch information
buu342 committed May 14, 2024
1 parent 07d0f2a commit a9715eb
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions Plugin/io_export_s64_charexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ def setupData(self, object, skeletonList, meshList):
if (m.data.has_custom_normals):
m.data.calc_normals_split()

# Get the mesh's world matrix
mtx = mathutils.Matrix.Identity(4)
if (self.setting_applytransforms):
mtx = m.matrix_world
mtx_norm = mathutils.Matrix.inverted(mathutils.Matrix.transposed(mathutils.Matrix.to_3x3(mtx)))

# Create a copy of the mesh
self.duplicatemodel = m
mcopy = None
Expand Down Expand Up @@ -196,13 +202,19 @@ def setupData(self, object, skeletonList, meshList):

# Create the vertex
vert = S64Vertex()
vert.coor = v.co[:]
if (isNewBlender()):
vert.coor = (mtx @ v.co)[:]
else:
vert.coor = (mtx * v.co)[:]

# Add the vertex normal
#if (mcopy.has_custom_normals):
# vert.norm = mcopy.loops[loop_index].normal[:]
#else:
vert.norm = v.normal[:]
if (isNewBlender()):
vert.norm = (mtx_norm @ v.normal).normalized()[:]
else:
vert.norm = (mtx_norm * v.normal).normalized()[:]

# Try to add the vertex color
try:
Expand Down Expand Up @@ -291,6 +303,10 @@ def setupData(self, object, skeletonList, meshList):
# Go through all skeletons and add the bone's data
for s in skeletonList:

mtx = mathutils.Matrix.Identity(4)
if (self.setting_applytransforms):
mtx = s.matrix_world

# Get the action before we mess with it, and then mess with it
actionbefore = s.animation_data.action
s.animation_data.action = a
Expand Down Expand Up @@ -529,20 +545,22 @@ class ObjectExport(bpy.types.Operator):
bl_options = {'REGISTER', 'UNDO'}
filename_ext = ".S64"

filter_glob = bpy.props.StringProperty(default="*.S64", options={'HIDDEN'}, maxlen=255)
setting_triangulate = bpy.props.BoolProperty(name="Triangulate", description="Triangulate objects.", default=False)
setting_onlyselected = bpy.props.BoolProperty(name="Selected only", description="Export selected objects only.", default=False)
setting_onlyvisible = bpy.props.BoolProperty(name="Visible only", description="Export visible objects only.", default=True)
setting_animfps = bpy.props.FloatProperty(name="Animation FPS", description="By default, Sausage64 assumes animations are 30FPS. Changing this value will scale the animation to match this framerate.", min=0.0, max=1000.0, default=30.0)
setting_scale = bpy.props.FloatProperty(name="Export Scale", description="The size of the exported model", min=0.0, max=1000.0, default=1.0)
setting_upaxis = bpy.props.EnumProperty(name="Up Axis", description="The selected axis points upward", items=(('Z', "Z", "The Z axis points up"), ('Y', "Y", "The Y axis points up")), default='Z')
filepath = bpy.props.StringProperty(subtype='FILE_PATH')
filter_glob = bpy.props.StringProperty(default="*.S64", options={'HIDDEN'}, maxlen=255)
setting_triangulate = bpy.props.BoolProperty(name="Triangulate", description="Triangulate objects.", default=False)
setting_onlyselected = bpy.props.BoolProperty(name="Selected only", description="Export selected objects only.", default=False)
setting_onlyvisible = bpy.props.BoolProperty(name="Visible only", description="Export visible objects only.", default=True)
setting_animfps = bpy.props.FloatProperty(name="Animation FPS", description="By default, Sausage64 assumes animations are 30FPS. Changing this value will scale the animation to match this framerate.", min=0.0, max=1000.0, default=30.0)
setting_scale = bpy.props.FloatProperty(name="Export Scale", description="The size of the exported model", min=0.0, max=1000.0, default=1.0)
setting_applytransforms = bpy.props.BoolProperty(name="Apply transforms ⚠", description="Apply all object transforms (position, rotation, scale) before exporting.\nWARNING! Known to break armatures/animations", default=False)
setting_upaxis = bpy.props.EnumProperty(name="Up Axis", description="The selected axis points upward", items=(('Z', "Z", "The Z axis points up"), ('Y', "Y", "The Y axis points up")), default='Z')
filepath = bpy.props.StringProperty(subtype='FILE_PATH')

# If we are running on Blender 2.9.3 or newer, it will expect the new "annotation"
# syntax on these parameters. In order to make newer versions of blender happy
# we will hack these parameters into the annotation dictionary
if isNewBlender():
__annotations__ = {"filter_glob" : filter_glob,
"setting_applytransforms" : setting_applytransforms,
"setting_triangulate" : setting_triangulate,
"setting_onlyselected" : setting_onlyselected,
"setting_onlyvisible" : setting_onlyvisible,
Expand Down

0 comments on commit a9715eb

Please sign in to comment.