You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When i tried to use random position and apply physics properties, the objects appear at a really strange position that far away from the expected position and exceed the random range. Please see the screen shot, i print the origin position and final position after randomlization of all objects. You could see the first render is fine, but the second results is really werid. Below you could find my code, could you please help me with this issue?
Thank you in advance!!
Minimal code example
importblenderprocasbprocimportargparseimportosimportnumpyasnpparser=argparse.ArgumentParser()
parser.add_argument('camera', nargs='?', default="examples/camera_positions_test", help="Path to the camera file")
parser.add_argument('scene', nargs='?', default="examples/scene.blend", help="Path to the scene.blend file")
parser.add_argument('output_dir', nargs='?', default="examples/output", help="Path to where the final files will be saved")
parser.add_argument('--num_images', type=int, default=3, help="Number of images to render")
args=parser.parse_args()
bproc.init()
objs=bproc.loader.load_blend(args.scene)
print("Current category IDs for objects:")
forobjinobjs:
category_id=obj.get_cp("category_id") ifobj.has_cp("category_id") elseNoneprint(f"Object: {obj.get_name()}, Category ID: {category_id}")
print("Objects in the scene:")
forobjinobjs:
print(obj.get_name())
plane=Noneforobjinobjs:
ifobj.get_name() =="plane":
plane=objbreakifplaneisNone:
raiseValueError("No object named 'plane' was found in the scene. Please check your scene file.")
plane.set_location([0, 0, 0])
plane.enable_rigidbody(active=False, collision_shape="MESH")
movable_objs= [objforobjinobjsifobj.get_name() !="plane"]
forobjinmovable_objs:
obj.enable_rigidbody(active=True, mass=1.0, collision_shape="CONVEX_HULL")
forobjinobjs:
origin=obj.get_location()
print(f"Object: {obj.get_name()}, Origin: {origin}")
defrandomize_objects(objects):
forobjinobjects:
random_position=np.random.uniform(low=[-10,-10, 10], high=[0, 0, 20])
obj.set_location(random_position)
random_rotation=np.random.uniform(low=[np.pi/2, 0, 0], high=[np.pi/2, 0, np.pi])
obj.set_rotation_euler(random_rotation)
forj, objinenumerate(objs):
ifobj.get_name() =="plane":
obj.set_cp("category_id", 0)
else:
obj.set_cp("category_id", j+1)
print("Current category IDs for objects:")
forobjinobjs:
category_id=obj.get_cp("category_id") ifobj.has_cp("category_id") elseNoneprint(f"Object: {obj.get_name()}, Category ID: {category_id}")
# lightlight=bproc.types.Light()
light.set_type("AREA")
light.set_location([5, -5, 100])
light.set_energy(100000)
# camera sizebproc.camera.set_resolution(640, 640)
withopen(args.camera, "r") asf:
forlineinf.readlines():
line= [float(x) forxinline.split()]
position, euler_rotation=line[:3], line[3:6]
matrix_world=bproc.math.build_transformation_mat(position, euler_rotation)
bproc.camera.add_camera_pose(matrix_world)
bproc.renderer.enable_normals_output()
bproc.renderer.enable_segmentation_output(map_by=["category_id", "instance", "name"])
foriinrange(args.num_images):
randomize_objects(movable_objs)
bproc.object.simulate_physics_and_fix_final_poses(
min_simulation_time=4,
max_simulation_time=20,
check_object_interval=1
)
forobjinmovable_objs:
final_position=obj.get_location()
print(f"Object: {obj.get_name()}, Final Position: {final_position}")
data=bproc.renderer.render()
bproc.writer.write_coco_annotations(
os.path.join(args.output_dir, f'coco_data_{i}'),
instance_segmaps=data["instance_segmaps"],
instance_attribute_maps=data["instance_attribute_maps"],
colors=data["colors"],
color_file_format="JPEG"
)
print(f"Rendered {args.num_images} images with randomized 'PlanetaryGearSystem' positions.")
Files required to run the code
No response
Expected behavior
BlenderProc version
Github man branch
The text was updated successfully, but these errors were encountered:
And i just found, when i decrease the number of object until there is only one object. The simulation was stable, the object didn't appear at a far position.
I was thinking it could be the problem of corrputed mesh. So i change to linux system and apply vhacd algorithm, but unfortunately the results are still the same, some objects appear at really far away position after rendering. After several days' try, i can also provide additional information:
It caused by physical simulation, because when i shut down this function, the positions of objects are normal, but they are floating on the air because of no gravity.
When i set the plane(passive object) large enough, and decrease the scale of objects, increase the range of random_position, which means the objects have enough space to move, in this case, the possiblity of problem decrease apparently.
Describe the issue
When i tried to use random position and apply physics properties, the objects appear at a really strange position that far away from the expected position and exceed the random range. Please see the screen shot, i print the origin position and final position after randomlization of all objects. You could see the first render is fine, but the second results is really werid. Below you could find my code, could you please help me with this issue?
Thank you in advance!!
Minimal code example
Files required to run the code
No response
Expected behavior
BlenderProc version
Github man branch
The text was updated successfully, but these errors were encountered: