forked from reattiva/Urho3D-Blender
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path__init__.py
1617 lines (1360 loc) · 59.9 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
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
# LOD: be sure all have the same material or a new geometry is created
#
# This script is licensed as public domain.
#
# http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.props.html
# http://www.blender.org/documentation/blender_python_api_2_59_0/bpy.props.html
# http://www.blender.org/documentation/blender_python_api_2_66_4/bpy.props.html
# http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.Panel.html
# http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.PropertyGroup.html
# http://www.blender.org/documentation/blender_python_api_2_66_4/bpy.types.WindowManager.html
# http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Layouts
# http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Properties
# http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Interface
# http://wiki.blender.org/index.php/Dev:IT/2.5/Py/Scripts/Cookbook/Code_snippets/Interface
# http://wiki.blender.org/index.php/Dev:IT/2.5/Py/Scripts/Cookbook/Code_snippets/Multi-File_packages
# http://wiki.blender.org/index.php/Doc:2.6/Manual/Extensions/Python/Properties
# http://www.blender.org/documentation/blender_python_api_2_66_4/info_tutorial_addon.html
DEBUG = 0
if DEBUG: print("Urho export init")
bl_info = {
"name": "Urho3D export",
"description": "Urho3D export",
"author": "reattiva",
"version": (0, 6),
"blender": (2, 83, 0),
"location": "Properties > Render > Urho export",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Import-Export"}
if "decompose" in locals():
import imp
imp.reload(decompose)
imp.reload(export_urho)
imp.reload(export_scene)
imp.reload(utils)
imp.reload(materials)
if DEBUG and "testing" in locals(): imp.reload(testing)
from .decompose import TOptions, Scan
from .export_urho import UrhoExportData, UrhoExportOptions, UrhoWriteModel, UrhoWriteAnimation, \
UrhoWriteTriggers, UrhoExport
from .export_scene import SOptions, UrhoScene, UrhoExportScene, UrhoWriteMaterialsList
from .utils import PathType, FOptions, GetFilepath, CheckFilepath, ErrorsMem
from .materials import write_material
if DEBUG: from .testing import PrintUrhoData, PrintAll
import os
import time
import sys
import shutil
import logging
import bpy
from bpy.props import StringProperty, BoolProperty, EnumProperty, FloatProperty, IntProperty
from bpy.app.handlers import persistent
from mathutils import Quaternion
from math import radians
#--------------------
# Loggers
#--------------------
# A list to save export messages
logList = []
# Create a logger
log = logging.getLogger("ExportLogger")
log.setLevel(logging.DEBUG)
# Formatter for the logger
FORMAT = '%(levelname)s:%(message)s'
formatter = logging.Formatter(FORMAT)
# Console filter: no more than 3 identical messages
consoleFilterMsg = None
consoleFilterCount = 0
class ConsoleFilter(logging.Filter):
def filter(self, record):
global consoleFilterMsg
global consoleFilterCount
if consoleFilterMsg == record.msg:
consoleFilterCount += 1
if consoleFilterCount > 2:
return False
else:
consoleFilterCount = 0
consoleFilterMsg = record.msg
return True
consoleFilter = ConsoleFilter()
# Logger handler which saves unique messages in the list
logMaxCount = 500
class ExportLoggerHandler(logging.StreamHandler):
def emit(self, record):
global logList
try:
if len(logList) < logMaxCount:
msg = self.format(record)
if not msg in logList:
logList.append(msg)
#self.flush()
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
# Delete old handlers
for handler in reversed(log.handlers):
log.removeHandler(handler)
# Create a logger handler for the list
listHandler = ExportLoggerHandler()
listHandler.setFormatter(formatter)
log.addHandler(listHandler)
# Create a logger handler for the console
consoleHandler = logging.StreamHandler()
consoleHandler.addFilter(consoleFilter)
log.addHandler(consoleHandler)
#--------------------
# Blender UI
#--------------------
# Addon preferences, they are visible in the Users Preferences Addons page,
# under the Urho exporter addon row
class UrhoAddonPreferences(bpy.types.AddonPreferences):
bl_idname = __package__
outputPath: StringProperty(
name = "Default export path",
description = "Default path where to export",
default = "",
maxlen = 1024,
subtype = "DIR_PATH")
modelsPath: StringProperty(
name = "Default Models subpath",
description = "Models subpath (relative to output)",
default = "Models")
animationsPath: StringProperty(
name = "Default Animations subpath",
description = "Animations subpath (relative to output)",
default = "Models")
materialsPath: StringProperty(
name = "Default Materials subpath",
description = "Materials subpath (relative to output)",
default = "Materials")
techniquesPath: StringProperty(
name = "Default Techniques subpath",
description = "Techniques subpath (relative to output)",
default = "Techniques")
texturesPath: StringProperty(
name = "Default Textures subpath",
description = "Textures subpath (relative to output)",
default = "Textures")
objectsPath: StringProperty(
name = "Default Objects subpath",
description = "Objects subpath (relative to output)",
default = "Objects")
scenesPath: StringProperty(
name = "Default Scenes subpath",
description = "Scenes subpath (relative to output)",
default = "Scenes")
bonesPerGeometry: IntProperty(
name = "Per geometry",
description = "Max numbers of bones per geometry",
min = 64, max = 2048,
default = 64)
bonesPerVertex: IntProperty(
name = "Per vertex",
description = "Max numbers of bones per vertex",
min = 4, max = 256,
default = 4)
reportWidth: IntProperty(
name = "Window width",
description = "Width of the report window",
default = 500)
maxMessagesCount: IntProperty(
name = "Max number of messages",
description = "Max number of messages in the report window",
default = 500)
def draw(self, context):
layout = self.layout
layout.prop(self, "outputPath")
layout.prop(self, "modelsPath")
layout.prop(self, "animationsPath")
layout.prop(self, "materialsPath")
layout.prop(self, "techniquesPath")
layout.prop(self, "texturesPath")
layout.prop(self, "objectsPath")
layout.prop(self, "scenesPath")
row = layout.row()
row.label(text = "Max number of bones:")
row.prop(self, "bonesPerGeometry")
row.prop(self, "bonesPerVertex")
row = layout.row()
row.label(text = "Report window:")
row.prop(self, "reportWidth")
row.prop(self, "maxMessagesCount")
# Here we define all the UI objects to be added in the export panel
class UrhoExportSettings(bpy.types.PropertyGroup):
# This is called each time a property (created with the parameter 'update')
# changes its value
def update_func(self, context):
# Avoid infinite recursion
if self.updatingProperties:
return
self.updatingProperties = True
# Save preferred output path
addonPrefs = context.preferences.addons[__package__].preferences
if self.outputPath:
addonPrefs.outputPath = self.outputPath
# Skeleton implies weights
if self.skeletons:
self.geometryWei = True
self.objAnimations = False
else:
self.geometryWei = False
self.animations = False
# Use Fcurves only for actions
if not ('ACTION' in self.animationSource):
self.actionsByFcurves = False
# Morphs need geometries
if not self.geometries:
self.morphs = False
# Tangent needs position, normal and UV
if not self.geometryPos or not self.geometryNor or not self.geometryUV:
self.geometryTan = False
# Morph normal needs geometry normal
if not self.geometryNor:
self.morphNor = False
# Morph tangent needs geometry tangent
if not self.geometryTan:
self.morphTan = False
# Morph tangent needs normal
if not self.morphNor:
self.morphTan = False
# Select errors and merge are incompatible
if self.selectErrors:
self.merge = False
self.updatingProperties = False
def update_func2(self, context):
if self.updatingProperties:
return
self.updatingProperties = True
# Select errors and merge are incompatible
if self.merge:
self.selectErrors = False
self.updatingProperties = False
def update_subfolders(self, context):
# Move folders between the output path and the subfolders
# (this should have been done with operators)
if self.updatingProperties:
return
self.updatingProperties = True
if self.addDir:
# Move the last folder from the output path to the subfolders
self.addDir = False
last = os.path.basename(os.path.normpath(self.outputPath))
ilast = self.outputPath.rindex(last)
if last and ilast >= 0:
self.outputPath = self.outputPath[:ilast]
self.modelsPath = os.path.join(last, self.modelsPath)
self.animationsPath = os.path.join(last, self.animationsPath)
self.materialsPath = os.path.join(last, self.materialsPath)
self.techniquesPath = os.path.join(last, self.techniquesPath)
self.texturesPath = os.path.join(last, self.texturesPath)
self.objectsPath = os.path.join(last, self.objectsPath)
self.scenesPath = os.path.join(last, self.scenesPath)
if self.removeDir:
# Move the first common folder from the subfolders to the output path
self.removeDir = False
ifirst = self.modelsPath.find(os.path.sep) + 1
first = self.modelsPath[:ifirst]
if first and \
self.animationsPath.startswith(first) and \
self.materialsPath.startswith(first) and \
self.techniquesPath.startswith(first) and \
self.texturesPath.startswith(first) and \
self.objectsPath.startswith(first) and \
self.scenesPath.startswith(first):
self.outputPath = os.path.join(self.outputPath, first)
self.modelsPath = self.modelsPath[ifirst:]
self.animationsPath = self.animationsPath[ifirst:]
self.materialsPath = self.materialsPath[ifirst:]
self.techniquesPath = self.techniquesPath[ifirst:]
self.texturesPath = self.texturesPath[ifirst:]
self.objectsPath = self.objectsPath[ifirst:]
self.scenesPath = self.scenesPath[ifirst:]
if self.addSceneDir:
# Append the scene name to the subfolders
self.addSceneDir = False
sceneName = context.scene.name
last = os.path.basename(os.path.normpath(self.modelsPath))
if sceneName != last:
self.modelsPath = os.path.join(self.modelsPath, sceneName)
self.animationsPath = os.path.join(self.animationsPath, sceneName)
self.materialsPath = os.path.join(self.materialsPath, sceneName)
self.techniquesPath = os.path.join(self.techniquesPath, sceneName)
self.texturesPath = os.path.join(self.texturesPath, sceneName)
self.objectsPath = os.path.join(self.objectsPath, sceneName)
self.scenesPath = os.path.join(self.scenesPath, sceneName)
self.updatingProperties = False
def errors_update_func(self, context):
if self.updatingProperties:
return
self.updatingProperties = True
errorName = self.errorsEnum
self.errorsEnum = 'NONE'
self.updatingProperties = False
selectErrors(context, self.errorsMem, errorName)
def errors_items_func(self, context):
items = [('NONE', "", ""),
('ALL', "all", "")]
for error in self.errorsMem.Names():
items.append( (error, error, "") )
return items
# Revert all the export settings back to their default values
def reset(self, context):
addonPrefs = context.preferences.addons[__package__].preferences
self.updatingProperties = False
self.minimize = False
self.onlyErrors = False
self.showDirs = False
self.useSubDirs = True
self.fileOverwrite = False
self.source = 'ONLY_SELECTED'
self.scale = 1.0
self.modifiers = False
self.origin = 'LOCAL'
self.selectErrors = True
self.forceElements = False
self.merge = False
self.mergeNotMaterials = False
self.geometrySplit = False
self.lods = False
self.strictLods = True
self.optimizeIndices = False
self.skeletons = False
self.onlyKeyedBones = False
self.onlyDeformBones = False
self.onlyVisibleBones = False
self.actionsByFcurves = False
self.parentBoneSkinning = False
self.derigify = False
self.clampBoundingBox = False
self.animations = False
self.objAnimations = False
self.animationSource = 'USED_ACTIONS'
self.animationExtraFrame = True
self.animationTriggers = False
self.animationRatioTriggers = False
self.animationPos = True
self.animationRot = True
self.animationSca = False
self.filterSingleKeyFrames = False
self.geometries = True
self.geometryPos = True
self.geometryNor = True
self.geometryCol = False
self.geometryColAlpha = False
self.geometryUV = False
self.geometryUV2 = False
self.geometryTan = False
self.geometryWei = False
self.morphs = False
self.morphNor = True
self.morphTan = False
self.materials = False
self.materialsList = False
self.textures = False
self.prefabs = True
self.objectsPrefab = False
self.collectivePrefab = False
self.fullScene = False
self.selectedObjects = False
self.trasfObjects = False
self.physics = False
self.collisionShape = 'TRIANGLEMESH'
# Revert the output paths back to their default values
def reset_paths(self, context, forced):
addonPrefs = context.preferences.addons[__package__].preferences
if forced or (not self.outputPath and addonPrefs.outputPath):
self.outputPath = addonPrefs.outputPath
if forced or (not self.modelsPath and addonPrefs.modelsPath):
self.modelsPath = addonPrefs.modelsPath
self.animationsPath = addonPrefs.animationsPath
self.materialsPath = addonPrefs.materialsPath
self.techniquesPath = addonPrefs.techniquesPath
self.texturesPath = addonPrefs.texturesPath
self.objectsPath = addonPrefs.objectsPath
self.scenesPath = addonPrefs.scenesPath
# --- Accessory ---
updatingProperties: BoolProperty(default = False)
minimize: BoolProperty(
name = "Minimize",
description = "Minimize the export panel",
default = False)
onlyErrors: BoolProperty(
name = "Log errors",
description = "Show only warnings and errors in the log",
default = False)
showDirs: BoolProperty(
name = "Show dirs",
description = "Show the dirs list",
default = False)
addDir: BoolProperty(
name = "Output folder to subfolders",
description = "Move the last output folder to the subfolders",
default = False,
update = update_subfolders)
removeDir: BoolProperty(
name = "Subfolders to output folder",
description = "Move a common subfolder to the output folder",
default = False,
update = update_subfolders)
addSceneDir: BoolProperty(
name = "Scene to subfolders",
description = "Append the scene name to the subfolders",
default = False,
update = update_subfolders)
# --- Output settings ---
outputPath: StringProperty(
name = "",
description = "Path where to export",
default = "",
maxlen = 1024,
subtype = "DIR_PATH",
update = update_func)
useSubDirs: BoolProperty(
name = "Use sub folders",
description = "Use sub folders inside the output folder (Materials, Models, Textures ...)",
default = True)
modelsPath: StringProperty(
name = "Models",
description = "Models subpath (relative to output)")
animationsPath: StringProperty(
name = "Animations",
description = "Animations subpath (relative to output)")
materialsPath: StringProperty(
name = "Materials",
description = "Materials subpath (relative to output)")
techniquesPath: StringProperty(
name = "Techniques",
description = "Techniques subpath (relative to output)")
texturesPath: StringProperty(
name = "Textures",
description = "Textures subpath (relative to output)")
objectsPath: StringProperty(
name = "Objects",
description = "Objects subpath (relative to output)")
scenesPath: StringProperty(
name = "Scenes",
description = "Scenes subpath (relative to output)")
fileOverwrite: BoolProperty(
name = "Files overwrite",
description = "If enabled existing files are overwritten without warnings",
default = False)
# --- Source settings ---
source: EnumProperty(
name = "Source",
description = "Objects to be exported",
items=(('ALL', "All", "all the objects in the scene"),
('ONLY_SELECTED', "Only selected", "only the selected objects in visible layers")),
default='ONLY_SELECTED')
orientation: EnumProperty(
name = "Front view",
description = "Front view of the model",
items = (('X_MINUS', "Left (--X +Z)", ""),
('X_PLUS', "Right (+X +Z)", ""),
('Y_MINUS', "Front (--Y +Z)", ""),
('Y_PLUS', "Back (+Y +Z) *", ""),
('Z_MINUS', "Bottom (--Z --Y)", ""),
('Z_PLUS', "Top (+Z +Y)", "")),
default = 'X_PLUS')
scale: FloatProperty(
name = "Scale",
description = "Scale to apply on the exported objects",
default = 1.0,
min = 0.0,
max = 1000.0,
step = 10,
precision = 1)
modifiers: BoolProperty(
name = "Apply modifiers",
description = "Apply the object modifiers before exporting",
default = False)
origin: EnumProperty(
name = "Mesh origin",
description = "Origin for the position of vertices/bones",
items=(('GLOBAL', "Global", "Blender's global origin"),
('LOCAL', "Local", "object's local origin (orange dot)")),
default = 'LOCAL')
selectErrors: BoolProperty(
name = "Select vertices with errors",
description = "If a vertex has errors (e.g. invalid UV, missing UV or color or weights) select it",
default = True,
update = update_func)
errorsMem = ErrorsMem()
errorsEnum: EnumProperty(
name = "",
description = "List of errors",
items = errors_items_func,
update = errors_update_func)
forceElements: BoolProperty(
name = "Force missing elements",
description = "If a vertex element (UV, color, weights) is missing add it with a zero value",
default = False)
merge: BoolProperty(
name = "Merge objects",
description = ("Merge all the objects in a single file, one common geometry for each material. "
"It uses the current object name."),
default = False,
update = update_func2)
mergeNotMaterials: BoolProperty(
name = "Don't merge materials",
description = "Create a different geometry for each material of each object",
default = False)
geometrySplit: BoolProperty(
name = "One vertex buffer per object",
description = "Split each object into its own vertex buffer",
default = False)
lods: BoolProperty(
name = "Use LODs",
description = "Search for the LOD distance if the object name, objects with the same name are added as LODs",
default = False)
strictLods: BoolProperty(
name = "Strict LODs",
description = "Add a new vertex if the LOD0 does not contain a vertex with the exact same position, normal and UV",
default = True)
optimizeIndices: BoolProperty(
name = "Optimize indices (slow)",
description = "Linear-Speed vertex cache optimisation",
default = True)
# --- Components settings ---
skeletons: BoolProperty(
name = "Skeletons",
description = "Export model armature bones",
default = False,
update = update_func)
onlyKeyedBones: BoolProperty(
name = "Only keyed bones",
description = "In animinations export only bones with keys",
default = False)
onlyDeformBones: BoolProperty(
name = "Only deform bones",
description = "Don't export bones without Deform and its children",
default = False,
update = update_func2)
onlyVisibleBones: BoolProperty(
name = "Only visible bones",
description = "Don't export bones not visible and its children",
default = False,
update = update_func2)
actionsByFcurves: BoolProperty(
name = "Read actions by Fcurves",
description = "Should be much faster than updating the whole scene, usable only for Actions and for Quaternion rotations",
default = False)
derigify: BoolProperty(
name = "Derigify",
description = "Remove extra bones from Rigify armature",
default = False,
update = update_func)
clampBoundingBox: BoolProperty(
name = "Clamp bones bounding box",
description = "Clamp each bone bounding box between bone head & tail. Use case: ragdoll, IK...",
default = False)
parentBoneSkinning: BoolProperty(
name = "Use skinning for parent bones",
description = "If an object has a parent of type BONE use a 100% skinning on its vertices "
"(use this only for a quick prototype)",
default = False,
update = update_func)
animations: BoolProperty(
name = "Animations",
description = "Export bones animations (Skeletons needed)",
default = False)
objAnimations: BoolProperty(
name = "of objects",
description = "Export objects animations (without Skeletons)",
default = False)
animationSource: EnumProperty(
name = "",
items = (('ALL_ACTIONS', "All Actions", "Export all the actions in memory"),
('CURRENT_ACTION', "Current Action", "Export the object's current action linked in the Dope Sheet editor"),
('USED_ACTIONS', "Actions used in tracks", "Export only the actions used in NLA tracks"),
('SELECTED_ACTIONS', "Selected Strips' Actions", "Export the actions of the current selected NLA strips"),
('SELECTED_STRIPS', "Selected Strips", "Export the current selected NLA strips"),
('SELECTED_TRACKS', "Selected Tracks", "Export the current selected NLA tracks"),
('ALL_STRIPS', "All Strips", "Export all NLA strips"),
('ALL_TRACKS', "All Tracks (not muted)", "Export all NLA tracks"),
('TIMELINE', "Timelime", "Export the timeline (NLA tracks sum)")),
default = 'USED_ACTIONS',
update = update_func)
animationExtraFrame: BoolProperty(
name = "Ending extra frame",
description = "In Blender to avoid pauses in a looping animation you normally want to skip the last frame "
"when it is the same as the first one. Urho needs this last frame, use this option to add it. "
"It is needed only when using the Timeline or Nla-Tracks.",
default = True)
animationTriggers: BoolProperty(
name = "Export markers as triggers",
description = "Export action pose markers (for actions, strips and tracks) or scene markers (for timeline) "
"as triggers, the time is expressed in seconds",
default = False)
animationRatioTriggers: BoolProperty(
name = "Normalize time",
description = "Export the time of triggers as a number from 0 (start) to 1 (end)",
default = False)
#---------------------------------
animationPos: BoolProperty(
name = "Position",
description = "Within animations export bone positions",
default = True)
animationRot: BoolProperty(
name = "Rotation",
description = "Within animations export bone rotations",
default = True)
animationSca: BoolProperty(
name = "Scale",
description = "Within animations export bone scales",
default = False)
filterSingleKeyFrames: BoolProperty(
name = "Remove single tracks",
description = "Do not export tracks which contain only one keyframe, useful for layered animations",
default = False)
geometries: BoolProperty(
name = "Geometries",
description = "Export vertex buffers, index buffers, geometries, lods",
default = True,
update = update_func)
geometryPos: BoolProperty(
name = "Position",
description = "Within geometry export vertex position",
default = True,
update = update_func)
geometryNor: BoolProperty(
name = "Normal",
description = "Within geometry export vertex normal (enable 'Auto Smooth' to export custom normals)",
default = True,
update = update_func)
geometryCol: BoolProperty(
name = "Color",
description = "Within geometry export vertex color",
default = False)
geometryColAlpha: BoolProperty(
name = "Alpha",
description = "Within geometry export vertex alpha (append _ALPHA to the color layer name)",
default = False)
geometryUV: BoolProperty(
name = "UV",
description = "Within geometry export vertex UV",
default = False,
update = update_func)
geometryUV2: BoolProperty(
name = "UV2",
description = "Within geometry export vertex UV2 (append _UV2 to the texture name)",
default = False,
update = update_func)
geometryTan: BoolProperty(
name = "Tangent",
description = "Within geometry export vertex tangent (Position, Normal, UV needed)",
default = False,
update = update_func)
geometryWei: BoolProperty(
name = "Weights",
description = "Within geometry export vertex bones weights (Skeletons needed)",
default = False)
morphs: BoolProperty(
name = "Morphs (shape keys)",
description = "Export vertex morphs (Geometries needed)",
default = False)
morphNor: BoolProperty(
name = "Normal",
description = "Within morph export vertex normal (Geometry Normal needed)",
default = True,
update = update_func)
morphTan: BoolProperty(
name = "Tangent",
description = "Within morph export vertex tangent (Morph Normal, Geometry Tangent needed)",
default = False,
update = update_func)
materials: BoolProperty(
name = "Export materials",
description = "Export XML materials",
default = False,
update = update_func)
materialsList: BoolProperty(
name = "Materials text list",
description = "Write a txt file with the list of materials filenames",
default = False)
textures: BoolProperty(
name = "Copy textures",
description = "Copy diffuse textures",
default = False,
update = update_func)
prefabs: BoolProperty(
name = "Export Urho Prefabs",
description = "Export Urho3D XML objects (prefabs)",
default = False,
update = update_func)
# --- Nodes/Prefabs ---
objectsPrefab: BoolProperty(
name = "Objects prefabs",
description = "Create a prefab/node for each object in the current scene",
default = False,
update = update_func)
collectivePrefab: BoolProperty(
name = "Collective prefab",
description = "Create one prefab/node for the whole scene",
default = False,
update = update_func)
fullScene: BoolProperty(
name = "Full scene",
description = "Create a Urho3D scene",
default = False,
update = update_func)
selectedObjects: BoolProperty(
name = "Only selected objects",
description = "Create a prefab/node for selected object only",
default = False,
update = update_func)
trasfObjects: BoolProperty(
name = "Position, Rotation, Scale",
description = "Add Position, Rotation, Scale to the nodes",
default = False)
physics: BoolProperty(
name = "Physics",
description = "Add RigidBody, Shape to the nodes",
default = False)
shapeItems = [ ('BOX', "Box", ""), ('CAPSULE', "Capsule", ""), ('CONE', "Cone", ""), \
('CONVEXHULL', "ConvexHull", ""), ('CYLINDER', "Cylinder", ""), ('SPHERE', "Sphere", ""), \
('STATICPLANE', "StaticPlane", ""), ('TRIANGLEMESH', "TriangleMesh", "") ]
collisionShape: EnumProperty(
name = "CollisionShape",
description = "Collision shape type",
items = shapeItems,
default = 'TRIANGLEMESH',
update = update_func2)
bonesGlobalOrigin: BoolProperty(name = "Bones global origin", default = False)
actionsGlobalOrigin: BoolProperty(name = "Actions global origin", default = False)
# Reset settings button
class UrhoExportResetOperator(bpy.types.Operator):
""" Reset export settings """
bl_idname = "urho.exportreset"
bl_label = "Revert settings to default"
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_confirm(self, event)
def execute(self, context):
context.scene.urho_exportsettings.reset(context)
return {'FINISHED'}
# Reset output paths button
class UrhoExportResetPathsOperator(bpy.types.Operator):
""" Reset paths """
bl_idname = "urho.exportresetpaths"
bl_label = "Revert paths to default"
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_confirm(self, event)
def execute(self, context):
context.scene.urho_exportsettings.reset_paths(context, True)
return {'FINISHED'}
# View log button
class UrhoReportDialog(bpy.types.Operator):
""" View export log """
bl_idname = "urho.report"
bl_label = "Urho export report"
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
global logMaxCount
wm = context.window_manager
addonPrefs = context.preferences.addons[__package__].preferences
logMaxCount = addonPrefs.maxMessagesCount
return wm.invoke_props_dialog(self, width = addonPrefs.reportWidth)
#return wm.invoke_popup(self, width = addonPrefs.reportWidth)
def draw(self, context):
layout = self.layout
scene = context.scene
for line in logList:
lines = line.split(":", 1)
if lines[0] == 'CRITICAL':
lineicon = 'RADIO'
elif lines[0] == 'ERROR':
lineicon = 'CANCEL'
elif lines[0] == 'WARNING':
lineicon = 'ERROR'
elif lines[0] == 'INFO':
lineicon = 'INFO'
else:
lineicon = 'TEXT'
layout.label(text = lines[1], icon = lineicon)
# Export button
class UrhoExportOperator(bpy.types.Operator):
""" Start exporting """
bl_idname = "urho.export"
bl_label = "Export"
def execute(self, context):
ExecuteAddon(context)
return {'FINISHED'}
def invoke(self, context, event):
return self.execute(context)
# Export without report window
class UrhoExportCommandOperator(bpy.types.Operator):
""" Start exporting """
bl_idname = "urho.exportcommand"
bl_label = "Export command"
def execute(self, context):
ExecuteAddon(context, silent=True)
return {'FINISHED'}
def invoke(self, context, event):
return self.execute(context)
# The export panel, here we draw the panel using properties we have created earlier
class UrhoExportRenderPanel(bpy.types.Panel):
bl_idname = "URHOEXPORT_PT_RenderPanel"
bl_label = "Urho export"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "render"
#bl_options = {'DEFAULT_CLOSED'}
# Draw the export panel
def draw(self, context):
layout = self.layout
scene = context.scene
settings = scene.urho_exportsettings
row = layout.row()
#row=layout.row(align=True)
minimizeIcon = 'ADD' if settings.minimize else 'REMOVE'
row.prop(settings, "minimize", text="", icon=minimizeIcon, toggle=False)
row.operator("urho.export", icon='EXPORT')
#split = layout.split(percentage=0.1)
if sys.platform.startswith('win'):
row.operator("wm.console_toggle", text="", icon='CONSOLE')
row.prop(settings, "onlyErrors", text="", icon='FORCE_WIND')
row.operator("urho.report", text="", icon='TEXT')
if settings.minimize:
return
row = layout.row()
row.label(text = "Output:")
row.operator("urho.exportresetpaths", text="", icon='LIBRARY_DATA_DIRECT')
box = layout.box()
box.label(text = "Output folder:")
box.prop(settings, "outputPath")
box.prop(settings, "fileOverwrite")
row = box.row()
row.prop(settings, "useSubDirs")
showDirsIcon = 'REMOVE' if settings.showDirs else 'ADD'
if settings.showDirs:
subrow = row.row(align=True)
subrow.prop(settings, "addDir", text="", icon='TRIA_DOWN_BAR')