-
Notifications
You must be signed in to change notification settings - Fork 5
/
demo_trimesh_render.py
51 lines (38 loc) · 1.49 KB
/
demo_trimesh_render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Make use of the codebase from https://github.com/Jianghanxiao/3DHelper
from trimesh_render import lookAt, getSpherePositions
from trimesh_URDF import getURDF
import numpy as np
from PIL import Image
import trimesh
import io
import os
MODELID = "7265"
URDFPATH = f"/local-scratch/localhome/hja40/Desktop/Dataset/data/models3d/partnetsim/mobility_v1_alpha5/{MODELID}/mobility.urdf"
OUTPUTDIR = "/local-scratch/localhome/hja40/Desktop/Research/test"
if not os.path.exists(OUTPUTDIR):
os.mkdir(OUTPUTDIR)
def getRGB(scene):
data = scene.save_image()
rgb = Image.open(io.BytesIO(data))
return rgb
if __name__ == "__main__":
urdf, controller = getURDF(URDFPATH)
# Interact with the URDF
# controller["link_0"].interact(-0.5235987755982988)
mesh = urdf.getMesh()
coordinate = trimesh.creation.axis()
mesh.add_geometry(coordinate)
# Define camera parameters
resolution = (512, 512)
fov = (90, 90)
mesh.set_camera(resolution=resolution, fov=fov)
# Get the positions of the cameras on a sphere centered at the object center
center = mesh.centroid
positions = getSpherePositions(center=center, radius=4)
# Loop over the camera positions and render the images
for i, pos in enumerate(positions):
# Set the camera view and render the image
matrix = lookAt(eye=pos, target=center, up=np.array([0.0, 0.0, 1.0]))
mesh.camera_transform = matrix
rgb = getRGB(mesh)
rgb.save(f"{OUTPUTDIR}/{MODELID}_rgb_{i}.png")