http://nickpisca.com/BLAST/index.php?title=AttractorToolsOrient-Kokkugia&feed=atom&action=history
AttractorToolsOrient-Kokkugia - Revision history
2024-03-28T13:03:56Z
Revision history for this page on the wiki
MediaWiki 1.28.1
http://nickpisca.com/BLAST/index.php?title=AttractorToolsOrient-Kokkugia&diff=346&oldid=prev
Nickpisca: Created page with "http://www.kokkugia.com/wiki/scriptLibrary/rvb/attractorToolsOrient.rvb https://web-beta.archive.org/web/20101214095823/http://www.kokkugia.com/wiki/scriptLibrary/rvb/attract..."
2017-04-24T20:26:05Z
<p>Created page with "http://www.kokkugia.com/wiki/scriptLibrary/rvb/attractorToolsOrient.rvb https://web-beta.archive.org/web/20101214095823/http://www.kokkugia.com/wiki/scriptLibrary/rvb/attract..."</p>
<p><b>New page</b></p><div>http://www.kokkugia.com/wiki/scriptLibrary/rvb/attractorToolsOrient.rvb<br />
<br />
https://web-beta.archive.org/web/20101214095823/http://www.kokkugia.com/wiki/scriptLibrary/rvb/attractorToolsOrient.rvb<br />
<br />
<br />
<br />
<br />
Option Explicit<br />
'------------------------------------------------------------------------------<br />
' Subroutine: attractorToolsOrient<br />
' Purpose: orients objects toward multiple attractors with a falloff<br />
' Author: Roland Snooks | 2006 | www.kokkugia.com<br />
'------------------------------------------------------------------------------<br />
<br />
Call Main()<br />
Sub Main()<br />
Dim i, j, arrObjects, arrAttract, thresholdDist, scaleFactor, arrBBox, arrCntrPt, counter, arrAttPt <br />
Dim dblAttDistTest, dblClosestAttDist, dblClosestAtt, adjAmount<br />
<br />
' input<br />
arrObjects = Rhino.GetObjects("select vector field")<br />
arrAttract = Rhino.GetObjects("select point attractors", 0)<br />
thresholdDist = Rhino.GetReal("distance threshold", 10, 0)<br />
scaleFactor = Rhino.GetReal("scale factor", 1, 0)<br />
<br />
' loop through each object and get the closest attractor<br />
For i = 0 To UBound(arrObjects)<br />
<br />
' get object bounding box centerpoint<br />
arrCntrPt = Rhino.CurveMidPoint(arrObjects(i))<br />
<br />
' loop through attractors to find the distance to the closest<br />
counter = 0<br />
For j = 0 To UBound(arrAttract)<br />
' get closest point - use for curves rather than points<br />
'dblParam = Rhino.CurveClosestPoint(arrAttract(j), arrCntrPt)<br />
'arrAttPt = Rhino.EvaluateCurve(arrAttract(j), dblParam)<br />
arrAttPt = Rhino.PointCoordinates(arrAttract(j))<br />
<br />
' get distance<br />
dblAttDistTest = Rhino.Distance(arrAttPt, arrCntrPt)<br />
<br />
' is it closer<br />
If counter < 1 Then<br />
dblClosestAttDist = dblAttDistTest<br />
dblClosestAtt = counter<br />
Else<br />
If dblAttDistTest < thresholdDist Then<br />
If dblAttDistTest < dblClosestAttDist Then <br />
dblClosestAttDist = dblAttDistTest<br />
dblClosestAtt = counter<br />
End If<br />
End If <br />
End If<br />
counter = counter + 1<br />
<br />
Next <br />
<br />
' if the object is within the threshold then operate on it<br />
If dblClosestAttDist < thresholdDist Then<br />
<br />
' caculate the adjustment amount<br />
adjAmount = (thresholdDist - dblClosestAttDist)/thresholdDist <br />
'adjAmount = 1 - ((thresholdDist - dblClosestAttDist)/thresholdDist) ' decrease infinite amount<br />
'adjAmount = ((thresholdDist - dblClosestAttDist)/thresholdDist) * scaleFactor + 1 ' increase by factor of up to 100% x scaleFactor<br />
<br />
' based on attractor proximity do something to the object (eg scale)<br />
<br />
' scale<br />
'Rhino.ScaleObject arrObjects(i), arrCntrPt, array(adjAmount,adjAmount,adjAmount) ' scale<br />
<br />
' change color<br />
at_ChangeColor arrObjects(i),thresholdDist,dblClosestAttDist,scaleFactor <br />
<br />
' rotate<br />
at_rotate arrObjects(i),arrAttract(dblClosestAtt),adjAmount<br />
<br />
<br />
End If<br />
<br />
Next <br />
<br />
End Sub<br />
<br />
Function at_ChangeColor(obj,tDist,aDist,sFactor)<br />
Dim objColor, newColor<br />
' caculate color<br />
newColor = 255 - ((1 - ((tDist - aDist)/tDist)) * 255) <br />
'newColor = 255<br />
' change color<br />
objColor = Rhino.ObjectColor(obj, newColor)<br />
'Rhino.print objColor<br />
' at_ChangeColor=<br />
End Function<br />
<br />
Function at_rotate(obj,attr,adj)<br />
Dim currentVec, aLoc, dirVec, currentAngle, arrAngle, diffAngle, angle, xProd, adjAngle<br />
<br />
aLoc = Rhino.PointCoordinates(attr)<br />
<br />
' get closest end on line and current direction vector<br />
If (Rhino.Distance((Rhino.CurveEndPoint(obj)), aLoc)) > (Rhino.Distance((Rhino.CurveStartPoint(obj)), aLoc)) Then<br />
currentVec = Rhino.VectorCreate((Rhino.CurveEndPoint(obj)),(Rhino.CurveStartPoint(obj)))<br />
Else<br />
currentVec = Rhino.VectorCreate((Rhino.CurveStartPoint(obj)),(Rhino.CurveEndPoint(obj)))<br />
End If<br />
<br />
' get vector to attractor<br />
<br />
dirVec = Rhino.VectorCreate((Rhino.CurveMidPoint(obj)),aLoc)<br />
<br />
' get cross product<br />
xProd = Rhino.VectorCrossProduct(currentVec,dirVec)<br />
<br />
' get angle between vectors<br />
angle = Rhino.Angle2(array(array(0,0,0),currentVec),array(array(0,0,0),dirVec))<br />
<br />
' adjust angle based on adj amount <br />
adjAngle = (adj*angle(0)) <br />
<br />
' rotate object using cross prod as axis<br />
Rhino.RotateObject obj, Rhino.CurveMidPoint(obj), adjAngle, xProd<br />
<br />
End Function<br />
<br />
<br />
<br />
<br />
<br />
[[Category:RhinoScript]]</div>
Nickpisca