[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4245] contrib/py/scripts/addons: new addon for 3d printer utilities.
Campbell Barton
ideasman42 at gmail.com
Fri Feb 8 12:12:22 CET 2013
Revision: 4245
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4245
Author: campbellbarton
Date: 2013-02-08 11:12:21 +0000 (Fri, 08 Feb 2013)
Log Message:
-----------
new addon for 3d printer utilities.
Added Paths:
-----------
contrib/py/scripts/addons/object_print3d_utils/
contrib/py/scripts/addons/object_print3d_utils/__init__.py
contrib/py/scripts/addons/object_print3d_utils/export.py
contrib/py/scripts/addons/object_print3d_utils/mesh_helpers.py
contrib/py/scripts/addons/object_print3d_utils/operators.py
contrib/py/scripts/addons/object_print3d_utils/readme.rst
contrib/py/scripts/addons/object_print3d_utils/report.py
contrib/py/scripts/addons/object_print3d_utils/todo.rst
contrib/py/scripts/addons/object_print3d_utils/ui.py
Added: contrib/py/scripts/addons/object_print3d_utils/__init__.py
===================================================================
--- contrib/py/scripts/addons/object_print3d_utils/__init__.py (rev 0)
+++ contrib/py/scripts/addons/object_print3d_utils/__init__.py 2013-02-08 11:12:21 UTC (rev 4245)
@@ -0,0 +1,138 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8-80 compliant>
+
+bl_info = {
+ "name": "3D Print Toolbox",
+ "author": "Campbell Barton",
+ "blender": (2, 65, 0),
+ "location": "3D View > Toolbox",
+ "description": "Utilities for 3D printing",
+ "warning": "",
+ "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+ "Scripts/XXX",
+ "tracker_url": "",
+ "support": 'OFFICIAL',
+ "category": "Mesh"}
+
+
+if "bpy" in locals():
+ import imp
+ imp.reload(ui)
+ imp.reload(operators)
+else:
+ import bpy
+ from bpy.props import (StringProperty,
+ BoolProperty,
+ IntProperty,
+ FloatProperty,
+ FloatVectorProperty,
+ EnumProperty,
+ PointerProperty,
+ )
+ from bpy.types import (Operator,
+ AddonPreferences,
+ PropertyGroup,
+ )
+ from . import ui
+ from . import operators
+
+import math
+
+class Print3DSettings(PropertyGroup):
+ export_format = EnumProperty(
+ name="Format",
+ description="Format type to export to",
+ items=(('STL', "STL", ""),
+ ('PLY', "PLY", ""),
+ ('X3D', "X3D", ""),
+ ('OBJ', "OBJ", "")),
+ default='STL',
+ )
+ export_path = StringProperty(
+ name="Export Directory",
+ description="Path to directory where the files are created",
+ default="//", maxlen=1024, subtype="DIR_PATH",
+ )
+ angle_sharp = FloatProperty(
+ name="Angle",
+ subtype='ANGLE',
+ default=math.radians(160.0),
+ min=0.0, max=math.radians(180.0),
+ )
+ thickness_min = FloatProperty(
+ name="Thickness",
+ description="Minimum thickness",
+ subtype='DISTANCE',
+ default=0.01,
+ min=0.0, max=1.0,
+ )
+ threshold_zero = FloatProperty(
+ name="Threshold",
+ description="Limit for checking zero area/length",
+ default=0.0001,
+ precision=5,
+ min=0.0, max=0.2,
+ )
+ angle_distort = FloatProperty(
+ name="Angle",
+ description="Limit for checking distorted faces",
+ subtype='ANGLE',
+ default=math.radians(15.0),
+ min=0.0, max=math.radians(180.0),
+ )
+
+classes = (
+ ui.Print3DToolBarObject,
+ ui.Print3DToolBarMesh,
+
+ operators.Print3DInfoVolume,
+ operators.Print3DInfoArea,
+
+ operators.Print3DCheckDegenerate,
+ operators.Print3DCheckSolid,
+ operators.Print3DCheckIntersections,
+ operators.Print3DCheckThick,
+ operators.Print3DCheckSharp,
+ operators.Print3DCheckAll,
+
+ operators.Print3DCleanIsolated,
+ operators.Print3DCleanDistorted,
+ operators.Print3DCleanThin,
+
+ operators.Print3DSelectReport,
+
+ operators.Print3DExport,
+
+ Print3DSettings,
+ )
+
+
+def register():
+ for cls in classes:
+ bpy.utils.register_class(cls)
+
+ bpy.types.Scene.print_3d = PointerProperty(type=Print3DSettings)
+
+
+def unregister():
+ for cls in classes:
+ bpy.utils.unregister_class(cls)
+
+ del bpy.types.Scene.print_3d
Added: contrib/py/scripts/addons/object_print3d_utils/export.py
===================================================================
--- contrib/py/scripts/addons/object_print3d_utils/export.py (rev 0)
+++ contrib/py/scripts/addons/object_print3d_utils/export.py 2013-02-08 11:12:21 UTC (rev 4245)
@@ -0,0 +1,111 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8-80 compliant>
+
+# Export wrappers and integration with external tools.
+
+import bpy
+import os
+
+
+def write_mesh(context, info, report_cb):
+ scene = context.scene
+ print_3d = scene.print_3d
+
+ obj_base = scene.object_bases.active
+ obj = obj_base.object
+
+ context_override = context.copy()
+ context_override["selected_bases"] = [obj_base]
+ context_override["selected_objects"] = [obj]
+
+ export_format = print_3d.export_format
+
+ export_path = bpy.path.abspath(print_3d.export_path)
+
+ # Create name 'export_path/blendname-objname'
+ # add the filename component
+ if bpy.data.is_saved:
+ name = os.path.basename(bpy.data.filepath)
+ name = os.path.splitext(name)[0]
+ else:
+ name = "untitled"
+ # add object name
+ name += "-%s" % bpy.path.clean_name(obj.name)
+
+ # first ensure the path is created
+ os.makedirs(export_path, exist_ok=True)
+
+ filepath = os.path.join(export_path, name)
+
+ # ensure addon is enabled
+ import addon_utils
+
+ def addon_ensure(addon_id):
+ # Enable the addon, dont change preferences.
+ default_state, loaded_state = addon_utils.check(addon_id)
+ if not loaded_state:
+ addon_utils.enable(addon_id, default_set=False)
+
+ if export_format == 'STL':
+ 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,
+ )
+ elif export_format == 'PLY':
+ 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,
+ )
+ 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,
+ )
+ elif export_format == 'OBJ':
+ 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,
+ )
+ else:
+ assert(0)
+
+ if 'FINISHED' in ret:
+ info.append(("%r ok" % os.path.basename(filepath), None))
+
+ if report_cb is not None:
+ report_cb({'INFO'}, "Exported: %r" % filepath)
+ return True
+ else:
+ info.append(("%r fail" % os.path.basename(filepath), None))
+ return False
Added: contrib/py/scripts/addons/object_print3d_utils/mesh_helpers.py
===================================================================
--- contrib/py/scripts/addons/object_print3d_utils/mesh_helpers.py (rev 0)
+++ contrib/py/scripts/addons/object_print3d_utils/mesh_helpers.py 2013-02-08 11:12:21 UTC (rev 4245)
@@ -0,0 +1,249 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8-80 compliant>
+
+# Generic helper functions, to be used by any modules.
+
+import bmesh
+import array
+
+
+def bmesh_copy_from_object(obj, transform=True, triangulate=True):
+ """
+ Returns a transformed, triangulated copy of the mesh
+ """
+
+ assert(obj.type == 'MESH')
+
+ me = obj.data
+ if obj.mode == 'EDIT':
+ bm_orig = bmesh.from_edit_mesh(me)
+ bm = bm_orig.copy()
+ else:
+ bm = bmesh.new()
+ bm.from_mesh(me)
+
+ # TODO. remove all customdata layers.
+ # would save ram
+
+ if transform:
+ bm.transform(obj.matrix_world)
+
+ if triangulate:
+ bmesh.ops.triangulate(bm, faces=bm.faces, use_beauty=True)
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list