Skip to content

Commit

Permalink
Import all Mario animations button. (#182)
Browse files Browse the repository at this point in the history
* Import all Mario animations button.

Added a button to import all of mario´s animations easily and with naming.

Commented out an uncessary print at readValueIndex that was slowing down animation import times by about 4 times on my machine.

* Requested changes

Fixed formating, swapped segmentData reference for an empty dict as this data is not needed for importing Mario´s animations.

Co-authored-by: Lilaa3 <supergameplaystore@gmail.com>
  • Loading branch information
Lilaa3 and Lilaa3 authored Nov 27, 2022
1 parent 1034b47 commit f7032e2
Show file tree
Hide file tree
Showing 2 changed files with 259 additions and 6 deletions.
52 changes: 46 additions & 6 deletions fast64_internal/sm64/sm64_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
defaultExtendSegment4,
level_enums,
enumLevelNames,
marioAnimations,
)

sm64_anim_types = {"ROTATE", "TRANSLATE"}
Expand Down Expand Up @@ -498,22 +499,22 @@ def getNextBone(boneStack, armatureObj):
return bone, boneStack


def importAnimationToBlender(romfile, startAddress, armatureObj, segmentData, isDMA):
def importAnimationToBlender(romfile, startAddress, armatureObj, segmentData, isDMA, animName):
boneStack = findStartBones(armatureObj)
startBoneName = boneStack[0]
if armatureObj.data.bones[startBoneName].geo_cmd not in animatableBoneTypes:
startBone, boneStack = getNextBone(boneStack, armatureObj)
startBoneName = startBone.name
boneStack = [startBoneName] + boneStack

animationHeader, armatureFrameData = readAnimation("sm64_anim", romfile, startAddress, segmentData, isDMA)
animationHeader, armatureFrameData = readAnimation(animName, romfile, startAddress, segmentData, isDMA)

if len(armatureFrameData) > len(armatureObj.data.bones) + 1:
raise PluginError("More bones in animation than on armature.")

# bpy.context.scene.render.fps = 30
bpy.context.scene.frame_end = animationHeader.frameInterval[1]
anim = bpy.data.actions.new("sm64_anim")
anim = bpy.data.actions.new(animName)

isRootTranslation = True
# boneFrameData = [[x keyframes], [y keyframes], [z keyframes]]
Expand Down Expand Up @@ -691,7 +692,7 @@ def readValueIndex(romfile, startAddress):

# multiply 2 because value is the index in array of shorts (???)
startOffset = int.from_bytes(romfile.read(2), "big") * 2
print(str(hex(startAddress)) + ": " + str(numFrames) + " " + str(startOffset))
#print(str(hex(startAddress)) + ": " + str(numFrames) + " " + str(startOffset))
return SM64_AnimIndex(numFrames, startOffset)


Expand Down Expand Up @@ -950,7 +951,43 @@ def execute(self, context):
if type(armatureObj.data) is not bpy.types.Armature:
raise PluginError("Armature not selected.")

importAnimationToBlender(romfileSrc, animStart, armatureObj, segmentData, context.scene.isDMAImport)
importAnimationToBlender(romfileSrc, animStart, armatureObj, segmentData, context.scene.isDMAImport, "sm64_anim")
romfileSrc.close()
self.report({"INFO"}, "Success!")
except Exception as e:
if romfileSrc is not None:
romfileSrc.close()
raisePluginError(self, e)
return {"CANCELLED"} # must return a set

return {"FINISHED"} # must return a set


class SM64_ImportAllMarioAnims(bpy.types.Operator):
bl_idname = "object.sm64_import_mario_anims"
bl_label = "Import All Mario Animations"
bl_options = {"REGISTER", "UNDO", "PRESET"}

# Called on demand (i.e. button press, menu item)
# Can also be called from operator search menu (Spacebar)
def execute(self, context):
romfileSrc = None
try:
checkExpanded(bpy.path.abspath(context.scene.importRom))
romfileSrc = open(bpy.path.abspath(context.scene.importRom), "rb")
except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"}
try:
if len(context.selected_objects) == 0:
raise PluginError("Armature not selected.")
armatureObj = context.active_object
if type(armatureObj.data) is not bpy.types.Armature:
raise PluginError("Armature not selected.")

