[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36990] branches/soc-2011-salad: Merging soc-2011-pepper into salad.

Joerg Mueller nexyon at gmail.com
Sun May 29 02:56:43 CEST 2011


Revision: 36990
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36990
Author:   nexyon
Date:     2011-05-29 00:56:42 +0000 (Sun, 29 May 2011)
Log Message:
-----------
Merging soc-2011-pepper into salad.

Modified Paths:
--------------
    branches/soc-2011-salad/release/scripts/startup/bl_operators/object.py
    branches/soc-2011-salad/release/scripts/startup/bl_ui/properties_object_constraint.py
    branches/soc-2011-salad/release/scripts/startup/bl_ui/space_view3d.py
    branches/soc-2011-salad/source/blender/blenkernel/BKE_constraint.h
    branches/soc-2011-salad/source/blender/blenkernel/intern/constraint.c
    branches/soc-2011-salad/source/blender/collada/CMakeLists.txt
    branches/soc-2011-salad/source/blender/collada/DocumentExporter.cpp
    branches/soc-2011-salad/source/blender/editors/armature/poseobject.c
    branches/soc-2011-salad/source/blender/editors/object/object_constraint.c
    branches/soc-2011-salad/source/blender/editors/space_action/action_ops.c
    branches/soc-2011-salad/source/blender/editors/space_graph/graph_edit.c
    branches/soc-2011-salad/source/blender/editors/space_graph/graph_ops.c
    branches/soc-2011-salad/source/blender/editors/space_view3d/drawarmature.c
    branches/soc-2011-salad/source/blender/editors/transform/transform.c
    branches/soc-2011-salad/source/blender/editors/transform/transform_ops.c
    branches/soc-2011-salad/source/blender/makesdna/DNA_armature_types.h
    branches/soc-2011-salad/source/blender/makesdna/DNA_constraint_types.h
    branches/soc-2011-salad/source/blender/makesrna/intern/rna_armature.c
    branches/soc-2011-salad/source/blender/makesrna/intern/rna_constraint.c
    branches/soc-2011-salad/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp
    branches/soc-2011-salad/source/gameengine/Converter/KX_BlenderScalarInterpolator.h
    branches/soc-2011-salad/source/gameengine/Converter/KX_IpoConvert.cpp
    branches/soc-2011-salad/source/gameengine/Converter/KX_IpoConvert.h
    branches/soc-2011-salad/source/gameengine/Expressions/PyObjectPlus.h
    branches/soc-2011-salad/source/gameengine/Ketsji/CMakeLists.txt
    branches/soc-2011-salad/source/gameengine/Ketsji/KX_GameObject.cpp
    branches/soc-2011-salad/source/gameengine/Ketsji/KX_GameObject.h
    branches/soc-2011-salad/source/gameengine/Ketsji/KX_Scene.cpp
    branches/soc-2011-salad/source/gameengine/Ketsji/SConscript
    branches/soc-2011-salad/source/gameengine/SceneGraph/SG_IObject.cpp
    branches/soc-2011-salad/source/gameengine/SceneGraph/SG_IObject.h

Added Paths:
-----------
    branches/soc-2011-salad/release/scripts/modules/mocap_tools.py
    branches/soc-2011-salad/source/blender/collada/AnimationExporter.cpp
    branches/soc-2011-salad/source/blender/collada/AnimationExporter.h
    branches/soc-2011-salad/source/gameengine/Ketsji/BL_Action.cpp
    branches/soc-2011-salad/source/gameengine/Ketsji/BL_Action.h
    branches/soc-2011-salad/source/gameengine/Ketsji/BL_ActionManager.cpp
    branches/soc-2011-salad/source/gameengine/Ketsji/BL_ActionManager.h

Property Changed:
----------------
    branches/soc-2011-salad/


Property changes on: branches/soc-2011-salad
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk/blender:36834-36987
   + /branches/soc-2011-pepper:36830-36989
/trunk/blender:36834-36989

