diff options
author | Campbell Barton <ideasman42@gmail.com> | 2006-05-28 14:44:29 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2006-05-28 14:44:29 +0400 |
commit | 98b2e98c79448c35ee4f805dee16bc0f0ffb6063 (patch) | |
tree | d582c651c15818ac3efec0d11e3faa772252e063 /release/scripts/bpymodules/BPyMesh.py | |
parent | e47719d253c3be3217816a8dc83c64e0d3d9828d (diff) |
Added a 2d convex hull function to BPyMathutils
Added a 2D Line intersection function
Added a function to BPyMesh that gets the mesh space vertex location of a Faces UV Pixel.
Diffstat (limited to 'release/scripts/bpymodules/BPyMesh.py')
-rw-r--r-- | release/scripts/bpymodules/BPyMesh.py | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/release/scripts/bpymodules/BPyMesh.py b/release/scripts/bpymodules/BPyMesh.py index b0351e16a76..79bfd19452f 100644 --- a/release/scripts/bpymodules/BPyMesh.py +++ b/release/scripts/bpymodules/BPyMesh.py @@ -190,6 +190,54 @@ def getMeshFromObject(ob, container_mesh=None, apply_modifiers=True, vgroups=Tru return mesh + + +#============================================================================# +# Takes a face, and a pixel x/y on the image and returns a worldspace x/y/z # +# will return none if the pixel is not inside the faces UV # +#============================================================================# +def getUvPixelLoc(face, pxLoc, img_size = None, uvArea = None): + TriangleArea= Blender.Mathutils.TriangleArea + Vector= Blender.Mathutils.Vector + + if not img_size: + w,h = face.image.size + else: + w,h= img_size + + scaled_uvs= [Vector(uv.x*w, uv.y*h) for uv in f.uv] + + if len(scaled_uvs)==3: + indicies= ((0,1,2),) + else: + indicies= ((0,1,2), (0,2,3)) + + for fidxs in indicies: + for i1,i2,i3 in fidxs: + # IS a point inside our triangle? + # UVArea could be cached? + uv_area = TriangleArea(scaled_uvs[i1], scaled_uvs[i2], scaled_uvs[i3]) + area0 = TriangleArea(pxLoc, scaled_uvs[i2], scaled_uvs[i3]) + area1 = TriangleArea(pxLoc, scaled_uvs[i1], scaled_uvs[i3]) + area2 = TriangleArea(pxLoc, scaled_uvs[i1], scaled_uvs[i2]) + if area0 + area1 + area2 > uv_area + 1: # 1 px bleed/error margin. + pass # if were a quad the other side may contain the pixel so keep looking. + else: + # We know the point is in the tri + area0 /= uv_area + area1 /= uv_area + area2 /= uv_area + + # New location + return Vector(\ + face.v[i1].co[0]*area0 + face.v[i2].co[0]*area1 + face.v[i3].co[0]*area2,\ + face.v[i1].co[1]*area0 + face.v[i2].co[1]*area1 + face.v[i3].co[1]*area2,\ + face.v[i1].co[2]*area0 + face.v[i2].co[2]*area1 + face.v[i3].co[2]*area2\ + ) + + return None + + type_tuple= type( (0,) ) type_list= type( [] ) def ngon(from_data, indices): @@ -230,8 +278,7 @@ def ngon(from_data, indices): oldmode = Mesh.Mode() Mesh.Mode(Mesh.SelectModes['VERTEX']) - for v in temp_mesh.verts: - v.sel= 1 + temp_mesh.sel= True # Select all verst # Must link to scene scn= Scene.GetCurrent() |