BlenderProc icon indicating copy to clipboard operation
BlenderProc copied to clipboard

Manipulate object materials in every iteration

Open sanmiyom opened this issue 2 years ago • 6 comments

Hello,

I want to change all the materials (textures, colors, etc.) randomly between each render. However, only thing changes seem to be the camera pose. All the materials stay same. How can I change them as well?

I'm using bpy library to manipulate the materials.

bproc.renderer.set_max_amount_of_samples(128)

bproc.camera.set_intrinsics_from_K_matrix([[1739, 0, 1224], [0, 1739, 1024], [0, 0, 1]], 2448, 2048)

print("Simulation is starting..")
for i in range(5):

    print(f"Image #{i} is being rendered..")

    scene.set_random_grass()
    scene.set_random_logo()
    scene.set_random_sky()

    scene.make_some_objects_invisible()
    
    cam_pose = bproc.math.build_transformation_mat([34, 0, 5], [np.pi / 2, 0, radians(uniform(0,100))])
    bproc.camera.add_camera_pose(cam_pose)
    
    # Render the scene
    data = bproc.renderer.render()
    
    # Write the rendering into an hdf5 file
    bproc.writer.write_hdf5("output/", data)
    
print("Simulation is done!")

Thanks in advance.

sanmiyom avatar Aug 04 '22 07:08 sanmiyom

Hey,

sorry your example does not contain any material randomization and the functions: set_random_grass(), set_random_logo() and set_random_sky() are not BlenderProc functions.

In theory, you would need to change the materials before rendering inside of the loop. For how to do that, check out the material examples in the documentation.

Best, Max

themasterlink avatar Aug 05 '22 06:08 themasterlink

Hello,

Inside those functions, I do bpy.data.materials["material1"].color = some_other_color.

sanmiyom avatar Aug 05 '22 06:08 sanmiyom

Can you please construct a minimal example where it doesn't work?

Best, Max

themasterlink avatar Aug 05 '22 06:08 themasterlink

PS: The code you posted makes no sense, please you our wrapper classes: https://dlr-rm.github.io/BlenderProc/blenderproc.api.types.html#blenderproc.types.Material

It has a function to set the color: https://dlr-rm.github.io/BlenderProc/blenderproc.api.types.html#blenderproc.types.Material.set_principled_shader_value

themasterlink avatar Aug 05 '22 06:08 themasterlink

I do various manipulations inside those functions. Why is there nothing changing when I manipulate them using bpy.data.materials instead of blenderproc functions?

I think the manipulations are carried out for the first iteration. After first render happened, nothing changes anymore. This is my actual question.

Best.

sanmiyom avatar Aug 05 '22 06:08 sanmiyom

Sorry for the late response. Your question got overlooked. Are you still looking for an answer?

This does seem weird, but I would need the code for this in a minimal example at best and then I can tell you why.

themasterlink avatar Aug 25 '22 07:08 themasterlink