for adress, animName in marioAnimations:
importAnimationToBlender(romfileSrc, adress, armatureObj, {}, context.scene.isDMAImport, animName)

romfileSrc.close()
self.report({"INFO"}, "Success!")
except Exception as e:
Expand All @@ -970,7 +1007,9 @@ class SM64_ImportAnimPanel(SM64_Panel):
# called every frame
def draw(self, context):
col = self.layout.column()
propsAnimImport = col.operator(SM64_ImportAnimMario.bl_idname)
propsAnimImport = col.operator(SM64_ImportAnimMario.bl_idname)
propsMarioAnimsImport = col.operator(SM64_ImportAllMarioAnims.bl_idname)

col.prop(context.scene, "isDMAImport")
if not context.scene.isDMAImport:
col.prop(context.scene, "animIsAnimList")
Expand All @@ -985,6 +1024,7 @@ def draw(self, context):
sm64_anim_classes = (
SM64_ExportAnimMario,
SM64_ImportAnimMario,
SM64_ImportAllMarioAnims,
)

sm64_anim_panels = (
Expand Down
213 changes: 213 additions & 0 deletions fast64_internal/sm64/sm64_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1768,3 +1768,216 @@ def __init__(self, geoAddr, level, switchDict):
("macro_yellow_coin", "Yellow Coin", "Yellow Coin"),
("macro_yellow_coin_2", "Yellow Coin 2", "Yellow Coin 2"),
]

