plastic

12-06-2010, 10:45 AM

Thanks for the link.

I tried to put that into a script but no success yet.

I don't quite understand yet how this algorithm is supposed to work, but I'm getting closer...

(

local meshObj = $Plane001

local theChannel=1

local UVsearch=[0.25,0.4]

--collect all faces

local meshFaces=meshObj.faces as bitarray

--collect all verts for each face

theMapFaces=for f in meshFaces collect meshop.getMapFace meshObj theChannel f

--collect UV coords of each face/vertex

theFaceVertsUVCoords=for v in theMapFaces collect

(

#(meshop.getMapVert meshObj theChannel v.x, meshop.getMapVert meshObj theChannel v.y, meshop.getMapVert meshObj theChannel v.z)

)

--Check if point is in triangle

for f in theFaceVertsUVCoords do

(

A=f[1]

B=f[2]

C=f[3]

u=UVsearch.x

v=UVsearch.y

P = A + u * (C - A) + v * (B - A)

--Compute vectors

v0 = C - A

v1 = B - A

v2 = P - A

--Compute dot products

dot00 = dot v0 v0

dot01 = dot v0 v1

dot02 = dot v0 v2

dot11 = dot v1 v1

dot12 = dot v1 v2

--Compute barycentric coordinate

invDenom = 1.0 / (dot00 * dot11 - dot01 * dot01)

u = (dot11 * dot02 - dot01 * dot12) * invDenom

v = (dot00 * dot12 - dot01 * dot02) * invDenom

--Check if point is in triangle

result=(u > 0) and (v > 0) and (u + v < 1)

format "A:% B:% C:% u:% v:% result:%\n" A B C u v result

)

)

output:

A:[0,0.25,0] B:[0,0,0] C:[0.25,0.25,0] u:0.25 v:0.4 result:true

A:[0.25,0,0] B:[0.25,0.25,0] C:[0,0,0] u:0.25 v:0.4 result:true

A:[0.25,0.25,0] B:[0.25,0,0] C:[0.5,0.25,0] u:0.25 v:0.4 result:true

A:[0.5,0,0] B:[0.5,0.25,0] C:[0.25,0,0] u:0.25 v:0.4 result:true

A:[0.5,0.25,0] B:[0.5,0,0] C:[0.75,0.25,0] u:0.25 v:0.4 result:true

A:[0.75,0,0] B:[0.75,0.25,0] C:[0.5,0,0] u:0.25 v:0.4 result:true

A:[0.75,0.25,0] B:[0.75,0,0] C:[1,0.25,0] u:0.25 v:0.4 result:true

A:[1,0,0] B:[1,0.25,0] C:[0.75,0,0] u:0.25 v:0.4 result:true

A:[0,0.5,0] B:[0,0.25,0] C:[0.25,0.5,0] u:0.25 v:0.4 result:true

A:[0.25,0.25,0] B:[0.25,0.5,0] C:[0,0.25,0] u:0.25 v:0.4 result:true

A:[0.25,0.5,0] B:[0.25,0.25,0] C:[0.5,0.5,0] u:0.25 v:0.4 result:true

A:[0.5,0.25,0] B:[0.5,0.5,0] C:[0.25,0.25,0] u:0.25 v:0.4 result:true

A:[0.5,0.5,0] B:[0.5,0.25,0] C:[0.75,0.5,0] u:0.25 v:0.4 result:true

A:[0.75,0.25,0] B:[0.75,0.5,0] C:[0.5,0.25,0] u:0.25 v:0.4 result:true

A:[0.75,0.5,0] B:[0.75,0.25,0] C:[1,0.5,0] u:0.25 v:0.4 result:true

A:[1,0.25,0] B:[1,0.5,0] C:[0.75,0.25,0] u:0.25 v:0.4 result:true

A:[0,0.75,0] B:[0,0.5,0] C:[0.25,0.75,0] u:0.25 v:0.4 result:true

A:[0.25,0.5,0] B:[0.25,0.75,0] C:[0,0.5,0] u:0.25 v:0.4 result:true

A:[0.25,0.75,0] B:[0.25,0.5,0] C:[0.5,0.75,0] u:0.25 v:0.4 result:true

A:[0.5,0.5,0] B:[0.5,0.75,0] C:[0.25,0.5,0] u:0.25 v:0.4 result:true

A:[0.5,0.75,0] B:[0.5,0.5,0] C:[0.75,0.75,0] u:0.25 v:0.4 result:true

A:[0.75,0.5,0] B:[0.75,0.75,0] C:[0.5,0.5,0] u:0.25 v:0.4 result:true

A:[0.75,0.75,0] B:[0.75,0.5,0] C:[1,0.75,0] u:0.25 v:0.4 result:true

A:[1,0.5,0] B:[1,0.75,0] C:[0.75,0.5,0] u:0.25 v:0.4 result:true

A:[0,1,0] B:[0,0.75,0] C:[0.25,1,0] u:0.25 v:0.4 result:true

A:[0.25,0.75,0] B:[0.25,1,0] C:[0,0.75,0] u:0.25 v:0.4 result:true

A:[0.25,1,0] B:[0.25,0.75,0] C:[0.5,1,0] u:0.25 v:0.4 result:true

A:[0.5,0.75,0] B:[0.5,1,0] C:[0.25,0.75,0] u:0.25 v:0.4 result:true

A:[0.5,1,0] B:[0.5,0.75,0] C:[0.75,1,0] u:0.25 v:0.4 result:true

A:[0.75,0.75,0] B:[0.75,1,0] C:[0.5,0.75,0] u:0.25 v:0.4 result:true

A:[0.75,1,0] B:[0.75,0.75,0] C:[1,1,0] u:0.25 v:0.4 result:true

A:[1,0.75,0] B:[1,1,0] C:[0.75,0.75,0] u:0.25 v:0.4 result:true

result:true for everything is wrong...

vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.