blendify.renderables package#

Submodules#

blendify.renderables.base module#

class blendify.renderables.base.Renderable(material: Material, colors: Colors, **kwargs)[source]#

Bases: Positionable

Base class for all renderable objects (Meshes, PointClouds, Primitives).

update_colors(colors: Colors)[source]#

Updates object color properties, sets Blender structures accordingly

Parameters:

colors (Colors) – target colors information

update_material(material: Material)[source]#

Updates object material properties, sets Blender structures accordingly :param material: target material :type material: Material

class blendify.renderables.base.RenderableObject(**kwargs)[source]#

Bases: Renderable

Base class for renderable objects, that can be represented by a single bpy.types.Object (Meshes and Primitives).

property emit_shadows: bool#
update_colors(colors: Colors)[source]#

Updates object color properties, sets Blender structures accordingly

Parameters:

colors (Colors) – target colors information

update_material(material: Material)[source]#

Updates object material properties, sets Blender structures accordingly

Parameters:

material (Material) – target material

blendify.renderables.collection module#

class blendify.renderables.collection.RenderablesCollection(*args, **kwargs)[source]#

Bases: object

add_circle_mesh(radius: float, material: Material, colors: Colors, num_vertices: int = 32, fill_type: str = 'NGON', quaternion: Union[ndarray, Tuple[float, float, float, float]] = (1, 0, 0, 0), translation: Union[ndarray, Tuple[float, float, float]] = (0, 0, 0), tag: Optional[str] = None) CircleMesh[source]#

Add primitives.CircleMesh object to the scene. The object supports only uniform coloring (UniformColors).

Parameters:
  • radius (float) – radius of a primitive in [0, inf]

  • material (Material) – Material instance

  • colors (Colors) – Colors instance

  • num_vertices (int, optional) – number of vertices in primitive in [3, 10000000] (default: 32)

  • fill_type (str, optional) – fill type, one of [NOTHING, NGON, TRIFAN] (default: NGON)

  • quaternion (Vector4d, optional) – rotation applied to the Blender object (default: (1,0,0,0))

  • translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))

  • tag (str, optional) – name of the created object in Blender. If None is passed, the tag is automatically generated (default: None)

Returns:

created and added to the scene object

Return type:

primitives.CircleMesh

add_cube_mesh(size: float, material: Material, colors: Colors, quaternion: Union[ndarray, Tuple[float, float, float, float]] = (1, 0, 0, 0), translation: Union[ndarray, Tuple[float, float, float]] = (0, 0, 0), tag: Optional[str] = None) CubeMesh[source]#

Add primitives.CircleMesh object to the scene. The object supports only uniform coloring (UniformColors).

Parameters:
  • size (float) – size of a primitive in [0, inf]

  • material (Material) – Material instance

  • colors (Colors) – Colors instance

  • quaternion (Vector4d, optional) – rotation applied to the Blender object (default: (1,0,0,0))

  • translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))

  • tag (str, optional) – name of the created object in Blender. If None is passed, the tag is automatically generated (default: None)

Returns:

created and added to the scene object

Return type:

primitives.CircleMesh

add_curve_nurbs(keypoints: ndarray, radius: float, material: Material, colors: Colors, quaternion: Union[ndarray, Tuple[float, float, float, float]] = (1, 0, 0, 0), translation: Union[ndarray, Tuple[float, float, float]] = (0, 0, 0), tag: Optional[str] = None) CurveBezier[source]#

Add primitives.CurveBezier object to the scene. Keypoints are intermediate points of the Bezier Curve. The object supports only uniform coloring (UniformColors).

Parameters:
  • keypoints (np.ndarray) – keypoints for the curve

  • radius (float) – radius of a primitive in [0, inf]

  • material (Material) – Material instance

  • colors (Colors) – Colors instance

  • quaternion (Vector4d, optional) – rotation applied to the Blender object (default: (1,0,0,0))

  • translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))

  • tag (str, optional) – name of the created object in Blender. If None is passed, the tag is automatically generated (default: None)

Returns:

created and added to the scene object

Return type:

primitives.CurveBezier

