Blender Asked by meerlol on January 3, 2021
Heads up: I’m a Blender noob, so forgive me if my question or my script is just plain stupid 🙂
I’m trying to generate synthetic data for a machine learning problem (an image classifier). For this I created a script that imports an object. The lifts it to a random height, rotates it randomly around all axes. And the I drop it on the ground plane. And what I would like to do is the render the scene after the object has been dropped. But the problem is that my scene looks the same every render. Can anyone point me to some obvious mistakes I’m making? FYI, the file below just tries the same object 10 times.
import math
import os
from random import randint
os.environ['CUDA_VISIBLE_DEVICES'] = '0,1,2,3'
bpy.context.scene.render.engine = 'CYCLES'
bpy.data.scenes["Scene"].cycles.device = 'GPU'
bpy.data.scenes["Scene"].cycles.feature_set = 'SUPPORTED'
bpy.context.preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'
cprefs = bpy.context.preferences.addons['cycles'].preferences
cprefs.get_devices()
# Enable all CPU and GPU devices
for device in cprefs.devices:
if device.name == 'TITAN Xp':
device.use = True
else:
device.use = False
directory = os.environ['LDRAW'] + "/parts/"
files = os.listdir(directory)
files = ['3010.dat']
context = bpy.context
for filename in files:
print(filename)
if filename.endswith(".dat"):
filebase = os.path.splitext(filename)[0]
for i in range(0, 10):
print(i)
context.scene.frame_set(0)
bpy.ops.import_scene.importldraw(filepath=directory + filename)
# bpy.ops.object.origin_set(type="ORIGIN_CENTER_OF_MASS")
bpy.ops.rigidbody.objects_add(type='ACTIVE')
context.object.rigid_body.linear_damping = 0.9
bpy.ops.transform.translate(value=(0,0,randint(1,5)))
bpy.ops.transform.rotate(value=math.radians(randint(0,360)), orient_axis='Z')
bpy.ops.transform.rotate(value=math.radians(randint(0,360)), orient_axis='X')
bpy.ops.transform.rotate(value=math.radians(randint(0,360)), orient_axis='Y')
bpy.ops.nla.bake(frame_start=1, frame_end=200, bake_types={'OBJECT'})
context.scene.frame_set(200)
# bpy.ops.ptcache.bake(bake=False)
camera=1
for ob in context.scene.objects:
if ob.type == 'CAMERA':
context.scene.camera = ob
context.scene.render.image_settings.file_format = 'PNG'
context.scene.render.filepath = "/storage2/herman/render/" +filebase + "/" + filebase + "-" + str(i) + "-" + str(camera) + ".png"
bpy.ops.render.render(write_still = 1)
camera=camera+1
bpy.ops.object.delete()
```
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP