Skip to content

Commit d1ca9d1

Browse files
committed
add offscreen testing
1 parent f63b7d5 commit d1ca9d1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Test offscreen renderer for SAPIEN
2+
"""
3+
import sapien.core as sapien
4+
from sapien.utils import Viewer
5+
import numpy as np
6+
from PIL import Image
7+
8+
9+
def main():
10+
engine = sapien.Engine() # Create a physical simulation engine
11+
renderer = sapien.VulkanRenderer() # Create a Vulkan renderer
12+
engine.set_renderer(renderer) # Bind the renderer and the engine
13+
14+
scene = engine.create_scene() # Create an instance of simulation world (aka scene)
15+
scene.set_timestep(1 / 100.0) # Set the simulation frequency
16+
17+
# NOTE: How to build actors (rigid bodies) is elaborated in create_actors.py
18+
scene.add_ground(altitude=0) # Add a ground
19+
actor_builder = scene.create_actor_builder()
20+
actor_builder.add_box_collision(half_size=[0.5, 0.5, 0.5])
21+
actor_builder.add_box_visual(half_size=[0.5, 0.5, 0.5], color=[1., 0., 0.])
22+
box = actor_builder.build(name='box') # Add a box
23+
box.set_pose(sapien.Pose(p=[0, 0, 0.5]))
24+
25+
# Add some lights so that you can observe the scene
26+
rscene = scene.get_renderer_scene()
27+
rscene.set_ambient_light([0.5, 0.5, 0.5])
28+
rscene.add_directional_light([0, 1, -1], [0.5, 0.5, 0.5])
29+
30+
actor = scene.create_actor_builder().build_kinematic()
31+
actor.set_pose(sapien.Pose([-3, 0, 0.5]))
32+
cam = scene.add_mounted_camera('', actor, sapien.Pose(), 128, 128, 0, 1, 0.01, 10)
33+
34+
scene.update_render()
35+
cam.take_picture()
36+
color = cam.get_color_rgba()
37+
38+
Image.fromarray((color[..., :3].clip(0, 1) * 255).astype(np.uint8)).save("output.png")
39+
40+
41+
if __name__ == '__main__':
42+
main()

0 commit comments

Comments
 (0)