blenderproc.python.types.MeshObjectUtility module¶
-
class
blenderproc.python.types.MeshObjectUtility.
MeshObject
(bpy_object)[source]¶ Bases:
blenderproc.python.types.EntityUtility.Entity
-
add_displace_modifier
(texture, mid_level=0.5, strength=0.1, min_vertices_for_subdiv=10000, subdiv_level=2)[source]¶ Adds a displace modifier with a texture to an object.
If the mesh has less than min_vertices_for_subdiv vertices, also a subdivision modifier is added.
Parameters: - texture (
Texture
) – The texture that will be used to displace the vertices. - mid_level (
float
) – Texture value that gives no displacement. Parameter of displace modifier. - strength (
float
) – Amount to displace geometry. Parameter of displace modifier. - min_vertices_for_subdiv (
int
) – Checks if a subdivision is necessary. If the vertices of a object are less than ‘min_vertices_for_subdiv’ a Subdivision modifier will be add to the object. - subdiv_level (
int
) – Numbers of Subdivisions to perform when rendering. Parameter of Subdivision modifier.
- texture (
-
add_material
(material)[source]¶ Adds a new material to the object.
Parameters: material ( Material
) – The material to add.
-
add_modifier
(name, **kwargs)[source]¶ Adds a new modifier to the object.
Parameters: - name (
str
) – The name/type of the modifier to add. - kwargs – Additional attributes that should be set to the modifier.
- name (
-
add_uv_mapping
(projection, overwrite=False)[source]¶ Adds a UV mapping to the object based on the given projection type.
Parameters:
-
build_convex_decomposition_collision_shape
(vhacd_path, temp_dir=None, cache_dir='blenderproc_resources/decomposition_cache')[source]¶ Builds a collision shape of the object by decomposing it into near convex parts using V-HACD
Parameters: - vhacd_path (
str
) – The directory in which vhacd should be installed or is already installed. - temp_dir (
Optional
[str
]) – The temp dir to use for storing the object files created by v-hacd. - cache_dir (
str
) – If a directory is given, convex decompositions are stored there named after the meshes hash. If the same mesh is decomposed a second time, the result is loaded from the cache and the actual decomposition is skipped.
- vhacd_path (
-
create_bvh_tree
()[source]¶ Builds a bvh tree based on the object’s mesh.
Return type: BVHTree
Returns: The new bvh tree
-
duplicate
()[source]¶ Duplicates the object.
Return type: MeshObject
Returns: A new mesh object, which is a duplicate of this object.
-
enable_rigidbody
(active, collision_shape='CONVEX_HULL', collision_margin=0.001, collision_mesh_source='FINAL', mass=None, mass_factor=1, friction=0.5, angular_damping=0.1, linear_damping=0.04)[source]¶ Enables the rigidbody component of the object which makes it participate in physics simulations.
Parameters: - active (
bool
) – If True, the object actively participates in the simulation and its key frames are ignored. If False, the object still follows its keyframes and only acts as an obstacle, but is not influenced by the simulation. - collision_shape (
str
) – Collision shape of object in simulation. Default: ‘CONVEX_HULL’. Available: ‘BOX’, ‘SPHERE’, ‘CAPSULE’, ‘CYLINDER’, ‘CONE’, ‘CONVEX_HULL’, ‘MESH’, ‘COMPOUND’. - collision_margin (
float
) – The margin around objects where collisions are already recognized. Higher values improve stability, but also make objects hover a bit. - collision_mesh_source (
str
) – Source of the mesh used to create collision shape. Default: ‘FINAL’. Available: ‘BASE’, ‘DEFORM’, ‘FINAL’. - mass (
Optional
[float
]) – The mass in kilogram the object should have. If None is given the mass is calculated based on its bounding box volume and the given mass_factor. - mass_factor (
float
) – Scaling factor for mass. This is only considered if the given mass is None. Defines the linear function mass=bounding_box_volume*mass_factor (defines material density). - friction (
float
) – Resistance of object to movement. - angular_damping (
float
) – Amount of angular velocity that is lost over time. - linear_damping (
float
) – Amount of linear velocity that is lost over time.
- active (
-
get_bound_box
(local_coords=False)[source]¶ Return type: ndarray
Returns: 8x3 array describing the object aligned bounding box coordinates in world coordinates
-
get_bound_box_volume
()[source]¶ Gets the volume of the object aligned bounding box.
Return type: float
Returns: volume of a bounding box.
-
get_materials
()[source]¶ Returns the materials used by the mesh.
Return type: List
[Optional
[Material
]]Returns: A list of materials.
-
get_origin
()[source]¶ Returns the origin of the object.
Return type: ndarray
Returns: The origin in world coordinates.
-
get_parent
()[source]¶ Returns the parent object.
Return type: Optional
[Entity
]Returns: The parent object, None if it has no parent.
-
get_rigidbody
()[source]¶ Returns the rigid body component
Return type: Optional
[RigidBodyObject
]Returns: The rigid body component of the object.
-
has_rigidbody_enabled
()[source]¶ Checks whether object has rigidbody element enabled
Return type: bool
Returns: True if object has rigidbody element enabled
-
hide
(hide_object=True)[source]¶ Sets the visibility of the object.
Parameters: hide_object ( bool
) – Determines whether the object should be hidden in rendering.
-
join_with_other_objects
(objects)[source]¶ Joins the given list of objects with this object.
Does not change the global selection. The given object-references become invalid after the join operation.
Parameters: objects ( List
[MeshObject
]) – List of objects which will be merged with this object
-
mesh_as_bmesh
(return_copy=False)[source]¶ Returns a bmesh based on the object’s mesh.
Independent of return_copy, changes to the returned bmesh only take into affect after calling update_from_bmesh().
Parameters: return_copy – If True, a copy of the objects bmesh will be returned, otherwise the bmesh owned by blender is returned (the object has to be in edit mode for that). Return type: BMesh
Returns: The bmesh
-
move_origin_to_bottom_mean_point
()[source]¶ Moves the object center to bottom of the bounding box in Z direction and also in the middle of the X and Y plane, which then makes the placement easier.
-
new_material
(name)[source]¶ Creates a new material and adds it to the object.
Parameters: name ( str
) – The name of the new material.Return type: Material
-
persist_transformation_into_mesh
(location=True, rotation=True, scale=True)[source]¶ Apply the current transformation of the object, which are saved in the location, scale or rotation attributes to the mesh and sets them to their init values.
Parameters:
-
position_is_above_object
(position, down_direction=None, check_no_objects_in_between=True)[source]¶ Make sure the given position is straight above the given object.
If check_no_objects_in_between is True, this also checks that there are no other objects in between.
Parameters: - position (
Union
[Vector
,ndarray
]) – The position to check. - down_direction (
Union
[Vector
,ndarray
,None
]) – A vector specifying the direction straight down. If None is given, a vector into -Z direction is used. - check_no_objects_in_between – If True, it is also checked that no other objects are in between position and object.
Returns: True, if a ray sent into negative z-direction starting from the position hits the object first.
- position (
-
ray_cast
(origin, direction, max_distance=1.70141e+38)[source]¶ Cast a ray onto evaluated geometry, in object space.
Parameters: Return type: Returns: Whether the ray successfully hit the geometry The hit location of this ray cast, float array of 3 items in [-inf, inf] The face normal at the ray cast hit location, float array of 3 items in [-inf, inf] The face index, -1 when original data isn’t available, int in [-inf, inf]
-
replace_materials
(material)[source]¶ Replaces all materials of the object with the given new material.
Parameters: material ( Material
) – A material that should exclusively be used as new material for the object.
-
scale_uv_coordinates
(factor)[source]¶ Scales the UV coordinates of an object by a given factor. Scaling with a factor greater than one has the effect of making the texture look smaller on the object.
Parameters: factor (float) – The amount the UV coordinates will be scaled.
-
set_material
(index, material)[source]¶ Sets the given material at the given index of the objects material list.
Parameters:
-
set_origin
(point=None, mode='POINT')[source]¶ Sets the origin of the object.
This will not change the appearing pose of the object, as the vertex locations experience the inverse transformation applied to the origin.
Parameters: - point (
Union
[Vector
,ndarray
,list
,None
]) – The point in world coordinates to which the origin should be set. This parameter is only relevent if mode is set to “POINT”. - mode (
str
) – The mode specifying how the origin should be set. Available options are: [“POINT”, “CENTER_OF_MASS”, “CENTER_OF_VOLUME”]
Return type: ndarray
Returns: The new origin in world coordinates.
- point (
-
set_parent
(new_parent)[source]¶ Sets the parent of this object.
Parameters: new_parent ( Entity
) – The new parent object.
-
-
blenderproc.python.types.MeshObjectUtility.
compute_poi
(objects)[source]¶ Computes a point of interest in the scene. Point is defined as a location of the one of the selected objects that is the closest one to the mean location of the bboxes of the selected objects.
Parameters: objects ( List
[MeshObject
]) – The list of mesh objects that should be considered.Return type: ndarray
Returns: Point of interest in the scene.
-
blenderproc.python.types.MeshObjectUtility.
convert_to_meshes
(blender_objects)[source]¶ Converts the given list of blender objects to mesh objects
Parameters: blender_objects ( list
) – List of blender objects.Return type: List
[MeshObject
]Returns: The list of meshes.
-
blenderproc.python.types.MeshObjectUtility.
create_bvh_tree_multi_objects
(mesh_objects)[source]¶ Creates a bvh tree which contains multiple mesh objects.
Such a tree is later used for fast raycasting.
Parameters: mesh_objects ( List
[MeshObject
]) – The list of mesh objects that should be put into the BVH tree.Return type: BVHTree
Returns: The built BVH tree.
-
blenderproc.python.types.MeshObjectUtility.
create_from_blender_mesh
(blender_mesh, object_name=None)[source]¶ Creates a new Mesh object using the given blender mesh.
Parameters: Return type: Returns: The new Mesh object.
-
blenderproc.python.types.MeshObjectUtility.
create_primitive
(shape, **kwargs)[source]¶ Creates a new primitive mesh object.
Parameters: shape ( str
) – The name of the primitive to create. Available: [“CUBE”, “CYLINDER”, “CONE”, “PLANE”, “SPHERE”, “MONKEY”]Return type: MeshObject
Returns: The newly created MeshObject
-
blenderproc.python.types.MeshObjectUtility.
create_with_empty_mesh
(object_name, mesh_name=None)[source]¶ Creates an object with an empty mesh. :type object_name:
str
:param object_name: The name of the new object. :type mesh_name:Optional
[str
] :param mesh_name: The name of the contained blender mesh. If None is given, the object name is used. :rtype:MeshObject
:return: The new Mesh object.
-
blenderproc.python.types.MeshObjectUtility.
disable_all_rigid_bodies
()[source]¶ Disables the rigidbody element of all objects
-
blenderproc.python.types.MeshObjectUtility.
get_all_mesh_objects
()[source]¶ Returns all mesh objects in scene
Return type: List
[MeshObject
]Returns: List of all MeshObjects
-
blenderproc.python.types.MeshObjectUtility.
scene_ray_cast
(origin, direction, max_distance=1.70141e+38)[source]¶ Cast a ray onto all geometry from the scene, in world space.
Parameters: Return type: Tuple
[bool
,ndarray
,ndarray
,int
,MeshObject
,ndarray
]Returns: Whether the ray successfully hit any geometry The hit location of this ray cast, float array of 3 items in [-inf, inf] The face normal at the ray cast hit location, float array of 3 items in [-inf, inf] The face index, -1 when original data isn’t available, int in [-inf, inf] If any object has been hit, the MeshObject otherwise None. Some 4x4 matrix.