-
Notifications
You must be signed in to change notification settings - Fork 254
Open
Description
here is code
main.py
import os
os.environ['PYOPENGL_PLATFORM'] = 'egl'
import open3d as o3d
import renderer as renderer
if __name__ == '__main__':
try:
mesh_src = o3d.io.read_triangle_mesh("XXX.obj")
renderer.render_to_image(mesh_src, "XXX.jpg")
except Exception as e:
print(e)renderer.py
import open3d as o3d
import trimesh
import numpy as np
import matplotlib.pyplot as plt
import pyrender
def render_to_image(mesh, output_path: str, width=640, height=480):
_mesh = trimesh.Trimesh(
vertices=np.asarray(mesh.vertices),
faces=np.asarray(mesh.triangles),
vertex_normals=np.asarray(mesh.vertex_normals),
# vertex_colors=np.asarray(mesh.vertex_colors),
)
scene = pyrender.Scene()
mesh = pyrender.Mesh.from_trimesh(_mesh)
scene.add(mesh)
camera = pyrender.PerspectiveCamera(yfov=np.pi / 3.0)
camera_pose = np.array([
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, -0.5],
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.0, 0.0, 1.0]
])
scene.add(camera, pose=camera_pose)
light = pyrender.PointLight(color=np.ones(3), intensity=10.0)
scene.add(light, pose=camera_pose)
r = pyrender.OffscreenRenderer(viewport_width=width, viewport_height=height, point_size=1.0)
// crash here, no conole output, no exception, just crash.
color, depth = r.render(scene)
r.delete()
if output_path is not None and output_path != "":
plt.imsave(output_path, color)
return color, depthAfter debug, I found crash here:
total_sz = sum(attr_sizes)
offset = 0
for i, sz in enumerate(attr_sizes):
// crash here
glVertexAttribPointer(
i, sz, GL_FLOAT, GL_FALSE, FLOAT_SZ * total_sz,
ctypes.c_void_p(FLOAT_SZ * offset)
)
glEnableVertexAttribArray(i)
offset += szMetadata
Metadata
Assignees
Labels
No labels