[Bf-extensions-cvs] [a395b21] master: Bool Tools: T48309 new contrib addon, replaces object_booleans.py

meta-androcto noreply at git.blender.org
Sun May 1 02:57:48 CEST 2016


Commit: a395b213049fc3b66c8903fb603a7eb22b82a86a
Author: meta-androcto
Date:   Sun May 1 10:57:22 2016 +1000
Branches: master
https://developer.blender.org/rBACa395b213049fc3b66c8903fb603a7eb22b82a86a

Bool Tools: T48309 new contrib addon, replaces object_booleans.py

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

A	BoolTool.py
D	object_booleans.py

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

diff --git a/BoolTool.py b/BoolTool.py
new file mode 100644
index 0000000..ac0a479
--- /dev/null
+++ b/BoolTool.py
@@ -0,0 +1,1264 @@
+# ##### 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 ##### actObj.grease_pencil.clear()" by "bpy.context.scene.grease_pencil.clear()
+# Contributed to by TynkaTopi, meta-androcto
+
+bl_info = {
+    "name": "BoolTool",
+    "author": "Vitor Balbio, Mikhail Rachinskiy",
+    "version": (0, 3, 0),
+    "blender": (2, 77, 0),
+    "location": "View3D > Toolshelf > BoolTool",
+    "description": "Bool Tools Hotkey: ctrl,shift,B",
+    "warning": "",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Object/BoolTool",
+    "tracker_url": "https://developer.blender.org/maniphest/task/create/?project=3&type=Bug",
+    "category": "Object"}
+
+import bpy
+import bmesh
+import time
+from bpy.app.handlers import persistent
+from bpy.types import Operator
+
+
+# -------------------  Bool Tool FUNCTIONS------------------------------
+# Utils:
+
+# Hide boolean objects
+def update_BoolHide(self, context):
+	ao = context.scene.objects.active
+	objs = [i.object for i in ao.modifiers if i.type == 'BOOLEAN']
+	bool = False
+	if context.scene.BoolHide:
+		bool = True
+
+	for o in objs:
+		o.hide = bool
+
+# Object is a Canvas
+def isCanvas(_obj):
+    try:
+        if _obj["BoolToolRoot"]:
+            return True
+    except:
+        return False
+
+
+# Object is a Brush Tool Bool
+def isBrush(_obj):
+    try:
+        if _obj["BoolToolBrush"]:
+            return True
+    except:
+        return False
+
+
+# Object is a Poly Brush Tool Bool
+def isPolyBrush(_obj):
+    try:
+        if _obj["BoolToolPolyBrush"]:
+            return True
+    except:
+        return False
+
+
+def BT_ObjectByName(obj):
+    for ob in bpy.context.scene.objects:
+        if isCanvas(ob) or isBrush(ob):
+            if ob.name == obj:
+                return ob
+
+
+def FindCanvas(obj):
+    for ob in bpy.context.scene.objects:
+        if isCanvas(ob):
+            for mod in ob.modifiers:
+                if ("BTool_" in mod.name):
+                    if (obj.name in mod.name):
+                        return ob
+
+
+def isFTransf():
+    user_preferences = bpy.context.user_preferences
+    addon_prefs = user_preferences.addons[bl_info["name"]].preferences
+    if addon_prefs.fast_transform:
+        return True
+    else:
+        return False
+
+
+"""
+# EXPERIMENTAL FEATURES
+def isMakeVertexGroup():
+    user_preferences = bpy.context.user_preferences
+    addon_prefs = user_preferences.addons[bl_info["name"]].preferences
+    if addon_prefs.make_vertex_groups:
+        return True
+    else:
+        return False
+
+def isMakeBoundary():
+    user_preferences = bpy.context.user_preferences
+    addon_prefs = user_preferences.addons[bl_info["name"]].preferences
+    if addon_prefs.make_boundary:
+        return True
+    else:
+        return False
+"""
+
+
+def ConvertToMesh(obj):
+    act = bpy.context.scene.objects.active
+    bpy.context.scene.objects.active = obj
+    bpy.ops.object.convert(target="MESH")
+    bpy.context.scene.objects.active = act
+
+
+# Do the Union, Difference and Intersection Operations with a Brush
+def Operation(context, _operation):
+
+    useWire = bpy.context.user_preferences.addons['BoolTool'].preferences.use_wire
+
+    for selObj in bpy.context.selected_objects:
+        if selObj != context.active_object and (selObj.type == "MESH" or selObj.type == "CURVE"):
+            if selObj.type == "CURVE":
+                ConvertToMesh(selObj)
+            actObj = context.active_object
+            selObj.hide_render = True
+            cyclesVis = selObj.cycles_visibility
+            # for obj in bpy.context.scene.objects:
+            #   if isCanvas(obj):
+            #      for mod in obj.modifiers:
+            #         if(mod.name == "BTool_" + selObj.name):
+            #            obj.modifiers.remove(mod)
+
+            if useWire:
+                selObj.draw_type = "WIRE"
+            else:
+                selObj.draw_type = "BOUNDS"
+
+            cyclesVis.camera = False;
+            cyclesVis.diffuse = False;
+            cyclesVis.glossy = False;
+            cyclesVis.shadow = False;
+            cyclesVis.transmission = False;
+            if _operation=="SLICE":
+                clone=context.active_object.copy() #copies dupli_group property(empty), but group property is empty (users_group = None)
+                # clone.select=True
+                context.scene.objects.link(clone)
+                sliceMod = clone.modifiers.new("BTool_" + selObj.name, "BOOLEAN") #add mod to clone obj
+                sliceMod.object = selObj
+                sliceMod.operation = "DIFFERENCE"
+                clone["BoolToolRoot"] = True
+            newMod = actObj.modifiers.new("BTool_" + selObj.name, "BOOLEAN")
+            newMod.object = selObj
+            if _operation=="SLICE":
+                newMod.operation = "INTERSECT"
+            else:
+                newMod.operation = _operation
+
+            actObj["BoolToolRoot"] = True
+            selObj["BoolToolBrush"] = _operation
+            selObj["BoolTool_FTransform"] = "False"
+
+
+# Do Direct Union, Difference and Intersection Operations
+def Operation_Direct(context, _operation):
+    actObj = context.active_object
+
+    useWire = bpy.context.user_preferences.addons['name'].preferences.use_wire
+    for selObj in bpy.context.selected_objects:
+        if selObj != context.active_object and (selObj.type == "MESH" or selObj.type == "CURVE"):
+            if selObj.type == "CURVE":
+                ConvertToMesh(selObj)
+            actObj = context.active_object
+            if useWire:
+                selObj.draw_type = "WIRE"
+            else:
+                selObj.draw_type = "BOUNDS"
+            if _operation=="SLICE":
+                clone=context.active_object.copy() #copies dupli_group property(empty), but group property is empty (users_group = None)
+                # clone.select=True
+                clone.data=context.active_object.data.copy()
+                context.scene.objects.link(clone)
+                sliceMod = clone.modifiers.new("BTool_" + selObj.name, "BOOLEAN") #add mod to clone obj
+                sliceMod.object = selObj
+                sliceMod.operation = "DIFFERENCE"
+
+                bpy.ops.object.modifier_apply(modifier=sliceMod.name)
+
+            newMod = actObj.modifiers.new("BTool_" + selObj.name, "BOOLEAN")
+            if _operation=="SLICE":
+                newMod.operation = "INTERSECT"
+            else:
+                newMod.operation = _operation
+            newMod.object = selObj
+            bpy.ops.object.modifier_apply(modifier=newMod.name)
+            bpy.ops.object.select_all(action='DESELECT')
+            # selObj.select = True
+            # bpy.ops.object.delete()
+
+
+# Remove Obejcts form the BoolTool System
+def Remove(context, thisObj_name, Prop):
+    # Find the Brush pointed in the Tree View and Restore it, active is the Canvas
+    actObj = context.active_object
+
+    # Restore the Brush
+    def RemoveThis(_thisObj_name):
+        for obj in bpy.context.scene.objects:
+            # if it's the brush object
+            if obj.name == _thisObj_name:
+                cyclesVis = obj.cycles_visibility
+                obj.draw_type = "TEXTURED"
+                del obj["BoolToolBrush"]
+                del obj["BoolTool_FTransform"]
+                cyclesVis.camera = True;
+                cyclesVis.diffuse = True;
+                cyclesVis.glossy = True;
+                cyclesVis.shadow = True;
+                cyclesVis.transmission = True;
+
+                # Remove it from the Canvas
+                for mod in actObj.modifiers:
+                    if ("BTool_" in mod.name):
+                        if (_thisObj_name in mod.name):
+                            actObj.modifiers.remove(mod)
+
+    if Prop == "THIS":
+        RemoveThis(thisObj_name)
+
+    # If the remove was called from the Properties:
+    else:
+        # Remove the Brush Property
+        if Prop == "BRUSH":
+            Canvas = FindCanvas(actObj)
+            for mod in Canvas.modifiers:
+                if ("BTool_" in mod.name):
+                    if (actObj.name in mod.name):
+                        Canvas.modifiers.remove(mod)
+                        cyclesVis = actObj.cycles_visibility
+                        actObj.draw_type = "TEXTURED"
+                        del actObj["BoolToolBrush"]
+                        del actObj["BoolTool_FTransform"]
+                        cyclesVis.camera = True;
+                        cyclesVis.diffuse = True;
+                        cyclesVis.glossy = True;
+                        cyclesVis.shadow = True;
+                        cyclesVis.transmission = True;
+
+        if Prop == "CANVAS":
+            for mod in actObj.modifiers:
+                if ("BTool_" in mod.name):
+                    RemoveThis(mod.object.name)
+
+
+# Tooble the Enable the Brush Object Propertie
+def EnableBrush(context, objList, canvas):
+    for obj in objList:
+        for mod in canvas.modifiers:
+            if ("BTool_" in mod.name and mod.object.name == obj):
+
+                if (mod.show_viewport):
+                    mod.show_viewport = False
+                    mod.show_render = False
+                else:
+                    mod.show_viewport = True
+                    mod.s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list