bnp.objects.mesh

mesh2np(mesh: bpy.types.Mesh, world_matrix=None, geo_type="position", dtype=np.float32, is_local=False, frame=bpy.context.scene.frame_current, as_homogeneous=False) → np.ndarray

Convert a bpy.types.Mesh to np.ndarray at current frame.

Parameters:
  • mesh (bpy.types.Mesh) – input mesh
  • world_matrix (np.ndarray) – world matrix (equal to model matrix)
  • geo_type (str) – “position” or “normal”
  • dtype – dtype
  • is_local (bool) – return local positions if is_local else global positions
  • frame (int) – frame when you want to read (default: current frame)
  • as_homogeneous (bool) – whether to return vertices as homogeneous coordinates or not
Returns:

np.ndarray (vertex_number, 3) or (vertex_number, 4)

skinning_weights2np(obj: bpy.types.Object, dtype=np.float32) → np.ndarray

Get skinning weights (vertex weights in Blender) as np.ndarray

Parameters:
  • obj (bpy.types.Object) – object which has bpy.types.Mesh
  • dtype – dtype
Returns:

np.ndarray skinning weights (vtx_num, joint_num)

normalize_skinning_weights(obj: bpy.types.Object) → bpy.types.Mesh

Get a mesh after normalization of skinning weights (vertex weights in Blender)

Parameters:obj (bpy.types.Object) – object which has bpy.types.Mesh
Returns:bpy.types.Mesh mesh after normalization of skinning weights
get_active_vertex_indices(obj: bpy.types.Object) → list

Get active vertex indices from the mesh of the input obj

Parameters:obj (bpy.types.Object) – object which has bpy.types.Mesh
remove_shape_keys(obj, all=True)

Remove the selected shape key (blend weight). If all == true, remove all shape keys from obj

Parameters:obj (bpy.types.Object) – object which has bpy.types.Mesh
add_shape_keys(obj, name, blend_weight=1.0, vertices=None, slider_min=0.0, slider_max=1.0, from_mix=False)

Add a shape key (blend weight) to obj

Parameters:
  • obj (bpy.types.Object) – object which has bpy.types.Mesh
  • name (str) – name of the shape key. Any name is ok.
  • blend_weight (float) – blend weight
  • vertices (np.ndarray) – vertex positions (vtx_num, 3). None: vertex positions won’t be changed.
  • slider_min (float) – minimum value of the blend weight
  • slider_max (float) – maximum value of the blend weight
  • from_mix (bool) – create new shape from existing mix of shapes (see: https://docs.blender.org/api/current/bpy.types.Object.html#bpy.types.Object.shape_key_add)
adjust_shape_key(obj, name, blend_weight, vertices=None)

Adjust the value and vertices of the shape key

Parameters:
  • obj (bpy.types.Object) – object which has bpy.types.Mesh
  • name (str) – name of the shape key
  • blend_weight (float) – blend weight
  • vertices (np.ndarray) – vertex positions (vtx_num, 3). None: vertex positions won’t be changed.
insert_keyframes_to_shape_keys(obj, blend_weights)

Insert keyframes to shape keys (blend weights)

Parameters:
  • obj (bpy.types.Object) – object which has bpy.types.Mesh and shapekeys
  • blend_weights (dict) – dictionary like {FRAME: {SHAPE_KEY_NAME1: 1.0, SHAPE_KEY_NAME2: 0.0}} where FRAME should be str(int(target_frame)), SHAPE_KEY_NAME1 and SHAPE_KEY_NAME2 should be names of shape keys. Please check example 003.
get_keyframe_of_shapekeys(obj)

Get a sorted list which contains keyframes of obj’s shape keys(blend weights). If there is no keyframes, return an empty list.

Parameters:obj (bpy.types.Object) – obj
Returns:list sorted with keyframes (no duplication)