svg3d.shaders¶
- class svg3d.shaders.DiffuseShader(base_style, light_direction=array([1., 1., 0.5]), absorbance=0.6)[source]¶
Bases:
ShaderShade
Meshobjects with Lambertian (dot product diffuse) lighting.- __call__(face_index, mesh)[source]¶
Compute the shaded style for a face in a mesh.
- Parameters:
- Returns:
A dictionary containing the SVG style attributes for the shaded face.
- Return type:
- __init__(base_style, light_direction=array([1., 1., 0.5]), absorbance=0.6)[source]¶
Initialize the diffuse shader.
- Parameters:
base_color (str, optional) – A hexadecimal-formatted color string for the mesh. Default is “#71618D”.
light_direction (iterable of float, optional) – A 3-element array specifying the direction of the light source. Default is (1.0, 1.0, 0.5).
base_style (dict | None, optional) – The style dict for the
Shader.
- property diffuse_light_direction¶
A 3-element array representing the direction of the light source.
- Type:
np.ndarray
- classmethod from_color(base_color)[source]¶
Create a
Shaderinstance with a specified base color.- Parameters:
base_color (str) – The base color as a hexadecimal string (e.g., #FFFFFF).
- classmethod from_color_and_direction(base_color, light_direction)[source]¶
Create a
Shaderinstance with a specified base color and light direction.
- class svg3d.shaders.Shader(base_style=None)[source]¶
Bases:
ABCAbstract base class for shaders.
- abstract __call__(face_index, mesh)[source]¶
Compute the shaded style for a face in a mesh.
Abstract method to be implemented in subclasses.
- class svg3d.shaders.UniformShader(base_style=None)[source]¶
Bases:
ShaderShade all faces of a
Meshwith a single, uniform color.This shader is useful in figure generation and when simplicity and clarity are maximally important.
- svg3d.shaders.diffuse_lighting(face_index, mesh, light_direction=None, base_style=None, base_color='#71618D')[source]¶
Apply Lambertian (dot product diffuse) shading to a face in an
Mesh.This is a convenience function for backwards compatibility. The full-featured
Shaderclass should be used in most instances.
- svg3d.shaders.hex2rgb(hexc)[source]¶
Convert a hexadecimal color string to an RGB array normalized to [0, 1].
- Parameters:
hexc (str) – A hexadecimal color string, with or without a leading #.
- Returns:
A NumPy array containing RGB values normalized to the range [0, 1].
- Return type:
\((3,)\)
numpy.ndarray
Examples
>>> hex2rgb("#FFFFFF") array([1., 1., 1.]) >>> hex2rgb("000000") array([0., 0., 0.])
- svg3d.shaders.rgb2hex(rgb)[source]¶
Convert an RGB color array to a hexadecimal color string.
- Parameters:
rgb (\((3,)\)
numpy.ndarray: The RGB values to convert.)- Returns:
str
- Return type:
A hexadecimal color string in uppercase format, prefixed with #.
Examples
>>> rgb2hex(np.array([1.0, 1.0, 1.0])) '#FFFFFF' >>> rgb2hex(np.array([0.0, 0.0, 0.0])) '#000000'