Copied: branches/soc-2011-salad/release/scripts/modules/mocap_tools.py (from rev 36989, branches/soc-2011-pepper/release/scripts/modules/mocap_tools.py)
===================================================================
--- branches/soc-2011-salad/release/scripts/modules/mocap_tools.py	                        (rev 0)
+++ branches/soc-2011-salad/release/scripts/modules/mocap_tools.py	2011-05-29 00:56:42 UTC (rev 36990)
@@ -0,0 +1,451 @@
+from math import hypot, sqrt, isfinite
+import bpy
+import time
+from mathutils import Vector
+
+#Vector utility functions
+class NdVector:
+    vec = []
+    
+    def __init__(self,vec):
+        self.vec = vec[:]
+        
+    def __len__(self):
+        return len(self.vec)
+    
+    def __mul__(self,otherMember):
+        if type(otherMember)==type(1) or type(otherMember)==type(1.0):
+            return NdVector([otherMember*x for x in self.vec])
+        else:
+            a = self.vec
+            b = otherMember.vec
+            n = len(self)
+            return sum([a[i]*b[i] for i in range(n)])
+    
+    def __sub__(self,otherVec):
+        a = self.vec
+        b = otherVec.vec
+        n = len(self)
+        return NdVector([a[i]-b[i] for i in range(n)])
+        
+    def __add__(self,otherVec):
+        a = self.vec
+        b = otherVec.vec
+        n = len(self)
+        return NdVector([a[i]+b[i] for i in range(n)])
+    
+    def vecLength(self):
+        return sqrt(self * self)
+        
+    def vecLengthSq(self):
+        return (self * self)
+        
+    def __getitem__(self,i):
+        return self.vec[i]
+    
+    length = property(vecLength)
+    lengthSq = property(vecLengthSq)
+
+class dataPoint:
+    index = 0
+    co = Vector((0,0,0,0)) # x,y1,y2,y3 coordinate of original point
+    u = 0 #position according to parametric view of original data, [0,1] range
+    temp = 0 #use this for anything
+
+    def __init__(self,index,co,u=0):
+        self.index = index
+        self.co = co
+        self.u = u
+
+def autoloop_anim():
+    context = bpy.context
+    obj = context.active_object
+    fcurves = [x for x in obj.animation_data.action.fcurves if x.select]
+
+    data = []
+    end = len(fcurves[0].keyframe_points)
+        
+    for i in range(1,end):
+        vec = []
+        for fcurve in fcurves:
+            vec.append(fcurve.evaluate(i))
+        data.append(NdVector(vec))
+    
+    def comp(a,b):
+        return a*b
+    
+    N = len(data)
+    Rxy = [0.0] * N
+    for i in range(N):
+        for j in range(i,min(i+N,N)):
+            Rxy[i]+=comp(data[j],data[j-i]) 
+        for j in range(i):
+            Rxy[i]+=comp(data[j],data[j-i+N])
+        Rxy[i]/=float(N)
+    
+    def bestLocalMaximum(Rxy):
+        Rxyd = [Rxy[i]-Rxy[i-1] for i in range(1,len(Rxy))]
+        maxs = []
+        for i in range(1,len(Rxyd)-1):
+            a = Rxyd[i-1]
+            b = Rxyd[i]
+            print(a,b)
+            if (a>=0 and b<0) or (a<0 and b>=0): #sign change (zerocrossing) at point i, denoting max point (only)
+                maxs.append((i,max(Rxy[i],Rxy[i-1])))
+        return max(maxs,key=lambda x: x[1])[0]         
+    flm = bestLocalMaximum(Rxy[0:int(len(Rxy))])
+    
+    diff = []
+    
+    for i in range(len(data)-flm):
+        diff.append((data[i]-data[i+flm]).lengthSq)
+    
+    def lowerErrorSlice(diff,e):
+        bestSlice = (0,100000) #index, error at index
+        for i in range(e,len(diff)-e):
+            errorSlice = sum(diff[i-e:i+e+1])
+            if errorSlice<bestSlice[1]:
+                bestSlice = (i,errorSlice)
+        return bestSlice[0]
+    
+    margin = 2
+    
+    s = lowerErrorSlice(diff,margin)
+    
+    print(flm,s)
+    loop = data[s:s+flm+margin]
+    
+    #find *all* loops, s:s+flm, s+flm:s+2flm, etc... and interpolate between all
+    # to find "the perfect loop". Maybe before finding s? interp(i,i+flm,i+2flm)....
+    for i in range(1,margin+1):
+        w1 = sqrt(float(i)/margin)
+        loop[-i] = (loop[-i]*w1)+(loop[0]*(1-w1))
+
+    
+    for curve in fcurves:
+        pts = curve.keyframe_points
+        for i in range(len(pts)-1,-1,-1):
+            pts.remove(pts[i])
+    
+    for c,curve in enumerate(fcurves):
+        pts = curve.keyframe_points
+        for i in range(len(loop)):
+            pts.insert(i+1,loop[i][c])
+            
+    context.scene.frame_end = flm+1
+    
+    
+    
+    
+
+
+def simplifyCurves(curveGroup, error, reparaError, maxIterations, group_mode):
+
+    def unitTangent(v,data_pts):
+        tang = Vector((0,0,0,0)) #
+        if v!=0:
+            #If it's not the first point, we can calculate a leftside tangent
+            tang+= data_pts[v].co-data_pts[v-1].co
+        if v!=len(data_pts)-1:
+            #If it's not the last point, we can calculate a rightside tangent
+            tang+= data_pts[v+1].co-data_pts[v].co
+        tang.normalize()
+        return tang
+
+    #assign parametric u value for each point in original data
+    def chordLength(data_pts,s,e):
+        totalLength = 0
+        for pt in data_pts[s:e+1]:
+            i = pt.index
+            if i==s:
+                chordLength = 0
+            else:
+                chordLength = (data_pts[i].co-data_pts[i-1].co).length
+            totalLength+= chordLength
+            pt.temp = totalLength
+        for pt in data_pts[s:e+1]:
+            if totalLength==0:
+                print(s,e)
+            pt.u = (pt.temp/totalLength)
+
+    # get binomial coefficient, this function/table is only called with args (3,0),(3,1),(3,2),(3,3),(2,0),(2,1),(2,2)!
+    binomDict = {(3,0): 1, (3,1): 3, (3,2): 3, (3,3): 1, (2,0): 1, (2,1): 2, (2,2): 1}
+    #value at pt t of a single bernstein Polynomial
+
+    def bernsteinPoly(n,i,t):
+        binomCoeff = binomDict[(n,i)]
+        return binomCoeff * pow(t,i) * pow(1-t,n-i)
+            
+    # fit a single cubic to data points in range [s(tart),e(nd)].  
+    def fitSingleCubic(data_pts,s,e):
+
+        # A - matrix used for calculating C matrices for fitting
+        def A(i,j,s,e,t1,t2):
+            if j==1:
+                t = t1
+            if j==2:
+                t = t2
+            u = data_pts[i].u
+            return t * bernsteinPoly(3,j,u)
+        
+        # X component, used for calculating X matrices for fitting
+        def xComponent(i,s,e):
+            di = data_pts[i].co
+            u = data_pts[i].u
+            v0 = data_pts[s].co
+            v3 = data_pts[e].co
+            a = v0*bernsteinPoly(3,0,u)
+            b = v0*bernsteinPoly(3,1,u) #
+            c = v3*bernsteinPoly(3,2,u)
+            d = v3*bernsteinPoly(3,3,u)
+            return (di -(a+b+c+d))
+        
+        t1 = unitTangent(s,data_pts)
+        t2 = unitTangent(e,data_pts)    
+        c11 = sum([A(i,1,s,e,t1,t2)*A(i,1,s,e,t1,t2) for i in range(s,e+1)])
+        c12 = sum([A(i,1,s,e,t1,t2)*A(i,2,s,e,t1,t2) for i in range(s,e+1)])
+        c21 = c12
+        c22 = sum([A(i,2,s,e,t1,t2)*A(i,2,s,e,t1,t2) for i in range(s,e+1)])
+        
+        x1 = sum([xComponent(i,s,e)*A(i,1,s,e,t1,t2) for i in range(s,e+1)])
+        x2 = sum([xComponent(i,s,e)*A(i,2,s,e,t1,t2) for i in range(s,e+1)])
+        
+        # calculate Determinate of the 3 matrices
+        det_cc = c11 * c22 - c21 * c12
+        det_cx = c11 * x2 - c12 * x1
+        det_xc = x1 * c22 - x2 * c12
+
+        # if matrix is not homogenous, fudge the data a bit 
+        if det_cc == 0:
+            det_cc=0.01
+
+        # alpha's are the correct offset for bezier handles
+        alpha0 = det_xc / det_cc #offset from right (first) point
+        alpha1 = det_cx / det_cc #offset from left (last) point
+       
+        sRightHandle = data_pts[s].co.copy()
+        sTangent = t1*abs(alpha0)
+        sRightHandle+= sTangent #position of first pt's handle
+        eLeftHandle = data_pts[e].co.copy()
+        eTangent = t2*abs(alpha1)
+        eLeftHandle+= eTangent #position of last pt's handle.
+        
+        #return a 4 member tuple representing the bezier
+        return (data_pts[s].co,
+              sRightHandle,
+              eLeftHandle,
+              data_pts[e].co)
+
+    # convert 2 given data points into a cubic bezier.
+    # handles are offset along the tangent at a 3rd of the length between the points.          
+    def fitSingleCubic2Pts(data_pts,s,e):
+        alpha0 = alpha1 = (data_pts[s].co-data_pts[e].co).length / 3
+
+        sRightHandle = data_pts[s].co.copy()
+        sTangent = unitTangent(s,data_pts)*abs(alpha0)
+        sRightHandle+= sTangent #position of first pt's handle
+        eLeftHandle = data_pts[e].co.copy()
+        eTangent = unitTangent(e,data_pts)*abs(alpha1)
+        eLeftHandle+= eTangent #position of last pt's handle.
+        
+        #return a 4 member tuple representing the bezier
+        return (data_pts[s].co,
+          sRightHandle,
+          eLeftHandle,
+          data_pts[e].co)
+              
+    #evaluate bezier, represented by a 4 member tuple (pts) at point t.
+    def bezierEval(pts,t):
+        sumVec = Vector((0,0,0,0))
+        for i in range(4):
+            sumVec+=pts[i]*bernsteinPoly(3,i,t)
+        return sumVec
+
+    #calculate the highest error between bezier and original data
+    #returns the distance and the index of the point where max error occurs.
+    def maxErrorAmount(data_pts,bez,s,e):
+        maxError = 0
+        maxErrorPt = s
+        if e-s<3: return 0, None
+        for pt in data_pts[s:e+1]:
+            bezVal = bezierEval(bez,pt.u) 
+            tmpError = (pt.co-bezVal).length/pt.co.length
+            if tmpError >= maxError:
+                maxError = tmpError
+                maxErrorPt = pt.index
+        return maxError,maxErrorPt
+
+
+    #calculated bezier derivative at point t.
+    #That is, tangent of point t.
+    def getBezDerivative(bez,t):
+        n = len(bez)-1
+        sumVec = Vector((0,0,0,0))
+        for i in range(n-1):
+            sumVec+=bernsteinPoly(n-1,i,t)*(bez[i+1]-bez[i])
+        return sumVec
+        
+        
+    #use Newton-Raphson to find a better paramterization of datapoints,
+    #one that minimizes the distance (or error) between bezier and original data.
+    def newtonRaphson(data_pts,s,e,bez):

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list