PLY exporter: export selection or scene
D6060 now PLY exporter behaves similar to the rest of the export add-ons.
This commit is contained in:
parent
9dcfa9d13a
commit
f93992f6ef
|
@ -104,6 +104,11 @@ class ExportPLY(bpy.types.Operator, ExportHelper):
|
|||
filename_ext = ".ply"
|
||||
filter_glob: StringProperty(default="*.ply", options={'HIDDEN'})
|
||||
|
||||
use_selection: BoolProperty(
|
||||
name="Selection Only",
|
||||
description="Export selected objects only",
|
||||
default=False,
|
||||
)
|
||||
use_mesh_modifiers: BoolProperty(
|
||||
name="Apply Modifiers",
|
||||
description="Apply Modifiers to the exported mesh",
|
||||
|
@ -136,10 +141,6 @@ class ExportPLY(bpy.types.Operator, ExportHelper):
|
|||
default=1.0,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.active_object is not None
|
||||
|
||||
def execute(self, context):
|
||||
from . import export_ply
|
||||
|
||||
|
@ -169,6 +170,30 @@ class ExportPLY(bpy.types.Operator, ExportHelper):
|
|||
pass
|
||||
|
||||
|
||||
class PLY_PT_export_include(bpy.types.Panel):
|
||||
bl_space_type = 'FILE_BROWSER'
|
||||
bl_region_type = 'TOOL_PROPS'
|
||||
bl_label = "Include"
|
||||
bl_parent_id = "FILE_PT_operator"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
sfile = context.space_data
|
||||
operator = sfile.active_operator
|
||||
|
||||
return operator.bl_idname == "EXPORT_MESH_OT_ply"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False # No animation.
|
||||
|
||||
sfile = context.space_data
|
||||
operator = sfile.active_operator
|
||||
|
||||
layout.prop(operator, "use_selection")
|
||||
|
||||
|
||||
class PLY_PT_export_transform(bpy.types.Panel):
|
||||
bl_space_type = 'FILE_BROWSER'
|
||||
bl_region_type = 'TOOL_PROPS'
|
||||
|
@ -233,6 +258,7 @@ def menu_func_export(self, context):
|
|||
classes = (
|
||||
ImportPLY,
|
||||
ExportPLY,
|
||||
PLY_PT_export_include,
|
||||
PLY_PT_export_transform,
|
||||
PLY_PT_export_geometry,
|
||||
)
|
||||
|
@ -253,5 +279,6 @@ def unregister():
|
|||
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
|
||||
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
|
|
|
@ -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
|
||||
|
||||
if not mesh:
|
||||
raise Exception("Error, could not get mesh data from active object")
|
||||
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
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue