glitch3d 0.2.2.8 → 0.2.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
File without changes
data/image.py ADDED
@@ -0,0 +1,32 @@
1
+ # Make a mosaic with images
2
+ import sys
3
+ import os
4
+ from PIL import Image
5
+
6
+ RES_X = 5000
7
+ RES_Y = 5000
8
+ path = './renders/'
9
+ files = [path + f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
10
+ images = map(Image.open, files)
11
+ widths, heights = zip(*(i.size for i in images))
12
+
13
+ total_width = images[0].size[0] * 4
14
+ total_height = total_width
15
+
16
+ res = Image.new('RGB', (total_height,total_width))
17
+ print('stitching ' + str(len(files)) + ' images')
18
+
19
+ x_offset = 0
20
+ y_offset = 0
21
+ for file in files:
22
+ print(file)
23
+ image = Image.open(file)
24
+ print(image.size)
25
+ res.paste(image, (x_offset, y_offset))
26
+ x_offset += image.size[0]
27
+ if x_offset > total_width:
28
+ print('reset')
29
+ y_offset += image.size[1]
30
+ x_offset = 0
31
+
32
+ res.save('./mosaic.png')
@@ -0,0 +1,33 @@
1
+ ######################
2
+ ## FLUID SIMULATION ##
3
+ ######################
4
+ animate = True
5
+ context.scene.frame_end = NUMBER_OF_FRAMES
6
+
7
+ # Container
8
+ bpy.ops.mesh.primitive_cube_add(location=(0, 0, -0.4),radius=7)
9
+ container = bpy.data.objects['Cube']
10
+ container.name = 'Container'
11
+ container.modifiers.new(name='container', type='FLUID_SIMULATION')
12
+ container.modifiers['container'].settings.type = 'DOMAIN'
13
+ container.modifiers['container'].settings.generate_particles = 1
14
+ make_object_gradient_fabulous(container, rand_color(), rand_color())
15
+ container.location = (0, 0, 7)
16
+
17
+ # Emitter of fluid
18
+ bpy.ops.mesh.primitive_uv_sphere_add(location=(0,0,10))
19
+ emitter = bpy.data.objects['Sphere']
20
+ emitter.name = 'Emitter'
21
+ emitter.modifiers.new(name='emitter', type='FLUID_SIMULATION')
22
+ emitter.modifiers['emitter'].settings.type = 'INFLOW'
23
+ emitter.modifiers['emitter'].settings.inflow_velocity = mathutils.Vector((0, 0, -1))
24
+ emitter.scale = (0.5, 0.5, 0.5)
25
+
26
+ SUBJECT.modifiers.new(name='obstacle', type='FLUID_SIMULATION')
27
+ SUBJECT.modifiers['obstacle'].settings.type = 'OBSTACLE'
28
+ SUBJECT.modifiers['obstacle'].settings.volume_initialization = 'BOTH'
29
+ SUBJECT.modifiers['obstacle'].settings.surface_subdivisions = 6
30
+ SUBJECT.modifiers['obstacle'].settings.partial_slip_factor = 0.15
31
+
32
+ # Bake animation
33
+ bpy.ops.fluid.bake({'scene': context.scene, 'active_object': container})
@@ -48,10 +48,11 @@ texture_object(floor)
48
48
  OCEAN = add_ocean(10, 20)
49
49
 
50
50
  # Create lines as backdrop
51
- bpy.data.groups.new('Lines')
51
+ LINES = bpy.data.groups['Lines']
52
52
  for j in range(0,20):
53
53
  for i in range(0, 20):
54
54
  new_line = create_line('line' + str(uuid.uuid1()), series(30), 0.003, (j, -10, 2))
55
+ bpy.data.groups['Lines'].objects.link(new_line)
55
56
  new_line.location.z += i / 3
56
57
 
57
58
  # Add flying letters, lmao
@@ -0,0 +1,62 @@
1
+ # Game of life inspired scene
2
+ w = 40
3
+ f = 1
4
+ bpy.ops.anim.change_frame( frame = f )
5
+
6
+ cubes = [[ 0 for i in range(w)] for j in range(w)]
7
+ for x in range(w):
8
+ for y in range(w):
9
+ bpy.ops.mesh.primitive_cube_add( location=(x * 2, y * 2, 0 ))
10
+ cubes[x][y] = bpy.context.active_object
11
+ cubes[x][y].data.materials.append( mat );
12
+ cubes[x][y].scale=(.1,.1,.1)
13
+ bpy.ops.anim.keyframe_insert_menu( type='Scaling')
14
+
15
+ cells = [[ 0 for i in range(w)] for j in range(w)]
16
+ nextGen = [[ 0 for i in range(w)] for j in range(w)]
17
+
18
+ cells[16][14] = 1
19
+ cells[16][15] = 1
20
+ cells[15][15] = 1
21
+ cells[15][17] = 1
22
+ cells[16][16] = 1
23
+ cells[17][15] = 1
24
+ cells[17][17] = 1
25
+ cells[16][17] = 1
26
+
27
+ for l in range(50):
28
+ f += 5
29
+ bpy.ops.anim.change_frame( frame = f )
30
+ for x in range(w):
31
+ row = ""
32
+ for y in range(w):
33
+ nb = 0
34
+ for i in range(-1,2):
35
+ for j in range( -1, 2):
36
+ xx = (x + i + w) % w
37
+ yy = (y + j + w) % w
38
+
39
+ if not( xx == x and yy == y):
40
+ nb += cells[xx][yy]
41
+
42
+ if ( cells[x][y] == 1 and (nb == 2 or nb == 3)):
43
+ nextGen[x][y] = 1
44
+ elif ( cells[x][y] == 0 and nb == 3 ):
45
+ nextGen[x][y] = 1
46
+ else:
47
+ nextGen[x][y] = 0
48
+
49
+ n = cubes[x][y]
50
+ bpy.context.scene.objects.active = n
51
+ n.select = True
52
+ if cells[x][y] == 1 :
53
+ #row += 'X'
54
+ cubes[x][y].scale=(1,1,1)
55
+ else:
56
+ #row += '.'
57
+ cubes[x][y].scale=(.1,.1,.1)
58
+ bpy.ops.anim.keyframe_insert_menu( type='Scaling')
59
+
60
+ for x in range( w ):
61
+ for y in range(w):
62
+ cells[x][y] = nextGen[x][y]
@@ -1,6 +1,3 @@
1
- # DISCLAIMER: all of this could be done in a much more intelligent way (with more Python knowledge)
2
- # This is just what works for now for the needs of my current project
3
-
4
1
  REFLECTOR_SCALE = random.uniform(5, 8)
5
2
  REFLECTOR_STRENGTH = random.uniform(10, 15)
6
3
  REFLECTOR_LOCATION_PADDING = random.uniform(10, 12)
@@ -20,8 +17,6 @@ GREY = (0.2, 0.2, 0.2 ,1)
20
17
  BLUE = (0.1, 0.1, 0.8, 1)
21
18
  PINK = (0.8, 0.2, 0.7, 1.0)
22
19
  WORDS = string.ascii_lowercase
23
- WIREFRAMES = []
24
- VORONOIED = []
25
20
 
26
21
  def debug():
27
22
  code.interact(local=dict(globals(), **locals()))
@@ -46,14 +41,14 @@ def shoot(filepath):
46
41
  return bpy.ops.render.render(animation=animate, write_still=True)
47
42
  bpy.ops.render.render(write_still=True)
48
43
 
49
- def output_name(index, model_path):
50
- if animate == True:
44
+ def output_name(model_path, index = 0):
45
+ if animate:
51
46
  return './renders/' + os.path.splitext(model_path)[0].split('/')[-1] + '_' + str(index) + '_' + str(datetime.date.today()) + '_' + str(mode) + '.avi'
52
47
  else:
53
48
  return './renders/' + os.path.splitext(model_path)[0].split('/')[-1] + '_' + str(index) + '_' + str(datetime.date.today()) + '_' + str(mode) + '.png'
54
49
 
55
- def rotate(SUBJECT, index):
56
- SUBJECT.rotation_euler[2] = math.radians(index * (360.0 / shots_number))
50
+ def rotate(model_object, index):
51
+ model_object.rotation_euler.z = math.radians(index * (360.0 / shots_number))
57
52
 
58
53
  # RGB 0 -> 1
59
54
  def rand_color_value():
@@ -204,11 +199,10 @@ def duplicate_object(obj):
204
199
 
205
200
  def random_text():
206
201
  global WORDS
207
- chosen_word = random.choice(WORDS)
208
- return chosen_word
202
+ return random.choice(WORDS)
209
203
 
210
204
  def create_mesh(name, verts, faces, location):
211
- mesh_data = bpy.data.meshes.new("cube_mesh_data")
205
+ mesh_data = bpy.data.meshes.new("mesh_data")
212
206
  mesh_data.from_pydata(verts, [], faces)
213
207
  mesh_data.update()
214
208
  obj = bpy.data.objects.new(name, mesh_data)
@@ -219,7 +213,7 @@ def create_mesh(name, verts, faces, location):
219
213
  def spawn_text():
220
214
  identifier = str(uuid.uuid1())
221
215
  new_curve = bpy.data.curves.new(type="FONT",name="Curve - " + identifier)
222
- new_curve.extrude = 0.12
216
+ new_curve.extrude = 0.11
223
217
  new_text = bpy.data.objects.new("Text - " + identifier, new_curve)
224
218
  new_text.data.body = random_text()
225
219
  context.scene.objects.link(new_text)
@@ -329,20 +323,19 @@ def clone(obj):
329
323
  context.scene.objects.link(new_obj)
330
324
  return new_obj
331
325
 
332
- def add_ocean(spatial_size, resolution):
333
- bpy.ops.mesh.primitive_cube_add(location=(0, 0, -1),radius=1)
326
+ def add_ocean(spatial_size, resolution, depth = 100, scale=(4,4,4)):
327
+ bpy.ops.mesh.primitive_cube_add(location=(0, 0, -0.4),radius=1)
334
328
  ocean = last_added_object('CUBE')
335
- context.scene.objects.active = ocean
336
- ocean.scale = (2,2,2)
337
- bpy.ops.object.modifier_add(type='OCEAN')
329
+ ocean.scale = scale
330
+ ocean.modifiers.new(name='Ocean', type='OCEAN')
338
331
  ocean.modifiers["Ocean"].spatial_size = spatial_size
339
332
  ocean.modifiers["Ocean"].resolution = resolution
333
+ ocean.modifiers["Ocean"].depth = depth
340
334
  make_object_glossy(ocean, rand_color())
341
335
  make_object_gradient_fabulous(ocean, rand_color(), rand_color())
342
336
  mix_nodes(ocean.data.materials[0], ocean.data.materials[0].node_tree.nodes['Diffuse BSDF'], ocean.data.materials[0].node_tree.nodes['Glossy BSDF'])
343
337
  shadow = clone(ocean)
344
- shadow.location.x += 2
345
- shadow.location.y += 1
338
+ shadow.location += mathutils.Vector((1,1,-0.4))
346
339
  wireframize(shadow)
347
340
  shadow.name = 'shadow'
348
341
  ocean.name = 'ocean'
@@ -387,11 +380,14 @@ def build_pyramid(width=random.uniform(1,3), length=random.uniform(1,3), height=
387
380
  return create_mesh('Pyramid ' + str(uuid.uuid1()), verts, faces, location)
388
381
 
389
382
  def move_ocean(ocean):
390
- ocean.modifiers['Ocean'].time += 1.5
383
+ if animate:
384
+ ocean.modifiers['Ocean'].time += 0.01
385
+ else:
386
+ ocean.modifiers['Ocean'].time += 2
391
387
  ocean.modifiers['Ocean'].random_seed = round(random.uniform(0, 100))
392
- ocean.modifers['Ocean'].choppiness += 0.3
388
+ ocean.modifers['Ocean'].choppiness += random.uniform(0, 1.15)
393
389
 
394
- def camera_path(pitch = 0.0001):
390
+ def camera_path(pitch = 0.01):
395
391
  res = []
396
392
  initial_z = INITIAL_CAMERA_LOCATION[2]
397
393
  initial_x = INITIAL_CAMERA_LOCATION[0]
@@ -405,16 +401,17 @@ def camera_path(pitch = 0.0001):
405
401
  res.append((x, initial_x, initial_z))
406
402
  return res
407
403
 
408
- def pitched_array(min, max, pitch):
409
- return list(map(lambda x: (min + pitch * x), range(int((max - min) / pitch))))
404
+ def pitched_array(minimum, maximum, pitch):
405
+ return list(map(lambda x: (minimum + pitch * x), range(int((maximum - minimum) / pitch))))
410
406
 
411
- def still_routine():
407
+ def still_routine(index = 1):
412
408
  CAMERA.location.x = INITIAL_CAMERA_LOCATION[0] + round(random.uniform(-2, 2), 10)
413
409
  CAMERA.location.y = INITIAL_CAMERA_LOCATION[1] + round(random.uniform(-2, 2), 10)
414
410
  randomize_reflectors_colors()
415
411
  map(move_ocean, OCEAN)
416
412
  map(make_object_glossy, OCEAN)
417
413
  rotate(SUBJECT, index)
414
+ CAMERA.rotation_euler.y += math.radians(round(random.uniform(-30, +30)))
418
415
  for l in bpy.data.groups['Lines'].objects:
419
416
  rotation = rand_rotation()
420
417
  l.rotation_euler = rotation
@@ -422,31 +419,35 @@ def still_routine():
422
419
  prop.location = rand_location()
423
420
  prop.rotation_euler = rand_rotation()
424
421
  for obj in WIREFRAMES:
425
- obj.location = rand_location()
422
+ # obj.location = rand_location()
423
+ obj.location += mathutils.Vector((1,1,1))
426
424
  obj.rotation_euler = rand_rotation()
427
425
  for display in bpy.data.groups['Displays'].objects:
428
426
  display.location = rand_location()
429
427
  rotate(display, index)
430
428
 
431
429
  def animation_routine(frame):
432
- assert len(camera_path) >= NUMBER_OF_FRAMES
433
- CAMERA.location = camera_path[frame]
430
+ assert len(CAMERA_PATH) >= NUMBER_OF_FRAMES
431
+ CAMERA.location = CAMERA_PATH[frame]
434
432
  look_at(SUBJECT)
435
433
  randomize_reflectors_colors()
436
- map(move_ocean, OCEAN)
437
- map(make_object_glossy, OCEAN)
434
+ if OCEAN:
435
+ map(move_ocean, OCEAN)
436
+ map(make_object_glossy, OCEAN)
438
437
  glitch(SUBJECT)
439
438
  SUBJECT.rotation_euler.z += math.radians(4)
440
439
  for l in bpy.data.groups['Lines'].objects:
441
440
  l.rotation_euler.x += math.radians(5)
442
441
  l.rotation_euler.z += math.radians(5)
443
- for prop in props:
444
- prop.rotation_euler.x += math.radians(5)
445
- for obj in WIREFRAMES:
446
- obj.location.z += 0.1
447
- obj.rotation_euler.z += math.radians(5)
448
- for display in bpy.data.groups['Displays'].objects:
449
- display.rotation_euler.x += math.radians(3)
442
+ if props:
443
+ for prop in props:
444
+ prop.rotation_euler.x += math.radians(5)
445
+ if WIREFRAMES:
446
+ for obj in WIREFRAMES:
447
+ obj.location += mathutils.Vector((0.1, 0.1, 0.1))
448
+ obj.rotation_euler.rotate(mathutils.Euler((math.radians(2), math.radians(2), math.radians(5)), 'XYZ'))
449
+ # for display in bpy.data.groups['Displays'].objects:
450
+ # display.rotation_euler.x += math.radians(2)
450
451
 
451
452
  def create_line(name, point_list, thickness = 0.002, location = (0, -10, 0)):
452
453
  # setup basic line data
@@ -1,11 +1,11 @@
1
1
  # Rendering script
2
2
  # Run by calling the blender executable with -b -P <script_name>
3
3
  # Use `debug()` to pry into the script
4
+ # DISCLAIMER: all of this could be done in a much more intelligent way (with more Python knowledge)
5
+ # This is just what works for now for the needs of my current project
4
6
 
5
7
  import argparse
6
8
 
7
- DEBUG=False
8
-
9
9
  def get_args():
10
10
  parser = argparse.ArgumentParser()
11
11
  # get all script args
@@ -28,7 +28,11 @@ path = str(args.path)
28
28
  animate = (args.animate == 'True')
29
29
  shots_number = int(args.shots_number)
30
30
 
31
- import os, bpy, datetime, bmesh, random, math, mathutils, random, uuid, sys, logging, string, colorsys, code
31
+ #####################################
32
+ #####################################
33
+ #####################################
34
+
35
+ import os, bpy, datetime, random, math, mathutils, random, uuid, sys, logging, string, colorsys, code
32
36
 
33
37
  # Create directory for renders
34
38
  directory = os.path.dirname('./renders')
@@ -39,6 +43,15 @@ exec(open(os.path.join(path + '/glitch3d/bpy', 'helpers.py')).read())
39
43
  exec(open(os.path.join(path + '/glitch3d/bpy', 'render_settings.py')).read())
40
44
  exec(open(os.path.join(path + '/glitch3d/bpy', 'lighting.py')).read())
41
45
 
46
+ # Create groups
47
+ WIREFRAMES = []
48
+ VORONOIED = []
49
+ OCEAN = []
50
+ bpy.data.groups.new('Lines')
51
+ LINES = bpy.data.groups['Lines'].objects
52
+ for primitive in PRIMITIVES:
53
+ bpy.data.groups.new(primitive.lower().title())
54
+
42
55
  FISHEYE = True
43
56
  COLORS = rand_color_palette(5)
44
57
  INITIAL_CAMERA_LOCATION = (3, 3, 1)
@@ -70,10 +83,6 @@ if FISHEYE:
70
83
 
71
84
  render_settings(context.scene, animate, mode)
72
85
 
73
- # Initialize groups
74
- for primitive in PRIMITIVES:
75
- bpy.data.groups.new(primitive.lower().title())
76
-
77
86
  # Load model
78
87
  model_path = os.path.join(file)
79
88
  bpy.ops.import_scene.obj(filepath = model_path, use_edges=True)
@@ -81,21 +90,25 @@ SUBJECT = bpy.data.objects['glitch3d']
81
90
  SUBJECT.select = True
82
91
  bpy.ops.object.origin_set(type="ORIGIN_CENTER_OF_MASS")
83
92
  SUBJECT.location = ORIGIN
84
- make_object_glossy(SUBJECT, YELLOW, 0.1)
85
- voronoize(SUBJECT)
93
+ make_object_glossy(SUBJECT, YELLOW, 0.01)
94
+ # voronoize(SUBJECT)
86
95
 
87
96
  let_there_be_light(context.scene)
88
97
 
89
98
  exec(open(os.path.join(path + '/glitch3d/bpy/canvas', 'dreamatorium.py')).read())
99
+ # exec(open(os.path.join(path + '/glitch3d/bpy/canvas', 'aether.py')).read())
90
100
 
91
101
  print('Rendering images with resolution: ' + str(context.scene.render.resolution_x) + ' x ' + str(context.scene.render.resolution_y))
92
102
 
103
+ for plane in bpy.data.groups['Plane'].objects:
104
+ unwrap_model(plane)
105
+
93
106
  if animate:
94
107
  print('ANIMATION RENDERING BEGIN')
95
108
  context.scene.frame_start = 0
96
109
  context.scene.frame_end = NUMBER_OF_FRAMES
97
110
  bpy.ops.screen.frame_jump(end=False)
98
- camera_path = camera_path(0.08)
111
+ CAMERA_PATH = camera_path(0.008)
99
112
 
100
113
  for frame in range(0, NUMBER_OF_FRAMES):
101
114
  bpy.context.scene.frame_set(frame)
@@ -104,15 +117,15 @@ if animate:
104
117
  obj.keyframe_insert(data_path="rotation_euler", index=-1)
105
118
  obj.keyframe_insert(data_path="location", index=-1)
106
119
  bpy.ops.screen.frame_jump(end=False)
107
- shoot(output_name(index, model_path))
120
+ shoot(output_name(model_path))
108
121
 
109
122
  else:
110
123
  print('STILL RENDERING BEGIN')
111
124
  for index in range(0, int(shots_number)):
112
125
  print("-------------------------- " + str(index) + " --------------------------")
113
- still_routine()
126
+ still_routine(index)
114
127
  look_at(SUBJECT)
115
- shoot(output_name(index, model_path))
128
+ shoot(output_name(model_path, index))
116
129
 
117
130
 
118
131
  print('FINISHED ¯\_(ツ)_/¯')
@@ -9,9 +9,6 @@ module Glitch3d
9
9
  end
10
10
 
11
11
  def alter_faces(faces_objects_array, vertex_objects_array)
12
- # (FACE_GLITCH_ITERATION_RATIO * faces_objects_array.count).to_i.times do |_|
13
- # random_element(faces_objects_array).fuck(random_element(vertex_objects_array))
14
- # end
15
12
  faces_objects_array
16
13
  end
17
14
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Glitch3d
3
3
  module FindAndReplace
4
- # Find and replace for vertices
5
4
  def alter_vertices(vertices_objects_array)
6
5
  @target = rand(9).to_s
7
6
  @replacement = rand(9).to_s
@@ -11,7 +10,6 @@ module Glitch3d
11
10
  vertices_objects_array
12
11
  end
13
12
 
14
- # Assign some faces to different vertices
15
13
  def alter_faces(faces_objects_array, vertices_objects_array)
16
14
  faces_objects_array.sample(3) do |face|
17
15
  face.v1 = rand(0..vertices_objects_array.size - 1)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Glitch3d
3
- VERSION = '0.2.2.8'
3
+ VERSION = '0.2.2.9'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glitch3d
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2.8
4
+ version: 0.2.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - pskl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-12 00:00:00.000000000 Z
11
+ date: 2017-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,8 +89,8 @@ files:
89
89
  - bin/setup
90
90
  - fixtures/brain.obj
91
91
  - fixtures/cube.obj
92
- - fixtures/dude.jpg
93
92
  - fixtures/face.obj
93
+ - fixtures/hand.obj
94
94
  - fixtures/m4a1.obj
95
95
  - fixtures/male_head.obj
96
96
  - fixtures/mars.obj
@@ -99,7 +99,9 @@ files:
99
99
  - fixtures/textures/afx_face.jpeg
100
100
  - fixtures/textures/afx_logo.jpg
101
101
  - fixtures/textures/anime.jpg
102
+ - fixtures/textures/btc.jpg
102
103
  - fixtures/textures/checkered_texture.jpg
104
+ - fixtures/textures/dude.jpg
103
105
  - fixtures/textures/grid.jpg
104
106
  - fixtures/textures/kago.jpg
105
107
  - fixtures/textures/kawai.jpg
@@ -107,8 +109,11 @@ files:
107
109
  - fixtures/textures/spiral.jpg
108
110
  - fixtures/textures/vapor.jpg
109
111
  - glitch3d.gemspec
112
+ - image.py
110
113
  - lib/glitch3d.rb
114
+ - lib/glitch3d/bpy/canvas/aether.py
111
115
  - lib/glitch3d/bpy/canvas/dreamatorium.py
116
+ - lib/glitch3d/bpy/canvas/lyfe.py
112
117
  - lib/glitch3d/bpy/helpers.py
113
118
  - lib/glitch3d/bpy/lighting.py
114
119
  - lib/glitch3d/bpy/main.py