forked from Fast-64/fast64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
433 lines (356 loc) · 15.4 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
import bpy
from bpy.utils import register_class, unregister_class
from . import addon_updater_ops
from .fast64_internal.utility import prop_split, multilineLabel
from .fast64_internal.sm64 import sm64_register, sm64_unregister
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.props_panel_main import OOT_ObjectProperties
from .fast64_internal.utility_anim import utility_anim_register, utility_anim_unregister, ArmatureApplyWithMeshOperator
from .fast64_internal.f3d.f3d_material import mat_register, mat_unregister
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,
upgradeF3DVersionAll,
bsdf_conv_register,
bsdf_conv_unregister,
bsdf_conv_panel_regsiter,
bsdf_conv_panel_unregsiter,
)
from .fast64_internal.render_settings import (
Fast64RenderSettings_Properties,
resync_scene_props,
on_update_render_settings,
)
# info about add on
bl_info = {
"name": "Fast64",
"version": (2, 2, 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"),
("OOT", "OOT", "Ocarina Of Time"),
("Homebrew", "Homebrew", "Homebrew"),
)
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, "generateF3DNodeGraph", text="Generate F3D Node Graph For Materials")
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")
col.separator()
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)
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",
)
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")
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!")
box = layout.box()
box.label(text="Materials were successfully upgraded.")
box.label(text="Please purge your remaining materials.")
purge_box = box.box()
purge_box.scale_y = 0.25
purge_box.separator(factor=0.5)
purge_box.label(text="How to purge:")
purge_box.separator(factor=0.5)
purge_box.label(text="Go to the outliner, change the display mode")
purge_box.label(text='to "Orphan Data" (broken heart icon)')
purge_box.separator(factor=0.25)
purge_box.label(text='Click "Purge" in the top right corner.')
purge_box.separator(factor=0.25)
purge_box.label(text="Purge multiple times until the node groups")
purge_box.label(text="are gone.")
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")
upgradeF3DVersionAll(
[obj for obj in bpy.data.objects if obj.type == "MESH"],
list(bpy.data.armatures),
MatUpdateConvert.version,
)
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,
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()
SM64_ObjectProperties.upgrade_changed_props()
OOT_ObjectProperties.upgrade_changed_props()
for scene in bpy.data.scenes:
if scene.get("decomp_compatible", False):
scene.gameEditorMode = "Homebrew"
del scene["decomp_compatible"]
def upgrade_scene_props_node():
"""update f3d materials with SceneProperties node"""
has_old_f3d_mats = any(mat.is_f3d and mat.mat_ver < MatUpdateConvert.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):
upgrade_changed_props()
upgrade_scene_props_node()
resync_scene_props()
def gameEditorUpdate(self, context):
if self.gameEditorMode == "SM64":
self.f3d_type = "F3D"
elif self.gameEditorMode == "OOT":
self.f3d_type = "F3DEX2/LX2"
# 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)
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.generateF3DNodeGraph = bpy.props.BoolProperty(name="Generate F3D Node Graph", default=True)
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)
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.generateF3DNodeGraph
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
for cls in classes:
unregister_class(cls)
bpy.app.handlers.load_post.remove(after_load)
addon_updater_ops.unregister()
unregister_class(ExampleAddonPreferences)