marioAnimations = [
# ( Adress, "Animation name" ),
( 5162640, "0 - Climb up ledge (right leg going up)"),
( 5165520, "1 - Thrown from painting"),
( 5165544, "2 - Blown by wind"),
( 5172396, "3 - Dying on ground"),
( 5177044, "4 - Backflip"),
( 5179584, "5 - Climbing up tree movement"),
( 5185656, "6 - In tree"),
( 5186824, "7 - Swinging from tree"),
( 5186848, "8 - Go back into tree"),
( 5191920, "9 - Jump out of tree from hand stand"),
( 5194740, "10 - Hand stand in tree"),
( 5194764, "11 - Go back from hand stand"),
( 5188592, "12 - Hand stand in tree"),
( 5196388, "13 - In tree?"),
( 5197436, "14 - Standing straight with arms out"),
( 5197792, "15 - Skid on ground"),
( 5197816, "16 - Skid on ground, go back to normal"),
( 5199596, "17 - Crouching"),
( 5201048, "18 - Return from long jump"),
( 5202644, "19 - Forward long jump"),
( 5204600, "20 - Backward long jump"),
( 5205980, "21 - Launched from cannon"),
( 5207188, "22 - Walk while holding small object"),
( 5211916, "23 - Run while holding small object?"),
( 5215136, "24 - Walk while holding small object?"),
( 5219864, "25 - Cold, rubbing hands together"),
( 5225496, "26 - Cold (part 2)"),
( 5226920, "27 - Cold (part 3)"),
( 5230056, "28 - Climb on ledge"),
( 5231112, "29 - Waving"),
( 5232768, "30 - Look upward"),
( 5234576, "31 - Look upward then downward"),
( 5235700, "32 - Summon Peach"),
( 5243100, "33 - Lift hand"),
( 5245988, "34 - Take cap off"),
( 5248016, "35 - Walking at end, looking backward to sky"),
( 5256508, "36 - Look backward then run (at end)"),
( 5266160, "37 - Lift hand (slower?)"),
( 5274456, "38 - Fly at end"),
( 5282084, "39 - Peace sign"),
( 5291340, "40 - Get out of sand / snow"),
( 5292628, "41 - Jumping from lava"),
( 5293488, "42 - Flying (wing cap)"),
( 5295016, "43 - Hang onto monkey-bar"),
( 5296876, "44 - Thrown onto ground"),
( 5296900, "45 - Thrown forward"),
( 5302796, "46 - Dying while on stomach"),
( 5306100, "47 - Dying in gas"),
( 5313796, "48 - Coughing in gas"),
( 5319500, "49 - Throw key in air, catch it"),
( 5330436, "50 - Normal death"),
( 5338604, "51 - Hang from ledge"),
( 5341720, "52 - Lift up on ledge quickly"),
( 5343296, "53 - Wobble while on monkey-bars"),
( 5347276, "54 - Put hat on"),
( 5351252, "55 - Putting star under hat"),
( 5358356, "56 - Putting star under hat (part 2)"),
( 5359476, "57 - Head stuck under sand"),
( 5372172, "58 - Sliding on bottom"),
( 5372824, "59 - Triple jump then ground-pound"),
( 5374304, "60 - Ground-pound"),
( 5374328, "61 - Ground-pound part"),
( 5375380, "62 - Bottom stuck in snow / sand"),
( 5387148, "63 - Standing and holding small object"),
( 5390520, "64 - Pick up small object"),
( 5391892, "65 - Jump with small object (wearing wing cap)"),
( 5392704, "66 - Pick up small object"),
( 5393936, "67 - Coming down with small object (wearing wing cap)"),
( 5394296, "68 - Slide then fall with small object"),
( 5395224, "69 - Sliding with small object"),
( 5395248, "70 - Get up from ground with small object"),
( 5396716, "71 - On Koopa shell"),
( 5397832, "72 - Walking (not running)"),
( 5403208, "73 - Side flip?"),
( 5404784, "74 - Jump while riding shell"),
( 5405676, "75 - Landing from double jump"),
( 5407340, "76 - Mid-air part of double jump"),
( 5408288, "77 - Normal jump"),
( 5408312, "78 - Land from normal jump"),
( 5411044, "79 - Kick in mid-air"),
( 5412900, "80 - Double jump"),
( 5413596, "81 - Triple jump?"),
( 5414876, "82 - Throw object"),
( 5416032, "83 - Slide kick"),
( 5418280, "84 - On Koopa shell"),
( 5419872, "85 - Legs stuck under snow / sand"),
( 5431416, "86 - Fall from height"),
( 5431440, "87 - Fall hard from double jump"),
( 5433276, "88 - Picked up by enemy"),
( 5434636, "89 - Pick up large object"),
( 5437964, "90 - Get up after being thrown"),
( 5441520, "91 - Launch into flying position"),
( 5442516, "92 - Move on monkey-bars"),
( 5444052, "93 - Move on monkey-bars (part 2)"),
( 5445472, "94 - Missing cap after getting star"),
( 5457860, "95 - Open door and walk in"),
( 5463196, "96 - Exit door"),
( 5467492, "97 - Open door with key"),
( 5480428, "98 - Unknown, looks like Mario is bowing"),
( 5481448, "99 - Similar to last"),
( 5483352, "100 - Animates both last"),
( 5484876, "101 - Unknown, Mario moves arms"),
( 5486852, "102 - Kick in mid-air and land"),
( 5489076, "103 - Unknown, similar to 04F14C, punch left?"),
( 5489740, "104 - Punch left (part 2)"),
( 5490356, "105 - Punch right"),
( 5491396, "106 - Punch left (part 3)"),
( 5492732, "107 - Pick up small object and stand"),
( 5493948, "108 - Push against something while walking"),
( 5495508, "109 - Jump on Koopa shell (part 2)"),
( 5497072, "110 - Set small object down"),
( 5498484, "111 - Special triple jump"),
( 5498508, "112 - Similar to last, backward"),
( 5498884, "113 - Do a trip and go back to crouching"),
( 5501240, "114 - Running"),
( 5501264, "115 - Running"),
( 5505884, "116 - Get bumped by enemy"),
( 5508004, "117 - Get bumped by enemy (from behind)"),
( 5510172, "118 - Dying in sand"),
( 5515096, "119 - Stuck, looking around"),
( 5517836, "120 - Walking through sand"),
( 5528568, "121 - Dying from shock"),
( 5532480, "122 - Getting shocked"),
( 5533160, "123 - Bump into wall"),
( 5535796, "124 - Fall forward"),
( 5538372, "125 - Holding large object"),
( 5539764, "126 - Against wall"),
( 5544580, "127 - Sidestepping against wall"),
( 5548480, "128 - Sidestepping against wall"),
( 5553004, "129 - Sleepy (part 1)"),
( 5557588, "130 - Sleepy (part 2)"),
( 5563636, "131 - Sleepy (part 3)"),
( 5568648, "132 - Sleepy (part 4)"),
( 5573680, "133 - Sleeping"),
( 5574280, "134 - Lay down"),
( 5577460, "135 - Laying and sleeping"),
( 5579300, "136 - Belly flop"),
( 5579324, "137 - On belly"),
( 5580860, "138 - Get up after bumping into wall"),
( 5584116, "139 - Get up after belly flop, holding small object"),
( 5587364, "140 - Beginning of side kick"),
( 5588288, "141 - Get up from slide kick, go back to crouching"),
( 5589652, "142 - Sliding with hands back"),
( 5589676, "143 - Get up and stand"),
( 5591572, "144 - Go into falling from height position"),
( 5592860, "145 - Slide with hands back animation"),
( 5593404, "146 - Tiptoe"),
( 5599280, "147 - Land from spin jump"),
( 5600160, "148 - Spin jump"),
( 5600516, "149 - Start spin jump"),
( 5601072, "150 - Come up from crouch"),
( 5602028, "151 - Start crouch"),
( 5602720, "152 - Crouching"),
( 5605756, "153 - Crawling"),
( 5613048, "154 - Come up from crawling"),
( 5613968, "155 - In crawling position"),
( 5614876, "156 - Opening door with star"),
( 5620036, "157 - Opening door with star end, walk in"),
( 5622256, "158 - Hit by something (underwater start)"),
( 5626540, "159 - Kick legs while holding object"),
( 5627592, "160 - Holding object"),
( 5628260, "161 - Swimming while holding object"),
( 5629456, "162 - Stop while holding object"),
( 5631180, "163 - Let go of object"),
( 5634048, "164 - Holding object"),
( 5635976, "165 - Drowning"),
( 5641400, "166 - Die, slump over"),
( 5646324, "167 - Die, slump over?"),
( 5649660, "168 - Get hit from behind"),
( 5653848, "169 - Walking (metal Mario)"),
( 5655852, "170 - Single stroke from tapping A"),
( 5657100, "171 - Stop swimming"),
( 5658128, "172 - Strokes from holding A"),
( 5660112, "173 - Stop in water"),
( 5662248, "174 - Grab object"),
( 5663480, "175 - Press B"),
( 5665916, "176 - Jump (metal Mario)"),
( 5666632, "177 - Throw object"),
( 5669328, "178 - Floating"),
( 5671428, "179 - Get star"),
( 5678200, "180 - Get star (part 2) (underwater End)"),
( 5680324, "181 - Grab Bowser's tail"),
( 5680348, "182 - Holding Bowser"),
( 5682008, "183 - Let go of Bowser"),
( 5685264, "184 - Holding Bowser animation"),
( 5686316, "185 - Throw large object"),
( 5688660, "186 - Low energy"),
( 5689924, "187 - Walking with large object"),
( 5694332, "188 - Skid on ground start"),
( 5694356, "189 - Switch direction quickly"),
( 5696160, "190 - Land from side flip?"),
( 5697196, "191 - Side flip"),
( 5699408, "192 - Land from back flip / triple jump"),
( 5702136, "193 - Triple jump"),
( 5704880, "194 - Reading sign"),
( 5710580, "195 - Standing normal (part 1)"),
( 5712800, "196 - Standing normal (part 2)"),
( 5715020, "197 - Standing normal (part 3)"),
( 5717240, "198 - Hanging on monkey-bar"),
( 5719184, "199 - Hanging on monkey-bar, look around"),
( 5722304, "200 - Get up after sleeping (sitting)"),
( 5724228, "201 - Get up after sleeping (laying)"),
( 5726444, "202 - Begin walking"),
( 5728720, "203 - Wall kick/jump from tree"),
( 5728744, "204 - Hang onto pole / tree"),
( 5730404, "205 - Get star"),
( 5735864, "206 - End get star"),
( 5737600, "207 - Triple jump and start flying"),
( 5740584, "208 - Start special triple jump?"),
]

0 comments on commit f7032e2

Please sign in to comment.