I am trying to render a scene that simply contains a mesh of obj file and the material file. It looks okay when I try to view with
o3d.visualization.draw([{
"name": "Model",
"geometry": model,
"material": mat
}])
But when I try to render the same scene with the following code, the output image is just black. I have tried everything but nothing seems to be working at the moment
import numpy as np
import open3d as o3d
import cv2
def main():
render = o3d.visualization.rendering.OffscreenRenderer(640, 480)
model, mat=getModel()
render.scene.set_background([0, 0, 0, 0])
render.scene.add_geometry("model", model, mat)
render.scene.set_lighting(render.scene.LightingProfile.NO_SHADOWS, (0, 0, 0))
render.scene.camera.look_at([0, 0, 0], [0, 10, 0], [0, 0, 1])
img_o3d = render.render_to_image()
o3d.io.write_image("mtest2.jpeg", img_o3d, 9)
img = np.array(img_o3d)
cv2.imshow("model", img)
cv2.waitKey(1)
def getModel():
model_name = "mouse.obj"
model = o3d.io.read_triangle_mesh(model_name)
material = o3d.visualization.rendering.MaterialRecord()
material.shader = "defaultLit"
albedo_name = "albedo.jpeg"
material.albedo_img = o3d.io.read_image(albedo_name)
return (model, material)
main()