Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from 3b1b:master #20

Merged
merged 39 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f2e91ef
Use uniform for ValueTracker value instead of data
3b1b Jan 15, 2023
286b8fb
Set the stage for data to be treated as a structure numpy array
3b1b Jan 15, 2023
2815f60
First pass at changing data to structure numpy array
3b1b Jan 16, 2023
f4c50f6
Change rgbas -> rgba
3b1b Jan 16, 2023
801f449
Fix lock_matching_data
3b1b Jan 16, 2023
2dafcb3
Remove check_data_alignment
3b1b Jan 16, 2023
e37b667
Modify Mobject.interpolate
3b1b Jan 16, 2023
d868f68
Account for case of setting stroke width with null array
3b1b Jan 16, 2023
e554349
Fix get_style for null point case
3b1b Jan 16, 2023
7e45558
Allow Mobject subclasses to specify which parts of data should act li…
3b1b Jan 16, 2023
ca5e119
Use _data_defaults for DotCloud radius
3b1b Jan 16, 2023
d267c00
Update Surface to have a data array
3b1b Jan 16, 2023
9704f06
Use pointlike_data_keys for interpolation and rotation
3b1b Jan 16, 2023
408890e
Update TexturedSurface for using a data array
3b1b Jan 16, 2023
3ba5237
Account for edge case with end of loop near end
3b1b Jan 16, 2023
90ac1fc
Rename 'points' -> 'point'
3b1b Jan 16, 2023
3f2fd5b
Update calculation of path ends to not include adjacent pairs
3b1b Jan 16, 2023
6f9f83f
Unify shader_dtype and data_dtype
3b1b Jan 16, 2023
f63331e
Use Mobject.data in place of shader_data, remove read_data_into_shader
3b1b Jan 16, 2023
ba9f61b
Have ShaderWrapper read in data rather than other shader wrappers
3b1b Jan 16, 2023
29f51a7
Check if joint_angles are in locked_data_keys before computing
3b1b Jan 16, 2023
2ca8848
Merge branch 'master' of github.com:3b1b/manim into data-arrays
3b1b Jan 16, 2023
eba86be
Use resize_preserving_order in aligning VMobjects
3b1b Jan 16, 2023
5a95bfa
Delete align_stroke_width_data_to_points
3b1b Jan 16, 2023
74b42a6
Small renaming
3b1b Jan 16, 2023
bdcfbc3
Cleanup VMobject shader wrapper methods
3b1b Jan 16, 2023
3a09acd
Update type hint for ShaderWrapper.uniforms
3b1b Jan 16, 2023
3f8c861
Rename draw_stroke_behind_fill -> stroke_behind
3b1b Jan 16, 2023
f5480d0
Tidy up ShaderWrapper.read_in
3b1b Jan 16, 2023
db45d9e
Add array_is_constant
3b1b Jan 16, 2023
c23f020
Add Mobject.const_data_keys so that interpolations can be faster
3b1b Jan 16, 2023
ae50748
Default to resizing_preserving_order in set_points
3b1b Jan 16, 2023
3b40ccc
In Mobject.append_points, have most data default to the last value
3b1b Jan 16, 2023
a46e580
Make sure resize_preserving_order preserves data type
3b1b Jan 16, 2023
8ef93b0
Treat font_size as a float
3b1b Jan 16, 2023
1a15756
Make sure Mobject.become works with bounding_box
3b1b Jan 16, 2023
dd0e910
Account for null family case
3b1b Jan 16, 2023
bd2d45e
Handle edge case of low ring end
3b1b Jan 16, 2023
161bf73
Merge pull request #1965 from 3b1b/data-arrays
3b1b Jan 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Have ShaderWrapper read in data rather than other shader wrappers
  • Loading branch information
3b1b committed Jan 16, 2023
commit ba9f61b50ba162ce5629f3bbca286763f2cd1f7d
50 changes: 27 additions & 23 deletions manimlib/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,37 +1212,40 @@ def get_stroke_shader_wrapper(self) -> ShaderWrapper:

def get_shader_wrapper_list(self) -> list[ShaderWrapper]:
# Build up data lists
fill_sws = []
stroke_sws = []
bstroke_sws = []
fill_submobs = []
stroke_submobs = []
bstroke_submobs = []
for submob in self.family_members_with_points():
if submob.has_fill():
fill_sws.append(submob.get_fill_shader_wrapper())
fill_submobs.append(submob)
if submob.has_stroke():
lst = bstroke_sws if submob.draw_stroke_behind_fill else stroke_sws
lst.append(submob.get_stroke_shader_wrapper())
if submob.draw_stroke_behind_fill:
bstroke_submobs.append(submob)
else:
stroke_submobs.append(submob)

