-
Notifications
You must be signed in to change notification settings - Fork 3
/
CF_UnitMapper_01.py
70 lines (52 loc) · 1.81 KB
/
CF_UnitMapper_01.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import rhinoscriptsyntax as rs
def mapValue(val, inMin, inMax, outMin, outMax):
outR = outMax - outMin
inR = inMax - inMin
inVal = val - inMin
newVal = (inVal/inR) * outR
return outMin + newVal
def lerp(startPt, endPt, T):
len = rs.VectorSubtract(endPt, startPt)
nVec = rs.VectorScale(len, T)
return rs.VectorAdd(startPt, nVec)
def calcBiLinear(pt, bbMin, bbMax):
bX = mapValue(pt.X,bbMin[0],bbMax[0],0.0,1.0)
bY = mapValue(pt.Y,bbMin[1],bbMax[1],0.0,1.0)
return[bX,bY]
def main():
unitRectMin = rs.GetPoint("select unit rect MIN")
unitRectMax = rs.GetPoint("select unit rect MAX")
units = rs.GetObjects("select curves & polylines", 4)
mesh = rs.GetObject("select mesh",32)
for unit in units:
degree = rs.CurveDegree(unit)
unitPts = []
unitCoords =[]
if degree == 1:
polylinePts = rs.PolylineVertices(unit)
elif degree == 3:
polylinePts = rs.CurvePoints(unit)
else:
continue
for pt in polylinePts:
bc = calcBiLinear(pt,unitRectMin,unitRectMax)
unitCoords.append(bc)
unitPts.append(pt)
v = rs.MeshVertices(mesh)
faceVerts = rs.MeshFaceVertices(mesh)
for fv in faceVerts:
v0 = v[fv[0]]
v1 = v[fv[1]]
v2 = v[fv[2]]
v3 = v[fv[3]]
newPts = []
for i in range(0, len(unitPts)):
bLC = unitCoords[i]
nX1 = lerp(v0,v1,bLC[0])
nX2 = lerp(v3,v2 ,bLC[0])
pt = lerp(nX1,nX2,bLC[1])
#rs.AddPoint(pt)
newPts.append(pt)
rs.AddCurve(newPts,degree)
if __name__ == "__main__":
main()