Skip to content

Commit

Permalink
wip: update example files (some examples have bugs. will create an is…
Browse files Browse the repository at this point in the history
…sue to be fixed)
  • Loading branch information
hanson-hschang committed Sep 9, 2024
1 parent a1f9336 commit 8472c5f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __pycache__/
*.so

*.blend
*.blend1
*.swp
*.npz

Expand Down
18 changes: 17 additions & 1 deletion examples/br2/br2_pushed.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def setup(

class BR2Environment(BaseEnvironment):
def __init__(self, *args, **kwargs) -> None:
bsr.clear_mesh_objects()
super().__init__(*args, **kwargs)

def setup(
Expand Down Expand Up @@ -209,6 +208,8 @@ def main(
time_step: float = 1.0e-5,
recording_fps: int = 30,
):
bsr.clear_mesh_objects()

# Initialize the environment
env = BR2Environment(
final_time=final_time, time_step=time_step, recording_fps=recording_fps
Expand All @@ -221,6 +222,21 @@ def main(
time = env.step(time=time)
print("Simulation finished!")

# Set the final keyframe number
bsr.frame_manager.set_frame_end()

# Set the frame rate
bsr.frame_manager.set_frame_rate(fps=recording_fps)

# Set the view distance
bsr.set_view_distance(distance=1)

# Deslect all objects
bsr.deselect_all()

# Select the camera object
bsr.camera_manager.select()

# Save the simulation
env.save("BR2_simulation")

Expand Down
5 changes: 2 additions & 3 deletions examples/br2/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,11 @@ def __init__(
default_centerline_position=system.position_collection,
default_centerline_director=system.director_collection,
)
self.keyframe = 0

def save_params(self, system: ea.CosseratRod, time: float) -> None:
self.bpy_objs.update_states(
centerline_position=system.position_collection,
centerline_director=system.director_collection,
)
self.bpy_objs.set_keyframe(self.keyframe)
self.keyframe += 1
self.bpy_objs.set_keyframe(bsr.frame_manager.current_frame)
bsr.frame_manager.update()
6 changes: 2 additions & 4 deletions examples/camera_movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ def main(filename: str = "camera_movement"):

bsr.camera_manager.look_at = np.array([0.0, 0.0, 0.0])

for k, angle in enumerate(
np.linspace(0.0, 360.0, frame_rate * total_time + 1)
):
for angle in np.linspace(0.0, 360.0, frame_rate * total_time + 1):
bsr.camera_manager.location = np.array(
[
camera_radius * np.cos(np.radians(angle)),
camera_radius * np.sin(np.radians(angle)),
camera_heigh,
]
)
bsr.camera_manager.set_keyframe(k)
bsr.camera_manager.set_keyframe(bsr.frame_manager.current_frame)
bsr.frame_manager.update()

# Set the final keyframe number
Expand Down
File renamed without changes.

0 comments on commit 8472c5f

Please sign in to comment.