[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3756] branches/protopipe/jointproto.py : Refactored deviation check (>1.0 issue), code more compact now.
Aurel W
aurel.w at gmail.com
Wed Sep 19 00:46:45 CEST 2012
Revision: 3756
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3756
Author: aurel
Date: 2012-09-18 22:46:44 +0000 (Tue, 18 Sep 2012)
Log Message:
-----------
Refactored deviation check (>1.0 issue), code more compact now.
Modified Paths:
--------------
branches/protopipe/jointproto.py
Modified: branches/protopipe/jointproto.py
===================================================================
--- branches/protopipe/jointproto.py 2012-09-18 19:40:32 UTC (rev 3755)
+++ branches/protopipe/jointproto.py 2012-09-18 22:46:44 UTC (rev 3756)
@@ -158,25 +158,27 @@
### check the fit of the current alignment ###
# rotate descritpor points
r_vecs = map (lambda v : numpy.dot(rot_mat, numpy.transpose(v)), md)
+
# compute deviation angles
- deviation_angles = map (lambda v0, v1 :
- math.acos(numpy.dot(v0, v1)),
- r_vecs, mp)
-
deviation_error = False
- for angle in deviation_angles:
- # A threshhold of how the model is alowed to deviate from
- # the descritor, continue with next permutation if error
- # is too high.
- if angle > 0.01:
- print("deviation angle too high")
- deviation_error = True
- break
+ for (v0, v1) in zip(r_vecs, mp):
+ dot = numpy.dot(v0,v1)
+ if dot > 1.0:
+ dot = 1.0
+ elif dot < -1.0:
+ dot = -1.0
+ angle = math.acos(dot)
+ if angle > 0.01:
+ print("deviation angle too high")
+ deviation_error = True
+ break
+
if deviation_error:
continue # with permutation
# everything is fine and aligned
+ print(rot_mat)
return (True, rot_mat)
return (False, None)
@@ -248,12 +250,13 @@
def loadFromBlendFile(self, fpath):
# import external scene
- with bpy.data.libraries.load(fpath) as (ext_data, int_data):
+ with bpy.data.libraries.load(fpath,True) as (ext_data, int_data):
for scenename in ext_data.scenes:
if scenename[:3] == "pp_":
self.name = scenename
# append
if not self.name in int_data.scenes:
+ print("appending library scene")
int_data.scenes = [self.name]
# scan the scene for prototype objects
@@ -268,11 +271,18 @@
# find a model and assign it
modelName = tname[:-5] + "model"
if modelName in objects:
+ print("insert a model: ", modelName, objects[modelName])
jproto.setModel(objects[modelName])
+ else:
+ print("no model found")
# append to lib
self.protos.append(jproto)
+ bpy.data.scenes[self.name].update()
+ for obj in bpy.data.objects:
+ print("objname: ", obj.name)
+
def search(self, descriptor):
super().search(descriptor)
isreg = False
@@ -292,12 +302,15 @@
def __init__(self):
self.providers = []
+
def getProto(self, desc):
for provider in self.providers:
(isreg, rot_mat, jproto) = provider.search(desc)
if isreg:
return (True, rot_mat, jproto)
+ return (False, None, None)
+
def addJointProtoProvider(self, provider):
self.providers.append(provider)
More information about the Bf-extensions-cvs
mailing list