forked from johnzero7/XNALaraMesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xps_tools.py
931 lines (758 loc) · 28.1 KB
/
xps_tools.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
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
# -*- coding: utf-8 -*-
# <pep8 compliant>
from . import export_xnalara_model
from . import export_xnalara_pose
from . import import_xnalara_model
from . import import_xnalara_pose
from . import material_creator
from . import xps_types
import bpy
import os
from bpy.props import (
BoolProperty,
FloatProperty,
StringProperty,
EnumProperty,
)
from bpy_extras.io_utils import (
ImportHelper,
ExportHelper,
orientation_helper,
path_reference_mode,
axis_conversion,
)
uv_x_displace = 0
uv_y_displace = 0
class Import_Xps_Model_Op(bpy.types.Operator, ImportHelper):
'''Load an XNALara model File'''
bl_idname = "xps_tools.import_model"
bl_label = "Import XNALara/XPS Model"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_options = {'REGISTER', 'UNDO'}
filename_ext = ".mesh"
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
# filter File Extension
filter_glob : bpy.props.StringProperty(
default="*.ascii;*.mesh;*.xps",
options={'HIDDEN'},
)
uvDisplX : bpy.props.IntProperty(
name="X",
description="Displace UV X axis",
default=uv_x_displace,
)
uvDisplY : bpy.props.IntProperty(
name="Y",
description="Displace UV Y axis",
default=uv_y_displace,
)
impDefPose : bpy.props.BoolProperty(
name="Default Pose",
description="Import Default Pose",
default=False,
)
markSeams : bpy.props.BoolProperty(
name="Mark Seams",
description="Mark as Seams the edged merged by the addon",
default=True,
)
vColors : bpy.props.BoolProperty(
name="Vertex Colors",
description="Import Vertex Colors",
default=True,
)
joinMeshRips : bpy.props.BoolProperty(
name="Merge Doubles by Normal",
description="Merge vertices with the same position and normal",
default=True,
)
joinMeshParts : bpy.props.BoolProperty(
name="Join MeshParts",
description="Join MeshParts (meshes that contain 'nPart!' in the name)",
default=True,
)
connectBones : bpy.props.BoolProperty(
name="Connect Bones",
description="Connect Bones all bones",
default=True,
)
autoIk : bpy.props.BoolProperty(
name="AutoIK",
description="Set AutoIK",
default=True,
)
importNormals : bpy.props.BoolProperty(
name="Import Normals",
description="Import Custom Normals",
default=True,
)
# Only needed if you want to add into a dynamic menu
def menu_func(self, context):
self.layout.operator_context = 'INVOKE_DEFAULT'
self.layout.operator(
Import_Xps_Model_Op.bl_idname,
text="Text Export Operator")
@classmethod
def poll(cls, context):
# Always can import
return True
def execute(self, context):
xpsSettings = xps_types.XpsImportSettings(
self.filepath,
self.uvDisplX,
self.uvDisplY,
self.impDefPose,
self.joinMeshRips,
self.joinMeshParts,
self.markSeams and self.joinMeshRips,
self.vColors,
self.connectBones,
self.autoIk,
self.importNormals
)
material_creator.create_group_nodes()
status = import_xnalara_model.getInputFilename(xpsSettings)
if status == '{NONE}':
# self.report({'DEBUG'}, "DEBUG File Format unrecognized")
# self.report({'INFO'}, "INFO File Format unrecognized")
# self.report({'OPERATOR'}, "OPERATOR File Format unrecognized")
# self.report({'WARNING'}, "WARNING File Format unrecognized")
# self.report({'ERROR'}, "ERROR File Format unrecognized")
self.report({'ERROR'}, "ERROR File Format unrecognized")
return {'FINISHED'}
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
col.label(text='UV Displace')
col.prop(self, "uvDisplX")
col.prop(self, "uvDisplY")
col = layout.column(align=True)
col.label(text='Mesh')
col.prop(self, "joinMeshParts")
col.prop(self, "joinMeshRips")
sub = col.row()
sub.prop(self, "markSeams")
col.prop(self, "importNormals")
col.prop(self, "vColors")
sub.enabled = self.joinMeshRips
self.markSeams = self.joinMeshRips and self.markSeams
col = layout.column(align=True)
col.label(text='Armature')
col.prop(self, "impDefPose")
col.prop(self, "connectBones")
col.prop(self, "autoIk")
class Export_Xps_Model_Op(bpy.types.Operator, ExportHelper):
'''Save an XNALara model File'''
bl_idname = "xps_tools.export_model"
bl_label = "Export XNALara/XPS Model"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_options = {'REGISTER'}
# filename_ext = '.mesh';
filename_ext : bpy.props.EnumProperty(
name='Format',
description='Choose Export Format',
items=(
('.xps', 'XPS', 'Export as XPS Binary format (.xps)'),
('.mesh', 'MESH', 'Export as XnaLara/XPS Binary format (.mesh)'),
('.ascii', 'ASCII', 'Export as XnaLara/XPS Ascii format (.ascii)'),
),
default='.xps',
)
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
# filter File Extension
filter_glob : bpy.props.StringProperty(
default="*.ascii;*.mesh;*.xps",
options={'HIDDEN'},
)
uvDisplX : bpy.props.IntProperty(
name="X",
description="Displace UV X axis",
default=uv_x_displace,
)
uvDisplY : bpy.props.IntProperty(
name="Y",
description="Displace UV Y axis",
default=uv_y_displace,
)
expDefPose : bpy.props.BoolProperty(
name="Default Pose",
description="Export Default Pose",
default=False,
)
exportOnlySelected : bpy.props.BoolProperty(
name="Export Only Selected",
description="Export only selected objects",
default=True,
)
exportNormals : bpy.props.BoolProperty(
name="Export Normals",
description="Export Custom Normals",
default=True,
)
preserveSeams : bpy.props.BoolProperty(
name="Preserve Seams",
description="Split Edges marked as seams. They are marked as seams when imported back",
default=True,
)
vColors : bpy.props.BoolProperty(
name="Vertex Colors",
description="Export Vertex Colors",
default=True,
)
@classmethod
def poll(cls, context):
return bool(
next(
(obj for obj in context.selected_objects if obj.type == 'MESH'),
None))
def execute(self, context):
xpsSettings = xps_types.XpsExportSettings(
self.filepath,
self.uvDisplX,
self.uvDisplY,
self.exportOnlySelected,
self.expDefPose,
self.preserveSeams,
self.vColors,
self.exportNormals
)
export_xnalara_model.getOutputFilename(xpsSettings)
return {'FINISHED'}
def draw(self, context):
layout = self.layout
layout.prop(self, "exportOnlySelected")
layout.label(text="File Format:")
layout.prop(self, "filename_ext", expand=True)
isBinary = self.filename_ext in ('.mesh', '.xps')
col = layout.column(align=True)
col.label(text='Mesh')
col.prop(self, "preserveSeams")
col.prop(self, "exportNormals")
col.prop(self, "vColors")
col = layout.column(align=True)
col.label(text='UV Displace')
col.prop(self, "uvDisplX")
col.prop(self, "uvDisplY")
layout.prop(self, "expDefPose")
class Import_Xps_Pose_Op(bpy.types.Operator, ImportHelper):
'''Load an XNALara pose File'''
bl_idname = "xps_tools.import_pose"
bl_label = "Import XNALara/XPS Pose"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_options = {'REGISTER', 'UNDO'}
filename_ext = '.pose'
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
# filter File Extension
filter_glob : bpy.props.StringProperty(
default="*.pose",
options={'HIDDEN'},
)
@classmethod
def poll(cls, context):
return context.active_object and context.active_object.type == 'ARMATURE'
def execute(self, context):
import_xnalara_pose.getInputFilename(self.filepath)
return {'FINISHED'}
class Export_Xps_Pose_Op(bpy.types.Operator, ExportHelper):
'''Save an XNALara pose File'''
bl_idname = "xps_tools.export_pose"
bl_label = "Export XNALara/XPS Pose"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_options = {'REGISTER'}
filename_ext = '.pose'
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
# filter File Extension
filter_glob : bpy.props.StringProperty(
default="*.pose",
options={'HIDDEN'},
)
@classmethod
def poll(cls, context):
return context.active_object and context.active_object.type == 'ARMATURE'
def execute(self, context):
export_xnalara_pose.getOutputFilename(self.filepath)
return {'FINISHED'}
class Import_Poses_To_Keyframes_Op(bpy.types.Operator, ImportHelper):
'''Load a sequence of posese as keyframes'''
bl_idname = "xps_tools.import_poses_to_keyframes"
bl_label = "Import poses to keyframes"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_options = {'REGISTER', 'UNDO'}
filename_ext = '.pose'
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
# filter File Extension
filter_glob : bpy.props.StringProperty(
default="*.pose",
options={'HIDDEN'},
)
@classmethod
def poll(cls, context):
return context.active_object and context.active_object.type == 'ARMATURE'
def execute(self, context):
import_xnalara_pose.getInputPoseSequence(self.filepath)
return {'FINISHED'}
class Export_Frames_To_Poses_Op(bpy.types.Operator, ExportHelper):
'''Save frames as poses'''
bl_idname = "xps_tools.export_frames_to_poses"
bl_label = "Export frames to poses"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_options = {'REGISTER'}
filename_ext = '.pose'
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
# filter File Extension
filter_glob : bpy.props.StringProperty(
default="*.pose",
options={'HIDDEN'},
)
@classmethod
def poll(cls, context):
return context.active_object and context.active_object.type == 'ARMATURE'
def execute(self, context):
export_xnalara_pose.getOutputPoseSequence(self.filepath)
return {'FINISHED'}
class ArmatureBoneDictGenerate_Op(bpy.types.Operator):
''' Generate a BoneDict from armature'''
bl_idname = 'xps_tools.bones_dictionary_generate'
bl_label = 'Generate BoneDict'
bl_description = 'Generate a BoneDict from active armature'
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_options = {'REGISTER'}
filename_ext = '.txt'
check_extension = True
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
filepath : bpy.props.StringProperty(
name="File Path",
description="Bone Dictionary File",
maxlen=1024,
subtype='FILE_PATH',
)
# filter File Extension
filter_glob : bpy.props.StringProperty(
default="*.txt",
options={'HIDDEN'},
)
@classmethod
def poll(cls, context):
return context.active_object.type == 'ARMATURE'
def execute(self, context):
armatureObj = context.active_object
export_xnalara_model.boneDictGenerate(self.filepath, armatureObj)
return {'FINISHED'}
def invoke(self, context, event):
if not self.filepath:
self.filepath = 'BoneDict.txt'
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def check(self, context):
import os
change_ext = False
check_extension = self.check_extension
if check_extension is not None:
filepath = self.filepath
if os.path.basename(filepath):
filepath = bpy.path.ensure_ext(filepath,
self.filename_ext
if check_extension
else "")
if filepath != self.filepath:
self.filepath = filepath
change_ext = True
return (change_ext)
class ArmatureBoneDictRename_Op(bpy.types.Operator):
bl_idname = 'xps_tools.bones_dictionary_rename'
bl_label = 'Dictionary Rename'
bl_description = 'Use BoneDict to Rename Bones'
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_options = {'REGISTER', 'UNDO'}
filename_ext = '.txt'
check_extension = True
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
filepath : bpy.props.StringProperty(
name="File Path",
description="Bone Dictionary File",
maxlen=1024,
subtype='FILE_PATH',
)
# filter File Extension
filter_glob : bpy.props.StringProperty(
default="*.txt",
options={'HIDDEN'},
)
@classmethod
def poll(cls, context):
return bool(
next(
(obj for obj in context.selected_objects if obj.type == 'ARMATURE'),
None))
def execute(self, context):
armatureObj = next((obj for obj in context.selected_objects if obj.type == 'ARMATURE'), None)
import_xnalara_model.boneDictRename(self.filepath, armatureObj)
return {'FINISHED'}
def invoke(self, context, event):
if not self.filepath:
self.filepath = 'BoneDict.txt'
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def check(self, context):
import os
change_ext = False
check_extension = self.check_extension
if check_extension is not None:
filepath = self.filepath
if os.path.basename(filepath):
filepath = bpy.path.ensure_ext(filepath,
self.filename_ext
if check_extension
else "")
if filepath != self.filepath:
self.filepath = filepath
change_ext = True
return (change_ext)
class ArmatureBoneDictRestore_Op(bpy.types.Operator):
bl_idname = 'xps_tools.bones_dictionary_restore_name'
bl_label = 'Dictionary Restore Names'
bl_description = 'Use BoneDict to Restore Bone Names'
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_options = {'REGISTER', 'UNDO'}
filename_ext = '.txt'
check_extension = True
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
filepath : bpy.props.StringProperty(
name="File Path",
description="Bone Dictionary File",
maxlen=1024,
subtype='FILE_PATH',
)
# filter File Extension
filter_glob : bpy.props.StringProperty(
default="*.txt",
options={'HIDDEN'},
)
@classmethod
def poll(cls, context):
return bool(
next(
(obj for obj in context.selected_objects if obj.type == 'ARMATURE'),
None))
def execute(self, context):
armatureObj = next((obj for obj in context.selected_objects if obj.type == 'ARMATURE'), None)
import_xnalara_model.boneDictRestore(self.filepath, armatureObj)
return {'FINISHED'}
def invoke(self, context, event):
if not self.filepath:
self.filepath = 'BoneDict.txt'
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def check(self, context):
import os
change_ext = False
check_extension = self.check_extension
if check_extension is not None:
filepath = self.filepath
if os.path.basename(filepath):
filepath = bpy.path.ensure_ext(filepath,
self.filename_ext
if check_extension
else "")
if filepath != self.filepath:
self.filepath = filepath
change_ext = True
return (change_ext)
@orientation_helper(axis_forward='-Z', axis_up='Y')
class ImportXpsNgff(bpy.types.Operator, ImportHelper):
"""Load a Wavefront OBJ File"""
bl_idname = "import_xps_ngff.obj"
bl_label = "Import XPS NGFF"
bl_options = {'PRESET', 'UNDO'}
filename_ext = ".obj"
filter_glob : bpy.props.StringProperty(
default="*.obj;*.mtl;*.arl",
options={'HIDDEN'},
)
use_edges : bpy.props.BoolProperty(
name="Lines",
description="Import lines and faces with 2 verts as edge",
default=True,
)
use_smooth_groups : bpy.props.BoolProperty(
name="Smooth Groups",
description="Surround smooth groups by sharp edges",
default=True,
)
use_split_objects : bpy.props.BoolProperty(
name="Object",
description="Import OBJ Objects into Blender Objects",
default=True,
)
use_split_groups : bpy.props.BoolProperty(
name="Group",
description="Import OBJ Groups into Blender Objects",
default=True,
)
use_groups_as_vgroups : bpy.props.BoolProperty(
name="Poly Groups",
description="Import OBJ groups as vertex groups",
default=False,
)
use_image_search : bpy.props.BoolProperty(
name="Image Search",
description="Search subdirs for any associated images "
"(Warning, may be slow)",
default=True,
)
split_mode : bpy.props.EnumProperty(
name="Split",
items=(('ON', "Split", "Split geometry, omits unused verts"),
('OFF', "Keep Vert Order", "Keep vertex order from file"),
),
)
global_clamp_size : bpy.props.FloatProperty(
name="Clamp Size",
description="Clamp bounds under this value (zero to disable)",
min=0.0, max=1000.0,
soft_min=0.0, soft_max=1000.0,
default=0.0,
)
def execute(self, context):
# print("Selected: " + context.active_object.name)
from . import import_obj
if self.split_mode == 'OFF':
self.use_split_objects = False
self.use_split_groups = False
else:
self.use_groups_as_vgroups = False
keywords = self.as_keywords(ignore=("axis_forward",
"axis_up",
"filter_glob",
"split_mode",
))
global_matrix = axis_conversion(from_forward=self.axis_forward,
from_up=self.axis_up,
).to_4x4()
keywords["global_matrix"] = global_matrix
if bpy.data.is_saved and context.user_preferences.filepaths.use_relative_paths:
import os
keywords["relpath"] = os.path.dirname(bpy.data.filepath)
return import_obj.load(context, **keywords)
def draw(self, context):
layout = self.layout
row = layout.row(align=True)
row.prop(self, "use_smooth_groups")
row.prop(self, "use_edges")
box = layout.box()
row = box.row()
row.prop(self, "split_mode", expand=True)
row = box.row()
if self.split_mode == 'ON':
row.label(text="Split by:")
row.prop(self, "use_split_objects")
row.prop(self, "use_split_groups")
else:
row.prop(self, "use_groups_as_vgroups")
row = layout.split(percentage=0.67)
row.prop(self, "global_clamp_size")
layout.prop(self, "axis_forward")
layout.prop(self, "axis_up")
layout.prop(self, "use_image_search")
@orientation_helper(axis_forward='-Z', axis_up='Y')
class ExportXpsNgff(bpy.types.Operator, ExportHelper):
"""Save a Wavefront OBJ File"""
bl_idname = "export_xps_ngff.obj"
bl_label = 'Export XPS NGFF'
bl_options = {'PRESET'}
filename_ext = ".obj"
filter_glob : bpy.props.StringProperty(
default="*.obj;*.mtl;*.arl",
options={'HIDDEN'},
)
# context group
use_selection : bpy.props.BoolProperty(
name="Selection Only",
description="Export selected objects only",
default=False,
)
use_animation : bpy.props.BoolProperty(
name="Animation",
description="Write out an OBJ for each frame",
default=False,
)
# object group
use_mesh_modifiers : bpy.props.BoolProperty(
name="Apply Modifiers",
description="Apply modifiers (preview resolution)",
default=True,
)
# extra data group
use_edges : bpy.props.BoolProperty(
name="Include Edges",
description="",
default=True,
)
use_smooth_groups : bpy.props.BoolProperty(
name="Smooth Groups",
description="Write sharp edges as smooth groups",
default=False,
)
use_smooth_groups_bitflags : bpy.props.BoolProperty(
name="Bitflag Smooth Groups",
description="Same as 'Smooth Groups', but generate smooth groups IDs as bitflags "
"(produces at most 32 different smooth groups, usually much less)",
default=False,
)
use_normals : bpy.props.BoolProperty(
name="Write Normals",
description="Export one normal per vertex and per face, to represent flat faces and sharp edges",
default=True,
)
use_vcolors : bpy.props.BoolProperty(
name="Write Vert Colors",
description="Export Vertex Color",
default=True,
)
use_uvs : bpy.props.BoolProperty(
name="Include UVs",
description="Write out the active UV coordinates",
default=True,
)
use_materials : bpy.props.BoolProperty(
name="Write Materials",
description="Write out the MTL file",
default=True,
)
use_triangles : bpy.props.BoolProperty(
name="Triangulate Faces",
description="Convert all faces to triangles",
default=False,
)
use_nurbs : bpy.props.BoolProperty(
name="Write Nurbs",
description="Write nurbs curves as OBJ nurbs rather than "
"converting to geometry",
default=False,
)
use_vertex_groups : bpy.props.BoolProperty(
name="Polygroups",
description="",
default=False,
)
# grouping group
use_blen_objects : bpy.props.BoolProperty(
name="Objects as OBJ Objects",
description="",
default=True,
)
group_by_object : bpy.props.BoolProperty(
name="Objects as OBJ Groups ",
description="",
default=False,
)
group_by_material : bpy.props.BoolProperty(
name="Material Groups",
description="",
default=False,
)
keep_vertex_order : bpy.props.BoolProperty(
name="Keep Vertex Order",
description="",
default=False,
)
global_scale : bpy.props.FloatProperty(
name="Scale",
min=0.01, max=1000.0,
default=1.0,
)
path_mode = path_reference_mode
check_extension = True
def execute(self, context):
from . import export_obj
from mathutils import Matrix
keywords = self.as_keywords(ignore=("axis_forward",
"axis_up",
"global_scale",
"check_existing",
"filter_glob",
))
global_matrix = (Matrix.Scale(self.global_scale, 4) *
axis_conversion(to_forward=self.axis_forward,
to_up=self.axis_up,
).to_4x4())
keywords["global_matrix"] = global_matrix
return export_obj.save(context, **keywords)
class XpsImportSubMenu(bpy.types.Menu):
bl_idname = "OBJECT_MT_xnalara_import_submenu"
bl_label = "XNALara / XPS"
def draw(self, context):
layout = self.layout
layout.operator(Import_Xps_Model_Op.bl_idname, text="XNALara/XPS Model (.ascii/.mesh/.xps)",
#icon="OUTLINER_OB_ARMATURE",
)
layout.operator(Import_Xps_Pose_Op.bl_idname, text="XNALara/XPS Pose (.pose)",
#icon="POSE_DATA",
)
layout.operator(ImportXpsNgff.bl_idname, text="XPS NGFF (.obj)"
)
class XpsExportSubMenu(bpy.types.Menu):
bl_idname = "OBJECT_MT_xnalara_export_submenu"
bl_label = "XNALara / XPS"
def draw(self, context):
layout = self.layout
layout.operator(Export_Xps_Model_Op.bl_idname, text="XNALara/XPS Model (.ascii/.mesh/.xps)",
#icon="OUTLINER_OB_ARMATURE",
)
layout.operator(Export_Xps_Pose_Op.bl_idname, text="XNALara/XPS Pose (.pose)",
#icon="POSE_DATA",
)
layout.operator(ExportXpsNgff.bl_idname, text="XPS NGFF (.obj)"
)
#
# Registration
#
def menu_func_import(self, context):
my_icon = custom_icons["main"]["xps_icon"]
self.layout.menu(XpsImportSubMenu.bl_idname, icon_value=my_icon.icon_id)
def menu_func_export(self, context):
my_icon = custom_icons["main"]["xps_icon"]
self.layout.menu(XpsExportSubMenu.bl_idname, icon_value=my_icon.icon_id)
# --------------------------------------------------------------------------------
# Custom Icons
# --------------------------------------------------------------------------------
custom_icons = {}
def registerCustomIcon():
import bpy.utils.previews
pcoll = bpy.utils.previews.new()
script_path = os.path.dirname(__file__)
icons_dir = os.path.join(script_path, "icons")
pcoll.load("xps_icon", os.path.join(icons_dir, "icon.png"), 'IMAGE')
custom_icons["main"] = pcoll
def unregisterCustomIcon():
for pcoll in custom_icons.values():
bpy.utils.previews.remove(pcoll)
custom_icons.clear()
def register():
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
registerCustomIcon()
def unregister():
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
unregisterCustomIcon()
if __name__ == "__main__":
register()