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-16 12:37:11 +0300
committerMikhail Rachinskiy <mikhail.rachinskiy@gmail.com>2019-10-16 12:37:11 +0300
commit20f0c81f9a5bf86b05944655b76c46d1f163766a (patch)
tree5ae6f9195b6c396ab9b5c554e5b51b46a49e9634 /object_print3d_utils
parenta3087a1cc4bca076c9a230e99c2bc1dd7c49a5dc (diff)
3D-Print: remove object join workaround for PLY export
PLY exporter now supports export selection. Also do not force active object into selection.
Diffstat (limited to 'object_print3d_utils')
-rw-r--r--object_print3d_utils/export.py38
-rw-r--r--object_print3d_utils/mesh_helpers.py61
2 files changed, 3 insertions, 96 deletions
diff --git a/object_print3d_utils/export.py b/object_print3d_utils/export.py
index d1359ecf..bb451692 100644
--- a/object_print3d_utils/export.py
+++ b/object_print3d_utils/export.py
@@ -54,34 +54,15 @@ def image_copy_guess(filepath, objects):
def write_mesh(context, report_cb):
scene = context.scene
- collection = context.collection
layer = context.view_layer
unit = scene.unit_settings
print_3d = scene.print_3d
- obj = layer.objects.active
-
export_format = print_3d.export_format
global_scale = unit.scale_length if (unit.system != 'NONE' and print_3d.use_apply_scale) else 1.0
path_mode = 'COPY' if print_3d.use_export_texture else 'AUTO'
-
- context_override = context.copy()
- obj_tmp = None
-
- # PLY can only export single mesh objects!
- if export_format == 'PLY':
- context_backup = context.copy()
- bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
-
- from . import mesh_helpers
- obj_tmp = mesh_helpers.object_merge(context, context_override["selected_objects"])
- context_override["active_object"] = obj_tmp
- context_override["selected_objects"] = [obj_tmp]
- else:
- if obj not in context_override["selected_objects"]:
- context_override["selected_objects"].append(obj)
-
export_path = bpy.path.abspath(print_3d.export_path)
+ obj = layer.objects.active
# Create name 'export_path/blendname-objname'
# add the filename component
@@ -119,7 +100,6 @@ def write_mesh(context, report_cb):
addon_ensure("io_mesh_stl")
filepath = bpy.path.ensure_ext(filepath, ".stl")
ret = bpy.ops.export_mesh.stl(
- context_override,
filepath=filepath,
ascii=False,
use_mesh_modifiers=True,
@@ -130,16 +110,15 @@ def write_mesh(context, report_cb):
addon_ensure("io_mesh_ply")
filepath = bpy.path.ensure_ext(filepath, ".ply")
ret = bpy.ops.export_mesh.ply(
- context_override,
filepath=filepath,
use_mesh_modifiers=True,
+ use_selection=True,
global_scale=global_scale,
)
elif export_format == 'X3D':
addon_ensure("io_scene_x3d")
filepath = bpy.path.ensure_ext(filepath, ".x3d")
ret = bpy.ops.export_scene.x3d(
- context_override,
filepath=filepath,
use_mesh_modifiers=True,
use_selection=True,
@@ -150,7 +129,6 @@ def write_mesh(context, report_cb):
addon_ensure("io_scene_vrml2")
filepath = bpy.path.ensure_ext(filepath, ".wrl")
ret = bpy.ops.export_scene.vrml2(
- context_override,
filepath=filepath,
use_mesh_modifiers=True,
use_selection=True,
@@ -161,7 +139,6 @@ def write_mesh(context, report_cb):
addon_ensure("io_scene_obj")
filepath = bpy.path.ensure_ext(filepath, ".obj")
ret = bpy.ops.export_scene.obj(
- context_override,
filepath=filepath,
use_mesh_modifiers=True,
use_selection=True,
@@ -174,16 +151,7 @@ def write_mesh(context, report_cb):
# for formats that don't support images
if export_format in {'STL', 'PLY'}:
if path_mode == 'COPY':
- image_copy_guess(filepath, context_override["selected_objects"])
-
- if obj_tmp is not None:
- bpy.data.meshes.remove(obj_tmp.data) # Automatically unlinks and removes object
-
- # restore context
- for ob in context_backup["selected_objects"]:
- ob.select_set(True)
-
- layer.objects.active = context_backup["active_object"]
+ image_copy_guess(filepath, context.selected_objects)
if 'FINISHED' in ret:
if report_cb is not None:
diff --git a/object_print3d_utils/mesh_helpers.py b/object_print3d_utils/mesh_helpers.py
index 37170e53..6bf280af 100644
--- a/object_print3d_utils/mesh_helpers.py
+++ b/object_print3d_utils/mesh_helpers.py
@@ -192,67 +192,6 @@ def bmesh_check_thick_object(obj, thickness):
return array.array('i', faces_error)
-def object_merge(context, objects):
- """Caller must remove."""
-
- import bpy
-
- def cd_remove_all_but_active(seq):
- tot = len(seq)
- if tot > 1:
- act = seq.active_index
- for i in range(tot - 1, -1, -1):
- if i != act:
- seq.remove(seq[i])
-
- scene = context.scene
- layer = context.view_layer
- scene_collection = context.layer_collection.collection
-
- # deselect all
- for obj in scene.objects:
- obj.select_set(False)
-
- # add empty object
- mesh_tmp = bpy.data.meshes.new(name="~tmp~")
- obj_tmp = bpy.data.objects.new(name="~tmp~", object_data=mesh_tmp)
- scene_collection.objects.link(obj_tmp)
- obj_tmp.select_set(True)
-
- depsgraph = context.evaluated_depsgraph_get()
-
- # loop over all meshes
- for obj in objects:
- if obj.type != 'MESH':
- continue
-
- # convert each to a mesh
- obj_eval = obj.evaluated_get(depsgraph)
- mesh_new = obj_eval.to_mesh().copy()
-
- # remove non-active uvs/vcols
- cd_remove_all_but_active(mesh_new.vertex_colors)
- cd_remove_all_but_active(mesh_new.uv_layers)
-
- # join into base mesh
- obj_new = bpy.data.objects.new(name="~tmp-new~", object_data=mesh_new)
- scene_collection.objects.link(obj_new)
- obj_new.matrix_world = obj.matrix_world
-
- override = context.copy()
- override["active_object"] = obj_tmp
- override["selected_editable_objects"] = [obj_tmp, obj_new]
-
- bpy.ops.object.join(override)
-
- bpy.data.meshes.remove(mesh_new)
- obj_eval.to_mesh_clear()
-
- layer.update()
-
- return obj_tmp
-
-
def face_is_distorted(ele, angle_distort):
no = ele.normal
angle_fn = no.angle