blendersynth.blender.mesh
- class blendersynth.blender.mesh.Mesh(obj, material=None, scene=None, class_id=None)[source]
A mesh object. Can be a single mesh, or a hierarchy of meshes.
- add_child(obj)[source]
Add child Mesh or Object to this object. This will make the child object move with this object.
- Parameters:
obj (
Union
[Mesh
,Object
]) – Object to add as child
- property all_origins: List[mathutils.Vector]
Return list of origins of all objects within the mesh
- animate_path(frames=(0, 250), fracs=(0, 1))
Animate object along path.
- Parameters:
frames (
tuple
) – tuple of keyframes to animate at - length Nfracs (
tuple
) – tuple of fractions along path to animate at - length N
- assign_aov(aov)[source]
Assign AOV to object. Applies to all materials.
- Parameters:
aov (
AOV
) – AOV to assign
- assign_aovs(aovs)[source]
Assign multiple AOVs to object. Applies to all materials.
- Parameters:
aovs (
List
[AOV
]) – AOVs to assign
- assign_pass_index(index)[source]
Assign pass index to object. This can be used when mask rendering.
- Parameters:
index (
int
) – Pass index to assign
- property axes: ndarray
Return 3x3 rotation matrix (normalized) to represent axes
- centroid(method='median', seperate=False)[source]
Return the centroid of the mesh(es)
- Parameters:
method (
str
) – Seeorigin_to_centroid
for options.seperate (
bool
) – If True, will return a list of centroids for each object, rather than a single centroid.
- Return type:
Vector
- Returns:
Centroid of the mesh(es). If multiple meshes, will average the centroids.
- clamp_in_axis(axis='Z', mode='min', value=0)[source]
Clamp object in a given axis to a given value - ensure that, in this axis, the object never goes below (mode=’min’) or above (mode=’max’) the given value.
This can be used to ensure that an object never goes below the ground plane, for example.
- Parameters:
axis (
str
) – Axis to clamp inmode (
str
) – ‘min’ or ‘max’value (
float
) – Value to clamp to
- Return type:
ndarray
- Returns:
Vector of translation applied to object
- delete(delete_materials=True)[source]
Clear mesh from scene & mesh data.
- Parameters:
delete_materials (
bool
) – Also delete object materials from scene
- export_obj(obj_loc, **kwargs)[source]
Export object to .obj file.
- Parameters:
obj_loc (
str
) – Location to save .obj file tokwargs – Additional arguments to pass to bpy.ops.wm.obj_export
- follow_path(path, zero=True, animate=True, frames=(0, 250), fracs=(0, 1))
Follow path, with optional animation setting.
- Parameters:
path (
Curve
) – Curve objectzero (
bool
) – If True, set camera location to (0, 0, 0) [aligns camera with path]animate (
bool
) – If True, animate camera along pathframes (
tuple
) – tuple of keyframes to animate at - length Nfracs (
tuple
) – tuple of fractions along path to animate at - length N
- classmethod from_fbx(fbx_loc, class_id=None)[source]
Load object from .fbx file.
- Parameters:
fbx_loc (
str
) – Location of .fbx fileclass_id (
int
) – Class ID to assign to object
- Return type:
- classmethod from_glb(glb_loc, class_id=None)[source]
Load object from .glb file.
- Parameters:
glb_loc (
str
) – Location of .glb fileclass_id (
int
) – Class ID to assign to object
- Return type:
- classmethod from_numpy(vertices, faces, name='New_Mesh')[source]
Create Mesh from numpy arrays of vertices and faces.
- Return type:
- classmethod from_obj(obj_loc, class_id=None, forward_axis='-Z', up_axis='Y')[source]
Load object from .obj file.
- Parameters:
obj_loc (
str
) – Location of .obj fileclass_id (
int
) – Class ID to assign to objectforward_axis (
str
) – Axis to use as forward axisup_axis (
str
) – Axis to use as up axis
- Return type:
Note: we use bpy.ops.wm.obj_import instead of bpy.ops.import_scene.obj because the latter causes issues with materials & vertex ordering. (Changing vertex ordering makes the use of keypoints difficult.)
- classmethod from_primitive(name='cube', scale=None, location=None, rotation_euler=None, class_id=None, **kwargs)[source]
Create Mesh from primitive.
- Parameters:
name – Name of primitive to create. See
primitive_list
for optionsscale – Scale of object
location – Location of object
rotation_euler – Rotation of object
class_id – Class ID to assign to object
kwargs – Additional arguments to pass to primitive (see bpy.ops.mesh.primitive_cube_add, etc.)
- Return type:
- Returns:
Mesh object created from primitive
- classmethod from_scene(key, class_id=0)[source]
Create object from named object in scene.
- Parameters:
key (
str
) – Name of object in sceneclass_id (
int
) – Class ID to assign to object
- Return type:
- Returns:
Mesh loaded from scene
- get_armature(armature_name=None)[source]
Get armature. If no name given, return first armature found.
- Parameters:
armature_name (
str
) – Name of armature to load.- Return type:
- get_keypoints(idxs=None, position=None)[source]
Return 3D keypoint positions in world coordinates, given either:
- Parameters:
idxs (
list
) – list of indices or ndarray of keypoints to project (only valid for single-mesh objects)position (
Union
[ndarray
,List
[Vector
]]) – 3D position of keypoints to project - in LOCAL object coordinates
- Return type:
List
[Vector
]- Returns:
N list of Vectors of keypoints in world space, where N is the number of keypoints
- get_raw_bounds()[source]
Get the minimum and maximum bounds of all meshes in the object, under no deformations or transformations.
- Return type:
[mathutils.Vector, mathutils.Vector]
- get_shape_key(name, create=False)[source]
Get a given shape key object.
- Parameters:
name (
str
) – Name of shape keycreate (
bool
) – If True, create shape key if it doesn’t exist. Otherwise, raise error.
- Return type:
ShapeKey
- join(other_meshes)[source]
Join other meshes into this mesh. :type other_meshes:
Union
[List
[Mesh
],List
[Object
]] :param other_meshes: List of either Mesh or blender Object types :return:
- property location: mathutils.Vector
Location of object
- make_shape_key(name, data, value_min=0, value_max=1)[source]
Create a new shape key, optionally with data.
- Parameters:
name (
str
) – Name of shape keydata (
ndarray
) – Data to set shape key tovalue_min (
float
) – Minimum value of shape keyvalue_max (
float
) – Maximum value of shape key
- property matrix_world
Return world matrix of object(s).
- property origin: mathutils.Vector | List[mathutils.Vector]
Return origin of primary object.
To get origins of all objects within the mesh, use
all_origins
- origin_to_centroid(method='bounds')[source]
Move object origin to centroid.
Four methods available:
‘bounds’ - move the origin to the center of the bounds of the mesh
‘median’ - move the origin to the median point of the mesh
‘com_volume’ - move to the centre of mass of the volume of the mesh
‘com_area’ - Move to the centre of mass of the surface of the mesh
- Parameters:
method (
str
) – Selected method to move origin to centroid
- path_keyframe(frame, offset)
Set keyframe for camera path offset
- Parameters:
frame (
int
) – Frame numberoffset (
float
) – Offset fraction (0-1)
- primitive_list = ['cube', 'sphere', 'cylinder', 'plane', 'cone', 'monkey', 'torus']
List of available primitives
- remove()
Delete .obj from bpy.data if it exists
- render_visibility(value, frame=None)
Show/hide object in render
- Parameters:
value (
bool
) – True to show, False to hideframe (
int
) – Optional frame for animating
- rotate_by(rotation)
Add a rotation to the object. Must be in XYZ order, euler angles, radians.
- property rotation_euler: mathutils.Euler
Rotation in euler XYZ angles
- scale_by(scale)
Scale object
- set_class_id(class_id)[source]
Set the class ID of the object.
- Parameters:
class_id (
int
) – Class ID to assign to object
- set_dimensions(dimensions, frame=None)
Set dimensions of object.
- Parameters:
dimensions (
VectorLikeOrScalar
) – Dimensions to set. Either single value or 3 long vectorframe (
int
) – Optional frame for animating
- set_location(location, frame=None)
Set location of object.
- Parameters:
location (
VectorLike
) – Location vector to setframe (
int
) – Optional frame for animating
- set_minimum_to(axis='Z', pos=0)[source]
Set minimum of object to a given position in a given axis.
- Parameters:
axis (
str
) – Axis to set minimum inpos (
float
) – Position to set minimum to
- set_rotation_euler(rotation, frame=None)
Set euler rotation of object.
- Parameters:
rotation (
VectorLike
) – Rotation vectorframe (
int
) – Optional frame for animating
- set_scale(scale, frame=None)
Set scale of object.
- Parameters:
scale (
VectorLikeOrScalar
) – Scale to set. Either single value or 3 long vectorframe (
int
) – Optional frame for animating
- set_shape_key(name, value, frame=None)[source]
Set shape key to a given value.
- Parameters:
name (
str
) – Name of shape keyvalue (
float
) – Value to set shape key toframe (
int
) – If not None, set keyframe at this frame
- set_shape_key_data(name, data, create=True, value_min=0, value_max=1)[source]
Set shape key to a given value.
- Parameters:
name (
str
) – Name of shape keydata (
ndarray
) – Data to set shape key to (absolute positions - not offsets)create (
bool
) – If True, create shape key if it doesn’t exist. Otherwise, raise error.value_min (
float
) – Minimum value of shape keyvalue_max (
float
) – Maximum value of shape key
- set_shape_keys(data, frame=None)[source]
Set multiple shape keys at once.
- Parameters:
data (
dict
) – Dictionary of shape key names to valuesframe (
int
) – If not None, set keyframe at this frame
- property shape_keys: bpy.types.Key
Get the first shape keys object available
- track_to(obj)
Track to object.
- Parameters:
obj (
Union
[BsynObject
,Object
]) – BsynObject or Blender Object to track to
- translate(translation)
Translate object
- untrack()
Remove track to constraint from object
- viewport_visibility(value, frame=None)
Show/hide object in viewport
- Parameters:
value (
bool
) – True to show, False to hideframe (
int
) – Optional frame for animating