add_cylinder_mesh(radius: float, height: float, material: Material, colors: Colors, num_vertices: int = 32, fill_type: str = 'NGON', quaternion: Union[ndarray, Tuple[float, float, float, float]] = (1, 0, 0, 0), translation: Union[ndarray, Tuple[float, float, float]] = (0, 0, 0), tag: Optional[str] = None) CylinderMesh[source]#

Add primitives.CylinderMesh object to the scene. The object supports only uniform coloring (UniformColors).

Parameters:
  • radius (float) – radius of a primitive in [0, inf]

  • height (float) – height of a primitive in [0, inf]

  • material (Material) – Material instance

  • colors (Colors) – Colors instance

  • num_vertices (int, optional) – number of vertices in primitive in [3, 10000000] (default: 32)

  • fill_type (str, optional) – fill type, one of [NOTHING, NGON, TRIFAN] (default: NGON)

  • quaternion (Vector4d, optional) – rotation applied to the Blender object (default: (1,0,0,0))

  • translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))

  • tag (str, optional) – name of the created object in Blender. If None is passed, the tag is automatically generated (default: None)

Returns:

created and added to the scene object

Return type:

primitives.CylinderMesh

add_ellipsoid_nurbs(radius: Union[ndarray, Tuple[float, float, float]], material: Material, colors: Colors, quaternion: Union[ndarray, Tuple[float, float, float, float]] = (1, 0, 0, 0), translation: Union[ndarray, Tuple[float, float, float]] = (0, 0, 0), tag: Optional[str] = None) EllipsoidNURBS[source]#

Add primitives.EllipsoidNURBS object to the scene. Implemented as NURBS Sphere that is rescaled along axes, supports only uniform coloring (UniformColors).

Parameters:
  • radius (float) – radius of a primitive in [0, inf]

  • material (Material) – Material instance

  • colors (Colors) – Colors instance

  • quaternion (Vector4d, optional) – rotation applied to the Blender object (default: (1,0,0,0))

  • translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))

  • tag (str, optional) – name of the created object in Blender. If None is passed, the tag is automatically generated (default: None)

Returns:

created and added to the scene object

Return type:

primitives.EllipsoidNURBS

add_mesh(vertices: ndarray, faces: ndarray, material: Material, colors: Colors, quaternion: Union[ndarray, Tuple[float, float, float, float]] = (1, 0, 0, 0), translation: Union[ndarray, Tuple[float, float, float]] = (0, 0, 0), tag: Optional[str] = None) Mesh[source]#

Add Mesh object to the scene. The object supports uniform (UniformColors), per-vertex (VertexColors), per-vertex uv (VertexUV), per-face uv (FacesUV) and texture (TextureColors and FileTextureColors) coloring.

Parameters:
  • vertices (np.ndarray) – mesh vertices

  • faces (np.ndarray) – mesh faces

  • material (Material) – Material instance

  • colors (Colors) – Colors instance

  • quaternion (Vector4d, optional) – rotation applied to the Blender object (default: (1,0,0,0))

  • translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))

  • tag (str, optional) – name of the created object in Blender. If None is passed, the tag is automatically generated (default: None)

Returns:

created and added to the scene object

Return type:

Mesh

add_pointcloud(vertices: ndarray, material: Material, colors: Colors, point_size: float = 0.006, base_primitive: str = 'CUBE', particle_emission_strength: int = 1, quaternion: Union[ndarray, Tuple[float, float, float, float]] = (1, 0, 0, 0), translation: Union[ndarray, Tuple[float, float, float]] = (0, 0, 0), tag: Optional[str] = None) PointCloud[source]#

Add PointCloud object to the scene. The object supports uniform (UniformColors) and per-vertex (VertexColors) coloring.

Parameters:
  • vertices (np.ndarray) – point cloud vertices

  • material (Material) – Material instance

  • colors (Colors) – VertexColors or UniformColors instance

  • point_size (float, optional) – size of a primitive, representing each vertex (default: 0.006)

  • base_primitive (str, optional) – type of primitive for representing each point (possible values are PLANE, CUBE, SPHERE, default: CUBE)

  • particle_emission_strength (int, optional) – strength of the emission from each primitive. This is used to increase realism. Values <= 0 turn emission off, values > 0 set the power of emission (default: 1)

  • quaternion (Vector4d, optional) – rotation applied to the Blender object (default: (1,0,0,0))

  • translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))

  • tag (str, optional) – name of the created collection in Blender to represent the point cloud. If None is passed the tag is automatically generated (default: None)

