[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3741] branches/protopipe: First tests to scan joint prototypes from meshes.
Aurel W
aurel.w at gmail.com
Sat Sep 15 18:55:20 CEST 2012
Revision: 3741
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3741
Author: aurel
Date: 2012-09-15 16:55:20 +0000 (Sat, 15 Sep 2012)
Log Message:
-----------
First tests to scan joint prototypes from meshes.
Added Paths:
-----------
branches/protopipe/__init__.py
branches/protopipe/jointproto.py
branches/protopipe/tests.py
Added: branches/protopipe/__init__.py
===================================================================
--- branches/protopipe/__init__.py (rev 0)
+++ branches/protopipe/__init__.py 2012-09-15 16:55:20 UTC (rev 3741)
@@ -0,0 +1,48 @@
+#
+# Copyright 2012, Aurel Wildfellner.
+#
+# 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.
+#
+
+bl_info = {
+ "name": "ProtoPipe",
+ "author": "Aurel Wildfellner",
+ "version": (0, 0),
+ "blender": (2, 6, 3),
+ "location": "View3D > Tool Panel",
+ "description": "An interactive CAM tool to build objects out of pipes.",
+ "warning": "",
+ "wiki_url": "http://wiki.blender.org/index.php/Dev:2.6/",
+ "tracker_url": "",
+ "category": "Object"}
+
+
+
+if "bpy" in locals():
+ import imp
+ imp.reload(protopipe)
+else:
+ from . import *
+
+
+def register():
+ pass
+
+def unregister():
+ pass
+
+if __name__ == "__main__":
+ register()
+
Added: branches/protopipe/jointproto.py
===================================================================
--- branches/protopipe/jointproto.py (rev 0)
+++ branches/protopipe/jointproto.py 2012-09-15 16:55:20 UTC (rev 3741)
@@ -0,0 +1,111 @@
+#
+# Copyright 2012, Aurel Wildfellner.
+#
+# 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.
+#
+
+import bpy
+import bmesh
+from mathutils import *
+
+class JointProto:
+
+ """
+ This Class represent a joint to connect pipes to. The description
+ is loaded from a mesh model prototype.
+
+ Two lengths are specified:
+ The distance of the connecting pipe to the center of the joint.
+ The length of the overlaping part of the joing and the pipe.
+ | |
+ |_|
+ | | <-> // length out
+ | |_______
+ | | |======
+ ----------
+ <---> // length in
+ """
+
+ def __init__(self):
+ # list of normalized vectors
+ self.jointVectors = []
+ # the corresponding lengths of the joint
+ self.jointLengthsIn = []
+ self.jointLengthsOut = []
+ self.name = "Unnamed Joint Prototype"
+ pass
+
+
+ def setName(self, name)
+ self.name = name
+
+
+ def buildFromMeshProto(self, mesh):
+ self.jointVectors = []
+ self.jointLengthsIn = []
+ self.jointLengthsOut = []
+
+ bm = bmesh.new()
+ bm.from_mesh(mesh)
+
+ bm.verts.index_update()
+ bm.edges.index_update()
+
+ center_idx = self.findCenter(bm)
+ edges = bm.verts[center_idx].link_edges
+
+ # process every part of the joint
+ for edge in edges:
+ n_idx = -1
+ v0 = edge.verts[0]
+ v1 = edge.verts[1]
+ # select the right vertex on the edge
+ if v0.index == center_idx:
+ vec = v1.co - v0.co
+ n_idx = v1.index
+ else:
+ vec = v0.co - v1.co
+ n_idx = v0.index
+
+ # add edge as joint element
+ self.jointLengthsIn.append(vec.length)
+ self.jointVectors.append(vec.normalized())
+
+ # get outer length (overlapping segment)
+ for n_edge in bm.verts[n_idx].link_edges:
+ # don't take the last edge
+ if n_edge.index != edge.index:
+ self.jointLengthsOut.append(n_edge.calc_length())
+ break
+
+
+ def registerDescriptor(self, descriptor):
+ pass
+
+
+ def findCenter(self, bm):
+ """Returns the index of the point closest to the origin."""
+ center = Vector((0,0,0))
+ cur_idx = 0
+ cur_dist = 4200000
+ for v in bm.verts:
+ d = (v.co - center).length
+ if (cur_dist > d):
+ cur_dist = d
+ cur_idx = v.index
+ return cur_idx
+
+
+
Added: branches/protopipe/tests.py
===================================================================
--- branches/protopipe/tests.py (rev 0)
+++ branches/protopipe/tests.py 2012-09-15 16:55:20 UTC (rev 3741)
@@ -0,0 +1,15 @@
+
+import bpy
+import bmesh
+from mathutils import *
+
+from protopipe.jointproto import JointProto
+
+
+def findCenter():
+ jp = JointProto()
+ bm = bmesh.new()
+ bm.from_object(bpy.context.active_object)
+ idx = jp.findCenter(bm)
+ print("The index of the center: ", idx)
+
More information about the Bf-extensions-cvs
mailing list