-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path__init__.py
770 lines (688 loc) · 32.3 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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
bl_info = {
"name": "RE Chain Editor",
"author": "NSA Cloud, alphaZomega",
"version": (11, 0),
"blender": (3, 1, 2),
"location": "File > Import-Export",
"description": "Import and export RE Engine chain files.",
"warning": "",
"wiki_url": "https://github.com/NSACloud/RE-Chain-Editor",
"tracker_url": "https://github.com/NSACloud/RE-Chain-Editor/issues",
"category": "Import-Export"}
#Modified by alphaZomega to support RE2R, RE3R, RE8, RE2-3-7 RT, DMC5 and SF6
#TODO Fix Header only export
import bpy
from . import addon_updater_ops
import os
from bpy_extras.io_utils import ExportHelper,ImportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty, CollectionProperty,PointerProperty
from bpy.types import Operator, OperatorFileListElement,AddonPreferences
from .modules.gen_functions import textColors
from .modules.blender_re_chain import importChainFile,exportChainFile
from .modules.re_chain_propertyGroups import chainToolPanelPropertyGroup,chainHeaderPropertyGroup,chainWindSettingsPropertyGroup,chainSettingsPropertyGroup,ChainSettingSubDataPropertyGroup,CHAIN_UL_ChainSettingsSubDataList,chainGroupPropertyGroup,chainSubGroupPropertyGroup,chainNodePropertyGroup,chainJigglePropertyGroup,chainCollisionPropertyGroup,chainClipboardPropertyGroup,chainLinkPropertyGroup,collisionSubDataPropertyGroup,chainLinkCollisionNodePropertyGroup
from .modules.ui_re_chain_panels import OBJECT_PT_ChainObjectModePanel,OBJECT_PT_ChainPoseModePanel,OBJECT_PT_ChainPresetPanel,OBJECT_PT_ChainHeaderPanel,OBJECT_PT_WindSettingsPanel,OBJECT_PT_ChainSettingsPanel,OBJECT_PT_ChainSettingsSubDataPanel,OBJECT_PT_ChainGroupPanel,OBJECT_PT_ChainSubGroupPanel,OBJECT_PT_ChainNodePanel,OBJECT_PT_ChainJigglePanel,OBJECT_PT_ChainCollisionPanel,OBJECT_PT_ChainClipboardPanel,OBJECT_PT_ChainLinkPanel,OBJECT_PT_ChainVisibilityPanel,OBJECT_PT_ChainCollisionSubDataPanel,OBJECT_PT_ChainLinkCollisionPanel,OBJECT_PT_NodeVisPanel,OBJECT_PT_CollisionVisPanel,OBJECT_PT_AngleLimitVisPanel,OBJECT_PT_ColorVisPanel
from .modules.re_chain_operators import WM_OT_ChainFromBone,WM_OT_CollisionFromBones,WM_OT_AlignChainsToBones,WM_OT_AlignFrames,WM_OT_PointFrame,WM_OT_CopyChainProperties,WM_OT_PasteChainProperties,WM_OT_NewChainHeader,WM_OT_ApplyChainSettingsPreset,WM_OT_NewChainSettings,WM_OT_NewWindSettings,WM_OT_NewChainJiggle,WM_OT_ApplyChainGroupPreset,WM_OT_ApplyChainNodePreset,WM_OT_ApplyWindSettingsPreset,WM_OT_SavePreset,WM_OT_OpenPresetFolder,WM_OT_NewChainLink,WM_OT_CreateChainBoneGroup,WM_OT_SwitchToPoseMode,WM_OT_SwitchToObjectMode,WM_OT_HideNonNodes,WM_OT_HideNonAngleLimits,WM_OT_HideNonCollisions,WM_OT_UnhideAll,WM_OT_RenameBoneChain,WM_OT_ApplyAngleLimitRamp,WM_OT_AlignBoneTailsToAxis,WM_OT_SetAttrFlags,WM_OT_SetNodeAttrFlags,WM_OT_SetSettingAttrFlags,WM_OT_SetJiggleAttrFlags,WM_OT_CreateChainLinkCollision,WM_OT_CreateChainSubGroup,WM_OT_SetCFILPath
from .modules.blender_re_clsp import importCLSPFile,exportCLSPFile
class REChainPreferences(AddonPreferences):
bl_idname = __name__
# addon updater preferences
auto_check_update: bpy.props.BoolProperty(
name = "Auto-check for Update",
description = "If enabled, auto-check for updates using an interval",
default = False,
)
updater_interval_months: bpy.props.IntProperty(
name='Months',
description = "Number of months between checking for updates",
default=0,
min=0
)
updater_interval_days: bpy.props.IntProperty(
name='Days',
description = "Number of days between checking for updates",
default=7,
min=0,
)
updater_interval_hours: bpy.props.IntProperty(
name='Hours',
description = "Number of hours between checking for updates",
default=0,
min=0,
max=23
)
updater_interval_minutes: bpy.props.IntProperty(
name='Minutes',
description = "Number of minutes between checking for updates",
default=0,
min=0,
max=59
)
def draw(self, context):
layout = self.layout
split = layout.split(factor = .3)
col1 = split.column()
col2 = split.column()
col3 = split.column()
op = col2.operator(
'wm.url_open',
text='Donate on Ko-fi',
icon='FUND'
)
op.url = 'https://ko-fi.com/nsacloud'
addon_updater_ops.update_settings_ui(self,context)
class ImportREChain(bpy.types.Operator, ImportHelper):
'''Import RE Engine Chain File'''
bl_idname = "re_chain.importfile"
bl_label = "Import RE Chain"
bl_options = {'PRESET', "REGISTER", "UNDO"}
files : CollectionProperty(
name="File Path",
type=OperatorFileListElement,
)
directory : StringProperty(
subtype='DIR_PATH',
options={'SKIP_SAVE'}
)
filename_ext = ".chain.*"
filter_glob: StringProperty(default="*.chain.*", options={'HIDDEN'})
targetArmature : StringProperty(
name = "",
description = "The armature to attach chain objects to.\nNOTE: If bones that are used by the chain file are missing on the armature, any chain groups or collisions using those bones won't be imported",
default = "")
mergeChain : StringProperty(
name = "",
description = "Merges the imported chain with an existing chain collection.\nNote that the chain bones used by the imported file must be merged with the target armature.\nUse the Merge With Armature import option in RE Mesh Editor first.\n Leave blank if not merging a chain file",
default = "")
importUnknowns : BoolProperty(
name = "Import Unknown Hashes",
description = "This option forces all chain groups and collisions to be imported if the bones they're supposed to be attached to aren't present.\nThis will cause errors in the console, anything imported with missing hashes will also not appear correctly.\n However upon export, the exported chain file should remain identical to the original",
default = False)
def invoke(self, context, event):
armature = None
if bpy.data.armatures.get(self.targetArmature,None) == None:
try:#Pick selected armature if one is selected
if armature == None and bpy.context.active_object != None and bpy.context.active_object.type == "ARMATURE":
armature = bpy.context.active_object
except:
pass
if armature == None:
for obj in bpy.context.scene.objects:
if obj.type == "ARMATURE":
armature = obj
if armature != None:
self.targetArmature = armature.data.name
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def draw(self, context):
layout = self.layout
layout.label(text = "Target Armature:")
layout.prop_search(self, "targetArmature",bpy.data,"armatures")
layout.label(text = "Merge With Chain Collection:")
layout.prop_search(self, "mergeChain",bpy.data,"collections",icon = "COLLECTION_COLOR_02")
#layout.prop(self, "importUnknowns")#TODO
def execute(self, context):
options = {"targetArmature":self.targetArmature,"mergeChain":self.mergeChain,"importUnknowns":self.importUnknowns}
editorVersion = str(bl_info["version"][0])+"."+str(bl_info["version"][1])
print(f"\n{textColors.BOLD}RE Chain Editor V{editorVersion}{textColors.ENDC}")
print(f"Blender Version {bpy.app.version[0]}.{bpy.app.version[1]}.{bpy.app.version[2]}")
print("https://github.com/NSACloud/RE-Chain-Editor")
success = importChainFile(self.filepath,options,isChain2=False)
if success:
return {"FINISHED"}
else:
self.report({"INFO"},"Failed to import RE Chain. Make sure the mesh file is imported.")
return {"CANCELLED"}
def invoke(self, context, event):
armatureObj = None
if bpy.context.selected_objects != []:
for obj in bpy.context.selected_objects:
if obj.type == "ARMATURE":
armatureObj = obj
break
elif self.targetArmature.strip() == "":
if "REMeshLastImportedCollection" in bpy.context.scene:
meshCollection = bpy.data.collections.get(bpy.context.scene["REMeshLastImportedCollection"],bpy.context.scene.collection)
for obj in meshCollection.all_objects:
if obj.type == "ARMATURE":
armatureObj = obj
break
if armatureObj != None:
self.targetArmature = armatureObj.data.name
if self.directory:
return context.window_manager.invoke_props_dialog(self)
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
supportedChainVersions = set([54,53,48,52,39,46,24,44,21])
supportedChain2Versions = set([4,9,12,13])
class ExportREChain(bpy.types.Operator, ExportHelper):
'''Export RE Engine Chain File'''
bl_idname = "re_chain.exportfile"
bl_label = "Export RE Chain"
bl_options = {'PRESET'}
filename_ext: EnumProperty(
name="",
description="Set which game to export the chain for",
items=[ (".54", "Dragon's Dogma 2", "Dragon's Dogma 2"),
(".53", "Resident Evil 4 Remake", "Resident Evil 4 Remake"),
(".48", "Monster Hunter Rise", "Monster Hunter Rise"),
(".52", "Street Fighter 6", "Street Fighter 6"),
(".39", "Resident Evil 8", "Resident Evil 8"),
(".46", "Resident Evil 2/3/7 Ray Tracing", "Resident Evil 2/3/7 Ray Tracing Update"),
(".44", "RE:Verse", "RE:Verse"),
(".24", "RE3 / Resistance", "Resident Evil 3 / RE Resistance"),
(".21", "Devil May Cry 5 / RE2", "Devil May Cry 5 / Resident Evil 2"),
],
default = ".53"
)
targetCollection : StringProperty(
name = "",
description = "Set the chain collection to be exported",
default = "")
filter_glob: StringProperty(default="*.chain*", options={'HIDDEN'})
def invoke(self, context, event):
if bpy.data.collections.get(self.targetCollection,None) == None:
if bpy.context.scene.re_chain_toolpanel.chainCollection:
self.targetCollection = bpy.context.scene.re_chain_toolpanel.chainCollection.name
if ".chain" in self.targetCollection:#Remove blender suffix after .mesh if it exists
self.filepath = self.targetCollection.split(".chain")[0]+".chain" + self.filename_ext
if context.scene.get("REChainLastImportedChainVersion",0) in supportedChainVersions:
self.filename_ext = "."+str(context.scene["REChainLastImportedChainVersion"])
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def draw(self, context):
layout = self.layout
layout.label(text = "Chain Version:")
layout.prop(self,"filename_ext")
layout.label(text = "Chain Collection:")
layout.prop_search(self, "targetCollection",bpy.data,"collections",icon = "COLLECTION_COLOR_02")
def execute(self, context):
options = {"targetCollection":self.targetCollection}
try:
chainVersion = int(os.path.splitext(self.filepath)[1].replace(".",""))
except:
self.report({"INFO"},"Chain file path is missing number extension. Cannot export.")
return{"CANCELLED"}
editorVersion = str(bl_info["version"][0])+"."+str(bl_info["version"][1])
print(f"\n{textColors.BOLD}RE Chain Editor V{editorVersion}{textColors.ENDC}")
print(f"Blender Version {bpy.app.version[0]}.{bpy.app.version[1]}.{bpy.app.version[2]}")
print("https://github.com/NSACloud/RE-Chain-Editor")
success = exportChainFile(self.filepath,options, chainVersion)
if success:
self.report({"INFO"},"Exported RE Chain successfully.")
#Add batch export entry to RE Toolbox if it doesn't already have one
if hasattr(bpy.types, "OBJECT_PT_re_tools_quick_export_panel"):
if not any(item.path == self.filepath for item in bpy.context.scene.re_toolbox_toolpanel.batchExportList_items):
newExportItem = bpy.context.scene.re_toolbox_toolpanel.batchExportList_items.add()
newExportItem.fileType = "CHAIN"
newExportItem.path = self.filepath
newExportItem.chainCollection = self.targetCollection
print("Added path to RE Toolbox Batch Export list.")
else:
self.report({"INFO"},"RE Chain export failed. See Window > Toggle System Console for details.")
return {"FINISHED"}
class ImportRECLSP(bpy.types.Operator, ImportHelper):
'''Import RE Engine Collision Shape Preset File'''
bl_idname = "re_clsp.importfile"
bl_label = "Import RE CLSP"
bl_options = {'PRESET', "REGISTER", "UNDO"}
files : CollectionProperty(
name="File Path",
type=OperatorFileListElement,
)
directory : StringProperty(
subtype='DIR_PATH',
options={'SKIP_SAVE'}
)
filename_ext = ".clsp.*"
filter_glob: StringProperty(default="*.clsp.*", options={'HIDDEN'})
targetArmature : StringProperty(
name = "",
description = "The armature to attach collisions to.\nNOTE: If bones that are used by the clsp file are missing on the armature, any chain groups or collisions using those bones won't be imported",
default = "")
def invoke(self, context, event):
armature = None
if bpy.data.armatures.get(self.targetArmature,None) == None:
try:#Pick selected armature if one is selected
if armature == None and bpy.context.active_object != None and bpy.context.active_object.type == "ARMATURE":
armature = bpy.context.active_object
except:
pass
if armature == None:
for obj in bpy.context.scene.objects:
if obj.type == "ARMATURE":
armature = obj
if armature != None:
self.targetArmature = armature.data.name
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def draw(self, context):
layout = self.layout
layout.label(text = "Target Armature:")
layout.prop_search(self, "targetArmature",bpy.data,"armatures")
def execute(self, context):
options = {"targetArmature":self.targetArmature}
editorVersion = str(bl_info["version"][0])+"."+str(bl_info["version"][1])
print(f"\n{textColors.BOLD}RE Chain Editor V{editorVersion}{textColors.ENDC}")
print(f"Blender Version {bpy.app.version[0]}.{bpy.app.version[1]}.{bpy.app.version[2]}")
print("https://github.com/NSACloud/RE-Chain-Editor")
success = importCLSPFile(self.filepath,options)
if success:
return {"FINISHED"}
else:
self.report({"INFO"},"Failed to import RE CLSP. Make sure the armature for the mesh is imported.")
return {"CANCELLED"}
supportedCLSPVersions = set([3])
class ExportRECLSP(bpy.types.Operator, ExportHelper):
'''Export RE Engine Collsion Shape Preset File'''
bl_idname = "re_clsp.exportfile"
bl_label = "Export RE CLSP"
bl_options = {'PRESET'}
filename_ext: EnumProperty(
name="",
description="Set which game to export the chain for",
items=[ (".3", "(.3) Dragon's Dogma 2, MH Wilds", "Dragon's Dogma 2, MH Wilds"),
],
default = ".3"
)
targetCollection : StringProperty(
name = "",
description = "Set the CLSP collection to be exported",
default = "")
filter_glob: StringProperty(default="*.clsp*", options={'HIDDEN'})
def invoke(self, context, event):
if bpy.data.collections.get(self.targetCollection,None) == None:
if bpy.context.scene.re_chain_toolpanel.chainCollection:
self.targetCollection = bpy.context.scene.re_chain_toolpanel.chainCollection.name
if ".clsp" in self.targetCollection:#Remove blender suffix after .mesh if it exists
self.filepath = self.targetCollection.split(".clsp")[0]+".clsp" + self.filename_ext
if context.scene.get("REChainLastImportedCLSPVersion",0) in supportedCLSPVersions:
self.filename_ext = "."+str(context.scene["REChainLastImportedCLSPVersion"])
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def draw(self, context):
layout = self.layout
layout.label(text = "CLSP Version:")
layout.prop(self,"filename_ext")
layout.label(text = "CLSP Collection:")
layout.prop_search(self, "targetCollection",bpy.data,"collections",icon = "COLLECTION_COLOR_02")
def execute(self, context):
options = {"targetCollection":self.targetCollection}
try:
clspVersion = int(os.path.splitext(self.filepath)[1].replace(".",""))
except:
self.report({"INFO"},"CLSP file path is missing number extension. Cannot export.")
return{"CANCELLED"}
editorVersion = str(bl_info["version"][0])+"."+str(bl_info["version"][1])
print(f"\n{textColors.BOLD}RE Chain Editor V{editorVersion}{textColors.ENDC}")
print(f"Blender Version {bpy.app.version[0]}.{bpy.app.version[1]}.{bpy.app.version[2]}")
print("https://github.com/NSACloud/RE-Chain-Editor")
success = exportCLSPFile(self.filepath,options, clspVersion)
if success:
self.report({"INFO"},"Exported RE CLSP successfully.")
#Add batch export entry to RE Toolbox if it doesn't already have one
if hasattr(bpy.types, "OBJECT_PT_re_tools_quick_export_panel"):
try:
if not any(item.path == self.filepath for item in bpy.context.scene.re_toolbox_toolpanel.batchExportList_items):
newExportItem = bpy.context.scene.re_toolbox_toolpanel.batchExportList_items.add()
newExportItem.fileType = "CLSP"
newExportItem.path = self.filepath
newExportItem.chainCollection = self.targetCollection
print("Added path to RE Toolbox Batch Export list.")
except:
print("Failed to add path to RE Toolbox. RE Toolbox is likely outdated and needs an update.")
else:
self.report({"INFO"},"RE CLSP export failed. See Window > Toggle System Console for details.")
return {"FINISHED"}
class ImportREChain2(bpy.types.Operator, ImportHelper):
'''Import RE Engine Chain2 File'''
bl_idname = "re_chain2.importfile"
bl_label = "Import RE Chain2"
bl_options = {'PRESET', "REGISTER", "UNDO"}
files : CollectionProperty(
name="File Path",
type=OperatorFileListElement,
)
directory : StringProperty(
subtype='DIR_PATH',
options={'SKIP_SAVE'}
)
filename_ext = ".chain2.*"
filter_glob: StringProperty(default="*.chain2.*", options={'HIDDEN'})
targetArmature : StringProperty(
name = "",
description = "The armature to attach chain objects to.\nNOTE: If bones that are used by the chain file are missing on the armature, any chain groups or collisions using those bones won't be imported",
default = "")
mergeChain : StringProperty(
name = "",
description = "Merges the imported chain2 with an existing chain collection.\nNote that the chain bones used by the imported file must be merged with the target armature.\nUse the Merge With Armature import option in RE Mesh Editor first.\n Leave blank if not merging a chain file",
default = "")
importUnknowns : BoolProperty(
name = "Import Unknown Hashes",
description = "This option forces all chain groups and collisions to be imported if the bones they're supposed to be attached to aren't present.\nThis will cause errors in the console, anything imported with missing hashes will also not appear correctly.\n However upon export, the exported chain file should remain identical to the original",
default = False)
def invoke(self, context, event):
armature = None
if bpy.data.armatures.get(self.targetArmature,None) == None:
try:#Pick selected armature if one is selected
if armature == None and bpy.context.active_object != None and bpy.context.active_object.type == "ARMATURE":
armature = bpy.context.active_object
except:
pass
if armature == None:
for obj in bpy.context.scene.objects:
if obj.type == "ARMATURE":
armature = obj
if armature != None:
self.targetArmature = armature.data.name
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def draw(self, context):
layout = self.layout
layout.label(text = "Target Armature:")
layout.prop_search(self, "targetArmature",bpy.data,"armatures")
layout.label(text = "Merge With Chain Collection:")
layout.prop_search(self, "mergeChain",bpy.data,"collections",icon = "COLLECTION_COLOR_02")
#layout.prop(self, "importUnknowns")#TODO
def execute(self, context):
options = {"targetArmature":self.targetArmature,"mergeChain":self.mergeChain,"importUnknowns":self.importUnknowns}
editorVersion = str(bl_info["version"][0])+"."+str(bl_info["version"][1])
print(f"\n{textColors.BOLD}RE Chain Editor V{editorVersion}{textColors.ENDC}")
print(f"Blender Version {bpy.app.version[0]}.{bpy.app.version[1]}.{bpy.app.version[2]}")
print("https://github.com/NSACloud/RE-Chain-Editor")
success = importChainFile(self.filepath,options,isChain2=True)
if success:
return {"FINISHED"}
else:
self.report({"INFO"},"Failed to import RE Chain. Make sure the mesh file is imported.")
return {"CANCELLED"}
def invoke(self, context, event):
armatureObj = None
if bpy.context.selected_objects != []:
for obj in bpy.context.selected_objects:
if obj.type == "ARMATURE":
armatureObj = obj
break
elif self.targetArmature.strip() == "":
if "REMeshLastImportedCollection" in bpy.context.scene:
meshCollection = bpy.data.collections.get(bpy.context.scene["REMeshLastImportedCollection"],bpy.context.scene.collection)
for obj in meshCollection.all_objects:
if obj.type == "ARMATURE":
armatureObj = obj
break
if armatureObj != None:
self.targetArmature = armatureObj.data.name
if self.directory:
return context.window_manager.invoke_props_dialog(self)
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
supportedChainVersions = set([54,53,48,52,39,46,24,44,21])
class ExportREChain2(bpy.types.Operator, ExportHelper):
'''Export RE Engine Chain2 File'''
bl_idname = "re_chain2.exportfile"
bl_label = "Export RE Chain2"
bl_options = {'PRESET'}
filename_ext: EnumProperty(
name="",
description="Set which game to export the chain for",
items=[ (".4", "Dragon's Dogma 2", "Dragon's Dogma 2"),
(".9", "Dead Rising", "Dead Rising"),
(".13", "Monster Hunter Wilds", "Monster Hunter Wilds"),
],
default = ".13"
)
targetCollection : StringProperty(
name = "",
description = "Set the chain collection to be exported",
default = "")
filter_glob: StringProperty(default="*.chain2*", options={'HIDDEN'})
def invoke(self, context, event):
if bpy.data.collections.get(self.targetCollection,None) == None:
if bpy.context.scene.re_chain_toolpanel.chainCollection:
self.targetCollection = bpy.context.scene.re_chain_toolpanel.chainCollection.name
if ".chain" in self.targetCollection:#Remove blender suffix after .mesh if it exists
self.filepath = self.targetCollection.split(".chain2")[0]+".chain2" + self.filename_ext
if context.scene.get("REChainLastImportedChain2Version",0) in supportedChainVersions:
if context.scene["REChainLastImportedChain2Version"] == 12:
#MH Wilds beta fix
context.scene["REChainLastImportedChain2Version"] = 13
self.filename_ext = "."+str(context.scene["REChainLastImportedChain2Version"])
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def draw(self, context):
layout = self.layout
layout.label(text = "Chain Version:")
layout.prop(self,"filename_ext")
layout.label(text = "Chain Collection:")
layout.prop_search(self, "targetCollection",bpy.data,"collections",icon = "COLLECTION_COLOR_02")
def execute(self, context):
options = {"targetCollection":self.targetCollection}
try:
chainVersion = int(os.path.splitext(self.filepath)[1].replace(".",""))
except:
self.report({"INFO"},"Chain file path is missing number extension. Cannot export.")
return{"CANCELLED"}
editorVersion = str(bl_info["version"][0])+"."+str(bl_info["version"][1])
print(f"\n{textColors.BOLD}RE Chain Editor V{editorVersion}{textColors.ENDC}")
print(f"Blender Version {bpy.app.version[0]}.{bpy.app.version[1]}.{bpy.app.version[2]}")
print("https://github.com/NSACloud/RE-Chain-Editor")
success = exportChainFile(self.filepath,options, chainVersion,isChain2=True)
if success:
self.report({"INFO"},"Exported RE Chain successfully.")
#Add batch export entry to RE Toolbox if it doesn't already have one
if hasattr(bpy.types, "OBJECT_PT_re_tools_quick_export_panel"):
try:
if not any(item.path == self.filepath for item in bpy.context.scene.re_toolbox_toolpanel.batchExportList_items):
newExportItem = bpy.context.scene.re_toolbox_toolpanel.batchExportList_items.add()
newExportItem.fileType = "CHAIN2"
newExportItem.path = self.filepath
newExportItem.chainCollection = self.targetCollection
print("Added path to RE Toolbox Batch Export list.")
except:
print("Failed to add path to RE Toolbox. RE Toolbox is likely outdated and needs an update.")
else:
self.report({"INFO"},"RE Chain export failed. See Window > Toggle System Console for details.")
return {"FINISHED"}
# Registration
classes = [
REChainPreferences,
ImportREChain,
ExportREChain,
ImportRECLSP,
ExportRECLSP,
ImportREChain2,
ExportREChain2,
chainToolPanelPropertyGroup,
chainHeaderPropertyGroup,
chainWindSettingsPropertyGroup,
ChainSettingSubDataPropertyGroup,
CHAIN_UL_ChainSettingsSubDataList,
chainSettingsPropertyGroup,
chainGroupPropertyGroup,
chainSubGroupPropertyGroup,
chainNodePropertyGroup,
chainJigglePropertyGroup,
chainCollisionPropertyGroup,
chainLinkPropertyGroup,
chainLinkCollisionNodePropertyGroup,
collisionSubDataPropertyGroup,
chainClipboardPropertyGroup,
OBJECT_PT_ChainObjectModePanel,
OBJECT_PT_ChainClipboardPanel,
OBJECT_PT_ChainPoseModePanel,
OBJECT_PT_ChainPresetPanel,
OBJECT_PT_ChainHeaderPanel,
OBJECT_PT_WindSettingsPanel,
OBJECT_PT_ChainSettingsPanel,
OBJECT_PT_ChainSettingsSubDataPanel,
OBJECT_PT_ChainGroupPanel,
OBJECT_PT_ChainSubGroupPanel,
OBJECT_PT_ChainNodePanel,
OBJECT_PT_ChainJigglePanel,
OBJECT_PT_ChainCollisionPanel,
OBJECT_PT_ChainLinkPanel,
OBJECT_PT_ChainVisibilityPanel,
OBJECT_PT_ChainCollisionSubDataPanel,
OBJECT_PT_ChainLinkCollisionPanel,
OBJECT_PT_NodeVisPanel,
OBJECT_PT_CollisionVisPanel,
OBJECT_PT_AngleLimitVisPanel,
OBJECT_PT_ColorVisPanel,
WM_OT_ChainFromBone,
WM_OT_CollisionFromBones,
#WM_OT_AlignChainsToBones,
WM_OT_AlignFrames,
#WM_OT_PointFrame,
WM_OT_NewChainHeader,
WM_OT_NewChainSettings,
WM_OT_NewWindSettings,
WM_OT_NewChainJiggle,
WM_OT_NewChainLink,
WM_OT_CreateChainLinkCollision,
WM_OT_CreateChainSubGroup,
WM_OT_CopyChainProperties,
WM_OT_PasteChainProperties,
WM_OT_ApplyChainSettingsPreset,
WM_OT_ApplyChainGroupPreset,
WM_OT_ApplyChainNodePreset,
WM_OT_ApplyWindSettingsPreset,
WM_OT_SavePreset,
WM_OT_OpenPresetFolder,
WM_OT_CreateChainBoneGroup,
WM_OT_SwitchToPoseMode,
WM_OT_SwitchToObjectMode,
WM_OT_HideNonNodes,
WM_OT_HideNonAngleLimits,
WM_OT_HideNonCollisions,
WM_OT_UnhideAll,
WM_OT_RenameBoneChain,
WM_OT_ApplyAngleLimitRamp,
WM_OT_AlignBoneTailsToAxis,
WM_OT_SetAttrFlags,
WM_OT_SetNodeAttrFlags,
WM_OT_SetSettingAttrFlags,
WM_OT_SetJiggleAttrFlags,
WM_OT_SetCFILPath,
]
"""
def re_chain_import(self, context):
self.layout.operator(ImportREChain.bl_idname, text="RE Chain (.chain.x)")
def re_chain_export(self, context):
self.layout.operator(ExportREChain.bl_idname, text="RE Chain (.chain.x)")
def re_clsp_import(self, context):
self.layout.operator(ImportRECLSP.bl_idname, text="RE CLSP (.clsp.x)")
def re_clsp_export(self, context):
self.layout.operator(ExportRECLSP.bl_idname, text="RE CLSP (.clsp.x)")
def re_chain2_import(self, context):
self.layout.operator(ImportREChain2.bl_idname, text="RE Chain2 (.chain2.x)")
def re_chain2_export(self, context):
self.layout.operator(ExportREChain2.bl_idname, text="RE Chain2 (.chain2.x)")
"""
#Drag and drop importing, 4.1 or higher only
if bpy.app.version >= (4, 1, 0):
chainExtensionsString = ""
for chainVersion in supportedChainVersions:
chainExtensionsString += f".{str(chainVersion)};"
class CHAIN_FH_drag_import(bpy.types.FileHandler):
bl_idname = "CHAIN_FH_drag_import"
bl_label = "File handler for RE Chain importing"
bl_import_operator = "re_chain.importfile"
bl_file_extensions = chainExtensionsString
@classmethod
def poll_drop(cls, context):
return (context.area and context.area.type == 'VIEW_3D')
chain2ExtensionsString = ""
for chain2Version in supportedChain2Versions:
chain2ExtensionsString += f".{str(chain2Version)};"
class CHAIN2_FH_drag_import(bpy.types.FileHandler):
bl_idname = "CHAIN2_FH_drag_import"
bl_label = "File handler for RE Chain2 importing"
bl_import_operator = "re_chain2.importfile"
bl_file_extensions = chain2ExtensionsString
@classmethod
def poll_drop(cls, context):
return (context.area and context.area.type == 'VIEW_3D')
clspExtensionsString = ".3;"
class CLSP_FH_drag_import(bpy.types.FileHandler):
bl_idname = "CLSP_FH_drag_import"
bl_label = "File handler for RE CLSP importing"
bl_import_operator = "re_clsp.importfile"
bl_file_extensions = clspExtensionsString
@classmethod
def poll_drop(cls, context):
return (context.area and context.area.type == 'VIEW_3D')
class IMPORT_MT_re_chain_editor(bpy.types.Menu):
bl_label = "RE Chain Editor"
bl_idname = "IMPORT_MT_re_chain_editor"
def draw(self, context):
layout = self.layout
layout.operator(ImportREChain.bl_idname, text="RE Chain (.chain.x) (Physics)",icon = "LINK_BLEND")
layout.operator(ImportREChain2.bl_idname, text="RE Chain2 (.chain2.x) (Physics) (New)",icon = "LINK_BLEND")
layout.operator(ImportRECLSP.bl_idname, text="RE CLSP (.clsp.x) (Collisions)",icon = "SPHERE")
def re_chain_editor_import(self, context):
self.layout.menu("IMPORT_MT_re_chain_editor",icon = "LINK_BLEND")
class EXPORT_MT_re_chain_editor(bpy.types.Menu):
bl_label = "RE Chain Editor"
bl_idname = "EXPORT_MT_re_chain_editor"
def draw(self, context):
layout = self.layout
layout.operator(ExportREChain.bl_idname, text="RE Chain (.chain.x) (Physics)",icon = "LINK_BLEND")
layout.operator(ExportREChain2.bl_idname, text="RE Chain2 (.chain2.x) (Physics) (New)",icon = "LINK_BLEND")
layout.operator(ExportRECLSP.bl_idname, text="RE CLSP (.clsp.x) (Collisions)",icon = "SPHERE")
def re_chain_editor_export(self, context):
self.layout.menu("EXPORT_MT_re_chain_editor",icon = "LINK_BLEND")
def register():
addon_updater_ops.register(bl_info)
for classEntry in classes:
bpy.utils.register_class(classEntry)
bpy.utils.register_class(IMPORT_MT_re_chain_editor)
bpy.utils.register_class(EXPORT_MT_re_chain_editor)
#bpy.types.TOPBAR_MT_file_import.append(re_chain_import)
#bpy.types.TOPBAR_MT_file_export.append(re_chain_export)
#bpy.types.TOPBAR_MT_file_import.append(re_clsp_import)
#bpy.types.TOPBAR_MT_file_export.append(re_clsp_export)
#bpy.types.TOPBAR_MT_file_import.append(re_chain2_import)
#bpy.types.TOPBAR_MT_file_export.append(re_chain2_export)
bpy.types.TOPBAR_MT_file_import.append(re_chain_editor_import)
bpy.types.TOPBAR_MT_file_export.append(re_chain_editor_export)
#Blender 4.1 and higher drag and drop operators
if bpy.app.version >= (4, 1, 0):
bpy.utils.register_class(CHAIN_FH_drag_import)
bpy.utils.register_class(CHAIN2_FH_drag_import)
bpy.utils.register_class(CLSP_FH_drag_import)
bpy.types.Scene.re_chain_toolpanel = PointerProperty(type=chainToolPanelPropertyGroup)
#bpy.context.scene.re_chain_toolpanel.clipboardType = "None"
#REGISTER PROPERTY GROUP PROPERTIES
bpy.types.Object.re_chain_header = bpy.props.PointerProperty(type=chainHeaderPropertyGroup)
bpy.types.Object.re_chain_windsettings = bpy.props.PointerProperty(type=chainWindSettingsPropertyGroup)
bpy.types.Object.re_chain_chainsettings = bpy.props.PointerProperty(type=chainSettingsPropertyGroup)
bpy.types.Object.re_chain_chaingroup = bpy.props.PointerProperty(type=chainGroupPropertyGroup)
bpy.types.Object.re_chain_chainsubgroup = bpy.props.PointerProperty(type=chainSubGroupPropertyGroup)
bpy.types.Object.re_chain_chainnode = bpy.props.PointerProperty(type=chainNodePropertyGroup)
bpy.types.Object.re_chain_chainjiggle = bpy.props.PointerProperty(type=chainJigglePropertyGroup)
bpy.types.Object.re_chain_collision_subdata = bpy.props.PointerProperty(type=collisionSubDataPropertyGroup)
bpy.types.Object.re_chain_chaincollision = bpy.props.PointerProperty(type=chainCollisionPropertyGroup)
bpy.types.Object.re_chain_chainlink = bpy.props.PointerProperty(type=chainLinkPropertyGroup)
bpy.types.Object.re_chain_chainlink_collision = bpy.props.PointerProperty(type=chainLinkCollisionNodePropertyGroup)
bpy.types.Scene.re_chain_clipboard = bpy.props.PointerProperty(type=chainClipboardPropertyGroup)
def unregister():
addon_updater_ops.unregister()
for classEntry in classes:
bpy.utils.unregister_class(classEntry)
bpy.utils.unregister_class(IMPORT_MT_re_chain_editor)
bpy.utils.unregister_class(EXPORT_MT_re_chain_editor)
#bpy.types.TOPBAR_MT_file_import.remove(re_chain_import)
#bpy.types.TOPBAR_MT_file_export.remove(re_chain_export)
#bpy.types.TOPBAR_MT_file_import.remove(re_clsp_import)
#bpy.types.TOPBAR_MT_file_export.remove(re_clsp_export)
#bpy.types.TOPBAR_MT_file_import.remove(re_chain2_import)
#bpy.types.TOPBAR_MT_file_export.remove(re_chain2_export)
bpy.types.TOPBAR_MT_file_import.remove(re_chain_editor_import)
bpy.types.TOPBAR_MT_file_export.remove(re_chain_editor_export)
if bpy.app.version >= (4, 1, 0):
bpy.utils.unregister_class(CHAIN_FH_drag_import)
bpy.utils.unregister_class(CHAIN2_FH_drag_import)
bpy.utils.unregister_class(CLSP_FH_drag_import)
#UNREGISTER PROPERTY GROUP PROPERTIES
#del bpy.types.Object.re_chain_header
if __name__ == '__main__':
register()