-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
945 lines (827 loc) · 27.4 KB
/
main.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
# Name: in the postman's bag
# Version (date): 2021_06_07
# Author: Moshnyakov Anton
# E-mail: [email protected]
# Two way for script running:
#
# 1 Write in console:
# blender --background --python main.py
# where "blender" is directory of executable file of Blender
# in PATH in Environment variable
# (Win + R > SystemPropertiesAdvanced > Environment variable)
#
# 2 Or open file "start.blend" and click on Run Script (Alt + P)
# Output directory in variable PATH_OUT between ''
# Example for output directory in Windows D:\py\out is:
# PATH_OUT = r'D:\py\out'
PATH_OUT = r'C:\py\out'
# Select (uncomment) only one of a type object (OBJ_):
# OBJ_ = 'mix'
# OBJ_ = 'torus'
# OBJ_ = 'cube'
# OBJ_ = 'cone'
# OBJ_ = 'sphere'
OBJ_ = 'icosph'
# Set number of objects:
NUM_OBJS = 400
# Set number of objects in row/col
M_SIZE = 10
# Set timeline (if FR_START = 1, so FR_END will define number of frames):
FR_START = 1
FR_END = 500
# Set dimensions of frames:
FR_DIM_X = 1920
FR_DIM_Y = 1080
# Activating show telemetry:
TELEMETRY_SHOW = False
# Activating animation:
ANIM = False
import bpy
import math
from random import randint, choice
from pathlib import Path
C = bpy.context
D = bpy.data
O = bpy.ops
def degrees_to_radians(x,y,z):
x = math.radians(x)
y = math.radians(y)
z = math.radians(z)
return (x,y,z)
def del_all_objs():
O.object.select_all(action='SELECT')
O.object.delete(use_global=False,confirm=False)
while len(D.meshes) != 0:
D.meshes.remove(D.meshes[0])
while len(D.materials) != 0:
D.materials.remove(D.materials[0])
while len(D.textures) != 0:
D.textures.remove(D.textures[0])
while len(D.images) != 0:
D.images.remove(D.images[0])
while len(D.lights) != 0:
D.lights.remove(D.lights[0])
while len(D.curves) != 0:
D.curves.remove(D.curves[0])
def camera_add(x,y,z,rx,ry,rz,type_='PERSP'):
O.object.camera_add(
align = 'VIEW',
location = (x,y,z),
rotation = degrees_to_radians(rx,ry,rz))
C.scene.camera = D.objects[C.active_object.name]
if type_ == 'ORTHO':
C.object.data.ortho_scale = 23
C.object.data.type = 'ORTHO'
else:
C.object.data.type = 'PERSP'
return C.active_object.name
def light_add(name_type,x,y,z,energy_=80000,r=1,g=1,b=1):
O.object.light_add(type = name_type,location = (x,y,z))
C.object.data.color = (r,g,b)
C.object.data.energy = energy_
if name_type == 'AREA':
C.object.data.size = 50
return C.active_object.name
def light_chng(name,rgb,energy_=80000):
D.lights[name].color = rgb
D.lights[name].energy = energy_
return [name,rgb,energy_]
def gravity_add(x=0,y=0,z=0):
C.scene.gravity[0] = x
C.scene.gravity[1] = y
C.scene.gravity[2] = z
def export_image_settings(start_,end_,x,y,render_samples,stamp,anim):
C.scene.render.fps = 24
C.scene.render.fps_base = 1
C.scene.frame_start = start_
C.scene.frame_end = end_
C.scene.render.use_file_extension = True
if anim == True:
C.scene.render.image_settings.file_format = 'AVI_JPEG'
else:
C.scene.render.image_settings.file_format = 'JPEG'
C.scene.eevee.taa_render_samples = render_samples
C.scene.render.resolution_x = x
C.scene.render.resolution_y = y
C.scene.render.resolution_percentage = 100
C.scene.render.image_settings.quality = 100
C.scene.render.use_stamp = stamp
C.scene.render.use_stamp_date = False
C.scene.render.use_stamp_time = False
C.scene.render.use_stamp_render_time = False
C.scene.render.use_stamp_frame = False
C.scene.render.use_stamp_camera = False
C.scene.render.use_stamp_scene = False
C.scene.render.use_stamp_filename = False
C.scene.render.stamp_font_size = 16 # 20
C.scene.render.stamp_foreground = (0,0,0,1)
C.scene.render.stamp_background = (1,1,1,0.25)
C.scene.render.use_stamp_note = True
def bake_animation(start,end):
O.ptcache.free_bake_all()
pc = C.scene.rigidbody_world.point_cache
pc.frame_start = 1
pc.frame_end = end
O.ptcache.bake_all({'point cache': pc},bake = True)
def world_color(r=1,g=1,b=1,strength_=1):
world = D.worlds['World'].node_tree.nodes['Background']
world.inputs[0].default_value = (r,g,b,1)
world.inputs[1].default_value = strength_
C.scene.eevee.use_soft_shadows = True
def rgb_rand(start,end):
r = randint(start,end)*0.001
g = randint(start,end)*0.001
b = randint(start,end)*0.001
# bicycl e
# for not gray colors
dif = 0.05
while ((b >= (r - dif) and b <=(r + dif))
and (b >= (g - dif) and b <= (g + dif))):
b = randint(start,end)*0.001
return [r,g,b]
def rigidbody_for_obj(obj,shape,kinematic_,kg):
O.rigidbody.object_add()
obj.rigid_body.type = 'ACTIVE'
obj.rigid_body.collision_shape = shape
obj.rigid_body.kinematic = kinematic_
obj.rigid_body.mesh_source = 'BASE'
obj.rigid_body.collision_margin = 1
obj.rigid_body.mass = kg
obj.rigid_body.use_margin = True
def mat_for_obj(
obj,
mat_name,
rgba = [1,1,1,1],
shader = 'Principled BSDF',
blend_method = 'BLEND',
alpha = 1):
mat = D.materials.new(name = mat_name)
mat.use_nodes = True
mat.node_tree.nodes.new('ShaderNodeEmission')
mat.blend_method = blend_method
if blend_method == 'BLEND':
mat.use_backface_culling = False
mat.show_transparent_back = False # show backface
mat_in = mat.node_tree.nodes.get(shader)
mat_out = mat.node_tree.nodes.get('Material Output')
node_links = mat.node_tree.links.new
if shader == 'Principled BSDF':
mat_in.inputs[0].default_value = rgba
mat_in.inputs[5].default_value = 0
mat_in.inputs[7].default_value = 1
mat_in.inputs[18].default_value = 0
mat_in.inputs[19].default_value = alpha
out_name = 'BSDF'
elif shader == 'Emission':
mat_in.inputs['Color'].default_value = rgba
mat_in.inputs['Strength'].default_value = 1
out_name = 'Emission'
node_links(mat_out.inputs['Surface'],mat_in.outputs[out_name])
obj.active_material = mat
def mod_apply_bevel(obj,width_,segments_):
O.object.modifier_add(type = 'BEVEL')
obj.modifiers['Bevel'].width = width_
obj.modifiers['Bevel'].segments = segments_
O.object.modifier_apply(modifier='Bevel',report=True)
def mod_apply_subsurf(obj,levels_,render_levels_):
O.object.modifier_add(type='SUBSURF')
obj.modifiers['Subdivision'].levels = levels_
obj.modifiers['Subdivision'].render_levels = render_levels_
O.object.modifier_apply(modifier='Subdivision',report=True)
def torus():
name = 'torus'
min_size = 2
max_size = 14
return [name,min_size,max_size]
def cube():
name = 'cube'
min_size = 10
max_size = 28
return [name,min_size,max_size]
def cone():
name = 'cone'
min_size = 4
max_size = 22
return [name,min_size,max_size]
def sphere():
name = 'sphere'
min_size = 2
max_size = 14
return [name,min_size,max_size]
def mix():
name = 'mix'
min_size = 10
max_size = 28
return [name,min_size,max_size]
def icosph():
name = 'icosph'
min_size = 5
max_size = 22
return [name,min_size,max_size]
def arr_xyz(obj,arr_size,numObj,m_size):
arr_x = []
arr_y = []
arr_z = []
border = x = y = z = -arr_size + (arr_size/m_size)
for i in range(numObj):
arr_x.append(x)
arr_y.append(y)
arr_z.append(z)
if x < -border:
x += arr_size*2/m_size
elif y < -border:
x = border
y += arr_size*2/m_size
elif z < -border:
x = border
y = border
z += arr_size*2/m_size
return [arr_x,arr_y,arr_z]
def obj_add(obj_type,o_size,xyz):
if obj_type == 'cube':
O.mesh.primitive_cube_add(
size=o_size,
location=xyz)
elif obj_type == 'sphere':
O.mesh.primitive_uv_sphere_add(
radius=o_size,
location=xyz)
elif obj_type == 'torus':
O.mesh.primitive_torus_add(
location=xyz,
major_segments=40,
major_radius=o_size,
minor_radius=o_size/4)
elif obj_type == 'cone':
O.mesh.primitive_cone_add(
vertices=3,
radius1=o_size,
depth=o_size*1.5,
location=xyz)
elif obj_type == 'icosph':
O.mesh.primitive_ico_sphere_add(
radius=o_size,
location=xyz)
ob = C.active_object
r = randint(200,1000)*0.001
g = randint(200,1000)*0.001
b = randint(200,1000)*0.001
mat_for_obj(ob,'Mat',[r,g,b,0])
rigidbody_for_obj(ob,'CONVEX_HULL',False,100)
# add modifiers
if obj_type == 'cube':
mod_apply_bevel(ob,round(o_size)*0.1,1)
mod_apply_subsurf(ob,3,3)
elif obj_type == 'cone':
mod_apply_bevel(ob,o_size/4,4)
mod_apply_subsurf(ob,3,3)
elif obj_type == 'sphere':
mod_apply_subsurf(ob,1,1)
elif obj_type == 'torus':
mod_apply_subsurf(ob,1,1)
elif obj_type == 'icosph':
mod_apply_subsurf(ob,3,3)
len_vert = len(list(ob.data.vertices))
for i in range(len_vert):
f0 = ob.data.vertices[i].co[0]
f1 = ob.data.vertices[i].co[1]
f2 = ob.data.vertices[i].co[2]
r1 = randint(5,10)*0.1
ob.data.vertices[i].co = (f0*r1,f1*r1,f2*r1)
# mod_apply_subsurf(ob,1,1)
O.object.shade_smooth()
class mat_color():
def start(self,num_obj_,mat_name_,shader_='Principled BSDF'):
self.num_obj = num_obj_
self.mat_name = mat_name_
self.shader = shader_
self.red = [0]*self.num_obj
self.green = [0]*self.num_obj
self.blue = [0]*self.num_obj
self.alpha = [1]*self.num_obj
self.strength = [1]*self.num_obj
self.rt = -1
self.gt = -1
self.bt = -1
self.at = -1
self.stt = -1
self.rand_rgbt = -1
self.rand_rgb_fullt = -1
self.rand_at = -1
self.rand_grayt = -1
def r(self,value):
self.red = [value]*self.num_obj
self.rt = self.red[0]
def g(self,value):
self.green = [value]*self.num_obj
self.gt = self.green[0]
def b(self,value):
self.blue = [value]*self.num_obj
self.bt = self.blue[0]
def a(self,value):
self.alpha = [value]*self.num_obj
self.at = self.alpha[0]
def st(self,value):
self.strength = [value]*self.num_obj
self.stt = self.strength[0]
def rand_rgb(self,start_,end):
self.red = []
self.green = []
self.blue = []
for i in range(self.num_obj):
rgb = rgb_rand(start_,end)
self.red.append(rgb[0])
self.green.append(rgb[1])
self.blue.append(rgb[2])
if self.num_obj == 1:
self.rand_rgbt = [rgb[0],rgb[1],rgb[2]]
else:
self.rand_rgbt = [start_,end]
def rand_rgb_full(self,start_,end):
self.red = []
self.green = []
self.blue = []
for i in range(self.num_obj):
r = randint(start_,end)*0.001
g = randint(start_,end)*0.001
b = randint(start_,end)*0.001
self.red.append(r)
self.green.append(g)
self.blue.append(b)
if self.num_obj == 1:
self.rand_rgb_fullt = [rgb[0],rgb[1],rgb[2]]
else:
self.rand_rgb_fullt = [start_,end]
def rand_a(self,start_,end):
self.alpha = []
for i in range(self.num_obj):
al = randint(start_,end)*0.001
self.alpha.append(al)
if self.num_obj == 1:
self.rand_at = [al]
else:
self.rand_at = [start_,end]
def rand_gray(self,start_,end):
self.red = []
self.green = []
self.blue = []
for i in range(self.num_obj):
gray = randint(start_,end)*0.001
self.red.append(gray)
self.green.append(gray)
self.blue.append(gray)
if self.num_obj == 1:
self.rand_grayt = [gray]
else:
self.rand_grayt = [start_,end]
def change(self):
for i in range(self.num_obj):
r = self.red[i]
g = self.green[i]
b = self.blue[i]
a = self.alpha[i]
st = self.strength[i]
if i == 0:
mat = D.materials[self.mat_name].node_tree
else:
i = str(i)
i = i.zfill(3)
mat = D.materials[self.mat_name+'.'+str(i)].node_tree
mat_in = mat.nodes.get(self.shader)
mat_out = mat.nodes.get('Material Output')
node_links = mat.links.new
if self.shader == 'Principled BSDF':
mat_in.inputs[0].default_value = (r,g,b,0)
mat_in.inputs[19].default_value = a
out_name = 'BSDF'
elif self.shader == 'Emission':
mat_in.inputs['Color'].default_value = (r,g,b,0)
mat_in.inputs['Strength'].default_value = st
out_name = 'Emission'
node_links(mat_out.inputs['Surface'],mat_in.outputs[out_name])
# telemetry
out_arr = []
if self.rt != -1:
out_arr.append('r = ' + str(self.rt))
if self.gt != -1:
out_arr.append('g = ' + str(self.gt))
if self.bt != -1:
out_arr.append('b = ' + str(self.bt))
if self.at != -1:
out_arr.append('a = ' + str(self.at))
if self.stt != -1:
out_arr.append('st = ' + str(self.stt))
if self.rand_rgbt != -1:
out_arr.append('rand_rgb = ' + str(self.rand_rgbt))
if self.rand_rgb_fullt != -1:
out_arr.append('rand_rgb_full = ' + str(self.rand_rgb_fullt))
if self.rand_at != -1:
out_arr.append('rand_a = ' + str(self.rand_at))
if self.rand_grayt != -1:
out_arr.append('rand_gray = ' + str(self.rand_grayt))
self.start(self.num_obj,self.mat_name,self.shader)
return out_arr
del_all_objs()
light0 = light_add('POINT', -15, -20, 10)
light1 = light_add('POINT', 15, 25, -25)
light2 = light_add('AREA', 0, 0, 33,energy_=140000)
camera_add(20, -20, 40, 210, 180, -135)
gravity_add(z = -1)
world_color()
export_image_settings(
FR_START,
FR_END,
FR_DIM_X,
FR_DIM_Y,
64,
TELEMETRY_SHOW,
ANIM) # 64
# bicycle
# create big Icosphere
# Icosphere random moving and toss up objects
O.mesh.primitive_ico_sphere_add(subdivisions=1,radius=65)
ico = C.active_object
rigidbody_for_obj(ico, 'MESH', True, 15)
mat_for_obj(ico, 'Mat_icosphere',blend_method='OPAQUE')
mod_apply_bevel(ico, 1, 1)
mod_apply_subsurf(ico, 3, 3)
O.object.shade_smooth()
# frames with big Icosphere
fr_step_ico = 50
FR_END_ico = FR_END + fr_step_ico
for i in range(FR_START,FR_END_ico,fr_step_ico):
x = randint(0, 359)
y = randint(0, 359)
z = randint(0, 359)
C.scene.frame_set(i)
ico.rotation_euler = degrees_to_radians(x,y,z)
ico.keyframe_insert(data_path='rotation_euler')
# bicycle
# create sphere for protected camera
ico_rad = 15
protect_rad = 5
O.mesh.primitive_uv_sphere_add(radius=protect_rad,location=(20,-20,40))
cam_sphere = C.active_object
rigidbody_for_obj(cam_sphere,'MESH', True, 15)
mat_for_obj(cam_sphere, 'Mat_transparent',alpha=0)
mod_apply_subsurf(cam_sphere, 3, 3)
O.object.shade_smooth()
if OBJ_ == 'mix': OBJ = mix()
elif OBJ_ == 'torus': OBJ = torus()
elif OBJ_ == 'cube': OBJ = cube()
elif OBJ_ == 'cone': OBJ = cone()
elif OBJ_ == 'sphere': OBJ = sphere()
elif OBJ_ == 'icosph': OBJ = icosph()
# add array of little objs in Icosphere
ar = arr_xyz(OBJ,ico_rad,NUM_OBJS,M_SIZE)
# add objects in array
if (OBJ[0] != 'mix'):
for i in range(NUM_OBJS):
obj_size = randint(OBJ[1], OBJ[2])*0.1
xyz = [ar[0][i],ar[1][i],ar[2][i]]
obj_add(OBJ[0], obj_size, xyz)
print(str(i)+'.'+OBJ[0])
else:
for i in range(NUM_OBJS):
OBJ = choice([torus(),cube(),cone(),sphere()])
obj_size = randint(OBJ[1], OBJ[2])*0.1
xyz = [ar[0][i],ar[1][i],ar[2][i]]
obj_add(OBJ[0], obj_size, xyz)
print(str(i)+'.'+OBJ[0])
bake_animation(FR_START, FR_END)
ob = li = en = 1
ob_last = 50
li_last = 18
en_last = 21
ob_color = mat_color()
ob_color.start(NUM_OBJS,'Mat')
en_color = mat_color()
en_color.start(1,'Mat_icosphere')
arr_ob_1 = [
0,
0.25,
randint(0, 1000)*0.001,
randint(0, 750)*0.001,
randint(0, 500)*0.001,
randint(0, 250)*0.001,
randint(250, 750)*0.001,
randint(250, 500)*0.001,
randint(250, 1000)*0.001,
randint(500, 1000)*0.001,
randint(750, 1000)*0.001,
0.5,
0.75,
1]
arr_ob_2 = [
[0,1000],
[0,750],
[0,500],
[0,250],
[10,990],
[100,900],
[randint(0, 250),randint(251, 1000)],
[randint(0, 500),randint(501, 1000)],
[randint(0, 750),randint(751, 1000)],
[200,800],
[750,1000],
[500,1000],
[250,1000],
[250,750],
[250,500]]
if ANIM == False:
for fr in range(FR_START,FR_END+1):
x = choice(arr_ob_2)
y = choice(arr_ob_2[6:])
if ob==1 or ob==ob_last+1:
ob_color.r(1)
ob_color.g(1)
ob_color.b(1)
elif ob>=2 and ob<=5:
ob_color.rand_rgb(x[0],x[1])
elif ob==6:
ob_color.rand_rgb(x[0],x[1])
ob_color.r(choice(arr_ob_1))
elif ob==7:
ob_color.rand_rgb(x[0],x[1])
ob_color.g(choice(arr_ob_1))
elif ob==8:
ob_color.rand_rgb(x[0],x[1])
ob_color.b(choice(arr_ob_1))
elif ob==9:
ob_color.start(NUM_OBJS,'Mat','Emission')
C.scene.eevee.use_bloom = True # use bloom
ob_color.rand_rgb(x[0],x[1])
ob_color.r(choice(arr_ob_1))
ob_color.st(1)
elif ob==10:
ob_color.rand_rgb(x[0],x[1])
ob_color.g(choice(arr_ob_1))
ob_color.st(1)
elif ob==11:
ob_color.rand_rgb(x[0],x[1])
ob_color.b(choice(arr_ob_1))
ob_color.st(1)
elif ob>=12 and ob<=14:
ob_color.rand_rgb(x[0],x[1])
ob_color.st(randint(2,7))
elif ob==15:
ob_color.start(NUM_OBJS,'Mat')
C.scene.eevee.use_bloom = False
ob_color.rand_rgb(x[0],x[1])
ob_color.r(choice(arr_ob_1))
ob_color.g(choice(arr_ob_1))
elif ob==16:
ob_color.rand_rgb(x[0],x[1])
ob_color.g(choice(arr_ob_1))
ob_color.b(choice(arr_ob_1))
elif ob>=17 and ob<=18:
ob_color.rand_rgb(x[0],x[1])
ob_color.r(choice(arr_ob_1))
ob_color.b(choice(arr_ob_1))
elif ob==19:
ob_color.start(NUM_OBJS,'Mat','Emission')
C.scene.eevee.use_bloom = True
ob_color.a(choice(arr_ob_1[6:]))
ob_color.rand_gray(x[0],x[1])
ob_color.st(randint(1,5))
elif ob==20:
ob_color.a(choice(arr_ob_1[6:]))
ob_color.rand_rgb(x[0],x[1])
ob_color.st(randint(1,5))
elif ob>=21 and ob<=23:
ob_color.start(NUM_OBJS,'Mat')
C.scene.eevee.use_bloom = False
ob_color.rand_rgb_full(x[0],x[1])
ob_color.rand_a(y[0],y[1])
elif ob>=24 and ob<=26:
ob_color.start(NUM_OBJS,'Mat','Emission')
C.scene.eevee.use_bloom = True
ob_color.rand_rgb_full(x[0],x[1])
ob_color.rand_a(y[0],y[1])
ob_color.st(randint(1, 3))
elif ob>=27 and ob<=29:
ob_color.rand_rgb_full(x[0],x[1])
ob_color.st(randint(1, 3))
elif ob>=30 and ob<=32:
ob_color.start(NUM_OBJS,'Mat')
C.scene.eevee.use_bloom = False
ob_color.rand_rgb(x[0],x[1])
ob_color.rand_a(y[0],y[1])
elif ob>=33 and ob<=35:
ob_color.rand_a(y[0],y[1])
ob_color.r(choice(arr_ob_1))
ob_color.g(choice(arr_ob_1))
ob_color.b(choice(arr_ob_1))
elif ob>=36 and ob<=38:
ob_color.rand_rgb(x[0],x[1])
ob_color.rand_a(y[0],y[1])
elif ob>=39 and ob<=40:
ob_color.a(choice(arr_ob_1[6:]))
ob_color.rand_rgb(x[0],x[1])
elif ob>=41 and ob<=44:
ob_color.start(NUM_OBJS,'Mat','Emission')
C.scene.eevee.use_bloom = True
ob_color.rand_rgb(x[0],x[1])
ob_color.st(randint(11, 25))
elif ob>=45 and ob<=49:
ob_color.start(NUM_OBJS,'Mat')
C.scene.eevee.use_bloom = False
ob_color.rand_rgb_full(x[0],x[1])
elif ob==ob_last:
ob_color.start(NUM_OBJS,'Mat')
C.scene.eevee.use_bloom = False
ob_color.rand_rgb_full(x[0],x[1])
ob = 0
ob_telem = ob_color.change()
if li==1 or li==li_last+1:
r0 = g0 = b0 = 1
r1 = g1 = b1 = 1
r2 = g2 = b2 = 1
elif li==2:
r0 = g0 = b0 = 1
elif li==3:
r1 = g1 = b1 = 1
elif li==4:
r2 = g2 = b2 = 1
elif li==5:
rgb = rgb_rand(0, 1000)
r0 = rgb[0]
g0 = rgb[1]
b0 = rgb[2]
elif li==6:
rgb = rgb_rand(0, 1000)
r1 = rgb[0]
g1 = rgb[1]
b1 = rgb[2]
elif li==7:
rgb = rgb_rand(0, 1000)
r2 = rgb[0]
g2 = rgb[1]
b2 = rgb[2]
elif li>=8 and li<=10:
rgb = rgb_rand(0, 1000)
r0 = rgb[0]
g0 = rgb[1]
b0 = rgb[2]
rgb = rgb_rand(0, 1000)
r1 = rgb[0]
g1 = rgb[1]
b1 = rgb[2]
rgb = rgb_rand(0, 1000)
r2 = rgb[0]
g2 = rgb[1]
b2 = rgb[2]
elif li==11:
r0 = b0 = g0 = 1
rgb = rgb_rand(0, 1000)
r1 = rgb[0]
g1 = rgb[1]
b1 = rgb[2]
rgb = rgb_rand(0, 1000)
r2 = rgb[0]
g2 = rgb[1]
b2 = rgb[2]
elif li==12:
rgb = rgb_rand(100, 900)
r0 = rgb[0]
g0 = rgb[1]
b0 = rgb[2]
r1 = g1 = b1 = 1
rgb = rgb_rand(100, 900)
r2 = rgb[0]
g2 = rgb[1]
b2 = rgb[2]
elif li==13:
rgb = rgb_rand(100, 900)
r0 = rgb[0]
g0 = rgb[1]
b0 = rgb[2]
rgb = rgb_rand(100, 900)
r1 = rgb[0]
g1 = rgb[1]
b1 = rgb[2]
r2 = g2 = b2 = 1
elif li==14:
r0 = 1
g0 = randint(0, 1000)*0.001
b0 = randint(0, 1000)*0.001
r1 = randint(0, 1000)*0.001
g1 = 1
b1 = randint(0, 1000)*0.001
r2 = randint(0, 1000)*0.001
g2 = randint(0, 1000)*0.001
b2 = 1
elif li==15:
r0 = randint(0, 1000)*0.001
g0 = 1
b0 = randint(0, 1000)*0.001
r1 = randint(0, 1000)*0.001
g1 = randint(0, 1000)*0.001
b1 = 1
r2 = 1
g2 = randint(0, 1000)*0.001
b2 = randint(0, 1000)*0.001
elif li==16:
r0 = randint(0, 1000)*0.001
g0 = randint(0, 1000)*0.001
b0 = 1
r1 = 1
g1 = randint(0, 1000)*0.001
b1 = randint(0, 1000)*0.001
r2 = randint(0, 1000)*0.001
g2 = 1
b2 = randint(0, 1000)*0.001
elif li==17:
zz = rgb_rand(100, 1000)
r0 = zz[0]
g0 = zz[1]
b0 = zz[2]
zz = rgb_rand(100, 1000)
r1 = zz[0]
g1 = zz[1]
b1 = zz[2]
zz = rgb_rand(100, 1000)
r2 = zz[0]
g2 = zz[1]
b2 = zz[2]
elif li==li_last:
r0 = g0 = b0 = 0
r1 = g1 = b1 = 0
r2 = g2 = b2 = 0
li = 0
li1 = light_chng(light0, [r0,g0,b0])
li2 = light_chng(light1, [r1,g1,b1])
li3 = light_chng(light2, [r2,g2,b2],energy_=140000)
li_telem = [str(li1),str(li2),str(li3)]
r0 = g0 = b0 = 0
r1 = g1 = b1 = 0
r2 = g2 = b2 = 0
if en == 1 or en==en_last+1:
en_color.r(0)
en_color.g(0)
en_color.b(0)
elif en == 2 or en == 3 or en == 4:
en_color.r(1)
en_color.g(1)
en_color.b(1)
elif en == 5:
en_color.rand_rgb(100, 900)
en_color.r(1)
elif en == 6:
en_color.rand_rgb(100, 900)
en_color.g(1)
elif en == 7:
en_color.rand_rgb(100, 900)
en_color.b(1)
elif en >= 8 and en <= 14:
en_color.rand_rgb(0, 1000)
elif en >= 15 and en <= 20:
en_color.rand_rgb_full(randint(0, 500), randint(501,1000))
elif en == en_last:
en_color.rand_rgb_full(0, 1000)
en = 0
en_telem = en_color.change()
C.scene.frame_set(fr)
C.scene.render.stamp_note_text = (
'OBJS:\n'+str('\n'.join(ob_telem))+
'\n\nENV:\n'+str('\n'.join(en_telem))+
'\n\nLIGHTS:\n'+str('\n'.join(li_telem)))
path_out = PATH_OUT + '\\'
file_out = '0_' + str(fr)
path_file = Path(path_out, file_out)
C.scene.render.filepath = str(path_file)
O.render.render(write_still = True)
ob += 1
li += 1
en += 1
else:
# Animation settings:
x = choice(arr_ob_2)
y = choice(arr_ob_2[6:])
ob_color.rand_rgb(x[0],x[1])
ob_telem = ob_color.change()
r0 = randint(0, 1000)*0.001
g0 = randint(0, 1000)*0.001
b0 = 1
r1 = 1
g1 = randint(0, 1000)*0.001
b1 = randint(0, 1000)*0.001
r2 = randint(0, 1000)*0.001
g2 = 1
b2 = randint(0, 1000)*0.001
li1 = light_chng(light0, [r0,g0,b0])
li2 = light_chng(light1, [r1,g1,b1])
li3 = light_chng(light2, [r2,g2,b2],energy_=140000)
li_telem = [str(li1),str(li2),str(li3)]
en_color.rand_rgb(100, 900)
en_color.g(1)
en_telem = en_color.change()
C.scene.render.stamp_note_text = (
'OBJS:\n'+str('\n'.join(ob_telem))+
'\n\nENV:\n'+str('\n'.join(en_telem))+
'\n\nLIGHTS:\n'+str('\n'.join(li_telem)))
path_out = PATH_OUT + '\\'
file_out = 'anim'
path_file = Path(path_out, file_out)
C.scene.render.filepath = str(path_file)
O.render.render(animation = True)