Changeset View
Changeset View
Standalone View
Standalone View
io_mesh_ply/export_ply.py
| Context not available. | |||||
| operator, | operator, | ||||
| context, | context, | ||||
| filepath="", | filepath="", | ||||
| use_selection=False, | |||||
| use_mesh_modifiers=True, | use_mesh_modifiers=True, | ||||
| use_normals=True, | use_normals=True, | ||||
| use_uv_coords=True, | use_uv_coords=True, | ||||
| use_colors=True, | use_colors=True, | ||||
| global_matrix=None | global_matrix=None | ||||
| ): | ): | ||||
| obj = context.active_object | import bmesh | ||||
| if global_matrix is None: | |||||
| from mathutils import Matrix | |||||
| global_matrix = Matrix() | |||||
| if bpy.ops.object.mode_set.poll(): | if bpy.ops.object.mode_set.poll(): | ||||
| bpy.ops.object.mode_set(mode='OBJECT') | bpy.ops.object.mode_set(mode='OBJECT') | ||||
| mesh_owner_object = None | if use_selection: | ||||
| if use_mesh_modifiers and obj.modifiers: | obs = context.selected_objects | ||||
| depsgraph = context.evaluated_depsgraph_get() | |||||
| mesh_owner_object = obj.evaluated_get(depsgraph) | |||||
| mesh = mesh_owner_object.to_mesh() | |||||
| else: | else: | ||||
| mesh_owner_object = obj | obs = context.scene.objects | ||||
| mesh = mesh_owner_object.to_mesh() | |||||
| depsgraph = context.evaluated_depsgraph_get() | |||||
| bm = bmesh.new() | |||||
| for ob in obs: | |||||
| if use_mesh_modifiers: | |||||
| ob_eval = ob.evaluated_get(depsgraph) | |||||
| else: | |||||
| ob_eval = ob | |||||
| me = ob_eval.to_mesh() | |||||
| me.transform(ob.matrix_world) | |||||
| if not mesh: | bm.from_mesh(me) | ||||
| raise Exception("Error, could not get mesh data from active object") | |||||
| ob_eval.to_mesh_clear() | |||||
| mesh = bpy.data.meshes.new("TMP PLY EXPORT") | |||||
| bm.to_mesh(mesh) | |||||
| bm.free() | |||||
| if global_matrix is not None: | |||||
| mesh.transform(global_matrix) | |||||
| mesh.transform(global_matrix @ obj.matrix_world) | |||||
| if use_normals: | if use_normals: | ||||
| mesh.calc_normals() | mesh.calc_normals() | ||||
| ret = save_mesh(filepath, mesh, | ret = save_mesh( | ||||
| use_normals=use_normals, | filepath, | ||||
| use_uv_coords=use_uv_coords, | mesh, | ||||
| use_colors=use_colors, | use_normals=use_normals, | ||||
| ) | use_uv_coords=use_uv_coords, | ||||
| use_colors=use_colors, | |||||
| ) | |||||
| mesh_owner_object.to_mesh_clear() | bpy.data.meshes.remove(mesh) | ||||
| return ret | return ret | ||||
| Context not available. | |||||