mirror of
https://github.com/3b1b/manim.git
synced 2025-07-31 22:13:30 +08:00
Use null array for vert indices in place of None
This commit is contained in:
@ -502,7 +502,7 @@ class Camera(object):
|
|||||||
# Data buffer
|
# Data buffer
|
||||||
vert_data = shader_wrapper.vert_data
|
vert_data = shader_wrapper.vert_data
|
||||||
indices = shader_wrapper.vert_indices
|
indices = shader_wrapper.vert_indices
|
||||||
if indices is None:
|
if len(indices) == 0:
|
||||||
ibo = None
|
ibo = None
|
||||||
elif single_use:
|
elif single_use:
|
||||||
ibo = self.ctx.buffer(indices.astype(np.uint32))
|
ibo = self.ctx.buffer(indices.astype(np.uint32))
|
||||||
|
@ -1841,7 +1841,7 @@ class Mobject(object):
|
|||||||
|
|
||||||
def init_shader_data(self):
|
def init_shader_data(self):
|
||||||
# TODO, only call this when needed?
|
# TODO, only call this when needed?
|
||||||
self.shader_indices = None
|
self.shader_indices = np.zeros(0)
|
||||||
self.shader_wrapper = ShaderWrapper(
|
self.shader_wrapper = ShaderWrapper(
|
||||||
vert_data=self.data,
|
vert_data=self.data,
|
||||||
shader_folder=self.shader_folder,
|
shader_folder=self.shader_folder,
|
||||||
|
@ -37,7 +37,7 @@ class ShaderWrapper(object):
|
|||||||
is_fill: bool = False,
|
is_fill: bool = False,
|
||||||
):
|
):
|
||||||
self.vert_data = vert_data
|
self.vert_data = vert_data
|
||||||
self.vert_indices = vert_indices
|
self.vert_indices = vert_indices or np.zeros(0)
|
||||||
self.vert_attributes = vert_data.dtype.names
|
self.vert_attributes = vert_data.dtype.names
|
||||||
self.shader_folder = shader_folder
|
self.shader_folder = shader_folder
|
||||||
self.uniforms = uniforms or dict()
|
self.uniforms = uniforms or dict()
|
||||||
@ -68,9 +68,8 @@ class ShaderWrapper(object):
|
|||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
result = copy.copy(self)
|
result = copy.copy(self)
|
||||||
result.vert_data = np.array(self.vert_data)
|
result.vert_data = self.vert_data.copy()
|
||||||
if result.vert_indices is not None:
|
result.vert_indices = self.vert_indices.copy()
|
||||||
result.vert_indices = np.array(self.vert_indices)
|
|
||||||
if self.uniforms:
|
if self.uniforms:
|
||||||
result.uniforms = {key: np.array(value) for key, value in self.uniforms.items()}
|
result.uniforms = {key: np.array(value) for key, value in self.uniforms.items()}
|
||||||
if self.texture_paths:
|
if self.texture_paths:
|
||||||
@ -136,10 +135,7 @@ class ShaderWrapper(object):
|
|||||||
def combine_with(self, *shader_wrappers: ShaderWrapper) -> ShaderWrapper:
|
def combine_with(self, *shader_wrappers: ShaderWrapper) -> ShaderWrapper:
|
||||||
if len(shader_wrappers) > 0:
|
if len(shader_wrappers) > 0:
|
||||||
data_list = [self.vert_data, *(sw.vert_data for sw in 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)]
|
||||||
indices_list = [self.vert_indices, *(sw.vert_indices for sw in shader_wrappers)]
|
|
||||||
else:
|
|
||||||
indices_list = None
|
|
||||||
self.read_in(data_list, indices_list)
|
self.read_in(data_list, indices_list)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -157,10 +153,13 @@ class ShaderWrapper(object):
|
|||||||
# Stack the data
|
# Stack the data
|
||||||
np.concatenate(data_list, out=self.vert_data)
|
np.concatenate(data_list, out=self.vert_data)
|
||||||
|
|
||||||
if indices_list is None or self.vert_indices is None:
|
if indices_list is None:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
total_verts = sum(len(vi) for vi in indices_list)
|
total_verts = sum(len(vi) for vi in indices_list)
|
||||||
|
if total_verts == 0:
|
||||||
|
return self
|
||||||
|
|
||||||
self.vert_indices = resize_array(self.vert_indices, total_verts)
|
self.vert_indices = resize_array(self.vert_indices, total_verts)
|
||||||
|
|
||||||
# Stack vert_indices, but adding the appropriate offset
|
# Stack vert_indices, but adding the appropriate offset
|
||||||
|
Reference in New Issue
Block a user