-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path__init__.py
967 lines (791 loc) · 34.5 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
# ##### 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 #####
"""
Handles registering the add-on into Blender and drawing properties to the UI.
@author: Demian Wright
"""
import os
import bpy
from bpy.props import BoolProperty, EnumProperty, StringProperty, IntProperty, FloatProperty
from bpy_extras.io_utils import ExportHelper
# Blender requires imports from "." for self-defined modules.
from . import export_blb, const, logger
bl_info = {
"name": "Export: Blockland Brick (.blb)",
"author": "Demian Wright & Nick Smith",
"version": (2, 1, 0),
"blender": (2, 67, 0),
"location": "File > Export > Blockland Brick (.blb)",
"description": "Export Blockland brick format",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Import-Export"}
# TODO: Exporting DTS collision.
# TODO: Importing BLB files.
# TODO: Render brick preview.
# TODO: Check that all docstrings and comments are still up to date.
# TODO: Quad sorting is per object but BLBs support per-quad sorting: the exporter does not support quad sorting for smoothed objects.
# TODO: Serialize props to the start of the log?
# TODO: Add a section about brick grid to the readme.
# TODO: Make the capitalization consistent in the readme.
# TODO: Clarify brick grid and brick grid placement rules.
class ExportBLB(bpy.types.Operator, ExportHelper):
"""Export Blockland brick data."""
bl_idname = "export_scene.blb"
bl_label = "Export BLB"
bl_options = {"REGISTER", "PRESET"}
filename_ext = const.BLB_EXT
logfile_ext = const.LOG_EXT
filter_glob = StringProperty(default="*" + const.BLB_EXT, options={"HIDDEN"})
# ==========
# Properties
# ==========
# ==================
# Blender Properties
# ==================
# ------------
# Export Count
# ------------
export_count = EnumProperty(
items=[("SINGLE", "Single", "Export a single brick"),
("MULTIPLE", "Multiple", "Export multiple bricks at once")],
name="Bricks to Export",
description="How many bricks to export from this file",
default="SINGLE"
)
# ----------------
# Brick Definition
# ----------------
brick_definition = EnumProperty(
items=[("GROUPS", "Groups", "Bricks are in different groups"),
("LAYERS", "Layers", "Bricks are in different layers")],
name="Bricks Defined by",
description="The method for defining multiple bricks in a file",
default="GROUPS"
)
# ----------
# Brick Name
# ----------
brick_name_source = EnumProperty(
items=[("BOUNDS", "Bounds", "Brick name is in the name of the bounds object, after the bounds definition, separated with a space (directory set in export file dialog)"),
("FILE", "File", "Brick name is the same as the .blend file name (can be changed manually in the file dialog)")],
name="Brick Name from:",
description="Where to get the name of the exported brick",
default="BOUNDS"
)
# -------------------
# Brick Name Multiple
# -------------------
brick_name_source_multi = EnumProperty(
items=[("BOUNDS", "Bounds", "Brick name is in the name of the bounds object, after the bounds definition, separated with a space (directory set in export file dialog)"),
("GROUPS", "Groups", "Brick name is the group name (directory set in export file dialog)")],
name="Brick Names from:",
description="Where to get the name of the exported bricks",
default="BOUNDS"
)
# -------
# Objects
# -------
export_objects = EnumProperty(
items=[("SELECTION", "Selection", "Export only selected objects"),
("LAYERS", "Layers", "Export all objects in the visible layers"),
("SCENE", "Scene", "Export all objects in the active scene")],
name="Export Objects In:",
description="Only export the specified objects",
default="SELECTION"
)
# -------------
# Objects Multi
# -------------
export_objects_multi = EnumProperty(
items=[("LAYERS", "Layers", "Export all bricks in the visible layers"),
("SCENE", "Scene", "Export all bricks in the active scene")],
name="Export Bricks in:",
description="Only export the specified bricks",
default="LAYERS"
)
# ------------
# Forward Axis
# ------------
# For whatever reason BLB coordinates are rotated 90 degrees counter-clockwise to Blender coordinates.
# I.e. -X is facing you when the brick is planted and +X is the brick north instead of +Y which makes more sense to me.
# TODO: Support Z axis remapping.
axis_blb_forward = EnumProperty(
items=[("POSITIVE_X", "+X", "The positive X axis"),
("POSITIVE_Y", "+Y", "The positive Y axis"),
("NEGATIVE_X", "-X", "The negative X axis"),
("NEGATIVE_Y", "-Y", "The negative Y axis")],
name="Brick Forward Axis",
description="Set the Blender axis that will point forwards in the game",
default="POSITIVE_Y"
)
# -----
# Scale
# -----
export_scale = FloatProperty(
name="Scale",
description="The scale to export the brick at. A 1x1x1 brick at 100% scale is defined as being 1.0x1.0x1.2 Blender units in size on the XYZ axes.",
subtype="PERCENTAGE",
precision=3,
step=1,
default=100.0,
min=0.001,
soft_max=400.0,
)
# -------------
# Use Modifiers
# -------------
use_modifiers = BoolProperty(
name="Apply Modifiers",
description="Take modifiers into account (at preview settings) when exporting objects, does not apply the modifiers in the interface",
default=True,
)
# -----------
# Definitions
# -----------
custom_definitions = BoolProperty(
name="Custom Definition Tokens",
description="Set custom definitions tokens (case insensitive) to use in definition object names",
default=False,
)
deftoken_bounds = StringProperty(
name="Brick Bounds",
description="Token for objects that define brick bounds",
default="bounds",
)
deftoken_collision = StringProperty(
name="Collision Cuboid",
description="Token for objects that define collision cuboids",
default="collision",
)
# Sections
deftoken_quad_sort_top = StringProperty(
name="Top Quads",
description="Token for specifying that the object's vertices belong to the top section of the brick (used in brick coverage for hiding faces to improve performance)",
default="qt",
)
deftoken_quad_sort_bottom = StringProperty(
name="Bottom Quads",
description="Token for specifying that the object's vertices belong to the bottom section of the brick (used in brick coverage for hiding faces to improve performance)",
default="qb",
)
deftoken_quad_sort_north = StringProperty(
name="North Quads",
description="Token for specifying that the object's vertices belong to the north section of the brick (used in brick coverage for hiding faces to improve performance)",
default="qn",
)
deftoken_quad_sort_east = StringProperty(
name="East Quads",
description="Token for specifying that the object's vertices belong to the east section of the brick (used in brick coverage for hiding faces to improve performance)",
default="qe",
)
deftoken_quad_sort_south = StringProperty(
name="South Quads",
description="Token for specifying that the object's vertices belong to the south section of the brick (used in brick coverage for hiding faces to improve performance)",
default="qs",
)
deftoken_quad_sort_west = StringProperty(
name="West Quads",
description="Token for specifying that the object's vertices belong to the west section of the brick (used in brick coverage for hiding faces to improve performance)",
default="qw",
)
deftoken_quad_sort_omni = StringProperty(
name="Omni Quads",
description="Token for specifying that the object's vertices belong to the omni section of the brick, these vertices will never be hidden",
default="qo",
)
# Brick Grid
deftoken_gridx = StringProperty(
name="Brick Grid x",
description="Token for objects that define a volume within the brick bounds that will be filled with the 'x' symbol in the brick grid signifying that other bricks cannot be placed there",
default="gridx",
)
deftoken_griddash = StringProperty(
name="Brick Grid -",
description="Token for objects that define a volume within the brick bounds that will be filled with the '-' symbol in the brick grid signifying empty space",
default="grid-",
)
deftoken_gridu = StringProperty(
name="Brick Grid u",
description="Token for objects that define a volume within the brick bounds that will be filled with the 'u' symbol in the brick grid signifying that other bricks may be planted above",
default="gridu",
)
deftoken_gridd = StringProperty(
name="Brick Grid d",
description="Token for objects that define a volume within the brick bounds that will be filled with the 'd' symbol in the brick grid signifying that other bricks may be planted below",
default="gridd",
)
deftoken_gridb = StringProperty(
name="Brick Grid b",
description="Token for objects that define a volume within the brick bounds that will be filled with the 'b' symbol in the brick grid signifying that other bricks may be planted above or below",
default="gridb",
)
deftoken_gridx_priority = IntProperty(
name="Grid X Symbol Priority",
description="Priority of the 'x' symbol definition, higher priority definition override any overlapping definitions with lower priority (two or more symbols must not have the same priority)",
default=0,
min=0,
max=4,
)
deftoken_griddash_priority = IntProperty(
name="Grid - Symbol Priority",
description="Priority of the '-' symbol definition, higher priority definition override any overlapping definitions with lower priority (two or more symbols must not have the same priority)",
default=1,
min=0,
max=4,
)
deftoken_gridu_priority = IntProperty(
name="Grid U Symbol Priority",
description="Priority of the 'u' symbol definition, higher priority definition override any overlapping definitions with lower priority (two or more symbols must not have the same priority)",
default=2,
min=0,
max=4,
)
deftoken_gridd_priority = IntProperty(
name="Grid D Symbol Priority",
description="Priority of the 'd' symbol definition, higher priority definition override any overlapping definitions with lower priority (two or more symbols must not have the same priority)",
default=3,
min=0,
max=4,
)
deftoken_gridb_priority = IntProperty(
name="Grid B Symbol Priority",
description="Priority of the 'b' symbol definition, higher priority definition override any overlapping definitions with lower priority (two or more symbols must not have the same priority)",
default=4,
min=0,
max=4,
)
# Colors
deftoken_color = StringProperty(
name="Object Color",
description="Token for specifying a color for an object using its name. Token must be followed by 4 values (red green blue alpha) separated with spaces using a comma (,) as decimal separator. Integers 0-255 also supported.",
default="c",
)
deftoken_color_blank = StringProperty(
name="In-Game Color",
description="No color is written for these faces: in-game spray color is used",
default="blank",
)
deftoken_color_add = StringProperty(
name="Additive Color",
description="Blender material/vertex color is added to in-game spray color",
default="cadd",
)
deftoken_color_sub = StringProperty(
name="Subtractive Color",
description="Blender material/vertex color is subtracted from in-game spray color",
default="csub",
)
# ==============
# BLB Properties
# ==============
# ---------
# Collision
# ---------
custom_collision = BoolProperty(
name="Custom Collision",
description="Use custom collision definition objects (if any)",
default=True,
)
fallback_collision = EnumProperty(
items=[("BOUNDS", "Bounds", "Use brick bounds as collision"),
("AABB", "AABB", "Calculate axis-aligned bounding box collision from visible objects")],
name="Fallback Collision",
description="Collision type to use if no custom definitions exist",
default="BOUNDS"
)
# --------
# Coverage
# --------
calculate_coverage = BoolProperty(
name="Coverage",
description="Calculate brick coverage. Coverage relies on the quad section data to be of any use. The coverage system intelligently hides (non-omni) quads on the side of the brick when it is covered by other bricks.",
default=False,
)
coverage_top_calculate = BoolProperty(
name="Hide Own Top Faces",
description="Hide the top faces of this brick when the entire top side of this brick is covered",
default=False,
)
coverage_top_hide = BoolProperty(
name="Hide Adjacent Top Faces",
description="Hide the bottom faces of the adjacent brick(s) covering the top side of this brick",
default=False,
)
coverage_bottom_calculate = BoolProperty(
name="Hide Own Bottom Faces",
description="Hide the bottom faces of this brick when the entire bottom side of this brick is covered",
default=False,
)
coverage_bottom_hide = BoolProperty(
name="Hide Adjacent Bottom Faces",
description="Hide the top faces of the adjacent brick(s) covering the bottom side of this brick",
default=False,
)
coverage_north_calculate = BoolProperty(
name="Hide Own North Faces",
description="Hide the north faces of this brick when the entire north side of this brick is covered",
default=False,
)
coverage_north_hide = BoolProperty(
name="Hide Adjacent North Faces",
description="Hide the adjacent side faces of the adjacent brick(s) covering the north side of this brick",
default=False,
)
coverage_east_calculate = BoolProperty(
name="Hide Own East Faces",
description="Hide the east faces of this brick when the entire east side of this brick is covered",
default=False,
)
coverage_east_hide = BoolProperty(
name="Hide Adjacent East Faces",
description="Hide the adjacent side faces of the adjacent brick(s) covering the east side of this brick",
default=False,
)
coverage_south_calculate = BoolProperty(
name="Hide Own South Faces",
description="Hide the south faces of this brick when the entire south side of this brick is covered",
default=False,
)
coverage_south_hide = BoolProperty(
name="Hide Adjacent South Faces",
description="Hide the adjacent side faces of the adjacent brick(s) covering the south side of this brick",
default=False,
)
coverage_west_calculate = BoolProperty(
name="Hide Own West Faces",
description="Hide the west faces of this brick when the entire west side of this brick is covered",
default=False,
)
coverage_west_hide = BoolProperty(
name="Hide Adjacent West Faces",
description="Hide the adjacent side faces of the adjacent brick(s) covering the west side of this brick",
default=False,
)
# -------
# Sorting
# -------
auto_sort_quads = BoolProperty(
name="Automatic Quad Sorting",
description="Automatically sorts the quads of the meshes into the 7 sections. Coverage must be enabled for this to be of any use.",
default=True,
)
# -------------
# Use Materials
# -------------
use_materials = BoolProperty(
name="Use Material Colors",
description="Read quad colors from materials (recommended method, overrides object colors)",
default=True,
)
# -----------------
# Use Vertex Colors
# -----------------
use_vertex_colors = BoolProperty(
name="Use Vertex Colors",
description="Read quad colors from the first vertex color layer (overrides material colors)",
default=False,
)
# -----------------
# Use Object Colors
# -----------------
use_object_colors = BoolProperty(
name="Parse Object Colors",
description="Parse quad colors from object names using the definition token (intended as legacy support)",
default=False,
)
# -------------
# Calculate UVs
# -------------
calculate_uvs = BoolProperty(
name="Calculate UVs",
description="Calculate correct UV coordinates based on the brick texture name specified in the material name",
default=True,
)
# ---------
# Square SIDE UVs
# ---------
square_side_uvs = BoolProperty(
name="Square Side UVs",
description="Use a square that takes up the whole UV space as UVs for all SIDE material faces",
default=False,
)
# ---------
# Store UVs
# ---------
store_uvs = BoolProperty(
name="Store UVs",
description="Write calculated UVs into Blender objects (data in existing generated UV layers will be overwritten)",
default=True,
)
# -------------
# Round Normals
# -------------
round_normals = BoolProperty(
name="Round Normals",
description="Round vertex normal values to the precision defined below, if disabled normals will be written using up to 16 decimals whenever possible",
default=True,
)
# ---------
# Precision
# ---------
# Smaller values will increase floating point errors in the exported brick.
# Larger values will decrease the quality of the visuals as vertex positions will become more deformed
# Setting to 0 actually uses the minimum precision of 1e-16 since only 16 decimals are ever written to file.
# Some floats (like UV coordinates) are not rounded.
float_precision = StringProperty(
name="Precision",
description="The precision to round most floating point values (e.g. vertex coordinates) to. Changing this value is discouraged unless you know what you're doing. 16 decimal places supported. Use 0 to disable.",
default="0.000001",
)
# =======
# Writing
# =======
# ------------
# Pretty Print
# ------------
pretty_print = BoolProperty(
name="Pretty Print",
description="Trim unnecessary zeros from the end of all numbers and if a number is an integer, do not write any decimal places. If false will write as many decimal places as set in the Precision property.",
default=True,
)
# ---
# Log
# ---
write_log = BoolProperty(
name="Write Log",
description="Write a log file after exporting",
default=True,
)
write_log_warnings = BoolProperty(
name="Only on Warnings",
description="Only write a log file if warnings were generated",
default=True,
)
# ----------
# Terse Mode
# ----------
terse_mode = BoolProperty(
name="Terse Mode",
description="Exclude optional text from the BLB file making it slightly smaller and harder to read (not recommended, file size difference is negligible)",
default=False,
)
# ===============
# Export Function
# ===============
def execute(self, context):
"""Export the objects."""
print("\n____STARTING BLB EXPORT____")
props = self.properties
# Get the current filepath which may or may not be the absolute path to the currently open .blend file.
# Get only the name of the file from the filepath.
# Add in the BLB extension.
file_name = bpy.path.ensure_ext(bpy.path.display_name_from_filepath(self.filepath), self.filename_ext)
# The absolute path to the directory user has specified in the export dialog.
export_dir = os.path.split(self.filepath)[0] + os.sep
if export_dir == "\\":
# Export was probably initiated from a script, use the absolute path of the location where the script was executed.
export_dir = bpy.path.abspath("//")
# The name of the BLB file to export.
if props.brick_name_source == "FILE":
export_file = file_name
else:
export_file = None
message = export_blb.export(context, props, export_dir, export_file, file_name)
if isinstance(message, str):
# Log the message in case the user missed it.
logger.fatal(message)
# Show an error popup in the UI.
self.report({"ERROR"}, message)
logger.clear_log()
return {"CANCELLED"}
else:
# No error message, everything is OK.
logger.clear_log()
return {"FINISHED"}
# ==============
# User Interface
# ==============
def draw(self, context):
"""Draws the UI in the export menu."""
layout = self.layout
# ==================
# Blender Properties
# ==================
row = layout.row()
row.alignment = "CENTER"
row.label("Blender Properties", icon="SCENE_DATA")
# Property: Export Count
row = layout.row()
row.label("Bricks to Export:")
row = layout.row()
row.prop(self, "export_count", expand=True)
multi_export = self.export_count == "MULTIPLE"
# When doing multi-brick export, swap the brick name and objects properties and add in the brick definition property.
if multi_export:
bricks_in_groups = self.brick_definition == "GROUPS"
# Property: Brick Name Multiple
row = layout.row()
row.enabled = multi_export
row.label("Brick Names from:")
row = layout.row()
# Disable selecting values when bricks are in layers.
row.enabled = multi_export and bricks_in_groups
row.prop(self, "brick_name_source_multi", expand=True)
if not bricks_in_groups:
# If bricks are defined by layers, the brick names must come from bounds objects.
# Otherwise you need to put all objects in every layer in their own group to define the name which defeats the purpose.
self.brick_name_source_multi = "BOUNDS"
# Property: Brick Definition
row = layout.row()
row.enabled = multi_export
row.label("Bricks Defined by:")
row = layout.row()
row.enabled = multi_export
row.prop(self, "brick_definition", expand=True)
# Property: Export Objects Multi
row = layout.row()
row.label("Export Bricks in:")
row = layout.row()
row.enabled = multi_export
row.prop(self, "export_objects_multi", expand=True)
else:
# Property: Brick Name
row = layout.row()
row.enabled = not multi_export
row.label("Brick Name From:")
row = layout.row()
row.enabled = not multi_export
row.prop(self, "brick_name_source", expand=True)
# Property: Export Objects
row = layout.row()
row.label("Export Only:")
row = layout.row()
row.enabled = not multi_export
row.prop(self, "export_objects", expand=True)
# Property: BLB Forward Axis
row = layout.row()
row.label("Forward Axis:")
row = layout.row()
row.prop(self, "axis_blb_forward", expand=True)
# Property: Export Scale
layout.prop(self, "export_scale")
# Property: Use Modifiers.
layout.prop(self, "use_modifiers")
# Properties: Custom Definition Tokens
layout.prop(self, "custom_definitions", text="Custom Definition Tokens...")
if self.custom_definitions:
box = layout.box()
box.label("Definition Tokens", icon="SORTALPHA")
box.enabled = self.custom_definitions
def draw_definition_property(label_text, prop_name):
"""A helper function for drawing the definition properties."""
row = box.row()
split = row.split(percentage=0.6)
col = split.column()
col.label("{}:".format(label_text))
split = split.split()
col = split.column()
col.prop(self, prop_name, "")
def draw_grid_definition_property(symbol, prop_name):
"""A helper function for drawing the definition properties."""
row = box.row()
split = row.split(percentage=0.25)
col = split.column()
col.label("{}".format(symbol))
split = split.split(percentage=0.7)
col = split.column()
col.prop(self, prop_name, "")
split = split.split()
col = split.column()
col.prop(self, "{}_priority".format(prop_name), "")
# This has duplicate data but I don't know how to access the property names defined earlier since self.deftoken_bounds.name doesn't seem to work.
# For some reason self.deftoken_bounds = "deftoken_bounds" instead of an instance of StringProperty.
row = box.row()
row.alignment = "CENTER"
row.label("Definition Objects", icon="OBJECT_DATA")
row = box.row()
row.alignment = "CENTER"
row.label("Token In: Object Name")
draw_definition_property("Brick Bounds", "deftoken_bounds")
draw_definition_property("Collision Cuboids", "deftoken_collision")
row = box.row()
row.alignment = "CENTER"
row.label("Brick Grid Definition Objects", icon="GRID")
row = box.row()
row.alignment = "CENTER"
row.label("Token In: Object Name")
row = box.row()
split = row.split(percentage=0.25)
col = split.column()
col.label("Symbol")
split = split.split(percentage=0.7)
col = split.column()
col.label("Token")
split = split.split()
col = split.column()
col.label("Priority")
draw_grid_definition_property("b", "deftoken_gridb")
draw_grid_definition_property("d", "deftoken_gridd")
draw_grid_definition_property("u", "deftoken_gridu")
draw_grid_definition_property("-", "deftoken_griddash")
draw_grid_definition_property("x", "deftoken_gridx")
row = box.row()
row.alignment = "CENTER"
row.label("Quad Sorting Tokens", icon="FACESEL")
row = box.row()
row.alignment = "CENTER"
row.label("Token In: Object Name")
draw_definition_property("Top Quads", "deftoken_quad_sort_top")
draw_definition_property("Bottom Quads", "deftoken_quad_sort_bottom")
draw_definition_property("North Quads", "deftoken_quad_sort_north")
draw_definition_property("East Quads", "deftoken_quad_sort_east")
draw_definition_property("South Quads", "deftoken_quad_sort_south")
draw_definition_property("West Quads", "deftoken_quad_sort_west")
draw_definition_property("Omni Quads", "deftoken_quad_sort_omni")
row = box.row()
row.alignment = "CENTER"
row.label("Color Tokens", icon="COLOR")
row = box.row()
row.alignment = "CENTER"
row.label("Token In: Object/Material/Vertex Color Layer Name")
draw_definition_property("Object Colors", "deftoken_color")
draw_definition_property("In-Game Color", "deftoken_color_blank")
draw_definition_property("Additive Color", "deftoken_color_add")
draw_definition_property("Subtractive Color", "deftoken_color_sub")
layout.separator()
# ===
# BLB
# ===
row = layout.row()
row.alignment = "CENTER"
row.label("BLB Properties", icon="MESH_CUBE")
# Property: Custom Collision
layout.prop(self, "custom_collision")
# Property: Fallback Collision
row = layout.row()
row.label("Fallback Collision:")
row = layout.row()
row.prop(self, "fallback_collision", expand=True)
# Properties: Coverage
layout.prop(self, "calculate_coverage", text="Calculate Coverage...")
if self.calculate_coverage:
box = layout.box()
box.label("Coverage Options", icon="GROUP")
box.enabled = self.calculate_coverage
def draw_coverage_property(label_text):
"""A helper function for drawing the coverage properties."""
row = box.row()
split = row.split(percentage=0.28)
col = split.column()
col.label(label_text)
split = split.split(percentage=0.43)
col = split.column()
col.prop(self, "coverage_{}_hide".format(label_text.lower()), "")
split = split.split()
col = split.column()
col.prop(self, "coverage_{}_calculate".format(label_text.lower()), "")
row = box.row()
split = row.split(percentage=0.27)
col = split.column()
col.label("")
col.label("Side")
split = split.split(percentage=0.42)
col = split.column()
col.label("Hide")
col.label("Adjacent")
split = split.split()
col = split.column()
col.label("Hide")
col.label("Self")
draw_coverage_property("Top")
draw_coverage_property("Bottom")
draw_coverage_property("North")
draw_coverage_property("East")
draw_coverage_property("South")
draw_coverage_property("West")
# Properties: Quad Sorting
layout.prop(self, "auto_sort_quads")
# Property: Use Material Colors
layout.prop(self, "use_materials")
# Property: Use Vertex Colors
layout.prop(self, "use_vertex_colors")
# Property: Use Object Colors
layout.prop(self, "use_object_colors")
# Property: UVs
row = layout.row()
# split = row.split(percentage=0.53)
# col = split.column()
row.prop(self, "calculate_uvs")
if not self.calculate_uvs:
self.square_side_uvs = False
self.store_uvs = False
# Property: Square SIDE UVs
row = layout.row()
row.enabled = self.calculate_uvs
row.prop(self, "square_side_uvs")
# Property: Store UVs
row = layout.row()
row.enabled = self.calculate_uvs
row.prop(self, "store_uvs")
# Property: Round Normals
layout.prop(self, "round_normals")
# Property: Precision
layout.prop(self, "float_precision")
layout.separator()
# =======
# Writing
# =======
row = layout.row()
row.alignment = "CENTER"
row.label("File Properties", icon="TEXT")
# Property: Pretty Print
layout.prop(self, "pretty_print")
# Property: Write Log
row = layout.row()
split = row.split(percentage=0.4)
col = split.column()
col.prop(self, "write_log")
# Property: Write Log on Warnings
# Only show when Write Log is checked.
split = split.split()
# The "Only on Warnings" option is grayed out when "Write Log" is not enabled.
split.enabled = self.write_log
if not self.write_log:
self.write_log_warnings = False
col = split.column()
col.prop(self, "write_log_warnings")
# Property: Terse Mode
layout.prop(self, "terse_mode")
# =============
# Blender Stuff
# =============
def menu_export(self, context):
"""Adds the export option into the export menu."""
self.layout.operator(ExportBLB.bl_idname, text="Blockland Brick (.blb)")
def register():
"""Registers this module into Blender."""
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_file_export.append(menu_export)
def unregister():
"""Unregisters this module from Blender."""
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_file_export.remove(menu_export)
if __name__ == "__main__":
register()