[docs]classVertexColors(Colors):"""A container which stores a color information for each vertex of an object (vertex colors are interpolated over the faces) """def__init__(self,vertex_colors:np.ndarray):"""Create the vertex color container Args: vertex_colors (np.ndarray): numpy array of size (N,3) for RGB or (N,4) for RGBD colors """super().__init__()assert(np.ndim(vertex_colors)==2and3<=vertex_colors.shape[1]<=4), \
f"Expected colors array of shape (N,3) or (N,4) got shape {vertex_colors.shape}"assertvertex_colors.dtypein[np.float32,np.float64], \
"Colors should be stored as floating point numbers (np.float32 or np.float64)"assertnp.all(vertex_colors>=0)andnp.all(vertex_colors<=1),"Colors should be in range [0.0, 1.0]"has_alpha=vertex_colors.shape[1]==4ifnothas_alpha:vertex_colors=np.hstack([vertex_colors,np.ones((vertex_colors.shape[0],1),dtype=vertex_colors.dtype)])self._vertex_colors=vertex_colors.copy()self._metadata=ColorsMetadata(type=self.__class__,has_alpha=has_alpha,color=None,texture=None)@propertydefvertex_colors(self)->np.ndarray:"""Get current colors Returns: np.ndarray: current vertex colors """returnself._vertex_colors
[docs]classUniformColors(Colors):"""A container which stores a single uniform color for the whole object """def__init__(self,uniform_color:Union[Vector3d,Vector4d]):"""Create the uniform color container Args: uniform_color (Vector3d): a color in RGB format (to change alpha, use 'alpha' material property instead) """super().__init__()uniform_color=np.array(uniform_color)assertlen(uniform_color)in(3,4),"Color should be in RGB or RGBA format"assertuniform_color.max()<=1.anduniform_color.min()>=0.,"Color values should be in [0,1] range"self._color=uniform_colorself._metadata=ColorsMetadata(type=self.__class__,has_alpha=self._color.shape[0]==4,color=self._color,texture=None)@propertydefcolor(self)->np.ndarray:"""Get current color Returns: np.ndarray: current color """returnself._color