glitch3d 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1793293a1331bc23dd4107bd664cb3a58c94e08f
4
- data.tar.gz: 75032fca2f9644099ffec1691c9e9e43eff88dd1
3
+ metadata.gz: 688564a4811119581f00dbdbb11be49fa3806ab7
4
+ data.tar.gz: f83b133f69d6a5d9819594f29db45e653a378901
5
5
  SHA512:
6
- metadata.gz: 41b1e28a7a1025348d6d8238b11f5c5e7fc336967690b34cba59c037722dac80adfcab55e58c4290e18de1b9df7db9ab408300e87adab03a97e9ab0d431bed73
7
- data.tar.gz: b5020f50d233c5c863b4a6345b2cc9042022e6ac647d23943b6faadaf2996bb343ba106b06e46930c5190e88adc8afc5510ee2cb5b0765b4984bce8ca0681341
6
+ metadata.gz: 4776bb914bc36b06c585cbdc4b154252929b14b3da310adcd17a3d7625f729fd20a8a60f2660174d6cfd6f5f2462bf5944bc7d59fc7fcadafdf2c8677e0d275b
7
+ data.tar.gz: 3bcb160eadfb8d633a05c0b2e8f5d60402b62e5c9be5e0a4a3496b42c7493019663bea51ab0118490b666f2e3e00562f6dd5e5e849a629877fc9ff309a95ba66
data/.gitignore CHANGED
@@ -7,9 +7,9 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- /fixtures/models/*
11
10
  /renders/*
11
+ /fixtures/models/*
12
12
  /fixtures/*
13
+ !/fixtures/textures/*
13
14
  !/fixtures/skull.obj
14
- !/fixtures/textures/25.jpg
15
15
  .DS_Store
Binary file
File without changes
File without changes
Binary file
@@ -1,3 +1,21 @@
1
+ import bpy
2
+ import argparse
3
+ import datetime
4
+ import bmesh
5
+ import random
6
+ import code
7
+ import math
8
+ import mathutils
9
+ import random
10
+ import uuid
11
+ import sys
12
+
13
+ REFLECTOR_SCALE = 5
14
+ REFLECTOR_STRENGTH = 12
15
+ REFLECTOR_LOCATION_PADDING = 10
16
+ PROPS_NUMBER = 100
17
+ SHADERS = ['ShaderNodeBsdfGlossy', 'ShaderNodeBsdfDiffuse', 'ShaderNodeBsdfVelvet', 'ShaderNodeEmission']
18
+ props = []
1
19
  YELLOW = (1,0.7,0.1,1)
2
20
 
3
21
  def debug():
@@ -23,7 +41,7 @@ def shoot(camera, model_object, filepath):
23
41
  bpy.ops.render.render(write_still=True)
24
42
 
25
43
  def output_name(index, model_path):
26
- return 'renders/' + os.path.splitext(model_path)[0].split('/')[1] + '_' + str(index) + '_' + str(datetime.date.today()) + '.png'
44
+ return './' + os.path.splitext(model_path)[0].split('/')[1] + '_' + str(index) + '_' + str(datetime.date.today()) + '.png'
27
45
 
28
46
  def rotate(model_object, index):
29
47
  model_object.rotation_euler[2] = math.radians(index * (360.0 / shots_number))
@@ -47,10 +65,19 @@ def rand_color_vector():
47
65
  return (rand_color_value(), rand_color_value(), rand_color_value(), 1)
48
66
 
49
67
  def rand_scale():
50
- return round(random.uniform(0, 0.15), 10)
68
+ return round(random.uniform(0, 0.2), 10)
51
69
 
52
70
  def rand_scale_vector():
53
- return(rand_scale(), rand_scale(), rand_scale())
71
+ scale = rand_scale()
72
+ return(scale, scale, scale)
73
+
74
+ def unwrap_model(obj):
75
+ if obj == camera_object:
76
+ return False
77
+ context.scene.objects.active = obj
78
+ bpy.ops.object.mode_set(mode='EDIT')
79
+ bpy.ops.uv.unwrap()
80
+ bpy.ops.object.mode_set(mode='OBJECT')
54
81
 
55
82
  def get_args():
56
83
  parser = argparse.ArgumentParser()
@@ -83,41 +110,33 @@ def assign_node_to_output(material, new_node):
83
110
  def create_cycles_material():
84
111
  material = bpy.data.materials.new('Object Material - ' + str(uuid.uuid1()))
85
112
  material.use_nodes = True
86
- # nodes = material.node_tree.nodes
87
- # new_node = nodes.new(random.choice(SHADERS))
88
- # assign_node_to_output(material, new_node)
89
113
  return material
90
114
 
91
115
  def random_texture():
92
- texture_path = os.path.expanduser('fixtures/textures/checkered_texture.jpg')
93
- # new_texture = bpy.data.textures.new('ColorTex', type = 'IMAGE')
116
+ texture_folder_path = os.path.dirname(__file__).replace('lib/glitch3d/bpy', 'fixtures/textures/')
117
+ texture_path = texture_folder_path + random.choice(os.listdir(texture_folder_path))
94
118
  return bpy.data.images.load(texture_path)
95
- # rand.choice()
96
119
 
97
120
  def assign_texture_to_material(material, texture):
98
121
  assert material.use_nodes == True
99
122
  # If its a default material
100
123
  bsdf_node = material.node_tree.nodes['Diffuse BSDF']
101
- assign_node_to_output(material, bsdf_node)
102
124
  texture_node = material.node_tree.nodes.new('ShaderNodeTexImage')
103
- uv_node = material.node_tree.nodes.new('ShaderNodeUVMap')
104
- # uv_node.uv_map = 'UV'
105
125
  texture_node.image = texture
106
- material.node_tree.links.new(texture_node.outputs[0], bsdf_node.inputs[0])
107
- material.node_tree.links.new(texture_node.inputs['Vector'], uv_node.outputs['UV'])
126
+ material.node_tree.links.new(texture_node.outputs['Color'], bsdf_node.inputs['Color'])
108
127
 
109
- def make_object_gold(object):
128
+ def make_object_gold(obj):
110
129
  material = bpy.data.materials.new('Gold Material - ' + str(uuid.uuid1()))
111
130
  material.use_nodes = True
112
131
  glossy_node = material.node_tree.nodes.new('ShaderNodeBsdfGlossy')
113
132
  glossy_node.inputs[0].default_value = YELLOW
114
133
  # roughness
115
- glossy_node.inputs[1].default_value = 0.1
134
+ glossy_node.inputs[1].default_value = 0.2
116
135
  assign_node_to_output(material, glossy_node)
117
- assign_material(object, material)
136
+ assign_material(obj, material)
118
137
 
119
- def make_object_reflector(object):
120
- object.scale = (REFLECTOR_SCALE, REFLECTOR_SCALE, REFLECTOR_SCALE)
138
+ def make_object_reflector(obj):
139
+ obj.scale = (REFLECTOR_SCALE, REFLECTOR_SCALE, REFLECTOR_SCALE)
121
140
  emissive_material = bpy.data.materials.new('Emissive Material #' + str(index))
122
141
  emissive_material.use_nodes = True
123
142
  emission_node = emissive_material.node_tree.nodes.new('ShaderNodeEmission')
@@ -126,4 +145,15 @@ def make_object_reflector(object):
126
145
  # Set strength
127
146
  emission_node.inputs[1].default_value = REFLECTOR_STRENGTH
128
147
  assign_node_to_output(emissive_material, emission_node)
129
- assign_material(object, emissive_material)
148
+ assign_material(obj, emissive_material)
149
+
150
+ def texture_object(obj):
151
+ new_material = create_cycles_material()
152
+ assign_texture_to_material(new_material, random_texture())
153
+ assign_material(obj, new_material)
154
+
155
+ def duplicate_object(obj):
156
+ new_object = obj.copy()
157
+ new_object.data = obj.data.copy()
158
+ context.scene.objects.link(new_object)
159
+ return new_object
@@ -9,21 +9,8 @@
9
9
  # 4) Rotate model and shoot image at each step
10
10
  #
11
11
  # Use `debug()` to pry into the script
12
-
13
- import bpy
14
12
  import os
15
- import argparse
16
- import datetime
17
- import bmesh
18
- import random
19
- import code
20
- import math
21
- import mathutils
22
- import random
23
- import uuid
24
- import sys
25
-
26
- exec(open("lib/glitch3d/bpy/helpers.py").read())
13
+ exec(open(os.path.join(os.path.dirname(__file__), 'helpers.py')).read())
27
14
 
28
15
  # Arguments parsing
29
16
  args = get_args()
@@ -33,12 +20,6 @@ shots_number = int(args.shots_number)
33
20
 
34
21
  context = bpy.context
35
22
 
36
- REFLECTOR_SCALE = 5
37
- REFLECTOR_STRENGTH = 12
38
- REFLECTOR_LOCATION_PADDING = 10
39
- PROPS_NUMBER = 100
40
- SHADERS = ['ShaderNodeBsdfGlossy', 'ShaderNodeBsdfDiffuse', 'ShaderNodeBsdfVelvet', 'ShaderNodeEmission']
41
-
42
23
  # Scene
43
24
  new_scene = bpy.data.scenes.new("Automated Render Scene")
44
25
  bpy.ops.scene.delete() # Delete old scene
@@ -60,16 +41,45 @@ if mode == 'high':
60
41
  context.scene.cycles.samples = 100
61
42
  context.scene.render.resolution_percentage = 100
62
43
 
44
+ # Add background to world
45
+ texture_path = os.path.expanduser('fixtures/textures/checkered_texture.jpg')
46
+ world = bpy.data.worlds[0]
47
+ world.use_nodes = True
48
+ world_node_tree = world.node_tree
49
+ output_node = world_node_tree.nodes['Background']
50
+ texture_node = world_node_tree.nodes.new('ShaderNodeTexImage')
51
+ world_node_tree.links.new(texture_node.outputs['Color'], output_node.inputs['Color'])
52
+ texture_node.image = bpy.data.images.load(texture_path)
63
53
 
64
54
  # Delete current objects
65
- for index, object in enumerate(bpy.data.objects):
66
- bpy.data.objects.remove(object)
55
+ for index, obj in enumerate(bpy.data.objects):
56
+ bpy.data.objects.remove(obj)
67
57
 
68
58
  # Load model
69
59
  model_path = os.path.join(file)
70
60
  bpy.ops.import_scene.obj(filepath = model_path, use_edges=True)
71
61
  model_object = bpy.data.objects[0]
72
62
 
63
+ # Load props
64
+ bpy.ops.import_scene.obj(filepath = os.path.join('fixtures/m4a1.obj'), use_edges=True)
65
+ m4a1 = bpy.data.objects['m4a1']
66
+ texture_object(m4a1)
67
+ m4a1.location = rand_location()
68
+ m4a1.scale = rand_scale_vector()
69
+ m4a1.rotation_euler = rand_rotation()
70
+
71
+ bpy.ops.mesh.primitive_cube_add(location=rand_location(),radius=rand_scale(), rotation=rand_rotation())
72
+ cube = bpy.data.objects['Cube']
73
+ texture_object(cube)
74
+
75
+ bpy.ops.mesh.primitive_torus_add(location=rand_location(), rotation=rand_rotation(), major_radius=rand_scale(), minor_radius=rand_scale())
76
+ torus = bpy.data.objects['Torus']
77
+ texture_object(torus)
78
+
79
+ bpy.ops.mesh.primitive_cone_add(location=rand_location(), depth=1.0, rotation=rand_rotation(), radius1=rand_scale(), radius2=rand_scale())
80
+ cone = bpy.data.objects['Cone']
81
+ texture_object(cone)
82
+
73
83
  # Use center of mass to center object
74
84
  model_object.select = True
75
85
  bpy.ops.object.origin_set(type="ORIGIN_CENTER_OF_MASS")
@@ -84,8 +94,6 @@ camera_object = bpy.data.objects['Render Camera']
84
94
  new_scene.objects.link(camera_object)
85
95
  camera_object.location = (8, 8, 1)
86
96
 
87
- empty_materials()
88
-
89
97
  # Add reflectors
90
98
  bpy.ops.mesh.primitive_plane_add(location=(0,8 + REFLECTOR_LOCATION_PADDING, 0))
91
99
  bpy.ops.mesh.primitive_plane_add(location=(8 + REFLECTOR_LOCATION_PADDING,0,0))
@@ -108,110 +116,41 @@ for plane in [plane1, plane2, plane3]:
108
116
  make_object_reflector(plane)
109
117
 
110
118
  # Make floor
111
- bpy.ops.mesh.primitive_plane_add(location=(0,0,-2))
119
+ bpy.ops.mesh.primitive_plane_add(calc_uvs=True, location=(0,0,-2))
112
120
  floor = bpy.data.objects['Plane.003']
113
- floor.scale = (8,8,8)
114
- floor_material = create_cycles_material()
115
- assign_texture_to_material(floor_material, random_texture())
116
- assign_material(floor, floor_material)
117
-
118
- # Add props
119
- props = []
120
-
121
- for index in range(0, int(PROPS_NUMBER)):
122
- bpy.ops.mesh.primitive_cube_add(location=rand_location(),radius=rand_scale(), rotation=rand_rotation())
123
- if index == 0:
124
- object_name = 'Cube'
125
- elif index > 9:
126
- object_name = 'Cube.0' + str(index)
127
- elif index > 99:
128
- object_name = 'Cube.' + str(index)
129
- else:
130
- object_name = 'Cube.00' + str(index)
131
- object = bpy.data.objects[object_name]
132
- props.append(object)
133
- new_material = create_cycles_material()
134
- assign_texture_to_material(new_material, random_texture())
135
- assign_material(object, new_material)
136
-
137
- for index in range(0, int(PROPS_NUMBER)):
138
- bpy.ops.mesh.primitive_torus_add(location=rand_location(), rotation=rand_rotation(), major_radius=rand_scale(), minor_radius=rand_scale())
139
- if index == 0:
140
- object_name = 'Torus'
141
- elif index > 9:
142
- object_name = 'Torus.0' + str(index)
143
- elif index > 99:
144
- object_name = 'Torus.' + str(index)
145
- else:
146
- object_name = 'Torus.00' + str(index)
147
- object = bpy.data.objects[object_name]
148
- props.append(object)
149
- new_material = create_cycles_material()
150
- assign_texture_to_material(new_material, random_texture())
151
- assign_material(object, new_material)
152
-
153
- for index in range(0, int(PROPS_NUMBER)):
154
- bpy.ops.mesh.primitive_cone_add(location=rand_location(), depth=1.0, rotation=rand_rotation(), radius1=rand_scale(), radius2=rand_scale())
155
- if index == 0:
156
- object_name = 'Cone'
157
- elif index > 9:
158
- object_name = 'Cone.0' + str(index)
159
- elif index > 99:
160
- object_name = 'Cone.' + str(index)
161
- else:
162
- object_name = 'Cone.00' + str(index)
163
- object = bpy.data.objects[object_name]
164
- props.append(object)
165
- new_material = create_cycles_material()
166
- assign_texture_to_material(new_material, random_texture())
167
- assign_material(object, new_material)
121
+ floor.scale = (20,20,20)
122
+ texture_object(floor)
123
+
124
+ # Add more props
125
+ for index in range(1, int(PROPS_NUMBER)):
126
+ new_object = duplicate_object(cube)
127
+ props.append(new_object)
128
+ new_object.location = rand_location()
129
+ texture_object(new_object)
130
+
131
+ for index in range(1, int(PROPS_NUMBER)):
132
+ new_object = duplicate_object(torus)
133
+ props.append(new_object)
134
+ new_object.location = rand_location()
135
+ texture_object(new_object)
136
+
137
+ for index in range(1, int(PROPS_NUMBER)):
138
+ new_object = duplicate_object(cone)
139
+ props.append(new_object)
140
+ new_object.location = rand_location()
141
+ texture_object(new_object)
168
142
 
169
143
  # Import guns
170
- for index in range(0, 5):
171
- model_path_m4a1 = os.path.join('fixtures/m4a1.obj')
172
- bpy.ops.import_scene.obj(filepath = model_path_m4a1, use_edges=True)
173
- if index == 0:
174
- object_name = 'm4a1'
175
- elif index > 9:
176
- object_name = 'm4a1.0' + str(index)
177
- elif index > 99:
178
- object_name = 'm4a1.' + str(index)
179
- else:
180
- object_name = 'm4a1.00' + str(index)
181
- object = bpy.data.objects[object_name]
182
- props.append(object)
183
- object.location = rand_location()
184
- object.scale = rand_scale_vector()
185
- object.rotation_euler = rand_rotation()
186
- new_material = create_cycles_material()
187
- assign_texture_to_material(new_material, random_texture())
188
- assign_material(object, new_material)
144
+ for index in range(1, 5):
145
+ new_object = duplicate_object(m4a1)
146
+ props.append(new_object)
147
+ new_object.location = rand_location()
148
+ new_object.scale = rand_scale_vector()
149
+ new_object.rotation_euler = rand_rotation()
150
+ texture_object(new_object)
189
151
 
190
- # Add background to world
191
- world = bpy.data.worlds[0]
192
- world.use_nodes = True
193
- world_node_tree = world.node_tree
194
- gradient_node = world_node_tree.nodes.new(type="ShaderNodeTexGradient")
195
- texture_node = world_node_tree.nodes.new(type="ShaderNodeTexGradient")
196
-
197
- output_node = world_node_tree.nodes['Background']
198
- texture_node = world_node_tree.nodes.new('ShaderNodeTexture')
199
- world_node_tree.links.new(texture_node.outputs[0], output_node.inputs[0])
200
- texture_path = os.path.expanduser('fixtures/textures/25.jpg')
201
- new_texture = bpy.data.textures.new('ColorTex', type = 'IMAGE')
202
- new_texture.image = bpy.data.images.load(texture_path)
203
- texture_node.texture = new_texture
204
-
205
- background_node = world_node_tree.nodes['Background']
206
- world_node_tree.links.new(gradient_node.outputs['Color'], background_node.inputs['Color'])
207
- gradient_node.gradient_type = 'EASING'
208
-
209
- bpy.ops.object.mode_set(mode='EDIT')
210
- # UV unwrap objects
211
152
  for model in bpy.data.objects:
212
- context.scene.objects.active = model
213
- bpy.ops.uv.unwrap()
214
- bpy.ops.object.mode_set(mode = 'OBJECT')
153
+ unwrap_model(model)
215
154
 
216
155
  # ------
217
156
  # Shoot
@@ -1,3 +1,3 @@
1
1
  module Glitch3d
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/glitch3d.rb CHANGED
@@ -13,7 +13,7 @@ module Glitch3d
13
13
  BOUNDARY_LIMIT = 4 # Contain model within 2x2x2 cube
14
14
 
15
15
  BLENDER_EXECUTABLE_PATH = ENV['BLENDER_EXECUTABLE_PATH'].freeze
16
- RENDERING_SCRIPT_PATH = "lib/glitch3d/bpy/rendering.py".freeze
16
+ RENDERING_SCRIPT_PATH = File.dirname(__FILE__) + '/glitch3d/bpy/rendering.py'
17
17
 
18
18
  def clean_model(source_file)
19
19
  self.class.include Glitch3d::None
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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pskl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-12 00:00:00.000000000 Z
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,36 +91,11 @@ files:
91
91
  - fixtures/m4a1.obj
92
92
  - fixtures/male_head.obj
93
93
  - fixtures/skull.obj
94
- - fixtures/textures/00.jpg
95
- - fixtures/textures/01.jpg
96
- - fixtures/textures/02.jpg
97
- - fixtures/textures/03.jpg
98
- - fixtures/textures/04.jpg
99
- - fixtures/textures/05.jpg
100
- - fixtures/textures/06.jpg
101
- - fixtures/textures/07.jpg
102
- - fixtures/textures/08.jpg
103
- - fixtures/textures/09.jpg
104
- - fixtures/textures/10.jpg
105
- - fixtures/textures/11.jpg
106
- - fixtures/textures/12.jpg
107
- - fixtures/textures/13.jpg
108
- - fixtures/textures/14.jpg
109
- - fixtures/textures/15.jpg
110
- - fixtures/textures/16.jpg
111
- - fixtures/textures/17.jpg
112
- - fixtures/textures/18.jpg
113
- - fixtures/textures/19.jpg
114
- - fixtures/textures/20.jpg
115
- - fixtures/textures/21.jpg
116
- - fixtures/textures/22.jpg
117
- - fixtures/textures/23.jpg
118
- - fixtures/textures/24.jpg
119
- - fixtures/textures/25.jpg
120
- - fixtures/textures/27.jpg
121
- - fixtures/textures/28.jpg
122
- - fixtures/textures/29.jpg
123
- - fixtures/textures/30.jpg
94
+ - fixtures/textures/checkered_texture.jpg
95
+ - fixtures/textures/clouds.jpg
96
+ - fixtures/textures/flowers.jpg
97
+ - fixtures/textures/flowers1.jpg
98
+ - fixtures/textures/granite.jpg
124
99
  - glitch3d.gemspec
125
100
  - lib/glitch3d.rb
126
101
  - lib/glitch3d/bpy/helpers.py
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file