forked from Fast-64/fast64
-
Notifications
You must be signed in to change notification settings - Fork 6
/
__init__.py
498 lines (409 loc) · 17.7 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
import bpy
from bpy.utils import register_class, unregister_class
from bpy.path import abspath
from . import addon_updater_ops
from .fast64_internal.utility import prop_split, multilineLabel, draw_and_check_tab
from .fast64_internal.repo_settings import (
draw_repo_settings,
load_repo_settings,
repo_settings_operators_register,
repo_settings_operators_unregister,
)
from .fast64_internal.sm64 import sm64_register, sm64_unregister
from .fast64_internal.sm64.sm64_constants import sm64_world_defaults
from .fast64_internal.sm64.settings.properties import SM64_Properties
from .fast64_internal.sm64.sm64_geolayout_bone import SM64_BoneProperties
from .fast64_internal.sm64.sm64_objects import SM64_ObjectProperties
from .fast64_internal.oot import OOT_Properties, oot_register, oot_unregister
from .fast64_internal.oot.oot_constants import oot_world_defaults
from .fast64_internal.oot.props_panel_main import OOT_ObjectProperties
from .fast64_internal.utility_anim import utility_anim_register, utility_anim_unregister, ArmatureApplyWithMeshOperator
from .fast64_internal.mk64 import MK64_Properties, mk64_register, mk64_unregister
from .fast64_internal.f3d.f3d_material import (
F3D_MAT_CUR_VERSION,
mat_register,
mat_unregister,
check_or_ask_color_management,
)
from .fast64_internal.f3d.f3d_render_engine import render_engine_register, render_engine_unregister
from .fast64_internal.f3d.f3d_writer import f3d_writer_register, f3d_writer_unregister
from .fast64_internal.f3d.f3d_parser import f3d_parser_register, f3d_parser_unregister
from .fast64_internal.f3d.flipbook import flipbook_register, flipbook_unregister
from .fast64_internal.f3d.op_largetexture import op_largetexture_register, op_largetexture_unregister, ui_oplargetexture
from .fast64_internal.f3d_material_converter import (
MatUpdateConvert,
upgrade_f3d_version_all_meshes,
bsdf_conv_register,
bsdf_conv_unregister,
bsdf_conv_panel_regsiter,
bsdf_conv_panel_unregsiter,
)
from .fast64_internal.render_settings import (
Fast64RenderSettings_Properties,
ManualUpdatePreviewOperator,
resync_scene_props,
on_update_render_settings,
)
# info about add on
bl_info = {
"name": "Fast64 (SoH)",
"version": (2, 3, 0),
"author": "kurethedead",
"location": "3DView",
"description": "Plugin for exporting F3D display lists and other game data related to Nintendo 64 games.",
"category": "Import-Export",
"blender": (3, 2, 0),
}
gameEditorEnum = (
("SM64", "SM64", "Super Mario 64", 0),
("OOT", "OOT", "Ocarina Of Time", 1),
("MK64", "MK64", "Mario Kart 64", 3),
("Homebrew", "Homebrew", "Homebrew", 2),
)
class F3D_GlobalSettingsPanel(bpy.types.Panel):
bl_idname = "F3D_PT_global_settings"
bl_label = "F3D Global Settings"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Fast64"
@classmethod
def poll(cls, context):
return True
# called every frame
def draw(self, context):
col = self.layout.column()
col.scale_y = 1.1 # extra padding
prop_split(col, context.scene, "f3d_type", "F3D Microcode")
col.prop(context.scene, "saveTextures")
col.prop(context.scene, "f3d_simple", text="Simple Material UI")
col.prop(context.scene, "exportInlineF3D", text="Bleed and Inline Material Exports")
if context.scene.exportInlineF3D:
multilineLabel(
col.box(),
"While inlining, all meshes will be restored to world default values.\n You can configure these values in the world properties tab.",
icon="INFO",
)
col.prop(context.scene, "ignoreTextureRestrictions")
if context.scene.ignoreTextureRestrictions:
col.box().label(text="Width/height must be < 1024. Must be png format.")
class Fast64_GlobalSettingsPanel(bpy.types.Panel):
bl_idname = "FAST64_PT_global_settings"
bl_label = "Fast64 Global Settings"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Fast64"
@classmethod
def poll(cls, context):
return True
# called every frame
def draw(self, context):
col = self.layout.column()
col.scale_y = 1.1 # extra padding
scene = context.scene
fast64_settings: Fast64Settings_Properties = scene.fast64.settings
prop_split(col, scene, "gameEditorMode", "Game")
col.prop(scene, "exportHiddenGeometry")
col.prop(scene, "fullTraceback")
prop_split(col, fast64_settings, "anim_range_choice", "Anim Range")
draw_repo_settings(col.box(), context)
if not fast64_settings.repo_settings_tab:
col.prop(fast64_settings, "auto_pick_texture_format")
if fast64_settings.auto_pick_texture_format:
col.prop(fast64_settings, "prefer_rgba_over_ci")
class Fast64_GlobalToolsPanel(bpy.types.Panel):
bl_idname = "FAST64_PT_global_tools"
bl_label = "Fast64 Tools"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Fast64"
@classmethod
def poll(cls, context):
return True
# called every frame
def draw(self, context):
col = self.layout.column()
col.operator(ArmatureApplyWithMeshOperator.bl_idname)
# col.operator(CreateMetarig.bl_idname)
ui_oplargetexture(col, context)
addon_updater_ops.update_notice_box_ui(self, context)
def repo_path_update(self, context):
load_repo_settings(context.scene, abspath(self.repo_settings_path), True)
class Fast64Settings_Properties(bpy.types.PropertyGroup):
"""Settings affecting exports for all games found in scene.fast64.settings"""
version: bpy.props.IntProperty(name="Fast64Settings_Properties Version", default=0)
anim_range_choice: bpy.props.EnumProperty(
name="Anim Range",
description="What to use to determine what frames of the animation to export",
items=[
("action", "Action", "Export all frames from the action", 0),
(
"scene",
"Playback",
(
"Export all frames in the scene's animation preview playback range.\n"
"(export frames being played in Blender)"
),
1,
),
(
"intersect_action_and_scene",
"Smart",
(
"Intersect Action & Scene\n"
"Export all frames from the action that are also in the scene playback range.\n"
"(export frames being played in Blender that also are part of the action frames)"
),
2,
),
],
default="intersect_action_and_scene",
)
auto_pick_texture_format: bpy.props.BoolProperty(
name="Auto Pick Texture Format",
description="When enabled, fast64 will try to pick the best texture format whenever a texture is selected.",
default=True,
)
prefer_rgba_over_ci: bpy.props.BoolProperty(
name="Prefer RGBA Over CI",
description="When enabled, fast64 will default colored textures's format to RGBA even if they fit CI requirements, with the exception of textures that would not fit into TMEM otherwise",
)
dont_ask_color_management: bpy.props.BoolProperty(name="Don't ask to set color management properties")
repo_settings_tab: bpy.props.BoolProperty(default=True, name="Repo Settings")
repo_settings_path: bpy.props.StringProperty(name="Path", subtype="FILE_PATH", update=repo_path_update)
auto_repo_load_settings: bpy.props.BoolProperty(
name="Auto Load Repo's Settings",
description="When enabled, this will make fast64 automatically load repo settings if they are found after picking a decomp path",
default=True,
)
internal_fixed_4_2: bpy.props.BoolProperty(default=False)
internal_game_update_ver: bpy.props.IntProperty(default=0)
class Fast64_Properties(bpy.types.PropertyGroup):
"""
Properties in scene.fast64.
All new properties should be children of one of these three property groups.
"""
sm64: bpy.props.PointerProperty(type=SM64_Properties, name="SM64 Properties")
oot: bpy.props.PointerProperty(type=OOT_Properties, name="OOT Properties")
mk64: bpy.props.PointerProperty(type=MK64_Properties, name="MK64 Properties")
settings: bpy.props.PointerProperty(type=Fast64Settings_Properties, name="Fast64 Settings")
renderSettings: bpy.props.PointerProperty(type=Fast64RenderSettings_Properties, name="Fast64 Render Settings")
class Fast64_BoneProperties(bpy.types.PropertyGroup):
"""
Properties in bone.fast64 (bpy.types.Bone)
All new bone properties should be children of this property group.
"""
sm64: bpy.props.PointerProperty(type=SM64_BoneProperties, name="SM64 Properties")
class Fast64_ObjectProperties(bpy.types.PropertyGroup):
"""
Properties in object.fast64 (bpy.types.Object)
All new object properties should be children of this property group.
"""
sm64: bpy.props.PointerProperty(type=SM64_ObjectProperties, name="SM64 Object Properties")
oot: bpy.props.PointerProperty(type=OOT_ObjectProperties, name="OOT Object Properties")
class UpgradeF3DMaterialsDialog(bpy.types.Operator):
bl_idname = "dialog.upgrade_f3d_materials"
bl_label = "Upgrade F3D Materials"
bl_options = {"REGISTER", "UNDO"}
done = False
def draw(self, context):
layout = self.layout
if self.done:
layout.label(text="Success!")
layout.label(text="Materials were successfully upgraded.")
layout.separator(factor=0.25)
layout.label(text="You may click anywhere to close this dialog.")
return
layout.alert = True
box = layout.box()
box.label(text="Your project contains F3D materials that need to be upgraded in order to continue!")
box.label(text="Before upgrading, make sure to create a duplicate (backup) of this blend file.")
box.separator()
col = box.column()
col.alignment = "CENTER"
col.alert = True
col.label(text="Upgrade F3D Materials?")
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self, width=600)
def execute(self, context: "bpy.types.Context"):
if context.mode != "OBJECT":
bpy.ops.object.mode_set(mode="OBJECT")
upgrade_f3d_version_all_meshes()
self.done = True
return {"FINISHED"}
# def updateGameEditor(scene, context):
# if scene.currentGameEditorMode == 'SM64':
# sm64_panel_unregister()
# elif scene.currentGameEditorMode == 'Z64':
# oot_panel_unregister()
# else:
# raise PluginError("Unhandled game editor mode " + str(scene.currentGameEditorMode))
#
# if scene.gameEditorMode == 'SM64':
# sm64_panel_register()
# elif scene.gameEditorMode == 'Z64':
# oot_panel_register()
# else:
# raise PluginError("Unhandled game editor mode " + str(scene.gameEditorMode))
#
# scene.currentGameEditorMode = scene.gameEditorMode
class ExampleAddonPreferences(bpy.types.AddonPreferences, addon_updater_ops.AddonUpdaterPreferences):
bl_idname = __package__
def draw(self, context):
addon_updater_ops.update_settings_ui(self, context)
classes = (
Fast64Settings_Properties,
Fast64RenderSettings_Properties,
ManualUpdatePreviewOperator,
Fast64_Properties,
Fast64_BoneProperties,
Fast64_ObjectProperties,
F3D_GlobalSettingsPanel,
Fast64_GlobalSettingsPanel,
Fast64_GlobalToolsPanel,
UpgradeF3DMaterialsDialog,
)
def upgrade_changed_props():
"""Set scene properties after a scene loads, used for migrating old properties"""
SM64_Properties.upgrade_changed_props()
MK64_Properties.upgrade_changed_props()
SM64_ObjectProperties.upgrade_changed_props()
OOT_ObjectProperties.upgrade_changed_props()
for scene in bpy.data.scenes:
settings: Fast64Settings_Properties = scene.fast64.settings
if settings.internal_game_update_ver != 1:
set_game_defaults(scene, False)
settings.internal_game_update_ver = 1
if scene.get("decomp_compatible", False):
scene.gameEditorMode = "Homebrew"
del scene["decomp_compatible"]
settings = scene.fast64.renderSettings
light0Color = settings.pop("lightColor", None)
if light0Color is not None:
settings.light0Color = light0Color
light0Direction = settings.pop("lightDirection", None)
if light0Direction is not None:
settings.light0Direction = light0Direction
def upgrade_scene_props_node():
"""update f3d materials with SceneProperties node"""
has_old_f3d_mats = any(mat.is_f3d and mat.mat_ver < F3D_MAT_CUR_VERSION for mat in bpy.data.materials)
if has_old_f3d_mats:
bpy.ops.dialog.upgrade_f3d_materials("INVOKE_DEFAULT")
@bpy.app.handlers.persistent
def after_load(_a, _b):
settings = bpy.context.scene.fast64.settings
if any(mat.is_f3d for mat in bpy.data.materials):
check_or_ask_color_management(bpy.context)
if not settings.internal_fixed_4_2 and bpy.app.version >= (4, 2, 0):
upgrade_f3d_version_all_meshes()
if bpy.app.version >= (4, 2, 0):
settings.internal_fixed_4_2 = True
upgrade_changed_props()
upgrade_scene_props_node()
resync_scene_props()
try:
if settings.repo_settings_path:
load_repo_settings(bpy.context.scene, abspath(settings.repo_settings_path), True)
except Exception as exc:
print(exc)
def set_game_defaults(scene: bpy.types.Scene, set_ucode=True):
world_defaults = None
if scene.gameEditorMode == "SM64":
f3d_type = "F3D"
world_defaults = sm64_world_defaults
elif scene.gameEditorMode == "OOT":
f3d_type = "F3DEX2/LX2"
world_defaults = oot_world_defaults
elif scene.gameEditorMode == "MK64":
f3d_type = "F3DEX/LX"
elif scene.gameEditorMode == "Homebrew":
f3d_type = "F3D"
world_defaults = {} # This will set some pretty bad defaults, but trust the user
if set_ucode:
scene.f3d_type = f3d_type
if scene.world is not None:
scene.world.rdp_defaults.from_dict(world_defaults)
def gameEditorUpdate(scene: bpy.types.Scene, _context):
set_game_defaults(scene)
# called on add-on enabling
# register operators and panels here
# append menu layout drawing function to an existing window
def register():
if bpy.app.version < (3, 2, 0):
msg = "\n".join(
(
"This version of Fast64 does not support Blender 3.1.x and earlier Blender versions.",
"Your Blender version is: " + ".".join(str(i) for i in bpy.app.version),
"Please upgrade Blender to 3.2.0 or above.",
)
)
print(msg)
unsupported_exc = Exception("\n\n" + msg)
raise unsupported_exc
# Register addon updater first,
# this way if a broken version fails to register the user can still pick another version.
register_class(ExampleAddonPreferences)
addon_updater_ops.register(bl_info)
utility_anim_register()
mat_register()
render_engine_register()
bsdf_conv_register()
sm64_register(True)
oot_register(True)
mk64_register(True)
repo_settings_operators_register()
for cls in classes:
register_class(cls)
bsdf_conv_panel_regsiter()
f3d_writer_register()
flipbook_register()
f3d_parser_register()
op_largetexture_register()
# ROM
bpy.types.Scene.ignoreTextureRestrictions = bpy.props.BoolProperty(name="Ignore Texture Restrictions")
bpy.types.Scene.fullTraceback = bpy.props.BoolProperty(name="Show Full Error Traceback", default=False)
bpy.types.Scene.gameEditorMode = bpy.props.EnumProperty(
name="Game", default="SM64", items=gameEditorEnum, update=gameEditorUpdate
)
bpy.types.Scene.saveTextures = bpy.props.BoolProperty(name="Save Textures As PNGs (Breaks CI Textures)")
bpy.types.Scene.exportHiddenGeometry = bpy.props.BoolProperty(name="Export Hidden Geometry", default=True)
bpy.types.Scene.exportInlineF3D = bpy.props.BoolProperty(
name="Bleed and Inline Material Exports",
description="Inlines and bleeds materials in a single mesh. GeoLayout + Armature exports bleed over entire model",
default=False,
)
bpy.types.Scene.blenderF3DScale = bpy.props.FloatProperty(
name="F3D Blender Scale", default=100, update=on_update_render_settings
)
bpy.types.Scene.fast64 = bpy.props.PointerProperty(type=Fast64_Properties, name="Fast64 Properties")
bpy.types.Bone.fast64 = bpy.props.PointerProperty(type=Fast64_BoneProperties, name="Fast64 Bone Properties")
bpy.types.Object.fast64 = bpy.props.PointerProperty(type=Fast64_ObjectProperties, name="Fast64 Object Properties")
bpy.app.handlers.load_post.append(after_load)
# called on add-on disabling
def unregister():
utility_anim_unregister()
op_largetexture_unregister()
flipbook_unregister()
f3d_writer_unregister()
f3d_parser_unregister()
sm64_unregister(True)
oot_unregister(True)
mk64_unregister(True)
mat_unregister()
bsdf_conv_unregister()
bsdf_conv_panel_unregsiter()
render_engine_unregister()
del bpy.types.Scene.fullTraceback
del bpy.types.Scene.ignoreTextureRestrictions
del bpy.types.Scene.saveTextures
del bpy.types.Scene.gameEditorMode
del bpy.types.Scene.exportHiddenGeometry
del bpy.types.Scene.blenderF3DScale
del bpy.types.Scene.fast64
del bpy.types.Bone.fast64
del bpy.types.Object.fast64
repo_settings_operators_unregister()
for cls in classes:
unregister_class(cls)
bpy.app.handlers.load_post.remove(after_load)
addon_updater_ops.unregister()
unregister_class(ExampleAddonPreferences)