Returns:

created and added to the scene object

Return type:

PointCloud

add_sphere_nurbs(radius: float, material: Material, colors: Colors, quaternion: Union[ndarray, Tuple[float, float, float, float]] = (1, 0, 0, 0), translation: Union[ndarray, Tuple[float, float, float]] = (0, 0, 0), tag: Optional[str] = None) SphereNURBS[source]#

Add primitives.SphereNURBS object to the scene. The object supports only uniform coloring (UniformColors).

Parameters:
  • radius (float) – radius of a primitive in [0, inf]

  • material (Material) – Material instance

  • colors (Colors) – Colors instance

  • quaternion (Vector4d, optional) – rotation applied to the Blender object (default: (1,0,0,0))

  • translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))

  • tag (str, optional) – name of the created object in Blender. If None is passed, the tag is automatically generated (default: None)

Returns:

created and added to the scene object

Return type:

primitives.SphereNURBS

items()[source]#
keys()[source]#
remove(obj_or_tag: Union[Renderable, str])[source]#
values()[source]#

blendify.renderables.colors module#

class blendify.renderables.colors.Colors[source]#

Bases: ABC

An abstract container template for storing the object coloring information

property metadata: ColorsMetadata#
class blendify.renderables.colors.ColorsMetadata(type, color, has_alpha, texture)[source]#

Bases: NamedTuple

color: Optional[Union[ndarray, Tuple[float, float, float]]]#

Alias for field number 1

has_alpha: bool#

Alias for field number 2

texture: Optional[Image]#

Alias for field number 3

type: type#

Alias for field number 0

class blendify.renderables.colors.FacesUV(data: ndarray)[source]#

Bases: UVMap

A container which stores a UV coordinate for every vertex in every triangle face In the form of (M,3,2) array (M faces, 3 vertices in each face, 2 UV coordinates for each vertex in triangle)

class blendify.renderables.colors.FileTextureColors(texture_path: str, uv_map: UVMap)[source]#

Bases: UVColors

A container which stores path to the texture file and the corresponding UV mapping

property blender_texture: Image#

Get the current Blender texture created from the pixels array

Returns:

current Blender texture

Return type:

bpy.types.Image

class blendify.renderables.colors.TextureColors(texture: ndarray, uv_map: UVMap)[source]#

Bases: UVColors

A container which stores texture in form of pixels array and the corresponding UV mapping

property blender_texture: Image#

Get the current Blender texture created from the pixels array

Returns:

current Blender texture

Return type:

bpy.types.Image

class blendify.renderables.colors.UVColors(uv_map: UVMap)[source]#

Bases: Colors

An abstract container for storing color information bound to UV coordinate space

property uv_map: UVMap#

Get the stored UV map

Returns:

stored UV map

Return type:

UVMap

class blendify.renderables.colors.UVMap(data: ndarray)[source]#

Bases: ABC

An abstract container template for storing a UV coordinate map

property data: ndarray#

Get the stored UV map data

Returns:

UV map data

Return type:

np.ndarray

class blendify.renderables.colors.UniformColors(uniform_color: Union[ndarray, Tuple[float, float, float]])[source]#

Bases: Colors

A container which stores a single uniform color for the whole object

property color: ndarray#

Get current color

Returns:

current color

Return type:

np.ndarray

class blendify.renderables.colors.VertexColors(vertex_colors: ndarray)[source]#

Bases: Colors

A container which stores a color information for each vertex of an object (vertex colors are interpolated over the faces)

property vertex_colors: ndarray#

Get current colors

Returns:

current vertex colors

Return type:

np.ndarray

class blendify.renderables.colors.VertexUV(data: ndarray)[source]#

Bases: UVMap

A container which stores a UV coordinate for every vertex In the form of (N,2) array (N vertices, 2 UV coordinates for each)

