Quickstart¶
Real-time Rendering¶
Newton provides a simple OpenGL renderer for visualizing the simulation. The renderer requires pyglet (version >= 2.0) to be installed.
renderer = newton.utils.SimRendererOpenGL(model=model, path="Newton Simulator", scaling=2.0)
# at every frame:
renderer.begin_frame(sim_time)
renderer.render(state)
renderer.end_frame()
# pause the simulation (blocks the control flow):
renderer.pause = True
Keyboard shortcuts when working with the OpenGLRenderer (aka newton.utils.SimRendererOpenGL):
Key(s) |
Description |
---|---|
|
Move the camera like in a FPS game |
|
Toggle wireframe rendering |
|
Toggle backface culling |
|
Toggle the visibility of the coordinate system axes |
|
Toggle ground grid |
|
Toggle depth rendering |
|
Toggle info text in the top left corner |
|
Pause/continue the simulation |
|
Skip rendering to continue the simulation in the background (can speed up RL training while running the renderer) |
USD Rendering¶
Instead of rendering in real-time, you can also render the simulation as a time-sampled USD stage to be visualized in Omniverse.
renderer = newton.utils.SimRenderer(model=model, path="simulation.usd", scaling=2.0)
# at every frame:
renderer.begin_frame(sim_time)
renderer.render(state)
renderer.end_frame()
# to save the USD stage:
renderer.save()
Example: Creating a particle chain¶
import newton
builder = newton.ModelBuilder()
# anchor point (zero mass)
builder.add_particle((0, 1.0, 0.0), (0.0, 0.0, 0.0), 0.0)
# build chain
for i in range(1, 10):
builder.add_particle((i, 1.0, 0.0), (0.0, 0.0, 0.0), 1.0)
builder.add_spring(i - 1, i, 1.0e3, 0.0, 0)
model = builder.finalize("cpu")
print(f"{model.spring_indices.numpy()=}")
print(f"{model.particle_count=}")
print(f"{model.particle_mass.numpy()=}")
model.spring_indices.numpy()=array([0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9], dtype=int32)
model.particle_count=10
model.particle_mass.numpy()=array([0., 1., 1., 1., 1., 1., 1., 1., 1., 1.], dtype=float32)