forked from CoDEmanX/blender-cod
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path__init__.py
More file actions
1104 lines (914 loc) · 35.3 KB
/
Copy path__init__.py
File metadata and controls
1104 lines (914 loc) · 35.3 KB
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
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
"""
Blender-CoD: Blender Add-On for Call of Duty Modding
Copyright (c) 2017 CoDEmanX, Flybynyt, SE2Dev -- blender-cod@online.de
https://github.com/CoDEmanX/blender-cod
"""
import bpy
from bpy.types import Operator, AddonPreferences
from bpy.props import (BoolProperty, IntProperty, FloatProperty,
StringProperty, EnumProperty, CollectionProperty)
from bpy_extras.io_utils import ExportHelper, ImportHelper
from bpy.utils import register_class, unregister_class
import time
import os
bl_info = {
"name": "Blender-CoD",
"author": "CoDEmanX, Flybynyt, SE2Dev",
"version": (0, 7, 0),
"blender": (2, 90, 0),
"location": "File > Import | File > Export",
"description": "Import-Export XModel_Export, XAnim_Export",
"warning": "Alpha version, please report any bugs!",
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/Call_of_Duty_IO", # nopep8
"tracker_url": "http://projects.blender.org/tracker/index.php?func=detail&aid=30482", # nopep8
"category": "Import-Export"
}
def update_submenu_mode(self, context):
try:
unregister()
except:
pass
register()
def update_scale_length(self, context):
unit_map = {
'CENTI': 0.01,
'MILLI': 0.001,
'METER': 1.0,
'KILO': 1000.0,
'INCH': 0.0254,
'FOOT': 0.3048,
'YARD': 0.9144,
'MILE': 1609.343994,
}
if self.unit_enum in unit_map:
self.scale_length = unit_map[self.unit_enum]
class BlenderCoD_Preferences(AddonPreferences):
bl_idname = __name__
use_submenu: BoolProperty(
name="Group Import/Export Buttons",
default=False,
update=update_submenu_mode
)
unit_enum: EnumProperty(
items=(('CENTI', "Centimeters", ""),
('MILLI', "Millimeters", ""),
('METER', "Meters", ""),
('KILO', "Kilometers", ""),
('INCH', "Inches", ""),
('FOOT', "Feet", ""),
('YARD', "Yards", ""),
('MILE', "Miles", ""),
('CUSTOM', "Custom", ""),
),
name="Default Unit",
description="The default unit to interpret one Blender Unit as when "
"no units are specified in the scene presets",
default='INCH',
update=update_scale_length
)
scale_length: FloatProperty(
name="Unit Scale",
description="Scale factor to use, follows the same conventions as "
"Blender's unit scale in the scene properties\n"
"(Is the conversion factor to convert one Blender unit to "
"one meter)",
soft_min=0.001,
soft_max=100.0,
min=0.00001,
max=100000.0,
precision=6,
step=1,
default=1.0
)
def draw(self, context):
layout = self.layout
row = layout.row()
row.prop(self, "use_submenu")
# Scale Options
col = row.column(align=True)
col.label(text="Units:")
sub = col.split(align=True)
sub.prop(self, "unit_enum", text="")
sub = col.split(align=True)
sub.enabled = self.unit_enum == 'CUSTOM'
sub.prop(self, "scale_length")
# To support reload properly, try to access a package var, if it's there,
# reload everything
if "bpy" in locals():
import importlib
if "import_xmodel" in locals():
importlib.reload(import_xmodel)
if "export_xmodel" in locals():
importlib.reload(export_xmodel)
if "import_xanim" in locals():
importlib.reload(import_xanim)
if "export_xanim" in locals():
importlib.reload(export_xanim)
if "shared" in locals():
importlib.reload(shared)
if "PyCoD" in locals():
importlib.reload(PyCoD)
else:
from . import import_xmodel, export_xmodel, import_xanim, export_xanim
from . import shared
from . import PyCoD
class COD_MT_import_xmodel(bpy.types.Operator, ImportHelper):
bl_idname = "import_scene.xmodel"
bl_label = "Import XModel"
bl_description = "Import a CoD XMODEL_EXPORT / XMODEL_BIN File"
bl_options = {'PRESET'}
filename_ext = ".XMODEL_EXPORT;.XMODEL_BIN"
filter_glob: StringProperty(
default="*.XMODEL_EXPORT;*.XMODEL_BIN",
options={'HIDDEN'}
)
ui_tab: EnumProperty(
items=(('MAIN', "Main", "Main basic settings"),
('ARMATURE', "Armature", "Armature-related settings"),
),
name="ui_tab",
description="Import options categories",
default='MAIN'
)
global_scale: FloatProperty(
name="Scale",
min=0.001, max=1000.0,
default=1.0,
)
apply_unit_scale: BoolProperty(
name="Apply Unit",
description="Scale all data according to current Blender size,"
" to match CoD units",
default=True,
)
use_single_mesh: BoolProperty(
name="Combine Meshes",
description="Combine all meshes in the file into a single object", # nopep8
default=True
)
use_dup_tris: BoolProperty(
name="Import Duplicate Tris",
description=("Import tris that reuse the same vertices as another tri "
"(otherwise they are discarded)"),
default=True
)
use_custom_normals: BoolProperty(
name="Import Normals",
description=("Import custom normals, if available "
"(otherwise Blender will recompute them)"),
default=True
)
use_vertex_colors: BoolProperty(
name="Import Vertex Colors",
default=True
)
use_armature: BoolProperty(
name="Import Armature",
description="Import the skeleton",
default=True
)
use_parents: BoolProperty(
name="Import Relationships",
description="Import the parent / child bone relationships",
default=True
)
"""
force_connect_children : BoolProperty(
name="Force Connect Children",
description=("Force connection of children bones to their parent, "
"even if their computed head/tail "
"positions do not match"),
default=False,
)
""" # nopep8
attach_model: BoolProperty(
name="Attach Model",
description="Attach head to body, gun to hands, etc.",
default=False
)
merge_skeleton: BoolProperty(
name="Merge Skeletons",
description="Merge imported skeleton with the selected skeleton",
default=False
)
use_image_search: BoolProperty(
name="Image Search",
description=("Search subdirs for any associated images "
"(Warning, may be slow)"),
default=True
)
def execute(self, context):
from . import import_xmodel
start_time = time.perf_counter()
keywords = self.as_keywords(ignore=("filter_glob",
"check_existing",
"ui_tab"))
result = import_xmodel.load(self, context, **keywords)
if not result:
self.report({'INFO'}, "Import finished in %.4f sec." %
(time.perf_counter() - start_time))
return {'FINISHED'}
else:
self.report({'ERROR'}, result)
return {'CANCELLED'}
@classmethod
def poll(self, context):
return (context.scene is not None)
def draw(self, context):
layout = self.layout
layout.prop(self, 'ui_tab', expand=True)
if self.ui_tab == 'MAIN':
# Orientation (Possibly)
# Axis Options (Possibly)
row = layout.row(align=True)
row.prop(self, "global_scale")
sub = row.row(align=True)
sub.prop(self, "apply_unit_scale", text="")
layout.prop(self, 'use_single_mesh')
layout.prop(self, 'use_custom_normals')
layout.prop(self, 'use_vertex_colors')
layout.prop(self, 'use_dup_tris')
layout.prop(self, 'use_image_search')
elif self.ui_tab == 'ARMATURE':
layout.prop(self, 'use_armature')
col = layout.column()
col.enabled = self.use_armature
col.prop(self, 'use_parents')
# Possibly support force_connect_children?
# sub = col.split()
# sub.enabled = self.use_parents
# sub.prop(self, 'force_connect_children')
col.prop(self, 'attach_model')
sub = col.split()
sub.enabled = self.attach_model
sub.prop(self, 'merge_skeleton')
class COD_MT_import_xanim(bpy.types.Operator, ImportHelper):
bl_idname = "import_scene.xanim"
bl_label = "Import XAnim"
bl_description = "Import a CoD XANIM_EXPORT / XANIM_BIN File"
bl_options = {'PRESET'}
filename_ext = ".XANIM_EXPORT;.NT_EXPORT;.XANIM_BIN"
filter_glob: StringProperty(
default="*.XANIM_EXPORT;*.NT_EXPORT;*.XANIM_BIN",
options={'HIDDEN'}
)
files: CollectionProperty(type=bpy.types.PropertyGroup)
global_scale: FloatProperty(
name="Scale",
min=0.001, max=1000.0,
default=1.0,
)
apply_unit_scale: BoolProperty(
name="Apply Unit",
description="Scale all data according to current Blender size,"
" to match CoD units",
default=True,
)
use_actions: BoolProperty(
name="Import as Action(s)",
description=("Import each animation as a separate action "
"instead of appending to the current action"),
default=True
)
use_actions_skip_existing: BoolProperty(
name="Skip Existing Actions",
description="Skip animations that already have existing actions",
default=False
)
use_notetracks: BoolProperty(
name="Import Notetracks",
description=("Import notes to scene timeline markers "
"(or action pose markers if 'Import as Action' is enabled)"), # nopep8
default=True
)
use_notetrack_file: BoolProperty(
name="Import NT_EXPORT File",
description=("Automatically import the matching NT_EXPORT file "
"(if present) for each XANIM_EXPORT"),
default=True
)
fps_scale_type: EnumProperty(
name="Scale FPS",
description="Automatically convert all imported animation(s) to the specified framerate", # nopep8
items=(('DISABLED', "Disabled", "No framerate adjustments are applied"), # nopep8
('SCENE', "Scene", "Use the scene's framerate"),
('CUSTOM', "Custom", "Use custom framerate")
),
default='DISABLED',
)
fps_scale_target_fps: FloatProperty(
name="Target FPS",
description=("Custom framerate that all imported anims "
"will be adjusted to use"),
default=30,
min=1,
max=120
)
update_scene_fps: BoolProperty(
name="Update Scene FPS",
description=("Set the scene framerate to match the framerate "
"found in the first imported animation"),
default=False
)
anim_offset: FloatProperty(
name="Animation Offset",
description="Offset to apply to animation during import, in frames",
default=1.0,
)
def execute(self, context):
from . import import_xanim
start_time = time.perf_counter()
ignored_properties = ("filter_glob", "files", "apply_unit_scale")
result = import_xanim.load(
self,
context,
self.apply_unit_scale,
**self.as_keywords(ignore=ignored_properties))
if not result:
self.report({'INFO'}, "Import finished in %.4f sec." %
(time.perf_counter() - start_time))
return {'FINISHED'}
else:
self.report({'ERROR'}, result)
return {'CANCELLED'}
@classmethod
def poll(self, context):
return (context.scene is not None)
def draw(self, context):
layout = self.layout
row = layout.row(align=True)
row.prop(self, "global_scale")
sub = row.row(align=True)
sub.prop(self, "apply_unit_scale", text="")
layout.prop(self, 'use_actions')
sub = layout.split()
sub.enabled = self.use_actions
sub.prop(self, 'use_actions_skip_existing')
layout.prop(self, 'use_notetracks')
sub = layout.split()
sub.enabled = self.use_notetracks
sub.prop(self, 'use_notetrack_file')
sub = layout.box()
split = sub.split(factor=0.55)
split.label(text="Scale FPS:")
split.prop(self, 'fps_scale_type', text="")
if self.fps_scale_type == 'DISABLED':
sub.prop(self, "update_scene_fps")
elif self.fps_scale_type == 'SCENE':
sub.label(text="Target Framerate: %.2f" % context.scene.render.fps)
elif self.fps_scale_type == 'CUSTOM':
sub.prop(self, 'fps_scale_target_fps')
layout.prop(self, 'anim_offset')
class COD_MT_export_xmodel(bpy.types.Operator, ExportHelper):
bl_idname = "export_scene.xmodel"
bl_label = 'Export XModel'
bl_description = "Export a CoD XMODEL_EXPORT / XMODEL_BIN File"
bl_options = {'PRESET'}
filename_ext = ".XMODEL_EXPORT"
filter_glob: StringProperty(
default="*.XMODEL_EXPORT;*.XMODEL_BIN", options={'HIDDEN'})
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
# Used to map target_format values to actual file extensions
format_ext_map = {
'XMODEL_EXPORT': '.XMODEL_EXPORT',
'XMODEL_BIN': '.XMODEL_BIN'
}
target_format: EnumProperty(
name="Format",
description="The target format to export to",
items=(('XMODEL_EXPORT', "XMODEL_EXPORT",
"Raw text format used from CoD1-CoD:BO"),
('XMODEL_BIN', "XMODEL_BIN",
"Binary model format used by CoD:BO3")),
default='XMODEL_EXPORT'
)
version: EnumProperty(
name="Version",
description="XMODEL_EXPORT format version for export",
items=(('5', "Version 5", "vCoD, CoD:UO"),
('6', "Version 6", "CoD2, CoD4, CoD:WaW, CoD:BO"),
('7', "Version 7", "CoD:BO3")),
default='6'
)
use_selection: BoolProperty(
name="Selection only",
description=("Export selected meshes only "
"(object or weight paint mode)"),
default=False
)
global_scale: FloatProperty(
name="Scale",
min=0.001, max=1000.0,
default=1.0,
)
apply_unit_scale: BoolProperty(
name="Apply Unit",
description="Scale all data according to current Blender size,"
" to match CoD units",
default=True,
)
use_vertex_colors: BoolProperty(
name="Vertex Colors",
description=("Export vertex colors "
"(if disabled, white color will be used)"),
default=True
)
# White is 1 (opaque), black 0 (invisible)
use_vertex_colors_alpha: BoolProperty(
name="Calculate Alpha",
description=("Automatically calculate alpha channel for vertex colors "
"by averaging the RGB color values together "
"(if disabled, 1.0 is used)"),
default=False
)
use_vertex_colors_alpha_mode: EnumProperty(
name="Vertex Alpha Source Layer",
description="The target vertex color layer to use for calculating the alpha values", # nopep8
items=(('PRIMARY', "Active Layer",
"Use the active vertex color layer to calculate alpha"),
('SECONDARY', "Secondary Layer",
("Use the secondary (first inactive) vertex color layer to calculate alpha " # nopep8
"(If only one layer is present, the active layer is used)")),
),
default='PRIMARY'
)
use_vertex_cleanup: BoolProperty(
name="Clean Up Vertices",
description=("Try this if you have problems converting to xmodel. "
"Skips vertices which aren't used by any face "
"and updates references."),
default=False
)
apply_modifiers: BoolProperty(
name="Apply Modifiers",
description="Apply all mesh modifiers (except Armature)",
default=False
)
modifier_quality: EnumProperty(
name="Modifier Quality",
description="The quality at which to apply mesh modifiers",
items=(('PREVIEW', "Preview", ""),
('RENDER', "Render", ""),
),
default='PREVIEW'
)
use_armature: BoolProperty(
name="Armature",
description=("Export bones "
"(if disabled, only a 'tag_origin' bone will be written)"), # nopep8
default=True
)
"""
use_armature_pose : BoolProperty(
name="Pose animation to models",
description=("Export meshes with Armature modifier applied "
"as a series of XMODEL_EXPORT files"),
default=False
)
frame_start : IntProperty(
name="Start",
description="First frame to export",
default=1,
min=0
)
frame_end : IntProperty(
name="End",
description="Last frame to export",
default=250,
min=0
)
"""
use_weight_min: BoolProperty(
name="Minimum Bone Weight",
description=("Try this if you get 'too small weight' "
"errors when converting"),
default=False,
)
use_weight_min_threshold: FloatProperty(
name="Threshold",
description="Smallest allowed weight (minimum value)",
default=0.010097,
min=0.0,
max=1.0,
precision=6
)
def execute(self, context):
from . import export_xmodel
start_time = time.perf_counter()
ignore = ("filter_glob", "check_existing")
result = export_xmodel.save(self, context,
**self.as_keywords(ignore=ignore))
if not result:
self.report({'INFO'}, "Export finished in %.4f sec." %
(time.perf_counter() - start_time))
return {'FINISHED'}
else:
self.report({'ERROR'}, result)
return {'CANCELLED'}
@classmethod
def poll(self, context):
return (context.scene is not None)
def check(self, context):
'''
This is a modified version of the ExportHelper check() method
This one provides automatic checking for the file extension
based on what 'target_format' is (through 'format_ext_map')
'''
import os
from bpy_extras.io_utils import _check_axis_conversion
change_ext = False
change_axis = _check_axis_conversion(self)
check_extension = self.check_extension
if check_extension is not None:
filepath = self.filepath
if os.path.basename(filepath):
# If the current extension is one of the valid extensions
# (as defined by this class), strip the extension, and ensure
# that it has the correct one
# (needed when switching extensions)
base, ext = os.path.splitext(filepath)
if ext[1:] in self.format_ext_map:
filepath = base
target_ext = self.format_ext_map[self.target_format]
filepath = bpy.path.ensure_ext(filepath,
target_ext
if check_extension
else "")
if filepath != self.filepath:
self.filepath = filepath
change_ext = True
return (change_ext or change_axis)
# Extend ExportHelper invoke function to support dynamic default values
def invoke(self, context, event):
# self.use_frame_start = context.scene.frame_start
self.use_frame_start = context.scene.frame_current
# self.use_frame_end = context.scene.frame_end
self.use_frame_end = context.scene.frame_current
return super().invoke(context, event)
def draw(self, context):
layout = self.layout
layout.prop(self, 'target_format', expand=True)
layout.prop(self, 'version')
# Calculate number of selected mesh objects
if context.mode in ('OBJECT', 'PAINT_WEIGHT'):
objects = bpy.data.objects
meshes_selected = len(
[m for m in objects if m.type == 'MESH' and m.select_get()])
else:
meshes_selected = 0
layout.prop(self, 'use_selection',
text="Selected Only (%d meshes)" % meshes_selected)
row = layout.row(align=True)
row.prop(self, "global_scale")
sub = row.row(align=True)
sub.prop(self, "apply_unit_scale", text="")
# Axis?
sub = layout.split(factor=0.5)
sub.prop(self, 'apply_modifiers')
sub = sub.row()
sub.enabled = self.apply_modifiers
sub.prop(self, 'modifier_quality', expand=True)
# layout.prop(self, 'custom_normals')
if int(self.version) >= 6:
row = layout.row()
row.prop(self, 'use_vertex_colors')
sub = row.split()
sub.enabled = self.use_vertex_colors
sub.prop(self, 'use_vertex_colors_alpha')
sub = layout.split()
sub.enabled = (self.use_vertex_colors and
self.use_vertex_colors_alpha)
sub = sub.split(factor=0.5)
sub.label(text="Vertex Alpha Layer")
sub.prop(self, 'use_vertex_colors_alpha_mode', text="")
layout.prop(self, 'use_vertex_cleanup')
layout.prop(self, 'use_armature')
box = layout.box()
box.enabled = self.use_armature
sub = box.column(align=True)
sub.prop(self, 'use_weight_min')
sub = box.split(align=True)
sub.active = self.use_weight_min
sub.prop(self, 'use_weight_min_threshold')
class COD_MT_export_xanim(bpy.types.Operator, ExportHelper):
bl_idname = "export_scene.xanim"
bl_label = 'Export XAnim'
bl_description = "Export a CoD XANIM_EXPORT / XANIM_BIN File"
bl_options = {'PRESET'}
filename_ext = ".XANIM_EXPORT"
filter_glob: StringProperty(
default="*.XANIM_EXPORT;*.XANIM_BIN", options={'HIDDEN'})
# Used to map target_format values to actual file extensions
format_ext_map = {
'XANIM_EXPORT': '.XANIM_EXPORT',
'XANIM_BIN': '.XANIM_BIN'
}
target_format: EnumProperty(
name="Format",
description="The target format to export to",
items=(('XANIM_EXPORT', "XANIM_EXPORT",
"Raw text format used from CoD1-CoD:BO"),
('XANIM_BIN', "XANIM_BIN",
"Binary animation format used by CoD:BO3")),
default='XANIM_EXPORT'
)
use_selection: BoolProperty(
name="Selection Only",
description="Export selected bones only (pose mode)",
default=False
)
global_scale: FloatProperty(
name="Scale",
min=0.001, max=1000.0,
default=1.0,
)
apply_unit_scale: BoolProperty(
name="Apply Unit",
description="Scale all data according to current Blender size,"
" to match CoD units",
default=True,
)
use_all_actions: BoolProperty(
name="Export All Actions",
description="Export *all* actions rather than just the active one",
default=False
)
filename_format: StringProperty(
name="Format",
description=("The format string for the filenames when exporting multiple actions\n" # nopep8
"%action, %s - The action name\n"
"%number, %d - The action number\n"
"%base, %b - The base filename (at the top of the export window)\n" # nopep8
""),
default="%action"
)
use_notetracks: BoolProperty(
name="Notetracks",
description="Export notetracks",
default=True
)
use_notetrack_mode: EnumProperty(
name="Notetrack Mode",
description="Notetrack format to use. Always set 'CoD 7' for Black Ops, even if not using notetrack!", # nopep8
items=(('SCENE', "Scene",
"Separate NT_EXPORT notetrack file for 'World at War'"),
('ACTION', "Action",
"Separate NT_EXPORT notetrack file for 'Black Ops'")),
default='ACTION'
)
use_notetrack_format: EnumProperty(
name="Notetrack format",
description=("Notetrack format to use. "
"Always set 'CoD 7' for Black Ops, "
"even if not using notetrack!"),
items=(('5', "CoD 5",
"Separate NT_EXPORT notetrack file for 'World at War'"),
('7', "CoD 7",
"Separate NT_EXPORT notetrack file for 'Black Ops'"),
('1', "all other",
"Inline notetrack data for all CoD versions except WaW and BO")
),
default='1'
)
use_notetrack_file: BoolProperty(
name="Write NT_EXPORT",
description=("Create an NT_EXPORT file for "
"the exported XANIM_EXPORT file(s)"),
default=False
)
use_frame_range_mode: EnumProperty(
name="Frame Range Mode",
description="Decides what to use for the frame range",
items=(('SCENE', "Scene", "Use the scene's frame range"),
('ACTION', "Action", "Use the frame range from each action"),
('CUSTOM', "Custom", "Use a user-defined frame range")),
default='ACTION'
)
frame_start: IntProperty(
name="Start",
description="First frame to export",
min=0,
default=1
)
frame_end: IntProperty(
name="End",
description="Last frame to export",
min=0,
default=250
)
use_custom_framerate: BoolProperty(
name="Custom Framerate",
description=("Force all written files to use a user defined "
"custom framerate rather than the scene's framerate"),
default=False
)
use_framerate: IntProperty(
name="Framerate",
description=("Set frames per second for export, "
"30 fps is commonly used."),
default=30,
min=1,
max=1000
)
def execute(self, context):
from . import export_xanim
start_time = time.perf_counter()
result = export_xanim.save(
self,
context,
**self.as_keywords(ignore=("filter_glob", "check_existing")))
if not result:
msg = "Export finished in %.4f sec." % (time.perf_counter() - start_time)
self.report({'INFO'}, msg)
return {'FINISHED'}
else:
self.report({'ERROR'}, result)
return {'CANCELLED'}
@classmethod
def poll(self, context):
return (context.scene is not None)
def check(self, context):
'''
This is a modified version of the ExportHelper check() method
This one provides automatic checking for the file extension
based on what 'target_format' is (through 'format_ext_map')
'''
import os
from bpy_extras.io_utils import _check_axis_conversion
change_ext = False
change_axis = _check_axis_conversion(self)
check_extension = self.check_extension
if check_extension is not None:
filepath = self.filepath
if os.path.basename(filepath):
# If the current extension is one of the valid extensions
# (as defined by this class), strip the extension, and ensure
# that it has the correct one
# (needed when switching extensions)
base, ext = os.path.splitext(filepath)
if ext[1:] in self.format_ext_map:
filepath = base
target_ext = self.format_ext_map[self.target_format]
filepath = bpy.path.ensure_ext(filepath,
target_ext
if check_extension
else "")
if filepath != self.filepath:
self.filepath = filepath
change_ext = True
return (change_ext or change_axis)
'''
# Extend ExportHelper invoke function to support dynamic default values
def invoke(self, context, event):
self.use_frame_start = context.scene.frame_start
self.use_frame_end = context.scene.frame_end
# self.use_framerate = round(
# context.scene.render.fps / context.scene.render.fps_base)
return super().invoke(context, event)
'''
def draw(self, context):
layout = self.layout
layout.prop(self, 'target_format', expand=True)
layout.prop(self, 'use_selection')
row = layout.row(align=True)
row.prop(self, "global_scale")
sub = row.row(align=True)
sub.prop(self, "apply_unit_scale", text="")
action_count = len(bpy.data.actions)
sub = layout.split()
sub.enabled = action_count > 0
sub.prop(self, 'use_all_actions',
text='Export All Actions (%d actions)' % action_count)
# Filename Options
if self.use_all_actions and action_count > 0:
sub = layout.column(align=True)
sub.label(text="Filename Options:")
box = sub.box()
sub = box.column(align=True)
sub.prop(self, 'filename_format')
ex_num = action_count - 1
ex_action = bpy.data.actions[ex_num].name
ex_base = os.path.splitext(os.path.basename(self.filepath))[0]
try:
icon = 'NONE'
from . import export_xanim
template = export_xanim.CustomTemplate(self.filename_format)
example = template.format(ex_action, ex_base, ex_num)
except Exception as err:
icon = 'ERROR'
example = str(err)
sub.label(text=example, icon=icon)
# Notetracks
col = layout.column(align=True)
sub = col.row()
sub = sub.split(factor=0.45)
sub.prop(self, 'use_notetracks', text="Use Notetrack")
sub.row().prop(self, 'use_notetrack_mode', expand=True)
sub = col.column()
sub.enabled = self.use_notetrack_mode != 'NONE'
sub = sub.split()
sub.enabled = self.use_notetracks
sub.prop(self, 'use_notetrack_file')
# Framerate
layout.prop(self, 'use_custom_framerate')
sub = layout.split()
sub.enabled = self.use_custom_framerate
sub.prop(self, 'use_framerate')
# Frame Range
sub = layout.row()
sub.label(text="Frame Range:")
sub.prop(self, 'use_frame_range_mode', text="")
sub = layout.row(align=True)
sub.enabled = self.use_frame_range_mode == 'CUSTOM'
sub.prop(self, 'frame_start')
sub.prop(self, 'frame_end')