ddg.blender.mesh module
Collection of functions for Blender Mesh objects.
The related functions on the level of bmesh are found in bmeshutils.py module.
- ddg.blender.mesh.mesh(name, points, edges, faces, /)[source]
Create a mesh from points, edges and faces.
- Parameters:
- namestr
The
nameattribute of the mesh.- pointsarray_like of shape (num_points, 3)
The points of the mesh. The dtype must be some kind of floating point dtype.
- edgesarray_like of shape (num_edges, 2)
The
facesalready encode manifold edges, butedgescan encode additional non-manifold edges. Each row must contain two indices topoints. The dtype must be some kind of integer dtype.- facesarray_like of shape (num_faces, k)
The faces of the mesh, where
kis the number of vertices of each face. Each row must containkindices topoints. The dtype must be some kind of integer dtype.
- Returns:
- bpy.types.Mesh
- Raises:
- ValueError
If there already exists a mesh with the same name.
See also
ddg.curve_as_mesh
- ddg.blender.mesh.mesh_object(points, edges, faces, mesh_and_object_name, collection)[source]
Create a Blender mesh from points and faces and wrap it in a Blender object.
- Parameters:
- pointsarray_like of shape (num_points, 3)
The points of the mesh. The dtype must be some kind of floating point dtype.
- edgesarray_like of shape (num_edges, 2)
The
facesalready encode manifold edges, butedgescan encode additional non-manifold edges. Each row must contain two indices topoints. The dtype must be some kind of integer dtype.- facesarray_like of shape (num_faces, k)
The faces of the mesh, where
kis the number of vertices of each face. The dtype must be some kind of integer dtype.- mesh_and_object_namestr or tuple[str, str]
The
nameattribute of the mesh and the object. If only one string is passed, then use the same name for both.- collectionbpy.types.Collection, str, None
If
None, then the Blender object is not linked. Otherwise, the Collection or name of collection to link the object to.
- Returns:
- bpy.types.Object
- Raises:
- ValueError
If there already exists a Blender mesh or Blender object with the same name.
- ddg.blender.mesh.from_bmesh(bm, name, free=False)[source]
Write a BMesh to a new mesh.
- Parameters:
- bmbmesh.types.BMesh
- namestr
The
nameof the new mesh.- freebool (default=False)
If True,
bmis freed.
- Returns:
- bpy.types.Mesh
- ddg.blender.mesh.duplicate_by_properties(bobj, properties, collection=None, material=None, unlink_initial_object=True)[source]
Create duplicate Blender objects with certain properties
- Parameters:
- bobjbpy.types.Object
Blender object to duplicate.
- propertiesList
List of dictionaries that define the properties that are each applied to a duplicate
- collectionbpy.types.Collection or List, (default=None)
if bpy.types.Collection, links all duplicate object to single given collection if List, expects list of bpy.types.Collection, links one duplicate to each collection given
- materialbpy.types.Material or str, (default=None)
Name of Material or bpy.types.Material to be applied to the duplicate objects
- unlink_initial_objectbool, (default=True)
If
True, unlinkbobj.
- Returns:
- duplicateslist
A list of Blender objects : the created linked and transformed duplicates.
- ddg.blender.mesh.duplicate_by_transformation_matrices(bobj, transformation_matrices, collection=None, material=None, unlink_initial_object=True)[source]
Function creating duplicates of a Blender object. each duplicated has its properties changed given by properties.
- Parameters:
- bobjbpy.types.Object
Blender object to duplicate.
- transformation_matricesList
List of 4x4 matrices corresponding to the transformations.
- collectionbpy.types.Collection or List, (default=None)
bpy.types.Collection: links all duplicate object to single given collection List: expects list of bpy.types.Collection, links one duplicate to each collection given
- materialsbpy.types.Material or str or List, (default=None)
Name of the material or bpy.types.Material or List same length as properties populted with str (Name of the material) or bpy.types.Material (actual material object)
- unlink_initial_objectbool, (default=True)
unlinks the given originally Blender object from the scene
- Returns
- ——-
- duplicateslist
A list of Blender objects : the created linked and transformed duplicates.
- ddg.blender.mesh.duplicate_linked(bobj, n, collection=None)[source]
Creates n duplicate Blender objects.
- Parameters:
- bobjbpy.types.Object
Blender object to duplicate.
- nInteger
Integer of wanted number of duplicates
- collectionbpy.types.Collection or List of length n of bpy.types.Collection
a single bpy.types.Collection: links all duplicate object to single given collection List of length n populated with bpy.types.Collection : links one duplicate to each collection given
- Returns
- ——-
- duplicateslist
List of Blender objects : Created linked duplicates.
- ddg.blender.mesh.transform(bobj_or_mesh, M)[source]
Transform vertices by a matrix.
- Parameters:
- bobj_or_meshbpy.types.Object or bpy.types.Mesh
A Blender object (whose data is a mesh) or a mesh.
- Mnumpy.ndarray of shape (3, 3) or (4, 4)
- Returns:
- bpy.types.Object or bpy.types.Mesh
The input Blender object or mesh.
- ddg.blender.mesh.join(bobjs_or_meshes, name=None, keep_original=True, collection=None, remove_doubles_dist=None)[source]
Join Blender objects or meshes into a single Blender object.
- Parameters:
- bobjs_or_meshesSequence of bpy.types.Object or bpy.types.Mesh
Must be non-empty. Objects must have mesh data.
- namestr (default=None)
Name of the new object.
- keep_originalbool (default=True)
If
False, elements ofbobjs_or_meshesincluding their data are deleted.- collectionbpy.types.Collection (default=None)
Collection to link the object to. If
None, the object is not linked.- remove_doubles_distfloat or None (default=None)
If this parameter isn’t
None, redundant vertices are removed withbmesh.ops.remove_doubleswheredist=remove_doubles_dist.
- Returns:
- bpy.types.Object
- ddg.blender.mesh.connected_components(bobj, keep_original=True)[source]
Separates a Blender object into its connected components.
This is a fancier version of
bpy.ops.mesh.separatewhich takes care of mode switches and can handle objects which are hidden from the viewport.- Parameters:
- bobjbpy.types.Object
Object to be separated. Must have mesh data.
- keep_originalbool (default=True)
If
True, thenbobjis copied before separation.
- Returns:
- list of bpy.types.Object
The connected components of the Blender object.
See also
bpy.ops.mesh.separate
- ddg.blender.mesh.shade_smooth(bobj_or_mesh, smooth=True)[source]
Apply smooth or flat shading to each polygon of
bobj_or_mesh.- Parameters:
- bobj_or_meshbpy.types.Object or bpy.types.Mesh
An object (whose data is a mesh) or a mesh.
- smoothbool (default=True)
The
use_smoothattribute of every polygon is set to this value.
- Returns:
- bpy.types.Object or bpy.types.Mesh
The input Blender object or mesh.
- ddg.blender.mesh.clear(meshes=None, do_unlink=True, only_unused=False)[source]
Delete all given meshes.
- Parameters:
- meshesIterable of bpy.type.Mesh (default=None)
Meshes to be deleted. If the argument is not provided or None all meshes will be deleted.
- do_unlinkbool (default=True)
Unlink meshes from their objects and scenes, if needed, before deleting them.
- only_unusedbool (default=False)
Removes all unused meshes. If an Iterable of meshes is given as first parameter only those are effected, otherwise all meshes.
- Returns:
- None
- ddg.blender.mesh.intersection(bobj1, bobj2, collection, name='Intersection', intersection_operator=<function <lambda>>, remove_doubles_dist=0.001, attempt_curve_conversion=True)[source]
Intersects two mesh objects.
This function relies on Blender’s intersection operators. The
intersection_operatorparameter allows customization of the operator options, which usually need to be adjusted on a case by case basis. Note that the Blender’s intersection operators aren’t always reliable, especially for 2-dimensional intersections.- Parameters:
- bobj1bpy.types.Object
First object to intersect. Must have mesh data.
- bobj2bpy.types.Object
Second object to intersect. Must have mesh data.
- collectionbpy.types.Collection
Collection to add the intersection object to.
- namestr (default=”Intersection”)
Name of the intersection object.
- intersection_operatorCallable (default=lambda: bpy.ops.mesh.intersect(mode=”SELECT”))
Must have no input arguments. Called internally to compute the intersection.
- remove_doubles_distfloat or None (default=0.001)
If this parameter isn’t
None, redundant vertices are removed withbmesh.ops.remove_doubleswheredist=remove_doubles_dist.- attempt_curve_conversionbool (default=True)
If
True, thenbpy.ops.object.convert(target="CURVE")is applied to the intersection. This operator tries to convert the intersection’sdatafrombpy.types.Meshtobpy.types.Curve, but it may fail silently. If it does succeed, it may have unexpected results. For example, it converts a mesh consisting of a single triangle to the triangle’s boundary curve.
- Returns:
- bpy.types.Object or None
The intersection or
Noneif it is empty. If the intersection is non-empty, its data attribute is of typebpy.types.Curveorbpy.types.Mesh.
Notes
The intersection is computed as follows:
join
bobj1andbobj2- for each connected component
select all vertices in edit mode
call
intersection_operatorwhich should compute the intersection and select its verticesdelete unselected vertices, leaving just the intersection
join the intersections (if there are any)
optionally, delete redundant vertices
optionally, attempt to convert the intersection’s data to a curve using
bpy.ops.convert
Joining relies on
ddg.blender.mesh.join()which avoidsbpy.opsincludingbpy.ops.object.join.