Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Rachinskiy <mikhail.rachinskiy@gmail.com>2019-10-15 11:39:44 +0300
committerMikhail Rachinskiy <mikhail.rachinskiy@gmail.com>2019-10-15 11:39:44 +0300
commitf93992f6efe6afa5eb70a7f1d9ec5c6375fcb659 (patch)
tree9417c0cc07c7308f941ca166cec9bc8e28d2dd7b /io_mesh_ply/export_ply.py
parent9dcfa9d13a1617e05b13bb4ea4d364242b48fdbe (diff)
PLY exporter: export selection or scene
D6060 now PLY exporter behaves similar to the rest of the export add-ons.
Diffstat (limited to 'io_mesh_ply/export_ply.py')
-rw-r--r--io_mesh_ply/export_ply.py58
1 files changed, 37 insertions, 21 deletions
diff --git a/io_mesh_ply/export_ply.py b/io_mesh_ply/export_ply.py
index db79e950..8424bb36 100644
--- a/io_mesh_ply/export_ply.py
+++ b/io_mesh_ply/export_ply.py
@@ -189,43 +189,59 @@ def save(
operator,
context,
filepath="",
+ use_selection=False,
use_mesh_modifiers=True,
use_normals=True,
use_uv_coords=True,
use_colors=True,
global_matrix=None
):
- obj = context.active_object
-
- if global_matrix is None:
- from mathutils import Matrix
- global_matrix = Matrix()
+ import bmesh
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode='OBJECT')
- mesh_owner_object = None
- if use_mesh_modifiers and obj.modifiers:
- depsgraph = context.evaluated_depsgraph_get()
- mesh_owner_object = obj.evaluated_get(depsgraph)
- mesh = mesh_owner_object.to_mesh()
+ if use_selection:
+ obs = context.selected_objects
else:
- mesh_owner_object = obj
- mesh = mesh_owner_object.to_mesh()
+ obs = context.scene.objects
+
+ 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
+
+ try:
+ me = ob_eval.to_mesh()
+ except RuntimeError:
+ continue
- if not mesh:
- raise Exception("Error, could not get mesh data from active object")
+ me.transform(ob.matrix_world)
+ bm.from_mesh(me)
+ 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:
mesh.calc_normals()
- ret = save_mesh(filepath, mesh,
- use_normals=use_normals,
- use_uv_coords=use_uv_coords,
- use_colors=use_colors,
- )
+ ret = save_mesh(
+ filepath,
+ mesh,
+ 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