~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to release/scripts/bpymodules/BPyMesh.py

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
 
21
21
import Blender
 
22
import bpy
22
23
import BPyMesh_redux # seperated because of its size.
23
24
# reload(BPyMesh_redux)
24
25
redux= BPyMesh_redux.redux
384
385
        '''
385
386
        
386
387
        if not scn:
387
 
                scn= Blender.Scene.GetCurrent()
 
388
                scn= bpy.data.scenes.active
388
389
        if not container_mesh:
389
 
                mesh = Blender.Mesh.New()       
 
390
                mesh = bpy.data.meshes.new(ob.name)     
390
391
        else:
391
392
                mesh= container_mesh
392
393
                mesh.verts= None
393
394
        
394
 
        
395
395
        ob_type = ob.type
396
396
        dataname = ob.getData(1)
397
397
        tempob= None
427
427
        return mesh
428
428
 
429
429
 
430
 
def faceRayIntersect(f, orig, dir):
 
430
def faceRayIntersect(f, orig, rdir):
431
431
        '''
432
432
        Returns face, side
433
433
        Side is the side of a quad we intersect.
435
435
                side 1 == 0,2,3
436
436
        '''
437
437
        f_v= f.v
438
 
        isect= Blender.Mathutils.Intersect(f_v[0].co, f_v[1].co, f_v[2].co, dir, orig, 1) # 1==clip
 
438
        isect= Blender.Mathutils.Intersect(f_v[0].co, f_v[1].co, f_v[2].co, rdir, orig, 1) # 1==clip
439
439
        
440
440
        if isect:
441
441
                return isect, 0
442
442
        
443
443
        if len(f_v)==4:
444
 
                isect= Blender.Mathutils.Intersect(f_v[0].co, f_v[2].co, f_v[3].co, dir, orig, 1) # 1==clip
 
444
                isect= Blender.Mathutils.Intersect(f_v[0].co, f_v[2].co, f_v[3].co, rdir, orig, 1) # 1==clip
445
445
                if isect:
446
446
                        return isect, 1
447
447
        return False, 0
448
448
 
449
449
 
450
 
def pickMeshRayFace(me, orig, dir):
 
450
def pickMeshRayFace(me, orig, rdir):
451
451
        best_dist= 1000000
452
452
        best_isect= best_side= best_face= None
453
453
        for f in me.faces:
454
 
                isect, side= faceRayIntersect(f, orig, dir)
 
454
                isect, side= faceRayIntersect(f, orig, rdir)
455
455
                if isect:
456
456
                        dist= (isect-orig).length
457
457
                        if dist<best_dist:
463
463
        return best_face, best_isect, best_side
464
464
 
465
465
 
466
 
def pickMeshRayFaceWeight(me, orig, dir):
467
 
        f, isect, side = pickMeshRayFace(me, orig, dir)
 
466
def pickMeshRayFaceWeight(me, orig, rdir):
 
467
        f, isect, side = pickMeshRayFace(me, orig, rdir)
468
468
        
469
469
        if f==None:
470
470
                return None, None, None, None, None
490
490
 
491
491
 
492
492
 
493
 
def pickMeshGroupWeight(me, act_group, orig, dir):
494
 
        f, side, w0, w1, w2= pickMeshRayFaceWeight(me, orig, dir)
 
493
def pickMeshGroupWeight(me, act_group, orig, rdir):
 
494
        f, side, w0, w1, w2= pickMeshRayFaceWeight(me, orig, rdir)
495
495
        
496
496
        if f==None:
497
497
                return None
509
509
        
510
510
        return w0*vws[0] + w1*vws[1]  + w2*vws[2]
511
511
 
512
 
def pickMeshGroupVCol(me, orig, dir):
 
512
def pickMeshGroupVCol(me, orig, rdir):
513
513
        Vector= Blender.Mathutils.Vector
514
 
        f, side, w0, w1, w2= pickMeshRayFaceWeight(me, orig, dir)
 
514
        f, side, w0, w1, w2= pickMeshRayFaceWeight(me, orig, rdir)
515
515
        
516
516
        if f==None:
517
517
                return None
1151
1151
        return len([None for f in me.faces if ptInFaceXYBounds(f, obSpacePt) if faceIntersect(f)]) % 2
1152
1152
 
1153
1153
 
 
1154
def faceAngles(f):
 
1155
        '''
 
1156
        Returns the angle between all corners in a tri or a quad
 
1157
        
 
1158
        '''
 
1159
        AngleBetweenVecs = Blender.Mathutils.AngleBetweenVecs
 
1160
        def Ang(a1,a2):
 
1161
                try:            return AngleBetweenVecs(a1,a2)
 
1162
                except:         return 180
 
1163
        
 
1164
        if len(f) == 3:
 
1165
                if type(f) in (tuple, list):    v1,v2,v3 = f
 
1166
                else:                                                   v1,v2,v3 = [v.co for v in f]
 
1167
                a1= Ang(v2-v1,v3-v1)
 
1168
                a2= Ang(v1-v2,v3-v2)
 
1169
                a3 = 180 - (a1+a2) # a3= Mathutils.AngleBetweenVecs(v2-v3,v1-v3)
 
1170
                return a1,a2,a3
 
1171
        
 
1172
        else:
 
1173
                if type(f) in (tuple, list):    v1,v2,v3,v4 = f
 
1174
                else:                                                   v1,v2,v3,v4 = [v.co for v in f]
 
1175
                a1= Ang(v2-v1,v4-v1)
 
1176
                a2= Ang(v1-v2,v3-v2)
 
1177
                a3= Ang(v2-v3,v4-v3)
 
1178
                a4= Ang(v3-v4,v1-v4)
 
1179
                return a1,a2,a3,a4
 
1180
 
1154
1181
# NMesh wrapper
1155
1182
Vector= Blender.Mathutils.Vector
1156
1183
class NMesh(object):