[Bf-extensions-cvs] [8f1c831a] master: 3D-Print: new export option Data Layers

Mikhail Rachinskiy noreply at git.blender.org
Fri May 14 13:24:57 CEST 2021


Commit: 8f1c831af6419c469f5da22e013e67163662b15d
Author: Mikhail Rachinskiy
Date:   Fri May 14 15:12:47 2021 +0400
Branches: master
https://developer.blender.org/rBA8f1c831af6419c469f5da22e013e67163662b15d

3D-Print: new export option Data Layers

Enables export of normals, UVs, vertex colors and materials for
formats that support it.
Disabled by default to reduce filesize.

===================================================================

M	object_print3d_utils/__init__.py
M	object_print3d_utils/export.py
M	object_print3d_utils/ui.py

===================================================================

diff --git a/object_print3d_utils/__init__.py b/object_print3d_utils/__init__.py
index 9a2aefbe..87a69155 100644
--- a/object_print3d_utils/__init__.py
+++ b/object_print3d_utils/__init__.py
@@ -61,10 +61,10 @@ class SceneProperties(PropertyGroup):
         name="Format",
         description="Format type to export to",
         items=(
-            ('STL', "STL", ""),
+            ('OBJ', "OBJ", ""),
             ('PLY', "PLY", ""),
+            ('STL', "STL", ""),
             ('X3D', "X3D", ""),
-            ('OBJ', "OBJ", ""),
         ),
         default='STL',
     )
@@ -78,6 +78,13 @@ class SceneProperties(PropertyGroup):
         description="Apply scene scale setting on export",
         default=False,
     )
+    use_data_layers: BoolProperty(
+        name="Data Layers",
+        description=(
+            "Export normals, UVs, vertex colors and materials for formats that support it "
+            "significantly increasing filesize"
+        ),
+    )
     export_path: StringProperty(
         name="Export Directory",
         description="Path to directory where the files are created",
diff --git a/object_print3d_utils/export.py b/object_print3d_utils/export.py
index fc225ccc..2f846aaf 100644
--- a/object_print3d_utils/export.py
+++ b/object_print3d_utils/export.py
@@ -81,6 +81,7 @@ def write_mesh(context, report_cb):
     path_mode = 'COPY' if print_3d.use_export_texture else 'AUTO'
     export_path = bpy.path.abspath(print_3d.export_path)
     obj = layer.objects.active
+    export_data_layers = print_3d.use_data_layers
 
     # Create name 'export_path/blendname-objname'
     # add the filename component
@@ -129,9 +130,13 @@ def write_mesh(context, report_cb):
         filepath = bpy.path.ensure_ext(filepath, ".ply")
         ret = bpy.ops.export_mesh.ply(
             filepath=filepath,
+            use_ascii=False,
             use_mesh_modifiers=True,
             use_selection=True,
             global_scale=global_scale,
+            use_normals=export_data_layers,
+            use_uv_coords=export_data_layers,
+            use_colors=export_data_layers,
         )
     elif export_format == 'X3D':
         addon_ensure("io_scene_x3d")
@@ -140,8 +145,9 @@ def write_mesh(context, report_cb):
             filepath=filepath,
             use_mesh_modifiers=True,
             use_selection=True,
-            path_mode=path_mode,
             global_scale=global_scale,
+            path_mode=path_mode,
+            use_normals=export_data_layers,
         )
     elif export_format == 'OBJ':
         addon_ensure("io_scene_obj")
@@ -150,16 +156,18 @@ def write_mesh(context, report_cb):
             filepath=filepath,
             use_mesh_modifiers=True,
             use_selection=True,
-            path_mode=path_mode,
             global_scale=global_scale,
+            path_mode=path_mode,
+            use_normals=export_data_layers,
+            use_uvs=export_data_layers,
+            use_materials=export_data_layers,
         )
     else:
         assert 0
 
     # for formats that don't support images
-    if export_format in {'STL', 'PLY'}:
-        if path_mode == 'COPY':
-            image_copy_guess(filepath, context.selected_objects)
+    if path_mode == 'COPY' and export_format in {'STL', 'PLY'}:
+        image_copy_guess(filepath, context.selected_objects)
 
     if 'FINISHED' in ret:
         if report_cb is not None:
diff --git a/object_print3d_utils/ui.py b/object_print3d_utils/ui.py
index 83dda62b..6a0f6d6f 100644
--- a/object_print3d_utils/ui.py
+++ b/object_print3d_utils/ui.py
@@ -143,10 +143,13 @@ class VIEW3D_PT_print3d_export(View3DPrintPanel, Panel):
         print_3d = context.scene.print_3d
 
         layout.prop(print_3d, "export_path", text="")
+        layout.prop(print_3d, "export_format")
 
         col = layout.column()
         col.prop(print_3d, "use_apply_scale")
         col.prop(print_3d, "use_export_texture")
+        sub = col.column()
+        sub.active = print_3d.export_format != "STL"
+        sub.prop(print_3d, "use_data_layers")
 
-        layout.prop(print_3d, "export_format")
         layout.operator("mesh.print3d_export", text="Export", icon='EXPORT')



More information about the Bf-extensions-cvs mailing list