-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDTS_ParticlePanel.py
More file actions
1630 lines (1387 loc) · 69.5 KB
/
DTS_ParticlePanel.py
File metadata and controls
1630 lines (1387 loc) · 69.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
bl_info = {
"name": "DTScripts Particle Database",
"author": "Daniel Turton",
"version": (0,0,2),
"blender": (2, 6, 0),
"api": "",
"location": "On the Particles panel. Soon to be limited to showing only under Blender Game.",
"description": "Creates a database and slots on objects to assign them to elements from the database. Draws a panel for database element changes.",
"warning": "If this software borks your project or breaks into your neighbor's house, I'm not responsible. Back your stuff up.",
"wiki_url": "",
"tracker_url": "",
"category": "Game Engine"}
"""
DTScripts Particle Database
by Daniel Turton
Description:
(This will be fun. :) )
The DTScripts Particle Database is a framework that (hopefully) makes the process of creating particle effects a little easier.
Through the use of elements defined as materials, particles, projectiles and statics, the Particle Database will arrange data
for access through the game engine within a dictionary, allowing for access to and randomization of particles generated from static / emitter objects.
Once the elements have been defined, they are "pushed" to the Blender Game Engine through a text block, accessed by a script run at the start
of the game engine. This script parses the text block and adds the elements to a dictionary accordingly.
Once done, game engine scripts can access the information tied to objects by checking their "Content" string game property and the name of the sensor tied to the property.
This file contains the logic for the creation and control of the database.
This is only the Alpha version. I hope that you enjoy what it can do now and what it will do in the future.
Copyright (C) 2011 Daniel Turton
This file is part of the DTScripts Particle Database.
The DTScripts Particle Database 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 3 of the License, or
(at your option) any later version.
The DTScripts Particle Database 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 the DTScripts Particle Database. If not, see <http://www.gnu.org/licenses/>.
"""
import bpy
from bpy.props import *
import random
import time
ObjType = ''
DTdebug = 0
ElementDictionary = {}
def initSceneProperties(scene):
#Script Management
bpy.types.Scene.PhysPanelEdit = BoolProperty(
name = "PanelEditMode",
description = "Panel Edit Mode"
)
scene['PanelEditMode'] = 0
bpy.types.Scene.element_string = StringProperty(
name = "ElementString",
)
scene['ElementString'] = {}
bpy.types.Scene.element_db_status = StringProperty(
name = "element_db_status",
)
scene['element_db_status'] = ""
bpy.types.Object.DTSContent = StringProperty(
name = 'Content',
)
bpy.types.Scene.ElementName = StringProperty(
name = "Element Name",
)
bpy.types.Scene.MaterialWD = StringProperty(
)
bpy.types.Scene.MaterialWP = StringProperty(
)
bpy.types.Scene.MaterialDD = StringProperty(
)
bpy.types.Scene.MaterialDP = StringProperty(
)
bpy.types.Scene.Importchoice = StringProperty(
)
bpy.types.Scene.Elementchoice = StringProperty(
name = "Effect Script",
)
#Material stuff
bpy.types.Scene.EditAreaUpper = FloatProperty(
name = "Edit Area Upper",
)
scene['EditAreaUpper'] = 0.0
bpy.types.Scene.EditAreaLower = FloatProperty(
name = "Edit Area Lower",
)
scene['EditAreaLower'] = 0.0
bpy.types.Scene.EditWetHitDecal = StringProperty(
name = "Edit Wet Hit decal",
)
scene['EditWetHitDecal'] = ""
bpy.types.Scene.EditWetHitParticle = StringProperty(
name = "Edit Wet Hit particle",
)
scene['EditWetHitParticle'] = ""
bpy.types.Scene.EditDryHitDecal = StringProperty(
name = "Edit Dry Hit decal",
)
scene['EditDryHitDecal'] = ""
bpy.types.Scene.EditDryHitParticle = StringProperty(
name = "Edit Dry Hit particle",
)
scene['EditDryHitParticle'] = ""
#stuff for particles
bpy.types.Scene.EditModel = StringProperty(
name = "EditTiedModel",
description = "Edit Tied Model"
)
scene['EditModel'] = ""
bpy.types.Scene.EditObjVelocity = StringProperty(
name = "Edit Object Velocity",
)
scene['EditObjVelocity'] = ""
bpy.types.Scene.EditObjAnimation = StringProperty(
name = "Edit Object Animation",
)
scene['EditObjAnimation'] = ""
bpy.types.Scene.EditObjMulti = IntProperty(
name = "Edit Object Multiplier",
)
scene['EditObjMulti'] = ""
bpy.types.Scene.EditObjFluidMulti = IntProperty(
name = "Edit Object Fluid Multiplier",
)
scene['EditObjFluidMulti'] = ""
bpy.types.Scene.EditEmitFreq = IntProperty(
name = "Edit Emit Frequency",
)
scene['EditEmitFreq'] = ""
bpy.types.Scene.EditFragCountMax = IntProperty(
name = "Max",
)
scene['EditFragCountMax'] = 0
bpy.types.Scene.EditFragCountMin = IntProperty(
name = "Min",
)
scene['EditFragCountMin'] = 0
#stuff for statics
bpy.types.Scene.EditObjAnimStart = IntProperty(
name = "Edit Object Animation Start",
)
scene['EditObjAnimStart'] = ""
bpy.types.Scene.EditObjAnimEnd = IntProperty(
name = "Edit Object Animation End",
)
scene['EditObjAnimEnd'] = ""
return
#Party officially started here
initSceneProperties(bpy.context.scene)
#property groups go up here for priority registration
class ModelDB(bpy.types.PropertyGroup):
type = StringProperty(name = "type", default="None")
bpy.utils.register_class(ModelDB)
class ElementDB(bpy.types.PropertyGroup):
type = StringProperty(name = "type", default="None")
mat_type = StringProperty(name = "mat_type", default="None")
dry_hit_particle = CollectionProperty(type = ModelDB)
dry_hit_decal = CollectionProperty(type = ModelDB)
wet_hit_particle = CollectionProperty(type = ModelDB)
wet_hit_decal = CollectionProperty(type = ModelDB)
AreaLower = FloatProperty(name = "Lower Area")
AreaUpper = FloatProperty(name = "Upper Area")
model = CollectionProperty(type = ModelDB)
animation = CollectionProperty(type = ModelDB)
velocity = []
multiplier = StringProperty(name = "Multiplier", default="None")
fluid_multiplier = StringProperty(name = "Fluid Multiplier", default="None")
emit_frequency = StringProperty(name = "Emit Frequency", default="None")
frag_min = IntProperty(name = "Frag Min")
frag_max = IntProperty(name = "Frag Max")
bpy.utils.register_class(ElementDB)
bpy.types.Scene.element_db = CollectionProperty(type = ElementDB)
bpy.types.Scene.edit_element = CollectionProperty(type = ElementDB)
bpy.types.Scene.ParticleList = CollectionProperty(type = ElementDB)
bpy.types.Scene.MaterialList = CollectionProperty(type = ElementDB)
bpy.types.Scene.StaticList = CollectionProperty(type = ElementDB)
bpy.types.Scene.ProjectileList = CollectionProperty(type = ElementDB)
def ElementListsReset():
return
class ElementDB_Mods(bpy.types.Operator):
bl_idname = "dtscripts.db_mods"
bl_label = "Database Modifications"
purge = bpy.props.IntProperty()
dump = bpy.props.IntProperty()
db_import = bpy.props.IntProperty()
pushtobge = bpy.props.IntProperty()
output = {}
def listiterator(context, database1, list_entry, key):
element_db = bpy.context.scene.element_db
print("element_db" + "[" + list_entry + "]." + key)
for key1 in eval("element_db" + "[\"" + list_entry + "\"]." + key).keys():
if type(eval("element_db" + "[\"" + list_entry + "\"]." + key)[key1]) is list:
print(eval("element_db" + "[\"" + list_entry + "\"]." + key + "." + key1).keys())
if type(eval("element_db" + "[\"" + list_entry + "\"]." + key)[key1]) is not list:
return str(("\t") + key1 + " = " + str(eval("element_db" + "[\"" + list_entry + "\"]." + key)[key1]) + "\n")
def execute(self, context):
scn = context.scene
element_db = bpy.context.scene.element_db
if self.db_import:
dbase = bpy.context.scene.element_db
entry_count = 0
#set up script to evaluate strings!!!
for entry in dbase.keys():
dox.write("entry = " + dbase[entry]['name'] + "\n")
for key in dbase[entry].keys():
dox.write("\t" + key + " = " + dbase[entry][key] + "\n")
entry_count += 1
scn["element_db_status"] = "Database imported. " + str(entry_count) + " entries processed."
return{'FINISHED'}
if self.dump:
entry_count = 0
dumplevel_count = 0
dbase = bpy.context.scene.element_db
dox = bpy.data.texts.new("DB_Dump " + time.ctime())
dox.write("dts_info = {\"type\" : \"dump\", \"creation_time\" : \"" + time.ctime() + "\"}")
for entry in dbase.keys():
dox.write("{\n")
dox.write("entry = " + dbase[entry]['name'] + "\n")
for key in dbase[entry].keys():
print(entry,key)
if type(dbase[entry][key]) is list:
#print(self.listiterator(dbase,entry,key))
for key1 in eval("element_db" + "[\"" + entry + "\"]." + key).keys():
#if type(eval("element_db" + "[\"" + entry + "\"]." + key)[key1]) is list:
if type(eval("element_db" + "[\"" + entry + "\"]." + key)[key1]) is list:
for item in eval("element_db" + "[\"" + entry + "\"]." + key + "." + key1).keys():
print('List hit')
dox.write(eval("element_db" + "[\"" + entry + "\"]." + key + "." + key1))
if type(eval("element_db" + "[\"" + entry + "\"]." + key)[key1]) is not list:
#dox.write(str(("\t") + key + " : " + key1 + " = " + str(eval("element_db" + "[\"" + entry + "\"]." + key)[key1]) + "\n"))
dox.write(str(("\t") + key + " = " + key1 + "\n"))
#for key2 in dbase[entry][key]:
#dox.write("\t\t" + key2 + " = " + str(eval(dbase + "[" + entry + "][" + key + "]." + key2)) + "\n")
if type(dbase[entry][key]) is not list:
dox.write("\t" + key + " = " + str(dbase[entry][key]) + "\n")
dox.write("}\n")
entry_count += 1
scn["element_db_status"] = str(entry_count) + " database entries dumped to text block. Be sure to save the file externally."
return{'FINISHED'}
if self.purge:
dbase = bpy.context.scene.element_db
for item in dbase.keys():
dbase.remove(0)
scn["element_db_status"] = "Database purged. Please import a new database, or begin setting up elements to create a new one."
return{'FINISHED'}
if self.pushtobge:
entry_count = 0
dumplevel_count = 0
dbase = bpy.context.scene.element_db
#run a test for the existence of the file to avoid duplicates
try:
bpy.data.texts["GameExport"].clear()
except:
bpy.data.texts.new("GameExport")
dox = bpy.data.texts["GameExport"]
for entry in dbase.keys():
dox.write("{\n")
dox.write("entry = " + dbase[entry]['name'] + "\n")
for key in dbase[entry].keys():
if type(dbase[entry][key]) is list:
for key1 in eval("element_db" + "[\"" + entry + "\"]." + key).keys():
if type(eval("element_db" + "[\"" + entry + "\"]." + key)[key1]) is list:
for item in eval("element_db" + "[\"" + entry + "\"]." + key + "." + key1).keys():
dox.write(eval("element_db" + "[\"" + entry + "\"]." + key + "." + key1))
if type(eval("element_db" + "[\"" + entry + "\"]." + key)[key1]) is not list:
dox.write(str(("\t") + key + " = " + key1 + "\n"))
if type(dbase[entry][key]) is not list:
dox.write("\t" + key + " = " + str(dbase[entry][key]) + "\n")
dox.write("}\n")
entry_count += 1
scn["element_db_status"] = str(entry_count) + " database entries dumped to text block. Be sure to save the file externally."
for obj in bpy.data.objects:
if obj.DTSContent != "":
print(obj.name)
obj.game.properties['content'].value = obj.DTSContent
return{'FINISHED'}
if self.purge:
dbase = bpy.context.scene.element_db
for item in dbase.keys():
dbase.remove(0)
scn["element_db_status"] = "Database purged. Please import a new database, or begin setting up elements to create a new one."
return{'FINISHED'}
class DB_Import_Choice(bpy.types.Operator):
bl_idname = "dtscripts.db_import"
bl_label = "Import Database"
message = bpy.props.StringProperty()
DoxList = []
for item in bpy.data.texts.items():
DoxList.append((item[0], item[0], item[0]))
TextFileList = EnumProperty(
items=DoxList,
name="Text Documents: "
)
def execute(self, context):
dbase = bpy.context.scene.element_db
scn = context.scene
if self.TextFileList:
entry_count = 0
listvars = ["dry_hit_particle", "dry_hit_decal", "wet_hit_particle", "wet_hit_decal", "model", "animation"]
ignore_vars = ["{", "}"]
for line in bpy.data.texts[scn.Importchoice].as_string().split("\n"):
if line not in ignore_vars:
if line.startswith("entry") == True:
new_entry = dbase.add()
elem_var = (line.split("=")[0]).rstrip()
elem_def = (line.split("=")[1]).lstrip()
print("element name: " + elem_def)
new_entry.name = elem_def
entry_count += 1
if line.startswith("entry") != True:
print(line)
element_def = line.lstrip()
elem_var = (element_def.split("=")[0]).rstrip()
elem_def = (element_def.split("=")[1]).lstrip()
if elem_var in listvars:
collection_entry = eval("new_entry." + elem_var + ".add()")
collection_entry.name = elem_def
else:
print(line + " not in list.")
new_entry[elem_var] = elem_def
else:
print(line + " failed.")
scn["element_db_status"] = "Database imported. " + str(entry_count) + " entries processed."
return{'FINISHED'}
return{'FINISHED'}
class OBJECT_OT_ErrorWindow(bpy.types.Operator):
bl_idname = "dtscripts.errormessage"
bl_label = "Error window"
type = bpy.props.StringProperty()
message = bpy.props.StringProperty()
def execute(self, context):
return{'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_popup(self, width=400, height=200)
def draw(self, context):
self.layout.label("Message!")
row = self.layout
row.prop(self, "message")
class OBJECT_OT_EntryModifier(bpy.types.Operator):
bl_idname = "dtscripts.entrymodifier"
bl_label = "Entry Modifier"
add = bpy.props.StringProperty()
remove = bpy.props.StringProperty()
def execute(self, context):
obj = bpy.context.object
obj_game = bpy.context.object.game.properties
element_db = bpy.context.scene.element_db
if self.add:
element_db[obj.DTSContent].model.append(self.add)
return{'FINISHED'}
if self.remove:
element_db[obj.DTSContent].model.remove(self.remove)
if obj.name == self.remove:
obj.DTSContent = ""
return{'FINISHED'}
class OBJECT_OT_WetDecal(bpy.types.Operator):
bl_idname = "dtscripts.materialwd"
bl_label = "Wet Decal Operations"
remove = bpy.props.StringProperty()
add = bpy.props.StringProperty()
def execute(self, context):
scn = context.scene
obj = bpy.context.object
obj_game = obj.game.properties
element_db = bpy.context.scene.element_db
if self.remove:
elem_count = 0
for element in element_db[obj.DTSContent].wet_hit_decal.keys():
if element == self.remove:
element_db[obj.DTSContent].wet_hit_decal.remove(elem_count)
if obj.name == self.remove:
obj.DTSContent = ""
return{'FINISHED'}
elem_count += 1
return{'FINISHED'}
if self.add:
new_model = element_db[obj.DTSContent].wet_hit_decal.add()
new_model.name = scn.MaterialWD
return{'FINISHED'}
class OBJECT_OT_WetParticle(bpy.types.Operator):
bl_idname = "dtscripts.materialwp"
bl_label = "Wet Particle Operations"
remove = bpy.props.StringProperty()
add = bpy.props.StringProperty()
def execute(self, context):
scn = context.scene
obj = bpy.context.object
obj_game = obj.game.properties
element_db = bpy.context.scene.element_db
if self.remove:
elem_count = 0
for element in element_db[obj.DTSContent].wet_hit_particle.keys():
if element == self.remove:
element_db[obj.DTSContent].wet_hit_particle.remove(elem_count)
if obj.name == self.remove:
obj.DTSContent = ""
return{'FINISHED'}
elem_count += 1
return{'FINISHED'}
if self.add:
new_model = element_db[obj.DTSContent].wet_hit_particle.add()
new_model.name = scn.MaterialWP
return{'FINISHED'}
class OBJECT_OT_DryDecal(bpy.types.Operator):
bl_idname = "dtscripts.materialdd"
bl_label = "Dry Decal Operations"
remove = bpy.props.StringProperty()
add = bpy.props.StringProperty()
def execute(self, context):
global ObjType
scn = context.scene
obj = bpy.context.object
obj_game = obj.game.properties
element_db = bpy.context.scene.element_db
if self.remove:
elem_count = 0
for element in element_db[obj.DTSContent].dry_hit_decal.keys():
if element == self.remove:
element_db[obj.DTSContent].dry_hit_decal.remove(elem_count)
if obj.name == self.remove:
obj.DTSContent = ""
return{'FINISHED'}
elem_count += 1
return{'FINISHED'}
if self.add:
new_model = element_db[obj.DTSContent].dry_hit_decal.add()
new_model.name = scn.MaterialDD
return{'FINISHED'}
class OBJECT_OT_DryParticle(bpy.types.Operator):
bl_idname = "dtscripts.materialdp"
bl_label = "Dry Particle Operations"
remove = bpy.props.StringProperty()
add = bpy.props.StringProperty()
def execute(self, context):
scn = context.scene
obj = bpy.context.object
obj_game = obj.game.properties
element_db = bpy.context.scene.element_db
if self.remove:
elem_count = 0
for element in element_db[obj.DTSContent].dry_hit_particle.keys():
if element == self.remove:
element_db[obj.DTSContent].dry_hit_particle.remove(elem_count)
if obj.name == self.remove:
obj.DTSContent = ""
return{'FINISHED'}
elem_count += 1
return{'FINISHED'}
if self.add:
new_model = element_db[obj.DTSContent].dry_hit_particle.add()
new_model.name = scn.MaterialDP
return{'FINISHED'}
class OBJECT_OT_Particle(bpy.types.Operator):
bl_idname = "dtscripts.particle"
bl_label = "List Particles"
remove = bpy.props.StringProperty()
remove_anim = bpy.props.StringProperty()
info = bpy.props.StringProperty()
new = bpy.props.StringProperty()
setup = bpy.props.StringProperty()
proj_setup = bpy.props.StringProperty()
proj_new = bpy.props.StringProperty()
def execute(self, context):
global ObjType
scn = context.scene
obj = bpy.context.object
obj_game = obj.game.properties
element_db = bpy.context.scene.element_db
def addProperties(object, name, type, value):
#bpy.ops.object.select_name(name=object)
bpy.ops.object.game_property_new()
setting = bpy.context.object.game.properties[-1]
setting.name = name
setting.type = type
setting.value = value
return{'FINISHED'}
def particle_setup(particle):
#bpy.ops.object.select_name(name=particle)
addProperties(particle, "content", "STRING", 0)
bpy.ops.logic.sensor_add(type='ALWAYS', name="particle", object="")
print("setup occured")
def particle_create(particle):
print("creation starting")
#bpy.ops.object.select_name(name=obj.name)
new_entry = element_db.add()
new_entry.name = particle
new_entry.type = "particle"
new_model = new_entry.model.add()
new_model.name = obj.name
new_entry.velocity = []
new_entry['multiplier'] = 0
new_entry['fluid_multiplier'] = 0
new_entry['emit_frequency'] = 0
new_entry.frag_min = 0
new_entry.frag_max = 0
print("creation occured")
def projectile_create(particle):
print("creation starting")
#bpy.ops.object.select_name(name=obj.name)
new_entry = element_db.add()
new_entry.name = particle
new_entry.type = "projectile"
new_model = new_entry.model.add()
new_model.name = obj.name
new_entry.velocity = []
new_entry['multiplier'] = 0
new_entry['fluid_multiplier'] = 0
new_entry['emit_frequency'] = 0
new_entry.frag_min = 0
new_entry.frag_max = 0
print("creation occured")
def projectile_setup(projectile):
print("running projectile setup")
#bpy.ops.object.select_name(name=obj.name)
obj_data = bpy.data.objects[obj.name].game
bpy.ops.logic.sensor_add(type='COLLISION', name="bullet", object="")
bpy.ops.logic.controller_add(type='PYTHON', name="EffectCombo", object="")
bpy.context.object.game.controllers['EffectCombo'].text = bpy.data.texts[scn.Elementchoice]
#bpy.ops.logic.controller_add(type='LOGIC_AND', name="And", object="")
killobject = bpy.ops.logic.actuator_add(type='EDIT_OBJECT', name="KillBullet", object="")
obj.game.actuators['KillBullet'].mode = "ENDOBJECT"
addobject = bpy.ops.logic.actuator_add(type='EDIT_OBJECT', name="AddDecal", object="")
obj.game.actuators['AddDecal'].mode = "ADDOBJECT"
#obj_data.sensors["bullet"].link(obj_data.controllers["And"])
obj_data.sensors["bullet"].link(obj_data.controllers["EffectCombo"])
#obj_data.actuators["KillBullet"].link(obj_data.controllers["And"])
obj_data.actuators["KillBullet"].link(obj_data.controllers["EffectCombo"])
obj_data.actuators["AddDecal"].link(obj_data.controllers["EffectCombo"])
addProperties(projectile, "content", "STRING", 0)
addProperties(projectile, "bullet", "BOOL", 1)
if self.remove:
elem_count = 0
for element in element_db[obj.DTSContent].model.keys():
if element == self.remove:
if obj.name == self.remove:
element_db[obj.DTSContent].model.remove(elem_count)
obj.DTSContent = ""
return{'FINISHED'}
elem_count += 1
return{'FINISHED'}
if self.remove_anim:
elem_count = 0
for element in element_db[obj.DTSContent].anim.keys():
if element == self.remove:
element_db[obj.DTSContent].anim.remove(elem_count)
if obj.name == self.remove:
obj.DTSContent = ""
return{'FINISHED'}
elem_count += 1
return{'FINISHED'}
if self.info:
scn['EditObjAnimation'] = element_db[obj.DTSContent].animation
scn['EditObjVelocity'] = element_db[obj.DTSContent].velocity
scn['EditObjFluidMulti'] = element_db[obj.DTSContent]["fluid_multiplier"]
scn['EditObjMulti'] = element_db[obj.DTSContent]['multiplier']
scn['EditEmitFreq'] = element_db[obj.DTSContent]["emit_frequency"]
scn['EditFragCountMax'] = element_db[obj.DTSContent].frag_max
scn['EditFragCountMin'] = element_db[obj.DTSContent].frag_min
return{'FINISHED'}
if self.setup:
print("woot" + self.setup)
particle_setup(scn.ElementName)
obj.DTSContent = scn.ElementName
new_model = element_db[scn.ElementName].model.add()
new_model.name = obj.name
return{'FINISHED'}
if self.new:
if scn.ElementName in element_db.keys():
print("This already exists.")
if scn.ElementName not in element_db.keys():
particle_create(scn.ElementName)
particle_setup(scn.ElementName)
obj.DTSContent = scn.ElementName
return{'FINISHED'}
if self.proj_new:
if scn.ElementName in element_db.keys():
print("This already exists.")
return{'FINISHED'}
if scn.ElementName not in element_db.keys():
projectile_create(scn.ElementName)
projectile_setup(scn.ElementName)
obj.DTSContent = scn.ElementName
return{'FINISHED'}
if self.proj_setup:
projectile_setup(scn.ElementName)
new_model = element_db[scn.ElementName].model.add()
new_model.name = obj.name
obj.DTSContent = scn.ElementName
return{'FINISHED'}
return{'FINISHED'}
class OBJECT_OT_Material(bpy.types.Operator):
bl_idname = "dtscripts.material"
bl_label = "List Materials"
remove = bpy.props.StringProperty()
info = bpy.props.StringProperty()
setup = bpy.props.StringProperty()
new = bpy.props.StringProperty()
wet_dry = bpy.props.StringProperty()
def execute(self, context):
global ObjType
scn = context.scene
obj = bpy.context.object
obj_game = obj.game.properties
element_db = bpy.context.scene.element_db
def addProperties(object, name, prop_type, value):
#bpy.ops.object.select_name(name=object)
bpy.ops.object.game_property_new()
setting = bpy.context.object.game.properties[-1]
setting.name = name
setting.type = prop_type
setting.value = value
return{'FINISHED'}
def material_setup(material):
#bpy.ops.object.select_name(name=obj.name)
obj_data = bpy.data.objects[obj.name].game
bpy.ops.logic.sensor_add(type='COLLISION', name="wall", object="")
bpy.ops.logic.controller_add(type='PYTHON', name="EffectCombo", object="")
bpy.context.object.game.controllers['EffectCombo'].text = bpy.data.texts[scn.Elementchoice]
addProperties(material, "content", "STRING", 0)
obj_data.sensors["wall"].link(obj_data.controllers["EffectCombo"])
addProperties(material, "dmglevel", "INT", 0)
addProperties(material, "wall", "STRING", 0)
addProperties(material, "tank_level", "INT", 0)
addProperties(material, "type", "STRING", 0)
def material_create(material):
#bpy.ops.object.select_name(name=material)
new_entry = element_db.add()
new_entry.name = material
new_entry.type = "material"
new_entry.mat_type = "fluid"
new_entry.AreaLower = 0.0
new_entry.AreaUpper = 0.0
if self.remove:
obj.DTSContent = ""
return{'FINISHED'}
if self.info:
scn['EditAreaUpper'] = element_db[obj.DTSContent]['AreaUpper']
scn['EditAreaLower'] = element_db[obj.DTSContent]['AreaLower']
scn['EditWetHitDecal'] = element_db[obj.DTSContent].wet_hit_decal
scn['EditWetHitParticle'] = element_db[obj.DTSContent].wet_hit_particle
scn['EditDryHitDecal'] = element_db[obj.DTSContent].dry_hit_decal
scn['EditDryHitParticle'] = element_db[obj.DTSContent].dry_hit_particle
return{'FINISHED'}
if self.setup:
material_setup(scn.ElementName)
return{'FINISHED'}
if self.new:
if scn.ElementName in element_db.keys():
print("This already exists.")
return{'FINISHED'}
if scn.ElementName not in element_db.keys():
material_create(scn.ElementName)
material_setup(scn.ElementName)
obj.DTSContent = scn.ElementName
return{'FINISHED'}
if self.wet_dry:
element_db[obj.DTSContent]['mat_type'] = self.wet_dry
return{'FINISHED'}
class OBJECT_OT_AddAnim(bpy.types.Operator):
bl_idname = "dtscripts.addanim"
bl_label = "List Particles"
add_anim = bpy.props.StringProperty()
info = bpy.props.StringProperty()
AnimList = []
for item in bpy.data.actions:
AnimList.append((item.name, item.name, item.name))
AnimListProp = EnumProperty(
items=AnimList,
name="Animations: "
)
def execute(self, context):
global ObjType
scn = context.scene
obj = bpy.context.object
obj_game = obj.game.properties
element_db = bpy.context.scene.element_db
if self.AnimListProp:
element_db[obj.DTSContent].animation.append(self.AnimListProp, 0,0)
return{'FINISHED'}
class OBJECT_OT_Static(bpy.types.Operator):
bl_idname = "dtscripts.static"
bl_label = "List Particles"
remove = bpy.props.StringProperty()
remove_anim = bpy.props.StringProperty()
add_anim = bpy.props.StringProperty()
info = bpy.props.StringProperty()
setup = bpy.props.StringProperty()
new = bpy.props.StringProperty()
StaticList = []
AnimList = []
def execute(self, context):
global ObjType
scn = context.scene
obj = bpy.context.object
obj_game = obj.game.properties
element_db = bpy.context.scene.element_db
def addProperties(object, name, type, value):
#bpy.ops.object.select_name(name=object)
bpy.ops.object.game_property_new()
setting = bpy.context.object.game.properties[-1]
setting.name = name
setting.type = type
setting.value = value
return{'FINISHED'}
def static_setup(static):
#bpy.ops.object.select_name(name=static)
obj_data = bpy.data.objects[obj.name].game
bpy.ops.logic.sensor_add(type='ALWAYS', name="decal", object="")
obj.game.sensors['decal'].use_pulse_true_level = True
bpy.ops.logic.controller_add(type='PYTHON', name="EffectCombo", object="")
bpy.context.object.game.controllers['EffectCombo'].text = bpy.data.texts[scn.Elementchoice]
killeffect = bpy.ops.logic.actuator_add(type='EDIT_OBJECT', name="KillEffect", object="")
obj.game.actuators['KillEffect'].mode = "ENDOBJECT"
addeffect = bpy.ops.logic.actuator_add(type='EDIT_OBJECT', name="Emitter", object="")
obj.game.actuators['Emitter'].mode = "ADDOBJECT"
obj.game.actuators['Emitter'].use_local_linear_velocity = True
obj_data.sensors["decal"].link(obj_data.controllers["EffectCombo"])
obj_data.actuators["KillEffect"].link(obj_data.controllers["EffectCombo"])
obj_data.actuators["Emitter"].link(obj_data.controllers["EffectCombo"])
addProperties(static, "content", "STRING", 0)
addProperties(static, "decal_timer", "TIMER", 0.000)
addProperties(static, "data_frame", "STRING", 0)
def static_create(static):
#bpy.ops.object.select_name(name=static)
new_entry = element_db.add()
new_entry.name = static
new_entry.type = "static"
new_model = new_entry.model.add()
new_model.name = str(obj.name)
if self.remove:
elem_count = 0
for element in element_db[obj.DTSContent].area.keys():
if element == self.remove:
element_db[obj.DTSContent].area.remove(elem_count)
if obj.name == self.remove:
obj.DTSContent = ""
return{'FINISHED'}
elem_count += 1
return{'FINISHED'}
if self.remove_anim:
element_db[obj.DTSContent].animation.remove(self.remove_anim)
return{'FINISHED'}
if self.info:
anim_data = element_db[obj.DTSContent].animation
scn['EditObjAnimation'] = element_db[obj.DTSContent].animation
return{'FINISHED'}
if self.new:
if scn.ElementName in element_db.keys():
print("This already exists.")
return{'FINISHED'}
if scn.ElementName not in element_db.keys():
static_create(scn.ElementName)
static_setup(scn.ElementName)
obj.DTSContent = scn.ElementName
return{'FINISHED'}
if self.setup:
static_setup(scn.ElementName)
obj.DTSContent = scn.ElementName
new_model = element_db[scn.ElementName].model.add()
new_model.name = obj.name
return{'FINISHED'}
def invoke(self, context, event):
scn = context.scene
for elem in bpy.context.scene.element_db.keys():
if elem not in scn.StaticList.keys():
if bpy.context.scene.element_db[elem].type == "static":
new_elem = scn.StaticList.add()
new_elem['name'] = bpy.context.scene.element_db[elem].name
for key in bpy.context.scene.element_db[elem].keys():
new_elem[key] = bpy.context.scene.element_db[elem][key]
return self.execute( context )
class OBJECT_OT_EditModebutton(bpy.types.Operator):
bl_idname = "dtscripts.edittoggle"
bl_label = "Panel Edit Mode toggle"
def execute(self, context):
print("Edit Mode Toggled!")
scene = context.scene
obj = bpy.context.object
obj_game = obj.game.properties
element_db = bpy.context.scene.element_db
element_count = 0
if obj.DTSContent != '' and obj.DTSContent not in element_db.keys():
scene['PanelEditMode'] = False
return{'FINISHED'}
if scene['PanelEditMode'] == False:
if obj.DTSContent == "":
scene['PanelEditMode'] = False
return{'FINISHED'}
if element_db[obj.DTSContent]['type']== "fluid" or element_db[obj.DTSContent]['type'] == "dry" or element_db[obj.DTSContent]['type'] == "material":
scene['PanelEditMode'] = True
for entry in scene.edit_element.keys():
if entry == obj.DTSContent:
scene.edit_element.remove(element_count)
element_count += 1
key = obj.DTSContent
backup_entry = scene.edit_element.add()
backup_entry['name'] = obj.DTSContent
values = scene.element_db[obj.DTSContent].keys()
for value in values:
backup_entry[value] = element_db[obj.DTSContent][value]
bpy.ops.dtscripts.material(info=obj.DTSContent)
return{'FINISHED'}
if element_db[obj.DTSContent]['type'] == "particle" or element_db[obj.DTSContent]['type'] == "projectile":
scene['PanelEditMode'] = True
for entry in scene.edit_element.keys():
if entry == obj.DTSContent:
scene.edit_element.remove(element_count)
element_count += 1
key = obj.DTSContent
backup_entry = scene.edit_element.add()
backup_entry['name'] = obj.DTSContent
values = scene.element_db[obj.DTSContent].keys()
for value in values:
backup_entry[value] = element_db[obj.DTSContent][value]
bpy.ops.dtscripts.particle(info=obj.DTSContent)
return{'FINISHED'}
if element_db[obj.DTSContent]['type'] == "static":
scene['PanelEditMode'] = True
for entry in scene.edit_element.keys():
if entry == obj.DTSContent:
scene.edit_element.remove(element_count)
element_count += 1
key = obj.DTSContent
backup_entry = scene.edit_element.add()
backup_entry['name'] = obj.DTSContent
values = scene.element_db[obj.DTSContent].keys()
for value in values:
backup_entry[value] = element_db[obj.DTSContent][value]
bpy.ops.dtscripts.static(info=obj.DTSContent)
return{'FINISHED'}
elif scene['PanelEditMode'] == True:
scene['PanelEditMode'] = False
return{'FINISHED'}
class OBJECT_OT_SaveEditbutton(bpy.types.Operator):
bl_idname = "dtscripts.saveedit"
bl_label = "Panel Save Edit toggle"