From b1674bee0ecbd77bc28f35e476a9d93eb2e49531 Mon Sep 17 00:00:00 2001 From: Kosvor2 Date: Mon, 20 Mar 2017 08:00:01 +0500 Subject: [PATCH 1/4] Create bvh_overlap_polys.py --- nodes/analyzer/bvh_overlap_polys.py | 79 +++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 nodes/analyzer/bvh_overlap_polys.py diff --git a/nodes/analyzer/bvh_overlap_polys.py b/nodes/analyzer/bvh_overlap_polys.py new file mode 100644 index 000000000..2c924eed2 --- /dev/null +++ b/nodes/analyzer/bvh_overlap_polys.py @@ -0,0 +1,79 @@ +# ##### 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 ##### + +import bpy +import numpy as np +from mathutils.bvhtree import BVHTree +from bpy.props import FloatProperty, BoolProperty +from sverchok.node_tree import SverchCustomTreeNode +from sverchok.data_structure import (updateNode) + + +class SvBvhOverlapNode(bpy.types.Node, SverchCustomTreeNode): + ''' BVH Tree Overlap ''' + bl_idname = 'SvBvhOverlapNode' + bl_label = 'bvh_overlap' + bl_icon = 'OUTLINER_OB_EMPTY' + + triangles = BoolProperty(name="all triangles", + description="all triangles", default=False, + update=updateNode) + + epsilon = FloatProperty(name="epsilon", + default=0.0, min=0.0, max=10.0, + update=updateNode) + + def draw_buttons(self, context, layout): + layout.prop(self, "triangles") + layout.prop(self, "epsilon") + + def sv_init(self, context): + self.inputs.new('StringsSocket', 'Vert(A)') + self.inputs.new('StringsSocket', 'Poly(A)') + self.inputs.new('StringsSocket', 'Vert(B)') + self.inputs.new('StringsSocket', 'Poly(B)') + self.outputs.new('StringsSocket', 'PolyIndex(A)') + self.outputs.new('StringsSocket', 'PolyIndex(B)') + self.outputs.new('StringsSocket', 'OverlapPoly(A)') + self.outputs.new('StringsSocket', 'OverlapPoly(B)') + + def process(self): + btr = BVHTree.FromPolygons + V1, P1, V2, P2 = [i.sv_get()[0] for i in self.inputs] + outIndA, outIndB, Pover1, Pover2 = self.outputs + Tri, epsi = self.triangles, self.epsilon + T1 = btr(V1, P1, all_triangles = Tri, epsilon = epsi) + T2 = btr(V2, P2, all_triangles = Tri, epsilon = epsi) + ind1 = np.unique([i[0] for i in T1.overlap(T2)]).tolist() + ind2 = np.unique([i[1] for i in T1.overlap(T2)]).tolist() + if outIndA.is_linked: + outIndA.sv_set([ind1]) + if outIndB.is_linked: + outIndB.sv_set([ind2]) + if Pover1.is_linked: + Pover1.sv_set([[P1[i] for i in ind1]]) + if Pover2.is_linked: + Pover2.sv_set([[P2[i] for i in ind2]]) + + +def register(): + bpy.utils.register_class(SvBvhOverlapNode) + + +def unregister(): + bpy.utils.unregister_class(SvBvhOverlapNode) -- GitLab From 3df40f37c55435ef7f7014ed2296ca39eee49e0e Mon Sep 17 00:00:00 2001 From: Kosvor2 Date: Mon, 20 Mar 2017 08:04:51 +0500 Subject: [PATCH 2/4] Update bvh_overlap_polys.py --- nodes/analyzer/bvh_overlap_polys.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/nodes/analyzer/bvh_overlap_polys.py b/nodes/analyzer/bvh_overlap_polys.py index 2c924eed2..3911ffdac 100644 --- a/nodes/analyzer/bvh_overlap_polys.py +++ b/nodes/analyzer/bvh_overlap_polys.py @@ -24,10 +24,10 @@ from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import (updateNode) -class SvBvhOverlapNode(bpy.types.Node, SverchCustomTreeNode): - ''' BVH Tree Overlap ''' - bl_idname = 'SvBvhOverlapNode' - bl_label = 'bvh_overlap' +class SvBvhOverlapNodeNew(bpy.types.Node, SverchCustomTreeNode): + ''' BVH Tree Overlap New ''' + bl_idname = 'SvBvhOverlapNodeNew' + bl_label = 'overlap_polygons' bl_icon = 'OUTLINER_OB_EMPTY' triangles = BoolProperty(name="all triangles", @@ -72,8 +72,8 @@ class SvBvhOverlapNode(bpy.types.Node, SverchCustomTreeNode): def register(): - bpy.utils.register_class(SvBvhOverlapNode) + bpy.utils.register_class(SvBvhOverlapNodeNew) def unregister(): - bpy.utils.unregister_class(SvBvhOverlapNode) + bpy.utils.unregister_class(SvBvhOverlapNodeNew) -- GitLab From 70edf08ee6257ab7934a264f8bc0c28dc03ea44e Mon Sep 17 00:00:00 2001 From: Kosvor2 Date: Tue, 21 Mar 2017 11:19:13 +0500 Subject: [PATCH 3/4] Update bvh_overlap_polys.py --- nodes/analyzer/bvh_overlap_polys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodes/analyzer/bvh_overlap_polys.py b/nodes/analyzer/bvh_overlap_polys.py index 3911ffdac..3d581cff9 100644 --- a/nodes/analyzer/bvh_overlap_polys.py +++ b/nodes/analyzer/bvh_overlap_polys.py @@ -38,7 +38,7 @@ class SvBvhOverlapNodeNew(bpy.types.Node, SverchCustomTreeNode): default=0.0, min=0.0, max=10.0, update=updateNode) - def draw_buttons(self, context, layout): + def draw_buttons_ext(self, context, layout): layout.prop(self, "triangles") layout.prop(self, "epsilon") -- GitLab From eacecf27c5cf61b3b399af9581f8fc9318cfdcff Mon Sep 17 00:00:00 2001 From: Kosvor2 Date: Tue, 21 Mar 2017 11:22:53 +0500 Subject: [PATCH 4/4] Update index.md --- index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/index.md b/index.md index 3b38faa2a..f6fc8cf22 100644 --- a/index.md +++ b/index.md @@ -267,3 +267,4 @@ SvBMtoElementNode SvExecNodeMod SvSeparateMeshNodeMK2 + SvBvhOverlapNodeNew -- GitLab