glitch3d 0.2.1 → 0.2.2.1
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.
- checksums.yaml +4 -4
- data/fixtures/face.obj +139130 -0
- data/fixtures/textures/anime.jpg +0 -0
- data/lib/glitch3d/bpy/animation_recording.py +12 -0
- data/lib/glitch3d/bpy/helpers.py +14 -6
- data/lib/glitch3d/bpy/rendering.py +27 -2
- data/lib/glitch3d/bpy/uv_glitch.py +1 -0
- data/lib/glitch3d/strategies/find_and_replace.rb +23 -0
- data/lib/glitch3d/version.rb +1 -1
- data/lib/glitch3d.rb +13 -5
- metadata +7 -2
Binary file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
scene = bpy.context.scene
|
2
|
+
scene.frame_start = 0
|
3
|
+
scene.frame_end = NUMBER_OF_FRAMES
|
4
|
+
bpy.ops.screen.frame_jump(end=False)
|
5
|
+
|
6
|
+
for frame in range(1, NUMBER_OF_FRAMES):
|
7
|
+
bpy.context.scene.frame_set(frame)
|
8
|
+
# do stuff here
|
9
|
+
for ob in context.scene.objects:
|
10
|
+
ob.keyframe_insert(data_path="location", index=-1)
|
11
|
+
|
12
|
+
bpy.ops.screen.frame_jump(end=False)
|
data/lib/glitch3d/bpy/helpers.py
CHANGED
@@ -13,12 +13,15 @@ import logging
|
|
13
13
|
import string
|
14
14
|
import colorsys
|
15
15
|
|
16
|
-
REFLECTOR_SCALE =
|
17
|
-
REFLECTOR_STRENGTH = 12
|
18
|
-
REFLECTOR_LOCATION_PADDING = 10
|
19
|
-
WIREFRAME_THICKNESS = 0.008
|
20
|
-
DISPLACEMENT_AMPLITUDE = 0.06
|
16
|
+
REFLECTOR_SCALE = random.uniform(4, 6)
|
17
|
+
REFLECTOR_STRENGTH = random.uniform(8, 12)
|
18
|
+
REFLECTOR_LOCATION_PADDING = random.uniform(10, 12)
|
19
|
+
WIREFRAME_THICKNESS = random.uniform(0.008, 0.01)
|
20
|
+
DISPLACEMENT_AMPLITUDE = random.uniform(0.06, 0.08)
|
21
|
+
REPLACE_TARGET = '6'
|
22
|
+
REPLACEMENT = '2'
|
21
23
|
ORIGIN = (0,0,0)
|
24
|
+
NUMBER_OF_FRAMES = 100
|
22
25
|
|
23
26
|
PRIMITIVES = ['PYRAMID', 'CUBE']
|
24
27
|
props = []
|
@@ -275,14 +278,19 @@ def build_object_line(obj, size, z_index, y_index, radius):
|
|
275
278
|
group_add(obj, new_obj)
|
276
279
|
new_obj.location = ((last_object_group(obj).location.x + 2 * radius), y_index, z_index)
|
277
280
|
|
281
|
+
# Displace vertex by random offset
|
278
282
|
def displace(vector):
|
279
283
|
return mathutils.Vector((vector.x + random.uniform(-DISPLACEMENT_AMPLITUDE, DISPLACEMENT_AMPLITUDE), vector.y + random.uniform(-DISPLACEMENT_AMPLITUDE, DISPLACEMENT_AMPLITUDE), vector.z + random.uniform(-DISPLACEMENT_AMPLITUDE, DISPLACEMENT_AMPLITUDE)))
|
280
284
|
|
285
|
+
# Replace vertex coordinate everywhere
|
286
|
+
def find_and_replace(vector):
|
287
|
+
return mathutils.Vector((float(str(vector.x).replace(REPLACE_TARGET, REPLACEMENT)), float(str(vector.y).replace(REPLACE_TARGET, REPLACEMENT)), float(str(vector.z).replace(REPLACE_TARGET, REPLACEMENT))))
|
288
|
+
|
281
289
|
def glitch(object):
|
282
290
|
bpy.ops.object.mode_set(mode='OBJECT')
|
283
291
|
assert object.type == 'MESH'
|
284
292
|
for vertex in object.data.vertices:
|
285
|
-
vertex.co =
|
293
|
+
vertex.co = find_and_replace(vertex.co)
|
286
294
|
|
287
295
|
def subdivide(object, cuts):
|
288
296
|
if context.scene.objects.active != object:
|
@@ -11,6 +11,7 @@
|
|
11
11
|
# Use `debug()` to pry into the script
|
12
12
|
import os
|
13
13
|
exec(open(os.path.join(os.path.dirname(__file__), 'helpers.py')).read())
|
14
|
+
exec(open(os.path.join(os.path.dirname(__file__), 'animation_recording.py')).read())
|
14
15
|
|
15
16
|
# Arguments parsing
|
16
17
|
args = get_args()
|
@@ -24,6 +25,7 @@ FIXTURES_FOLDER_PATH = path + '/../fixtures/'
|
|
24
25
|
DEBUG = False
|
25
26
|
FISHEYE = False
|
26
27
|
COLORS = rand_color_palette(5)
|
28
|
+
INITIAL_CAMERA_LOCATION = (8, 8, 1)
|
27
29
|
|
28
30
|
if DEBUG:
|
29
31
|
shots_number = 2
|
@@ -98,7 +100,7 @@ camera_data = bpy.data.cameras.new('Camera')
|
|
98
100
|
bpy.data.objects.new('Camera', object_data=camera_data)
|
99
101
|
camera_object = bpy.data.objects['Camera']
|
100
102
|
new_scene.objects.link(camera_object)
|
101
|
-
camera_object.location =
|
103
|
+
camera_object.location = INITIAL_CAMERA_LOCATION
|
102
104
|
|
103
105
|
if FISHEYE:
|
104
106
|
camera_object.data.type = 'PANO'
|
@@ -131,6 +133,24 @@ make_object_reflector(reflector1)
|
|
131
133
|
make_object_reflector(reflector2)
|
132
134
|
make_object_reflector(reflector3)
|
133
135
|
|
136
|
+
# Set up virtual displays
|
137
|
+
bpy.ops.mesh.primitive_grid_add(x_subdivisions=100, y_subdivisions=100, location=(0, 3, 2))
|
138
|
+
display1 = bpy.data.objects['Grid']
|
139
|
+
bpy.ops.mesh.primitive_grid_add(x_subdivisions=100, y_subdivisions=100, location=(3, 0, 2))
|
140
|
+
display2 = bpy.data.objects['Grid.001']
|
141
|
+
|
142
|
+
bpy.data.groups.new('Displays')
|
143
|
+
bpy.data.groups['Displays'].objects.link(display1)
|
144
|
+
bpy.data.groups['Displays'].objects.link(display2)
|
145
|
+
|
146
|
+
display1.rotation_euler.x += math.radians(90)
|
147
|
+
display2.rotation_euler.x += math.radians(90)
|
148
|
+
|
149
|
+
for display in [display1, display2]:
|
150
|
+
texture_object(display)
|
151
|
+
unwrap_model(display)
|
152
|
+
glitch(display)
|
153
|
+
|
134
154
|
# Adjust camera
|
135
155
|
context.scene.camera = camera_object
|
136
156
|
look_at(camera_object, model_object)
|
@@ -168,15 +188,20 @@ print('Rendering images with resolution: ' + str(context.scene.render.resolution
|
|
168
188
|
for index in range(0, int(shots_number)):
|
169
189
|
print("-------------------------- " + str(index) + " --------------------------")
|
170
190
|
rotate(model_object, index)
|
191
|
+
camera_object.location.x = INITIAL_CAMERA_LOCATION[0] + round(random.uniform(-2, 2), 10)
|
192
|
+
camera_object.location.y = INITIAL_CAMERA_LOCATION[1] + round(random.uniform(-2, 2), 10)
|
193
|
+
look_at(camera_object, model_object)
|
171
194
|
randomize_reflectors_colors()
|
172
195
|
OCEAN.modifiers['Ocean'].time += 1
|
196
|
+
OCEAN.modifiers['Ocean'].random_seed = round(random.uniform(0, 100))
|
173
197
|
make_object_glossy(OCEAN, rand_color())
|
174
198
|
OCEAN.modifiers['Ocean'].choppiness += 0.3
|
175
199
|
for prop in props:
|
176
200
|
prop.location = rand_location()
|
177
201
|
for obj in WIREFRAMES:
|
178
202
|
rotate(obj, index)
|
179
|
-
obj.
|
203
|
+
obj.location.z += round(random.uniform(-1, 1), 10)
|
204
|
+
obj.rotation_euler.z += math.radians(round(random.uniform(0, 90)))
|
180
205
|
m4a1.location = rand_location()
|
181
206
|
m4a1.rotation_euler = rand_rotation()
|
182
207
|
shoot(camera_object, model_object, output_name(index, model_path))
|
@@ -0,0 +1 @@
|
|
1
|
+
# Glitch UV map
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Glitch3d
|
3
|
+
module FindAndReplace
|
4
|
+
def alter_vertices(vertices_objects_array)
|
5
|
+
@target = rand(9).to_s
|
6
|
+
@replacement = rand(9).to_s
|
7
|
+
vertices_objects_array.each do |v|
|
8
|
+
find_and_replace(v)
|
9
|
+
end
|
10
|
+
vertices_objects_array
|
11
|
+
end
|
12
|
+
|
13
|
+
def alter_faces(faces_objects_array, vertices_objects_array)
|
14
|
+
faces_objects_array
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_and_replace(vertex)
|
18
|
+
vertex.x = vertex.x.to_s.tr(@target, @replacement).to_f
|
19
|
+
vertex.y = vertex.y.to_s.tr(@target, @replacement).to_f
|
20
|
+
vertex.z = vertex.z.to_s.tr(@target, @replacement).to_f
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/glitch3d/version.rb
CHANGED
data/lib/glitch3d.rb
CHANGED
@@ -25,10 +25,18 @@ module Glitch3d
|
|
25
25
|
create_glitched_file(glitch(read_source(source_file)), target_file, model_name)
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
# @param String source_file, 3d model file to take as input
|
29
|
+
# @param Hash args, parameters { 'stuff' => 'shit' }
|
30
|
+
def process_model(source_file, args = nil)
|
29
31
|
source_file = File.dirname(__FILE__) + '/../fixtures/cube.obj' if source_file.nil?
|
30
|
-
args = Hash[ARGV.join(' ').scan(/--?([^=\s]+)(?:=(\S+))?/)]
|
32
|
+
args = Hash[ARGV.join(' ').scan(/--?([^=\s]+)(?:=(\S+))?/)] if args.nil?
|
31
33
|
return clean_model(source_file) if args['clean']
|
34
|
+
|
35
|
+
if args.has_key?('version')
|
36
|
+
puts Glitch3d::VERSION
|
37
|
+
return nil
|
38
|
+
end
|
39
|
+
|
32
40
|
raise 'Set Blender executable path in your env variables before using glitch3d' if BLENDER_EXECUTABLE_PATH.nil?
|
33
41
|
self.class.include infer_strategy(args['mode'] || 'default')
|
34
42
|
@quality = args['quality'] || 'low'
|
@@ -41,11 +49,11 @@ module Glitch3d
|
|
41
49
|
end
|
42
50
|
|
43
51
|
def infer_strategy(mode)
|
44
|
-
return Glitch3d::Default if mode.nil?
|
52
|
+
return [ Glitch3d::Default, Glitch3d::Duplication, Glitch3d::FindAndReplace, Glitch3d::Localized, Glitch3d::None].sample if mode.nil?
|
45
53
|
begin
|
46
|
-
return eval("Glitch3d::#{mode.to_s.
|
54
|
+
return eval("Glitch3d::#{mode.to_s.gsub(/(?:_|^)(\w)/){$1.upcase}}")
|
47
55
|
rescue
|
48
|
-
raise "Strategy #{mode.to_s.
|
56
|
+
raise "Strategy #{mode.to_s..gsub(/(?:_|^)(\w)/){$1.upcase}} not found"
|
49
57
|
end
|
50
58
|
end
|
51
59
|
|
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.1
|
4
|
+
version: 0.2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pskl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,21 +89,26 @@ files:
|
|
89
89
|
- fixtures/brain.obj
|
90
90
|
- fixtures/cube.obj
|
91
91
|
- fixtures/demo.png
|
92
|
+
- fixtures/face.obj
|
92
93
|
- fixtures/m4a1.obj
|
93
94
|
- fixtures/male_head.obj
|
94
95
|
- fixtures/mars.obj
|
95
96
|
- fixtures/mecha.obj
|
96
97
|
- fixtures/skull.obj
|
98
|
+
- fixtures/textures/anime.jpg
|
97
99
|
- fixtures/textures/checkered_texture.jpg
|
98
100
|
- fixtures/textures/grid.jpg
|
99
101
|
- glitch3d.gemspec
|
100
102
|
- lib/glitch3d.rb
|
103
|
+
- lib/glitch3d/bpy/animation_recording.py
|
101
104
|
- lib/glitch3d/bpy/helpers.py
|
102
105
|
- lib/glitch3d/bpy/rendering.py
|
106
|
+
- lib/glitch3d/bpy/uv_glitch.py
|
103
107
|
- lib/glitch3d/objects/face.rb
|
104
108
|
- lib/glitch3d/objects/vertex.rb
|
105
109
|
- lib/glitch3d/strategies/default.rb
|
106
110
|
- lib/glitch3d/strategies/duplication.rb
|
111
|
+
- lib/glitch3d/strategies/find_and_replace.rb
|
107
112
|
- lib/glitch3d/strategies/localized.rb
|
108
113
|
- lib/glitch3d/strategies/none.rb
|
109
114
|
- lib/glitch3d/version.rb
|