blendify.renderables.materials module#

class blendify.renderables.materials.GlossyBSDFMaterial(roughness=0.4, distribution='GGX')[source]#

Bases: object

A class which manages the parameters of GlossyBSDF Blender material. Full docs: https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/glossy.html

create_material(name: str = 'object_material') Tuple[Material, ShaderNodeBsdfGlossy][source]#

Create the Blender material with the parameters stored in the current object

Parameters:

name (str) – a unique material name for Blender

Returns:

Blender material and the

shader node which uses the created material

Return type:

Tuple[bpy.types.Material, bpy.types.ShaderNodeBsdfGlossy]

property distribution#
class blendify.renderables.materials.Material[source]#

Bases: ABC

abstract create_material(name: str = 'object_material') Tuple[Material, ShaderNode][source]#
class blendify.renderables.materials.PrinsipledBSDFMaterial(metallic=0.0, specular=0.3, specular_tint=0.0, roughness=0.4, anisotropic=0.0, anisotropic_rotation=0.0, sheen=0.0, sheen_tint=0.5, clearcoat=0.0, clearcoat_roughness=0.0, ior=1.45, transmission=0.0, transmission_roughness=0.0, emission=(0, 0, 0, 0), emission_strength=0.0, alpha=1.0)[source]#

Bases: object

A class which manages the parameters of PrinsipledBSDF Blender material. Full docs: https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/principled.html

create_material(name: str = 'object_material') Tuple[Material, ShaderNodeBsdfPrincipled][source]#

Create the Blender material with the parameters stored in the current object

Parameters:

name (str) – a unique material name for Blender

Returns:

Blender material and the

shader node which uses the created material

Return type:

Tuple[bpy.types.Material, bpy.types.ShaderNodeBsdfPrincipled]

blendify.renderables.materials.material_property(name: str, blender_name: str)[source]#

Creates a property for the material class to set and get one of the material parameters both in the class and in Blender

Parameters:
  • name (str) – property name

  • blender_name (str) – a Blender parameter name to control

Returns:

A class property with defines parameter setting and getting behaviour

Return type:

property

blendify.renderables.mesh module#

class blendify.renderables.mesh.Mesh(vertices: ndarray, faces: ndarray, tag: str, **kwargs)[source]#

Bases: RenderableObject

Basic mesh, supports uniform (UniformColors), per-vertex (VertexColors) and texture (TextureColors and FileTextureColors) coloring with per-vertex uv (VertexUV) or per-face uv maps (FacesUV).

Properties:

emit_shadow (bool, optional): control whether mesh will emit shadow from any light source in the scene

set_smooth(smooth: bool = True)[source]#

Turns smooth shading on and off based on the bool argument

Parameters:

smooth (bool, optional) – If True shade smooth else shade flat (default: True)

update_vertices(vertices: ndarray)[source]#

Updates mesh vertices coordinates

Parameters:

vertices (np.ndarray) – new vertex coordinates

blendify.renderables.pc module#

blendify.renderables.pointcloud module#

MIT License

Copyright (c) 2018 Sebastian Bullinger Copyright (c) 2021 Vladimir Guzov and Ilia Petrov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class blendify.renderables.pointcloud.ParticleMetadata(colors_node: Optional[ShaderNode], extra_nodes: Tuple[ShaderNode], vertex_offset: int, num_particles: int, material_node: Optional[Material], bsdf_node: Optional[Material], texture_image: Optional[Image])[source]#

Bases: object

Helper class that stores pointers to blender objects (colors, bsdf and material nodes), connected to each Particle System object

bsdf_node: Optional[Material]#
colors_node: Optional[ShaderNode]#
extra_nodes: Tuple[ShaderNode]#
material_node: Optional[Material]#
num_particles: int#
texture_image: Optional[Image]#
vertex_offset: int#
class blendify.renderables.pointcloud.PointCloud(vertices: ndarray, tag: str, point_size: float = 0.006, base_primitive: str = 'CUBE', particle_emission_strength: int = 1, **kwargs)[source]#

Bases: Renderable

