-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
524 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
"""Example: Batch rendering a 12-frame animation of a rotating capsule.""" | ||
|
||
import jax | ||
import jax.numpy as jnp | ||
|
||
from renderer import (CameraParameters, LightParameters, Renderer, Scene, | ||
ShadowParameters, Texture, UpAxis, batch_models, | ||
merge_objects, rotation_matrix, transpose_for_display) | ||
|
||
# PROCESS: Set up models and objects | ||
|
||
scene: Scene = Scene() | ||
texture: Texture = jnp.array(( | ||
(255, 255, 255), # White | ||
(255, 0, 0), # Red | ||
(0, 255, 0), # Green | ||
(0, 0, 255), # Blue | ||
)).reshape((2, 2, 3))[:, ::-1, :] / 255.0 | ||
|
||
scene, capsule_id = scene.add_capsule( | ||
radius=0.1, | ||
half_height=0.4, | ||
up_axis=UpAxis.Z, | ||
diffuse_map=texture, | ||
) | ||
|
||
capsule_obj_ids = [] | ||
for i in range(12): | ||
scene, capsule_obj_id = scene.add_object_instance(capsule_id) | ||
capsule_obj_ids.append(capsule_obj_id) | ||
|
||
scene = scene.set_object_orientation( | ||
capsule_obj_id, | ||
rotation_matrix=rotation_matrix((0., 1., 0.), 30 * (i - 6)), | ||
) | ||
|
||
# PROCESS: Set up camera and light | ||
|
||
width = 640 | ||
height = 480 | ||
|
||
eye = [0., 4., 0.] | ||
target = [0., 0., 0.] | ||
|
||
light: LightParameters = LightParameters() | ||
camera_params: CameraParameters = CameraParameters( | ||
viewWidth=width, | ||
viewHeight=height, | ||
position=eye, | ||
target=target, | ||
) | ||
shadow_param = ShadowParameters() | ||
|
||
# PROCESS: Render | ||
|
||
merged_models = [ | ||
merge_objects([scene.objects[obj_id]]) for obj_id in capsule_obj_ids | ||
] | ||
buffers = Renderer.create_buffers(width, height, len(capsule_obj_ids)) | ||
camera = Renderer.create_camera_from_parameters(camera_params) | ||
|
||
_, (images, ) = jax.vmap(lambda model, buffer: Renderer.render( | ||
model=model, | ||
light=light, | ||
camera=camera, | ||
buffers=buffer, | ||
shadow_param=shadow_param, | ||
))(batch_models(merged_models), buffers) | ||
|
||
# PROCESS: show | ||
|
||
import matplotlib.animation as animation | ||
import matplotlib.pyplot as plt | ||
|
||
fig, ax = plt.subplots() | ||
|
||
# ims is a list of lists, each row is a list of artists to draw in the | ||
# current frame; here we are just animating one artist, the image, in | ||
# each frame | ||
ims = [] | ||
for i in range(images.shape[0]): | ||
img = images[i] | ||
im = ax.imshow(transpose_for_display(img), animated=True) | ||
if i == 0: | ||
# show an initial one first | ||
ax.imshow(transpose_for_display(img)) | ||
|
||
ims.append([im]) | ||
|
||
ani = animation.ArtistAnimation( | ||
fig, | ||
ims, | ||
interval=500, | ||
blit=True, | ||
repeat_delay=0, | ||
) | ||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "jaxrenderer" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
description = "Jax implementation of rasterizer renderer." | ||
authors = ["Joey Teng <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.