JacobLinCool commited on
Commit
842c883
·
1 Parent(s): b2489b1

feat: support `--` when executed from blender

Browse files

Former-commit-id: 808190204a388cacdc297b8777c73c0a624bf62f

Files changed (2) hide show
  1. .gitignore +2 -0
  2. create.py +16 -14
.gitignore CHANGED
@@ -150,3 +150,5 @@ cython_debug/
150
  # and can be added to the global gitignore or merged into this file. For a more nuclear
151
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
152
  #.idea/
 
 
 
150
  # and can be added to the global gitignore or merged into this file. For a more nuclear
151
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
152
  #.idea/
153
+
154
+ .DS_Store
create.py CHANGED
@@ -44,8 +44,10 @@ parser.add_argument(
44
 
45
 
46
  def main():
47
- if len(sys.argv) > 1:
48
- args = parser.parse_args()
 
 
49
 
50
  filepath = args.filepath
51
  rotate_x = args.rotate_x
@@ -121,12 +123,12 @@ def capture(
121
 
122
  # rotate the objects
123
  bpy.ops.transform.rotate(value=math.pi * -0.5 +
124
- deg_to_rad(rotate_x), orient_axis='X')
125
- bpy.ops.transform.rotate(value=deg_to_rad(rotate_y), orient_axis='Y')
126
  bpy.ops.transform.rotate(value=math.pi * -0.5 +
127
- deg_to_rad(rotate_z), orient_axis='Z')
128
 
129
- material = bpy.data.materials.new('Color')
130
  material.diffuse_color = (
131
  color_r if color_r != -1 else 1, color_g if color_g != -1 else 1, color_b if color_b != -1 else 1, 1)
132
 
@@ -138,15 +140,15 @@ def capture(
138
 
139
  # add light
140
  bpy.ops.object.light_add(
141
- type='POINT', location=(light_x, light_y, light_z))
142
- bpy.data.objects['Point'].data.energy = light_strength * 10
143
 
144
  # add camera
145
  bpy.ops.object.camera_add(
146
  location=(distance * 3, 0, 0), rotation=(math.pi*0.5, 0, math.pi*0.5))
147
- bpy.context.scene.camera = bpy.data.objects['Camera']
148
 
149
- render(filepath.replace('.svg', '.png'), size)
150
 
151
  return
152
 
@@ -161,7 +163,7 @@ def log(any):
161
  print("func:", key)
162
 
163
 
164
- def render(out=os.path.join(os.getcwd(), 'out.png'), size=2048):
165
  bpy.context.scene.render.filepath = out
166
  bpy.context.scene.render.resolution_x = size
167
  bpy.context.scene.render.resolution_y = size
@@ -170,8 +172,8 @@ def render(out=os.path.join(os.getcwd(), 'out.png'), size=2048):
170
 
171
 
172
  def collection_dimensions(collection):
173
- min_x = min_y = min_z = float('inf')
174
- max_x = max_y = max_z = float('-inf')
175
 
176
  for obj in collection.objects:
177
  min_x = min(min_x, obj.bound_box[0][0])
@@ -206,5 +208,5 @@ def reset():
206
  collections.remove(collection)
207
 
208
 
209
- if __name__ == '__main__':
210
  main()
 
44
 
45
 
46
  def main():
47
+ argv = sys.argv
48
+ argv = argv[argv.index("--") + 1:] if "--" in argv else argv[1:]
49
+ if len(argv) >= 1:
50
+ args = parser.parse_args(argv)
51
 
52
  filepath = args.filepath
53
  rotate_x = args.rotate_x
 
123
 
124
  # rotate the objects
125
  bpy.ops.transform.rotate(value=math.pi * -0.5 +
126
+ deg_to_rad(rotate_x), orient_axis="X")
127
+ bpy.ops.transform.rotate(value=deg_to_rad(rotate_y), orient_axis="Y")
128
  bpy.ops.transform.rotate(value=math.pi * -0.5 +
129
+ deg_to_rad(rotate_z), orient_axis="Z")
130
 
131
+ material = bpy.data.materials.new("Color")
132
  material.diffuse_color = (
133
  color_r if color_r != -1 else 1, color_g if color_g != -1 else 1, color_b if color_b != -1 else 1, 1)
134
 
 
140
 
141
  # add light
142
  bpy.ops.object.light_add(
143
+ type="POINT", location=(light_x, light_y, light_z))
144
+ bpy.data.objects["Point"].data.energy = light_strength * 10
145
 
146
  # add camera
147
  bpy.ops.object.camera_add(
148
  location=(distance * 3, 0, 0), rotation=(math.pi*0.5, 0, math.pi*0.5))
149
+ bpy.context.scene.camera = bpy.data.objects["Camera"]
150
 
151
+ render(filepath.replace(".svg", ".png"), size)
152
 
153
  return
154
 
 
163
  print("func:", key)
164
 
165
 
166
+ def render(out=os.path.join(os.getcwd(), "out.png"), size=2048):
167
  bpy.context.scene.render.filepath = out
168
  bpy.context.scene.render.resolution_x = size
169
  bpy.context.scene.render.resolution_y = size
 
172
 
173
 
174
  def collection_dimensions(collection):
175
+ min_x = min_y = min_z = float("inf")
176
+ max_x = max_y = max_z = float("-inf")
177
 
178
  for obj in collection.objects:
179
  min_x = min(min_x, obj.bound_box[0][0])
 
208
  collections.remove(collection)
209
 
210
 
211
+ if __name__ == "__main__":
212
  main()