Skip to content

Commit

Permalink
wip: update argument of enumerate from frame_current to frame_current…
Browse files Browse the repository at this point in the history
…_init to avoid confussion of input argument and yield value
  • Loading branch information
hanson-hschang committed Nov 3, 2024
1 parent 167eec1 commit 820c1cf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/camera_movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def main(
bsr.frame_manager.frame_start = frame_start

for frame_current, angle in bsr.frame_manager.enumerate(
angles, frame_current=frame_start
angles, frame_current_init=frame_start
):

# Set the camera location
Expand Down
2 changes: 1 addition & 1 deletion examples/pose_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def main(
bsr.frame_manager.frame_start = frame_start

for frame_current, angle in bsr.frame_manager.enumerate(
angles, frame_current=frame_start
angles, frame_current_init=frame_start
):

# Define path of of motion for positions of pose object
Expand Down
17 changes: 10 additions & 7 deletions src/bsr/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def frame_start(self, frame: int) -> None:
"""
assert (
isinstance(frame, int) and frame >= 0
), "frame must be a positive integer or 0"
), "frame must be a nonnegative integer"
bpy.context.scene.frame_start = frame

@property
Expand Down Expand Up @@ -100,7 +100,7 @@ def frame_end(self, frame: int) -> None:
"""
assert (
isinstance(frame, int) and frame >= 0
), "frame must be a positive integer or 0"
), "frame must be a nonnegative integer"
bpy.context.scene.frame_end = frame

@property
Expand Down Expand Up @@ -134,7 +134,7 @@ def frame_rate(self, fps: int | float) -> None:
bpy.context.scene.render.fps_base = int(fps) / fps

def enumerate(
self, iterable: Iterable, frame_current: Optional[int] = None
self, iterable: Iterable, frame_current_init: Optional[int] = None
) -> Iterable:
"""
Enumerate through the frames of the scene.
Expand All @@ -143,12 +143,15 @@ def enumerate(
----------
iterable : Iterable
An iterable object to enumerate.
frame_current : int, optional
The current frame number of the scene. The default is None.
frame_current_init : int, optional
The initial current frame number of the scene. The default is None.
If None, the number self.frame_current is used.
"""
if frame_current is not None:
self.frame_current = frame_current
if frame_current_init is not None:
assert (
isinstance(frame_current_init, int) and frame_current_init >= 0
), "frame_current_init must be a nonnegative integer"
self.frame_current = frame_current_init
for item in iterable:
yield self.frame_current, item
self.update() # Update the frame number
Expand Down
2 changes: 1 addition & 1 deletion tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_frame_manager_enumerate(self):
frame_manager = FrameManager()
frame_start = 10
for frame_current, frame in frame_manager.enumerate(
range(5), frame_current=frame_start
range(5), frame_current_init=frame_start
):
assert frame_current == (frame + frame_start)
assert frame_manager.frame_current == frame_current
Expand Down

0 comments on commit 820c1cf

Please sign in to comment.