[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3757] branches/protopipe/modelbuilder. py: Model gets inserted into scene + automatic naming

Aurel W aurel.w at gmail.com
Wed Sep 19 00:47:38 CEST 2012


Revision: 3757
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3757
Author:   aurel
Date:     2012-09-18 22:47:38 +0000 (Tue, 18 Sep 2012)
Log Message:
-----------
Model gets inserted into scene + automatic naming
Still registration issues.

Modified Paths:
--------------
    branches/protopipe/modelbuilder.py

Modified: branches/protopipe/modelbuilder.py
===================================================================
--- branches/protopipe/modelbuilder.py	2012-09-18 22:46:44 UTC (rev 3756)
+++ branches/protopipe/modelbuilder.py	2012-09-18 22:47:38 UTC (rev 3757)
@@ -28,12 +28,15 @@
 
 class ModelBuilder:
 
-    def __init__(self):
+    def __init__(self, obj):
+        self.buildLayer = 1
+        self.obj = obj
+        self.nextJointName = self.nextJointNameGen().__next__
         pass
 
-    def buildOnMesh(self, mesh):
+    def buildOnMesh(self):
         bm = bmesh.new()
-        bm.from_mesh(mesh)
+        bm.from_mesh(self.obj.data)
         bm.verts.index_update()
         bm.edges.index_update()
 
@@ -41,6 +44,33 @@
         for vert in bm.verts:
             desc = JointDescriptor()
             desc.buildFromVert(bm, vert.index)
-            
             (reg, rot_mat, jproto) = ppapp.jointFactory.getProto(desc)
-            print("reg: ", reg)
+            if reg:
+                self.insertJoint(vert.co, rot_mat, jproto)
+
+
+    def insertJoint(self, co, rot_mat, jproto):
+        #nobj = jproto.model.copy()
+        #FIXME voodoo workaround
+        print("model: ", jproto.model)
+        nobj = bpy.data.objects[jproto.model.name].copy()
+        # put on a layer
+        nobj.layers[self.buildLayer] = True
+        # translate
+        nobj.location = co
+        # rotate (convert to blender matrix)
+        bmat = mathutils.Matrix(rot_mat.tolist())
+        nobj.rotation_euler = bmat.to_euler()
+        # set the name
+        nobj.name = self.nextJointName()
+        #FIXME segfaults here
+        bpy.context.scene.objects.link(nobj)
+
+
+    def nextJointNameGen(self):
+        i = 0
+        while True:
+            yield self.obj.name + "_j" + str(i)
+            i += 1
+
+



More information about the Bf-extensions-cvs mailing list