Basic point cloud consisting of vertices, supports uniform (UniformColors) and per-vertex (VertexColors) coloring. Uses Blender-Photogrammetry-Importer to handle point clouds as Blender particle systems objects

Properties:
emit_shadow (bool, optional): control whether particles representing the point cloud will emit shadow from

any light source in the scene. This property may be turned off if the particle_emission_strength is big enough to avoid artifacts.

property emit_shadow#
update_colors(colors: Colors)[source]#

Updates object color properties, sets Blender structures accordingly

Parameters:

colors (Colors) – target colors information

update_material(material: Material)[source]#

Updates object material properties, sets Blender structures accordingly

Parameters:

material (Material) – target material

update_vertices(vertices: ndarray)[source]#

Updates pc vertices coordinates

Parameters:

vertices (np.ndarray) – new coordinates for point cloud vertices

blendify.renderables.primitives module#

class blendify.renderables.primitives.CircleMesh(radius: float, tag: str, num_vertices: int = 32, fill_type: str = 'NGON', **kwargs)[source]#

Bases: MeshPrimitive

Circle mesh primitive, supports only uniform coloring (UniformColors)

Properties:

emit_shadow (bool, optional): control whether the object will emit shadow from any light source in the scene

set_smooth(bool)#

turns smooth shading on and off based on the bool argument.

class blendify.renderables.primitives.CubeMesh(size: float, tag: str, **kwargs)[source]#

Bases: MeshPrimitive

Cube mesh primitive, supports only uniform coloring (UniformColors)

Properties:

emit_shadow (bool, optional): control whether the object will emit shadow from any light source in the scene.

set_smooth(bool)#

turns smooth shading on and off based on the bool argument.

class blendify.renderables.primitives.CurveBezier(keypoints: ndarray, radius: float, tag: str, **kwargs)[source]#

Bases: ParametricPrimitive

Bezier Curve, supports only uniform coloring (UniformColors)

Properties:

emit_shadow (bool, optional): control whether the object will emit shadow from any light source in the scene

class blendify.renderables.primitives.CylinderMesh(radius: float, height: float, tag: str, num_vertices: int = 32, fill_type: str = 'NGON', **kwargs)[source]#

Bases: MeshPrimitive

Cylinder mesh primitive, supports only uniform coloring (UniformColors)

Properties:

emit_shadow (bool, optional): control whether the object will emit shadow from any light source in the scene.

set_smooth(bool)#

turns smooth shading on and off based on the bool argument.

class blendify.renderables.primitives.EllipsoidNURBS(radius: Union[ndarray, Tuple[float, float, float]], tag: str, **kwargs)[source]#

Bases: ParametricPrimitive

NURBS Ellipsoid, implemented as NURBS Sphere that is rescaled along axes,

supports only uniform coloring (UniformColors)

Properties:

emit_shadow (bool, optional): control whether the object will emit shadow from any light source in the scene

class blendify.renderables.primitives.MeshPrimitive(**kwargs)[source]#

Bases: RenderableObject

Base class for mesh primitives. Used to throw Exceptions for non-implemented Colors subclasses (only UniformColors is supported) and add shared method for setting smooth shading.

Properties:

emit_shadow (bool, optional): control whether the object will emit shadow from any light source in the scene.

set_smooth(bool)[source]#

turns smooth shading on and off based on the bool argument.

set_smooth(smooth: bool = True)[source]#

Enables or disables the smooth surface imitation for the object

Parameters:

smooth (bool) – Whether to turn the smooth surface on or off

class blendify.renderables.primitives.ParametricPrimitive(**kwargs)[source]#

Bases: RenderableObject

Base class for parametric primitives. Used to throw Exceptions for non-implemented Colors subclasses (only UniformColors is supported)

Properties:

emit_shadow (bool, optional): control whether the object will emit shadow from any light source in the scene.

class blendify.renderables.primitives.SphereNURBS(radius: float, tag: str, **kwargs)[source]#

Bases: EllipsoidNURBS

NURBS Sphere, supports only uniform coloring (UniformColors)

Properties:

emit_shadow (bool, optional): control whether the object will emit shadow from any light source in the scene

Module contents#