-
Notifications
You must be signed in to change notification settings - Fork 18
/
tetra3d.py
2335 lines (1727 loc) · 99.4 KB
/
tetra3d.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
# Add-on for Tetra3D > Blender exporting
import bpy, os, bmesh, math, mathutils, aud, bpy_extras
from bpy.app.handlers import persistent
currentlyPlayingAudioName = None
currentlyPlayingAudioHandle = None
audioPaused = False
bl_info = {
"name" : "Tetra3D Addon", # The name in the addon search menu
"author" : "SolarLune Games",
"description" : "An addon for exporting GLTF content from Blender for use with Tetra3D.",
"blender" : (3, 0, 1), # Lowest version to use
"location" : "View3D",
"category" : "Gamedev",
"version" : (0, 16, 0),
"support" : "COMMUNITY",
"doc_url" : "https://github.com/SolarLune/Tetra3d/wiki/Blender-Addon",
}
objectTypes = [
("MESH", "Mesh", "A standard, visible mesh object.", 0, 0),
("GRID", "Grid", "A grid object; not visualized or 'physically present'. The vertices in Blender become grid points in Tetra3D; the edges become their connections.", 0, 1),
]
sectorTypes = [
("OBJECT", "Object", "An Object that lies in a sector will only render if the sector it is in also renders.", 0, 0),
("SECTOR", "Sector", "A Sector indicates a space that contains objects and maintains neighborly relationships with other Sectors.", 0, 1),
("STANDALONE", "Standalone", "A Standalone object will render regardless of if the sector it lies in renders (or if it lies in any sector at all).", 0, 2),
]
def listSectorTypes(self, context):
if context.object.type == "MESH" or (context.object.instance_type == "COLLECTION" and context.object.instance_collection is not None):
return sectorTypes
return sectorTypes[::2]
boundsTypes = [
("NONE", "No Bounds", "No collision will be created for this object", 0, 0),
("AABB", "AABB", "An AABB (axis-aligned bounding box). If the size isn't customized, it will be big enough to fully contain the mesh of the current object. Currently buggy when resolving intersections between AABB or other Triangle Nodes", 0, 1),
("CAPSULE", "Capsule", "A capsule, which can rotate. If the radius and height are not set, it will have a radius and height to fully contain the current object", 0, 2),
("SPHERE", "Sphere", "A sphere. If the radius is not custom set, it will have a large enough radius to fully contain the provided object", 0, 3),
("TRIANGLES", "Triangle Mesh", "A triangle mesh bounds type. Only works on mesh-type objects (i.e. an Empty won't generate a BoundingTriangles). Accurate, but slow. Currently buggy when resolving intersections between AABB or other Triangle Nodes", 0, 4),
]
gltfExportTypes = [
("GLB", ".glb", "Exports a single file, with all data packed in binary form. Textures can be packed into the file. Most efficient and portable, but more difficult to edit later", 0, 0),
("GLTF_SEPARATE", ".gltf + .bin + external textures", "Exports multiple files, with separate JSON, binary and texture data. Easiest to edit later", 0, 1),
]
sectorDetectionType = [
("VERTICES", "Vertices", "Sector neighborhood is determined by sectors sharing vertex positions. Accurate, but slower", 0, 0),
("AABB", "AABB", "Sector neighborhood is determined by AABB intersection. Fast, but inaccurate", 0, 1),
]
materialBlendModes = [
("DEFAULT", "Default", "Blends the destination by the material's color modulated by the material's alpha value. The default alpha-blending composite mode. Also known as BlendSourceOver", 0, 0),
("ADDITIVE", "Additive", "Adds the material's color to the destination. Also known as BlendLighter", 0, 1),
("MULTIPLY", "Multiply", "Multiplies the material's color by the destination. Known as Multiply compositing using a custom Blend object", 0, 2),
("CLEAR", "Clear", "Anywhere the material draws is cleared instead; useful to 'punch through' a scene to show the blank alpha zero. Also known as BlendClear", 0, 3),
]
materialTransparencyModes = [
("AUTO", "Auto", "The material is opaque until its material color has an alpha below 1; in this case, it switches to Transparent mode", 0, 0),
("OPAQUE", "Opaque", "The material is wholly opaque", 0, 1),
("ALPHA CLIP", "Alpha Clip", "Transparency is determined by the texture's alpha channel and is either wholly transparent or wholly opaque. Renders after all opaque objects and is sorted from back-to-front", 0, 2),
("TRANSPARENT", "Transparent", "Partial transparency. Renders after all opaque objects and is sorted from back-to-front", 0, 3),
]
materialBillboardModes = [
("NONE", "None", "No billboarding - the (unskinned) object with this material does not rotate to face the camera.", 0, 0),
("FIXEDVERTICAL", "Fixed Vertical", "Fixed Vertical billboarding - the (unskinned) object with this material faces the camera, with up always pointing towards the camera's local up vector (+Y). Good for top-down games.", 0, 1),
("HORIZONTAL", "Horizontal", "Horizontal billboarding - the (unskinned) object with this material rotates around to the face the camera only on the X and Z axes (not the Y axis).", 0, 2),
("FULL", "Full", "Full billboarding - the (unskinned) object rotates fully to face the camera.", 0, 3),
]
materialLightingModes = [
("DEFAULT", "Default", "Default lighting; light is dependent on normal of lit faces.", 0, 0),
("NORMAL", "Point Towards Lights", "Lighting acts as though faces always face light sources. Particularly useful for billboarded 2D sprites.", 0, 1),
("DOUBLE", "Double-Sided", "Double-sided lighting; lighting is dependent on normal of lit faces, but on both sides of a face.", 0, 2),
]
worldFogCompositeModes = [
("OFF", "Off", "No fog. Object colors aren't changed with distance from the camera.", 0, 0),
("ADDITIVE", "Additive", "Additive fog - this fog mode brightens objects in the distance, with full effect being adding the color given to the object's color at maximum distance (according to the camera's far range).", 0, 1),
("SUBTRACT", "Subtractive", "Subtractive fog - this fog mode darkens objects in the distance, with full effect being subtracting the object's color by the fog color at maximum distance (according to the camera's far range).", 0, 2),
("OVERWRITE", "Overwrite", "Overwrite fog - this fog mode overwrites the object's color with the fog color, with maximum distance being the camera's far distance.", 0, 3),
("TRANSPARENT", "Transparent", "Transparent fog - this fog mode fades the object out over distance, such that at maximum distance / fog range, the object is wholly transparent.", 0, 4),
]
worldFogCurveTypes = [
("LINEAR", "Smooth", "Smooth fog (Ease: Linear); this goes from 0% in the near range to 100% in the far range evenly.", "LINCURVE", 0),
("OUTCIRC", "Dense", "Dense fog (Ease: Out Circ); fog will increase aggressively in the near range, ramping up to 100% at the far range.", "SPHERECURVE", 1),
("INCIRC", "Light", "Light fog (Ease: In Circ); fog will increase aggressively towards the far range, ramping up to 100% at the far range.", "SHARPCURVE", 2),
]
gamePropTypes = [
("bool", "Bool", "Boolean data type", 0, 0),
("int", "Int", "Int data type", 0, 1),
("float", "Float", "Float data type", 0, 2),
("string", "String", "String data type", 0, 3),
("reference", "Object", "Object reference data type; converted to a string composed as follows on export - [SCENE NAME]:[OBJECT NAME]", 0, 4),
("color", "Color", "Color data type", 0, 5),
("vector3d", "3D Vector", "3D vector data type", 0, 6),
("file", "Filepath", "Filepath as a string", 0, 7),
("directory", "Directory Path", "Directory Path as a string", 0, 8),
]
batchModes = [
("OFF", "Off", "No automatic batching.", 0, 0),
("DYNAMIC", "Dynamic Batching", "Dynamic batching based off of one material (the first one).", 0, 1),
("STATIC", "Static Merging", "Static merging; merged objects cannot move or deviate in any way. After automatic static merging, the merged models will be automatically set to invisible.", 0, 2),
]
def filepathSet(self, value):
global currentlyPlayingAudioHandle, currentlyPlayingAudioName, audioPaused
if "valueFilepath" in self and self["valueFilepath"] == currentlyPlayingAudioName and value != self["valueFilepath"]:
currentlyPlayingAudioHandle.stop()
currentlyPlayingAudioHandle = None
currentlyPlayingAudioName = ""
audioPaused = False
self["valueFilepath"] = value
def filepathGet(self):
if "valueFilepath" in self:
return self["valueFilepath"]
return ""
class t3dGamePropertyItem__(bpy.types.PropertyGroup):
name: bpy.props.StringProperty(name="Name", default="New Property")
valueType: bpy.props.EnumProperty(items=gamePropTypes, name="Type")
valueBool: bpy.props.BoolProperty(name = "", description="The boolean value of the property")
valueInt: bpy.props.IntProperty(name = "", description="The integer value of the property")
valueFloat: bpy.props.FloatProperty(name = "", description="The float value of the property")
valueString: bpy.props.StringProperty(name = "", description="The string value of the property")
valueReference: bpy.props.PointerProperty(name = "", type=bpy.types.Object, description="The object to reference")
valueReferenceScene: bpy.props.PointerProperty(name = "", type=bpy.types.Scene, description="The scene to search for an object to reference; if this is blank, all objects from all scenes will appear in the object search field")
valueColor: bpy.props.FloatVectorProperty(name = "", description="The color value of the property", subtype="COLOR", default=[1, 1, 1, 1], size=4, min=0, max=1)
valueVector3D: bpy.props.FloatVectorProperty(name = "", description="The 3D vector value of the property", subtype="XYZ")
valueFilepath: bpy.props.StringProperty(name = "", description="The filepath of the property", subtype="FILE_PATH", set=filepathSet, get=filepathGet)
valueDirpath: bpy.props.StringProperty(name = "", description="The directory path of the property", subtype="DIR_PATH")
# valueFilepathAbsolute
# valueVector4D: bpy.props.FloatVectorProperty(name = "", description="The 4D vector value of the property")
class OBJECT_OT_tetra3dAddProp(bpy.types.Operator):
bl_idname = "object.tetra3daddprop"
bl_label = "Add Game Property"
bl_description= "Adds a game property to the currently selected object. A game property gets added to an Object's Properties object in Tetra3D"
bl_options = {'REGISTER', 'UNDO'}
mode : bpy.props.StringProperty()
def execute(self, context):
if self.mode == "scene":
target = context.scene
elif self.mode == "object":
target = context.object
elif self.mode == "material":
target = context.object.active_material
elif self.mode == "action":
target = context.active_action
# target = getattr(context, self.mode)
target.t3dGameProperties__.add()
target.t3dGameProperties__.move(len(target.t3dGameProperties__)-1, 0)
return {'FINISHED'}
class OBJECT_OT_tetra3dDeleteProp(bpy.types.Operator):
bl_idname = "object.tetra3ddeleteprop"
bl_label = "Delete Game Property"
bl_description= "Deletes a game property from the currently selected object"
bl_options = {'REGISTER', 'UNDO'}
index : bpy.props.IntProperty()
mode : bpy.props.StringProperty()
def execute(self, context):
if self.mode == "scene":
target = context.scene
elif self.mode == "object":
target = context.object
elif self.mode == "material":
target = context.object.active_material
elif self.mode == "action":
target = context.active_action
prop = target.t3dGameProperties__[self.index]
global currentlyPlayingAudioHandle, currentlyPlayingAudioName
if prop.valueType == "file" and prop.valueFilepath == currentlyPlayingAudioName and currentlyPlayingAudioHandle:
currentlyPlayingAudioHandle.stop()
currentlyPlayingAudioHandle = None
target.t3dGameProperties__.remove(self.index)
return {'FINISHED'}
class OBJECT_OT_tetra3dReorderProps(bpy.types.Operator):
bl_idname = "object.tetra3dreorderprops"
bl_label = "Re-order Game Property"
bl_description= "Moves a game property up or down in the list"
bl_options = {'REGISTER', 'UNDO'}
index : bpy.props.IntProperty()
moveUp : bpy.props.BoolProperty()
mode : bpy.props.StringProperty()
def execute(self, context):
if self.mode == "scene":
target = context.scene
elif self.mode == "object":
target = context.object
elif self.mode == "material":
target = context.object.active_material
elif self.mode == "action":
target = context.active_action
if self.moveUp:
target.t3dGameProperties__.move(self.index, self.index-1)
else:
target.t3dGameProperties__.move(self.index, self.index+1)
return {'FINISHED'}
class OBJECT_OT_tetra3dSetVector(bpy.types.Operator):
bl_idname = "object.t3dsetvec"
bl_label = "" ## We don't want the label to show
bl_description= "Sets vector value"
bl_options = {'REGISTER', 'UNDO'}
index : bpy.props.IntProperty()
mode : bpy.props.StringProperty()
buttonMode : bpy.props.StringProperty()
@classmethod
def description(cls, context, properties):
if properties.buttonMode == "object location":
return "Set to object world position"
else:
return "Set to 3D Cursor position"
def execute(self, context):
if self.mode == "scene":
target = context.scene
elif self.mode == "object":
target = context.object
elif self.mode == "material":
target = context.object.active_material
elif self.mode == "action":
target = context.active_action
if self.buttonMode == "object location":
target.t3dGameProperties__[self.index].valueVector3D = context.object.location
elif self.buttonMode == "3D cursor":
target.t3dGameProperties__[self.index].valueVector3D = context.scene.cursor.location
return {'FINISHED'}
class OBJECT_OT_tetra3dFocusObject(bpy.types.Operator):
bl_idname = "object.t3dfocusobject"
bl_label = "" ## We don't want the label to show
bl_description= "Focuses the camera on the specified object"
bl_options = {'REGISTER', 'UNDO'}
target : bpy.props.StringProperty()
def execute(self, context):
if self.target != "":
old_selected = bpy.context.selected_objects.copy()
ob = bpy.data.objects[self.target]
bpy.ops.object.select_all(action='DESELECT')
context.window.scene = ob.users_scene[0]
context.window.view_layer = ob.users_scene[0].view_layers[0]
override_window = context.window
override_screen = override_window.screen
areas = [area for area in override_screen.areas if area.type == "VIEW_3D"]
for area in areas:
override_region = [region for region in area.regions if region.type == 'WINDOW']
with context.temp_override(window=override_window, area=area, region=override_region[0]):
ob.select_set(True)
bpy.ops.view3d.view_selected()
context.region_data.view_distance += 25
# print(context.region_data)
bpy.ops.object.select_all(action='DESELECT')
for obj in old_selected:
obj.select_set(True)
return {'FINISHED'}
search_name = False
def enum_search(scene, context):
options = set()
def check_properties(o):
global search_name
for p in o.t3dGameProperties__:
if search_name:
options.add((p.name, p.name, ""))
else:
if p.valueType == "string":
options.add((p.valueString, p.valueString, ""))
for o in bpy.data.objects:
check_properties(o)
for o in bpy.data.materials:
check_properties(o)
for o in bpy.data.actions:
check_properties(o)
for o in bpy.data.scenes:
check_properties(o)
result = sorted(list(options), key=lambda x: x[0].lower())
return result
class OBJECT_OT_tetra3dSearchStringProperties(bpy.types.Operator):
bl_idname = "object.t3dsearchstringproperties"
bl_label = ""
bl_description = "Search for previously-used strings in the blend file"
bl_options = {'REGISTER', 'UNDO'}
bl_property = "search_options"
index : bpy.props.IntProperty()
search_options: bpy.props.EnumProperty(name="Search Options", items=enum_search)
mode : bpy.props.StringProperty()
search_name : bpy.props.BoolProperty()
def execute(self, context):
if self.mode == "scene":
target = context.scene
elif self.mode == "object":
target = context.object
elif self.mode == "material":
target = context.object.active_material
elif self.mode == "action":
target = context.active_action
if self.search_name:
target.t3dGameProperties__[self.index].name = self.search_options
else:
target.t3dGameProperties__[self.index].valueString = self.search_options
return {'FINISHED'}
def invoke(self, context, event):
global search_name
if self.search_name:
search_name = True
else:
search_name = False
context.window_manager.invoke_search_popup(self)
return {'FINISHED'}
def copyProp(fromProp, toProp):
toProp.name = fromProp.name
toProp.valueType = fromProp.valueType
toProp.valueBool = fromProp.valueBool
toProp.valueInt = fromProp.valueInt
toProp.valueFloat = fromProp.valueFloat
toProp.valueString = fromProp.valueString
toProp.valueReference = fromProp.valueReference
toProp.valueReferenceScene = fromProp.valueReferenceScene
toProp.valueColor = fromProp.valueColor
toProp.valueVector3D = fromProp.valueVector3D
toProp.valueFilepath = fromProp.valueFilepath
toProp.valueDirpath = fromProp.valueDirpath
class OBJECT_OT_tetra3dOverrideProp(bpy.types.Operator):
bl_idname = "object.tetra3doverrideprop"
bl_label = "Override Game Property"
bl_description= "Copies a game property to the collection instance for overriding."
bl_options = {'REGISTER', 'UNDO'}
objectIndex : bpy.props.IntProperty()
propIndex : bpy.props.IntProperty()
def execute(self, context):
targetProp = context.object.instance_collection.objects[self.objectIndex].t3dGameProperties__[self.propIndex]
newProp = None
for prop in context.object.t3dGameProperties__:
if prop.name == targetProp.name:
newProp = prop
break
if newProp is None:
newProp = context.object.t3dGameProperties__.add()
copyProp(targetProp, newProp)
return {'FINISHED'}
class OBJECT_OT_tetra3dCopyProps(bpy.types.Operator):
bl_idname = "object.tetra3dcopyprops"
bl_label = "Copy Game Properties"
bl_description= "Copies game properties from the currently selected object to all other selected objects"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
selected = context.object
for o in context.selected_objects:
if o == selected:
continue
o.t3dGameProperties__.clear()
for prop in selected.t3dGameProperties__:
newProp = o.t3dGameProperties__.add()
copyProp(prop, newProp)
return {'FINISHED'}
class MATERIAL_OT_tetra3dMaterialCopyProps(bpy.types.Operator):
bl_idname = "material.tetra3dcopyprops"
bl_label = "Overwrite Game Property on All Materials"
bl_description= "Overwrites game properties from the currently selected material to all other materials on this object"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
selected = context.object
for slot in selected.material_slots:
if slot.material == None or slot.material == selected.active_material:
continue
slot.material.t3dGameProperties__.clear()
for prop in selected.active_material.t3dGameProperties__:
newProp = slot.material.t3dGameProperties__.add()
copyProp(prop, newProp)
return {'FINISHED'}
class OBJECT_OT_tetra3dCopyOneProperty(bpy.types.Operator):
bl_idname = "object.tetra3dcopyoneproperty"
bl_label = "Copy Game Property"
bl_description= "Copies a single game property from the currently selected object to all other selected objects"
bl_options = {'REGISTER', 'UNDO'}
index : bpy.props.IntProperty()
def execute(self, context):
selected = context.object
for o in context.selected_objects:
if o == selected:
continue
fromProp = selected.t3dGameProperties__[self.index]
if fromProp.name in o.t3dGameProperties__:
toProp = o.t3dGameProperties__[fromProp.name]
else:
toProp = o.t3dGameProperties__.add()
copyProp(fromProp, toProp)
return {'FINISHED'}
class OBJECT_OT_tetra3dCopyNodePathToClipboard(bpy.types.Operator):
bl_idname = "object.tetra3dcopynodepath"
bl_label = "Copy Node Path To Clipboard"
bl_description= "Copies an object's node path to clipboard"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
bpy.context.window_manager.clipboard = objectNodePath(context.object)
return {'FINISHED'}
class OBJECT_OT_tetra3dClearProps(bpy.types.Operator):
bl_idname = "object.tetra3dclearprops"
bl_label = "Clear Game Properties"
bl_description= "Clears game properties from all currently selected objects"
bl_options = {'REGISTER', 'UNDO'}
mode : bpy.props.StringProperty()
def execute(self, context):
if self.mode == "object":
for o in context.selected_objects:
o.t3dGameProperties__.clear()
elif self.mode == "scene":
context.scene.t3dGameProperties__.clear()
elif self.mode == "material" and context.object.active_material is not None:
context.object.active_material.t3dGameProperties__.clear()
return {'FINISHED'}
class OBJECT_OT_tetra3dPlaySample(bpy.types.Operator):
bl_idname = "object.t3dplaysound"
bl_label = "Preview Music File"
bl_description= "Previews music file"
bl_options = {'REGISTER'}
filepath : bpy.props.StringProperty()
def execute(self, context):
global currentlyPlayingAudioHandle, currentlyPlayingAudioName, audioPaused
device = aud.Device()
if currentlyPlayingAudioHandle:
if currentlyPlayingAudioName == self.filepath:
currentlyPlayingAudioHandle.resume()
audioPaused = False
else:
currentlyPlayingAudioHandle.stop()
if not currentlyPlayingAudioHandle or currentlyPlayingAudioName != self.filepath:
sound = aud.Sound(bpy.path.abspath(self.filepath))
currentlyPlayingAudioHandle = device.play(sound)
currentlyPlayingAudioHandle.volume = 0.5
currentlyPlayingAudioHandle.loop_count = -1
currentlyPlayingAudioName = self.filepath
return {'FINISHED'}
class OBJECT_OT_tetra3dStopSample(bpy.types.Operator):
bl_idname = "object.t3dpausesound"
bl_label = "Pauses Previewing Music File"
bl_description= "Stops currently playing music file"
bl_options = {'REGISTER', 'UNDO'}
filepath : bpy.props.StringProperty()
def execute(self, context):
global currentlyPlayingAudioHandle, audioPaused
if currentlyPlayingAudioHandle:
currentlyPlayingAudioHandle.pause()
audioPaused = True
return {'FINISHED'}
class OBJECT_OT_tetra3dSetAnimationInterpolationAll(bpy.types.Operator):
bl_idname = "object.t3dsetanimationinterpolationall"
bl_label = "All Animations"
bl_description= "Sets interpolation for all keys in all animations in the blend file to the specified interpolation mode"
bl_options = {'REGISTER'}
interpolationType : bpy.props.StringProperty()
def execute(self, context):
for action in bpy.data.actions:
for curve in action.fcurves:
for point in curve.keyframe_points:
point.interpolation = self.interpolationType
return {'FINISHED'}
class OBJECT_OT_tetra3dSetAnimationInterpolation(bpy.types.Operator):
bl_idname = "object.t3dsetanimationinterpolation"
bl_label = "Current Animation"
bl_description= "Sets interpolation for all keys for the current animation on the object to the specified interpolation mode"
bl_options = {'REGISTER'}
interpolationType : bpy.props.StringProperty()
forAll : bpy.props.BoolProperty()
def execute(self, context):
if bpy.context.active_object and bpy.context.active_object.animation_data and bpy.context.active_object.animation_data.action:
action = bpy.context.active_object.animation_data.action
for curve in action.fcurves:
for point in curve.keyframe_points:
point.interpolation = self.interpolationType
return {'FINISHED'}
class RENDER_OT_tetra3dQuickSetRenderResolution(bpy.types.Operator):
bl_idname = "render.t3dquicksetrenderresolution"
bl_label = "Set render resolution"
bl_description= "Sets the render resolution for cameras in this blend file to quick-values"
bl_options = {'REGISTER', 'UNDO'}
resolutionHeight : bpy.props.IntProperty()
def execute(self, context):
asr = 16/9
context.scene.t3dRenderResolutionW__ = int(self.resolutionHeight * asr)
context.scene.t3dRenderResolutionH__ = int(self.resolutionHeight)
return {'FINISHED'}
def objectNodePath(object):
p = object.name
if object.parent:
if object.parent_type == "BONE":
armaturePath = ""
parentBoneName = object.parent_bone
armatureData = object.parent.data
parent = armatureData.bones[parentBoneName]
while parent:
armaturePath = parent.name + "/" + armaturePath
parent = parent.parent
p = objectNodePath(object.parent) + "/" + armaturePath + object.name
else:
p = objectNodePath(object.parent) + "/" + object.name
return p
class MESH_PT_tetra3d(bpy.types.Panel):
bl_idname = "MESH_PT_tetra3d"
bl_label = "Tetra3d Mesh Properties"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
def draw(self, context):
row = self.layout.row()
meshData = context.object.data
if meshData and context.object.type == "MESH":
row.prop(meshData, "t3dUniqueMesh__")
row = self.layout.row()
row.prop(meshData, "t3dUniqueMaterials__")
if "t3dUniqueMesh__" in meshData:
row.enabled = meshData["t3dUniqueMesh__"]
else:
row.enabled = False
class ACTION_PT_tetra3d(bpy.types.Panel):
bl_idname = "ACTION_PT_tetra3d"
bl_label = "Tetra3d Action Properties"
bl_space_type = 'DOPESHEET_EDITOR'
bl_region_type = 'UI'
bl_context = "ANIMATION"
bl_category = "Action"
@classmethod
def poll(self,context):
return context.active_action is not None
def draw(self, context):
row = self.layout.row()
row.prop(context.active_action, "t3dRelativeMotion__")
row = self.layout.row()
add = row.operator("object.tetra3daddprop", text="Add Game Property", icon="PLUS")
add.mode = "action"
# row.operator("object.tetra3dcopyprops", text="Overwrite All Game Properties", icon="COPYDOWN")
handleT3DProperties(self, None, context.active_action.t3dGameProperties__, "action")
row = self.layout.row()
# No scene equivalent for this, so there is no mode property for this class
clear = row.operator("object.tetra3dclearprops", text="Clear All Game Properties", icon="CANCEL")
clear.mode = "action"
class OBJECT_PT_tetra3d(bpy.types.Panel):
bl_idname = "OBJECT_PT_tetra3d"
bl_label = "Tetra3d Object Properties"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
@classmethod
def poll(self,context):
return context.object is not None
def draw(self, context):
row = self.layout.row()
np = objectNodePath(context.object)
np = " / ".join(np.split("/"))
row.label(text="Node Path : " + np)
row = self.layout.row()
row.operator("object.tetra3dcopynodepath", text="Copy Node Path to Clipboard", icon="COPYDOWN")
row = self.layout.row()
row.enabled = context.object.t3dObjectType__ == 'MESH'
row.prop(context.object, "t3dVisible__")
if context.object.type == "MESH":
box = self.layout.box()
row = box.row()
row.enabled = context.object.t3dObjectType__ == 'MESH'
row.prop(context.object, "t3dAutoBatch__")
row = box.row()
row.label(text="Object Type: ")
row.prop(context.object, "t3dObjectType__", expand=True)
row = box.row()
row.enabled = context.object.t3dObjectType__ == 'MESH'
row.prop(context.object, "t3dAutoSubdivide__")
if context.object.t3dAutoSubdivide__:
row.prop(context.object, "t3dAutoSubdivideSize__")
isCollection = context.object.instance_type == "COLLECTION" and context.object.instance_collection is not None
box = self.layout.box()
row = box.row()
row.label(text="Sector Type:")
if isCollection:
row = box.row()
row.enabled = context.object.t3dObjectType__ == 'MESH'
row.prop(context.object, "t3dSectorTypeOverride__", expand=True)
row = box.row()
if isCollection:
row.enabled = context.object.t3dSectorTypeOverride__
else:
row.enabled = context.object.t3dObjectType__ == 'MESH'
row.prop(context.object, "t3dSectorType__", expand=True)
row = self.layout.row()
row.prop(context.object, "t3dBoundsType__")
row = self.layout.row()
if context.object.t3dBoundsType__ == 'AABB':
row.prop(context.object, "t3dAABBCustomEnabled__")
if context.object.t3dAABBCustomEnabled__:
row = self.layout.row()
row.prop(context.object, "t3dAABBCustomSize__")
elif context.object.t3dBoundsType__ == 'CAPSULE':
row.prop(context.object, "t3dCapsuleCustomEnabled__")
if context.object.t3dCapsuleCustomEnabled__:
row = self.layout.row()
row.prop(context.object, "t3dCapsuleCustomRadius__")
row.prop(context.object, "t3dCapsuleCustomHeight__")
elif context.object.t3dBoundsType__ == 'SPHERE':
row.prop(context.object, "t3dSphereCustomEnabled__")
if context.object.t3dSphereCustomEnabled__:
row = self.layout.row()
row.prop(context.object, "t3dSphereCustomRadius__")
elif context.object.t3dBoundsType__ == 'TRIANGLES':
row.prop(context.object, "t3dTrianglesCustomBroadphaseEnabled__")
if context.object.t3dTrianglesCustomBroadphaseEnabled__:
row.prop(context.object, "t3dTrianglesCustomBroadphaseGridSize__")
row = self.layout.row()
row.separator()
if isCollection:
row = self.layout.row()
row.label(text="Collection Object Properties")
row.prop(context.scene, "t3dExpandOverrideProps__", icon="TRIA_DOWN" if context.scene.t3dExpandOverrideProps__ else "TRIA_RIGHT", icon_only=True, emboss=False)
if context.scene.t3dExpandOverrideProps__:
col = context.object.instance_collection
for objectIndex, object in enumerate(col.objects):
if object.parent == None:
row = self.layout.row()
box = row.box()
box.label(text="Object: " + object.name)
box.row().separator()
handleT3DProperties(self, box, object.t3dGameProperties__, "object", False)
row = self.layout.row()
row.label(text="Game Properties")
row.prop(context.scene, "t3dExpandGameProps__", icon="TRIA_DOWN" if context.scene.t3dExpandGameProps__ else "TRIA_RIGHT", icon_only=True, emboss=False)
if context.scene.t3dExpandGameProps__:
row = self.layout.row()
add = row.operator("object.tetra3daddprop", text="Add Game Property", icon="PLUS")
add.mode = "object"
row.operator("object.tetra3dcopyprops", text="Overwrite All Game Properties", icon="COPYDOWN")
handleT3DProperties(self, None, context.active_object.t3dGameProperties__, "object")
row = self.layout.row()
# No scene equivalent for this, so there is no mode property for this class
clear = row.operator("object.tetra3dclearprops", text="Clear All Game Properties", icon="CANCEL")
clear.mode = "object"
class SCENE_PT_tetra3d(bpy.types.Panel):
bl_idname = "SCENE_PT_tetra3d"
bl_label = "Tetra3d Scene Properties"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
@classmethod
def poll(self,context):
return context.scene is not None
def draw(self, context):
row = self.layout.row()
add = row.operator("object.tetra3daddprop", text="Add Game Property", icon="PLUS")
add.mode = "scene"
handleT3DProperties(self, None, context.scene.t3dGameProperties__, "scene")
row = self.layout.row()
clear = row.operator("object.tetra3dclearprops", text="Clear All Game Properties", icon="CANCEL")
clear.mode = "scene"
class CAMERA_PT_tetra3d(bpy.types.Panel):
bl_idname = "CAMERA_PT_tetra3d"
bl_label = "Tetra3d Camera Properties"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
@classmethod
def poll(self,context):
return context.object is not None and context.object.type == "CAMERA"
def draw(self, context):
row = self.layout.row()
row.prop(context.object.data, "type")
row = self.layout.row()
if context.object.data.type == "PERSP":
row.prop(context.object.data, "t3dFOV__")
else:
row.prop(context.object.data, "ortho_scale")
row = self.layout.row()
row.prop(context.object.data, "clip_start")
row.prop(context.object.data, "clip_end")
row = self.layout.row()
row.prop(context.object.data, "t3dMaxLightCount__")
box = self.layout.box()
box.prop(context.object.data, "t3dSectorRendering__")
row = box.row()
sectorRenderingOn = context.object.data.t3dSectorRendering__
row.enabled = sectorRenderingOn
row.prop(context.object.data, "t3dSectorRenderDepth__")
row.enabled = sectorRenderingOn
box = self.layout.box()
row = box.row()
row.prop(context.object.data, "t3dPerspectiveCorrectedTextureMapping__")
def handleT3DProperties(self, box, props, operatorType, enabled=True):
for index, prop in enumerate(props):
if box is None:
box = self.layout.box()
row = box.row()
row.prop(prop, "name")
op = row.operator(OBJECT_OT_tetra3dSearchStringProperties.bl_idname, text="", icon="VIEWZOOM")
op.search_name = True
op.index = index
op.mode = operatorType
moveUpOptions = row.operator(OBJECT_OT_tetra3dReorderProps.bl_idname, text="", icon="TRIA_UP")
moveUpOptions.index = index
moveUpOptions.moveUp = True
moveUpOptions.mode = operatorType
moveDownOptions = row.operator(OBJECT_OT_tetra3dReorderProps.bl_idname, text="", icon="TRIA_DOWN")
moveDownOptions.index = index
moveDownOptions.moveUp = False
moveDownOptions.mode = operatorType
copy = row.operator(OBJECT_OT_tetra3dCopyOneProperty.bl_idname, text="", icon="COPYDOWN")
copy.index = index
deleteOptions = row.operator(OBJECT_OT_tetra3dDeleteProp.bl_idname, text="", icon="TRASH")
deleteOptions.index = index
deleteOptions.mode = operatorType
row = box.row()
row.enabled = enabled
row.prop(prop, "valueType")
if prop.valueType == "bool":
row.prop(prop, "valueBool")
elif prop.valueType == "int":
row.prop(prop, "valueInt")
elif prop.valueType == "float":
row.prop(prop, "valueFloat")
elif prop.valueType == "string":
row.prop(prop, "valueString")
op = row.operator(OBJECT_OT_tetra3dSearchStringProperties.bl_idname, text="", icon="VIEWZOOM")
op.index = index
op.mode = operatorType
op.search_name = False
elif prop.valueType == "reference":
row.prop(prop, "valueReferenceScene")
if prop.valueReferenceScene != None:
row.prop_search(prop, "valueReference", prop.valueReferenceScene, "objects")
else:
row.prop(prop, "valueReference")
op = row.operator("object.t3dfocusobject", text="", icon="CAMERA_DATA")
if prop.valueReference:
op.target = prop.valueReference.name
elif prop.valueType == "color":
row.prop(prop, "valueColor")
elif prop.valueType == "vector3d":
row = box.row()
row.enabled = enabled
row.prop(prop, "valueVector3D")
if operatorType == "object" or operatorType == "material":
setCur = row.operator("object.t3dsetvec", text="", icon="OBJECT_ORIGIN")
setCur.index = index
setCur.mode = operatorType
setCur.buttonMode = "object location"
setCur = row.operator("object.t3dsetvec", text="", icon="PIVOT_CURSOR")
setCur.index = index
setCur.mode = operatorType
setCur.buttonMode = "3D cursor"
elif prop.valueType == "file":
row.prop(prop, "valueFilepath")
ext = os.path.splitext(prop.valueFilepath)[1]
if ext in bpy.path.extensions_audio:
global currentlyPlayingAudioHandle, audioPaused
if currentlyPlayingAudioHandle and not audioPaused:
playButton = row.operator("object.t3dpausesound", text="", icon="PAUSE")
else:
playButton = row.operator("object.t3dplaysound", text="", icon="PLAY")
playButton.filepath = prop.valueFilepath
elif prop.valueType == "directory":
row.prop(prop, "valueDirpath")
class MATERIAL_PT_tetra3d(bpy.types.Panel):
bl_idname = "MATERIAL_PT_tetra3d"
bl_label = "Tetra3d Material Properties"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "material"
@classmethod
def poll(self,context):
return context.material is not None
def draw(self, context):
row = self.layout.row()
row.prop(context.material, "t3dMaterialColor__")
# row = self.layout.row()
# row.prop(context.material, "t3dColorTexture0__")