fill_names = list(self.fill_data.dtype.names)
self.fill_shader_wrapper.read_in(
[sm.data[fill_names] for sm in fill_submobs],
[sm.get_fill_shader_vert_indices() for sm in fill_submobs],
)
self.stroke_shader_wrapper.read_in(
[sm.get_stroke_shader_data() for sm in stroke_submobs],
)
self.back_stroke_shader_wrapper.read_in(
[sm.get_stroke_shader_data() for sm in bstroke_submobs],
)

self_sws = [

shader_wrappers = [
self.back_stroke_shader_wrapper,
self.fill_shader_wrapper,
self.stroke_shader_wrapper
]
sw_lists = [
bstroke_sws,
fill_sws,
stroke_sws
]
for sw, sw_list in zip(self_sws, sw_lists):
if not sw_list:
sw.vert_data = resize_array(sw.vert_data, 0)
continue
if sw is sw_list[0]:
sw.combine_with(*sw_list[1:])
else:
sw.read_in(*sw_list)
sw.depth_test = any(sw.depth_test for sw in sw_list)
sw.uniforms.update(sw_list[0].uniforms)
return [sw for sw in self_sws if len(sw.vert_data) > 0]
for sw in shader_wrappers:
# TODO, handle depth test and uniforms...
pass
return [sw for sw in shader_wrappers if len(sw.vert_data) > 0]

def get_stroke_shader_data(self) -> np.ndarray:
# Set data array to be one longer than number of points,
Expand All @@ -1255,6 +1258,7 @@ def get_stroke_shader_data(self) -> np.ndarray:
return self.stroke_data

self.get_joint_angles() # Recomputes, only if refresh is needed

for key in self.stroke_data.dtype.names:
self.stroke_data[key][:n] = self.data[key]
self.stroke_data[-1] = self.stroke_data[-2]
Expand Down
37 changes: 25 additions & 12 deletions manimlib/shader_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Iterable
from typing import Iterable, List


# Mobjects that should be rendered with
Expand Down Expand Up @@ -136,25 +136,38 @@ def replace_code(self, old: str, new: str) -> None:

def combine_with(self, *shader_wrappers: ShaderWrapper) -> ShaderWrapper:
if len(shader_wrappers) > 0:
self.read_in(self.copy(), *shader_wrappers)
data_list = [self.vert_data, *(sw.vert_data for sw in shader_wrappers)]
if self.vert_indices is not None:
indices_list = [self.vert_indices, *(sw.vert_indices for sw in shader_wrappers)]
else:
indices_list = None
self.read_in(data_list, indices_list)
return self

def read_in(self, *shader_wrappers: ShaderWrapper) -> ShaderWrapper:
def read_in(
self,
vert_data_list: List[np.ndarray],
vert_indices_list: List[np.ndarray] | None = None
) -> ShaderWrapper:
# Assume all are of the same type
total_len = sum(len(sw.vert_data) for sw in shader_wrappers)
total_len = sum(len(data) for data in vert_data_list)
self.vert_data = resize_array(self.vert_data, total_len)
if self.vert_indices is not None:
total_verts = sum(len(sw.vert_indices) for sw in shader_wrappers)
if total_len == 0:
return self

if vert_indices_list is not None and self.vert_indices is not None:
total_verts = sum(len(vi) for vi in vert_indices_list)
self.vert_indices = resize_array(self.vert_indices, total_verts)

n_points = 0
n_verts = 0
for sw in shader_wrappers:
new_n_points = n_points + len(sw.vert_data)
self.vert_data[n_points:new_n_points] = sw.vert_data
if self.vert_indices is not None and sw.vert_indices is not None:
new_n_verts = n_verts + len(sw.vert_indices)
self.vert_indices[n_verts:new_n_verts] = sw.vert_indices + n_points
for k, data in enumerate(vert_data_list):
new_n_points = n_points + len(data)
self.vert_data[n_points:new_n_points] = data
if self.vert_indices is not None and vert_indices_list is not None:
vert_indices = vert_indices_list[k]
new_n_verts = n_verts + len(vert_indices)
self.vert_indices[n_verts:new_n_verts] = vert_indices + n_points
n_verts = new_n_verts
n_points = new_n_points
return self
Expand Down