destruction of previous slot api. if it returns, it'll
[blender.git] / release / scripts / bpymodules / BPyMesh.py
index 91f0348549d7da0a57089e30be67fe66540edf5f..415c2a12c6972374f7a5542859645054405549f4 100644 (file)
@@ -19,6 +19,7 @@
 
 
 import Blender
+import bpy
 import BPyMesh_redux # seperated because of its size.
 # reload(BPyMesh_redux)
 redux= BPyMesh_redux.redux
@@ -55,7 +56,7 @@ def meshWeight2List(me):
        
        if not len_groupNames:
                # no verts? return a vert aligned empty list
-               return [[] for i in xrange(len(me.verts))]
+               return [[] for i in xrange(len(me.verts))], []
        
        else:
                vWeightList= [[0.0]*len_groupNames for i in xrange(len(me.verts))]
@@ -384,14 +385,13 @@ def getMeshFromObject(ob, container_mesh=None, apply_modifiers=True, vgroups=Tru
        '''
        
        if not scn:
-               scn= Blender.Scene.GetCurrent()
+               scn= bpy.data.scenes.active
        if not container_mesh:
-               mesh = Blender.Mesh.New()       
+               mesh = bpy.data.meshes.new(ob.name)     
        else:
                mesh= container_mesh
                mesh.verts= None
        
-       
        ob_type = ob.type
        dataname = ob.getData(1)
        tempob= None
@@ -427,7 +427,7 @@ def getMeshFromObject(ob, container_mesh=None, apply_modifiers=True, vgroups=Tru
        return mesh
 
 
-def faceRayIntersect(f, orig, dir):
+def faceRayIntersect(f, orig, rdir):
        '''
        Returns face, side
        Side is the side of a quad we intersect.
@@ -435,23 +435,23 @@ def faceRayIntersect(f, orig, dir):
                side 1 == 0,2,3
        '''
        f_v= f.v
-       isect= Blender.Mathutils.Intersect(f_v[0].co, f_v[1].co, f_v[2].co, dir, orig, 1) # 1==clip
+       isect= Blender.Mathutils.Intersect(f_v[0].co, f_v[1].co, f_v[2].co, rdir, orig, 1) # 1==clip
        
        if isect:
                return isect, 0
        
        if len(f_v)==4:
-               isect= Blender.Mathutils.Intersect(f_v[0].co, f_v[2].co, f_v[3].co, dir, orig, 1) # 1==clip
+               isect= Blender.Mathutils.Intersect(f_v[0].co, f_v[2].co, f_v[3].co, rdir, orig, 1) # 1==clip
                if isect:
                        return isect, 1
        return False, 0
 
 
-def pickMeshRayFace(me, orig, dir):
+def pickMeshRayFace(me, orig, rdir):
        best_dist= 1000000
        best_isect= best_side= best_face= None
        for f in me.faces:
-               isect, side= faceRayIntersect(f, orig, dir)
+               isect, side= faceRayIntersect(f, orig, rdir)
                if isect:
                        dist= (isect-orig).length
                        if dist<best_dist:
@@ -463,8 +463,8 @@ def pickMeshRayFace(me, orig, dir):
        return best_face, best_isect, best_side
 
 
-def pickMeshRayFaceWeight(me, orig, dir):
-       f, isect, side = pickMeshRayFace(me, orig, dir)
+def pickMeshRayFaceWeight(me, orig, rdir):
+       f, isect, side = pickMeshRayFace(me, orig, rdir)
        
        if f==None:
                return None, None, None, None, None
@@ -490,8 +490,8 @@ def pickMeshRayFaceWeight(me, orig, dir):
 
 
 
-def pickMeshGroupWeight(me, act_group, orig, dir):
-       f, side, w0, w1, w2= pickMeshRayFaceWeight(me, orig, dir)
+def pickMeshGroupWeight(me, act_group, orig, rdir):
+       f, side, w0, w1, w2= pickMeshRayFaceWeight(me, orig, rdir)
        
        if f==None:
                return None
@@ -509,9 +509,9 @@ def pickMeshGroupWeight(me, act_group, orig, dir):
        
        return w0*vws[0] + w1*vws[1]  + w2*vws[2]
 
-def pickMeshGroupVCol(me, orig, dir):
+def pickMeshGroupVCol(me, orig, rdir):
        Vector= Blender.Mathutils.Vector
-       f, side, w0, w1, w2= pickMeshRayFaceWeight(me, orig, dir)
+       f, side, w0, w1, w2= pickMeshRayFaceWeight(me, orig, rdir)
        
        if f==None:
                return None
@@ -1151,6 +1151,33 @@ def pointInsideMesh(ob, pt):
        return len([None for f in me.faces if ptInFaceXYBounds(f, obSpacePt) if faceIntersect(f)]) % 2
 
 
+def faceAngles(f):
+       '''
+       Returns the angle between all corners in a tri or a quad
+       
+       '''
+       AngleBetweenVecs = Blender.Mathutils.AngleBetweenVecs
+       def Ang(a1,a2):
+               try:            return AngleBetweenVecs(a1,a2)
+               except:         return 180
+       
+       if len(f) == 3:
+               if type(f) in (tuple, list):    v1,v2,v3 = f
+               else:                                                   v1,v2,v3 = [v.co for v in f]
+               a1= Ang(v2-v1,v3-v1)
+               a2= Ang(v1-v2,v3-v2)
+               a3 = 180 - (a1+a2) # a3= Mathutils.AngleBetweenVecs(v2-v3,v1-v3)
+               return a1,a2,a3
+       
+       else:
+               if type(f) in (tuple, list):    v1,v2,v3,v4 = f
+               else:                                                   v1,v2,v3,v4 = [v.co for v in f]
+               a1= Ang(v2-v1,v4-v1)
+               a2= Ang(v1-v2,v3-v2)
+               a3= Ang(v2-v3,v4-v3)
+               a4= Ang(v3-v4,v1-v4)
+               return a1,a2,a3,a4
+
 # NMesh wrapper
 Vector= Blender.Mathutils.Vector
 class NMesh(object):