A playground for University of Bologna Students and a 6-days seminar about digital tools.

Digital generative tools are a very important part of architectural education. Andrew Kudless during his conference at SimAE was telling about chinese traditional woodcraftsmen: they spend their first two years of apprentice in making their own tools. Today, we have a large pool of digital ready made tools, built to respond to more or less specific problems or tasks, while keeping a level of flexibility and personalization. The majority of these tools have hidden capabilities, which can only be accessed bypassing the conventional interface and getting close to the machine logic of programming or building parametric components which generate shapes. Thus, seriality, differentiation, complexity can be implemented in architectural projects through code, in order to exploit the power of algorithmic based complex systems which are the basis of biological systems.


But, before going through such complexity, we must start with simple tasks and simple rules. Before playing seriously we need practice. This is the playground where a bunch of students will start to practice, a pool where they will share their results and questions. Maybe the stuff here that will be posted will seem obvious or naive to the navigated code-monkey, but, as I mentioned before, we all start from the basics and this is intended as a place to start. However, any comment and contribution is appreciated.

Playground is open, let's play! _ Alessio

12.5.09

CHAPTER 1 - Textures














Once upon a time and a very good time it was there was a moocow coming down along the road and this moocow that was coming down along the road met a nicens little boy named baby tuckoo..

..by the way, after applying a lot on scripting I finally start making some render and put some
pieces together.
For this part I took inspiration from the book "Design and visual communication" written by Bruno Munari and his studies about textures (organic or geometric, how to treat a surface to make variations on it but preserving its uniformity, rarefaction and thickening
).
First of all I made two grids one with squares and one with triangles and three kind of modules (squares, circles, triangles) and their submodules (in geometric progression). Then I started trying "without thinking".
I also watched at some natural configurations and tried with them.









Then I selected some configurations and I tried to put them on a script.

For this part David Rutten and Theverymany examples were vital.

I thought that best way to deal with textures, their
rarefaction and thickening , was to make an application were you can build surfaces (based on based on z = f(x,y[,d,a]) equation) and decide dimension and number of subdivisions (but you can also select an existing surface).

[the only problem is that in this manner I have linked dimension and subdivision, if you want to split them you have firstly to generate the surface and then rerun the script only to tasselate it. But I'll fix it soon, so don't worry]

After that I grouped 9 kind of tesselation I have developed, more or less complex, you
just simple have to set the different parameter and see what you get. It is likely to view how texture changes when you increase o decrease one or both u-v params. And I found that sometimes textures have a good-looking backside lol..
Post it if something nice comes out!















Next step is to see how textures interact with both the surface they are subdividing and the environmental conditions (I tried something about differentiation, attractors, L-system, cellula automata), and also how do they organize in three-dimensional forms and structures... And also something architectural finally... See you soon then!

[p.s.Vray for rhino sucks!]

Option Explicit
' . Script written by Vincenzo Reale
' . univin@libero.it
'Script version sabato 11 maggio 2009 05.02.28

Call SurfacesEditor()

Sub SurfacesEditor()

Dim arrparam, arrresults, arrvalues
Dim strsurf
Dim arrchoose
arrchoose = (array("1° SURFHONEY","2° SURFHEXAGON", "3° SURFGRID","4° SURFRND","5° SURFBOX","6° SURFWAVES","7° SURFBOXHOLE","8° SURFPYRAMID","9° SURFCURVES"))
If isnull (arrchoose) Then Exit Sub

arrparam = array("create surfaces from equation? (Y/N)","equation surfaces z = f(x,y[,D,A])", "u subdivisions (>1)","v subdivisions (>1)")
arrvalues = array("Y","cos(sqr(x^2 + y^2))","5","5")
arrchoose = Rhino.ListBox (arrchoose, "choose!", "SURFACE")
arrresults = rhino.propertylistbox(arrparam, arrvalues,"Parameters","Vink's Surface Editor")

Dim upar, vpar
upar = CInt (formatnumber (arrresults(2)))
If isnull(upar) Then Exit Sub
vpar = CInt (formatnumber (arrresults(3)))
If isnull (vpar) Then Exit Sub

If isarray(arrresults) Then
Select Case Ucase (arrresults(0))
Case "Y"
strsurf = createsurface(arrresults(1), upar,vpar)
Case "N"
strsurf = rhino.getobject("Select surface to texturize",8+16+32,True,True)
End Select

Select Case Ucase (arrchoose)
Case "1° SURFHONEY"
Call surfhoney(strsurf,upar,vpar)
Case "2° SURFHEXAGON"
Call surfhexagon (strsurf,upar,vpar)
Case "3° SURFGRID"
Call surfgrid (strsurf,upar,vpar)
Case "4° SURFRND"
Call surfrnd(strsurf,upar,vpar)
Case "5° SURFBOX"
Call surfbox (strsurf,upar,vpar)
Case "6° SURFWAVES"
Call surfwaves (strsurf,upar,vpar)
Case "7° SURFBOXHOLE"
Call surfboxhole(strsurf,upar,vpar)
Case "8° SURFPYRAMID"
Call surfpyramid (strsurf,upar,vpar)
Case "9° SURFCURVES"
Call surfcurves(strsurf,upar,vpar)

End Select
End If

Call rhino.EnableRedraw(True)
End Sub
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CREATE SURFACE -----

Function createsurface (streq, upar,vpar)
Dim arrCount(1), nCount, x, y, z
Dim intstart, intEnd
intstart = -5
intEnd = -5

arrCount(0) = upar
arrCount(1) = vpar

nCount = 0
Dim arrpoints()

For x = intstart To arrCount(0) + sgn(intstart) * (abs(intstart)+1)
For y = intend To arrCount(0) + sgn(intend) * (abs(intend)+1)
z = solveequation(streq,x,y)
ReDim Preserve arrpoints(ncount)
arrPoints(nCount) = Array(x, y, z )
nCount = nCount + 1
Next
Next

createsurface = Rhino.AddSrfPtGrid (arrCount, arrPoints)
Call rhino.EnableRedraw(True)

End Function

Function solveequation( ByVal strfunction, ByVal x, ByVal y)
Dim z
Dim D, A, Angledata

D = rhino.Hypot(x,y)
angleData= rhino.Angle(array(0,0,0), array(x,y,0))

' 0 The X,Y angle In degrees.
' 1 The elevation.
' 2 The delta In the X direction.
' 3 The delta In the Y direction.
' 4 The delta In the Z direction.

If isnull (angledata) Then
A = 0.0
Else
A = Rhino.ToRadians(Angledata(0)) 'l'angolo in coordinate polari

End If

On Error Resume Next
Execute("z =" & strfunction)

If err.number = 0 Then
solveequation = z
Else
solveequation = 0.0
End If

End Function
-----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 1 SURFHONEY -----

Sub surfhoney(strsurf,upar,vpar)
upar = upar*10
vpar = vpar*10
Dim dblheight : dblheight = rhino.getreal("extrusion height?" ,.3)
If isnull (dblheight) Then Exit Sub

Call rhino.enableredraw(False)
Dim i, j
Dim uvalone(1), uvaltwo
Dim arrUone, arrVone
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4, pt5, pt6
ReDim matrix (upar, vpar)
Dim tempt

arruone = array (0,0)
arrVone = array (0,0)
Dim strcell, arrct, arrptsurf, arrnorm, arrnormend, arrline, strcell2

If rhino.IsSurface(strsurf) Then
arruone = rhino.surfacedomain(strsurf,0)
arrVone = rhino.surfacedomain(strsurf,1)
End If

For i=0 To upar
For j=0 To vpar
uvalone(0)= ((arruone(1)-arruone(0))/upar)*i
uvalone(1) = ((arrVone(1)-arrVone(0))/vpar)*j
arrpttemp = rhino.EvaluateSurface(strsurf,uvalone)
matrix(i,j) = arrpttemp
Next
Next


Dim oct1, oct2, oct3, oct4, arrlinehuge, arrel1, arrel2
Dim rn


For i = 1 To upar-2 Step 4

For J=0 To vpar-2 Step 2
pt1 = matrix(i,j)
pt2 = matrix(i+1,j)
pt3 = matrix(i+2,j+1)
pt4 = matrix(i+1,j+2)
pt5 = matrix(i,j+2)
pt6 = matrix(i-1,j+1)
strcell = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt5,pt6,pt1),1)
arrct = array( (pt6(0)+pt3(0))/2,(pt6(1)+pt3(1))/2,(pt6(2)+pt3(2))/2)
arrptsurf = rhino.SurfaceClosestPoint(strsurf,arrct)
rn = rnd

strcell2 = rhino.ScaleObject(strcell,arrct,array(0.5,0.5,0.5),True)

arrnorm = rhino.SurfaceNormal(strsurf,arrptsurf)
arrnorm = rhino.VectorScale(arrnorm, dblheight)
arrnormend = rhino.PointAdd(arrct,arrnorm)
arrline = rhino.AddLine(arrct,arrnormend)


Call rhino.SelectObject (strcell)
rhino.Command("-patch " & "enter")
oct1=rhino.FirstObject
rhino.UnselectAllObjects

rhino.SelectObject (strcell2)
rhino.Command("-patch " & "enter")
oct2=rhino.FirstObject
rhino.UnselectAllObjects

oct3 = rhino.ExtrudeSurface(oct1,arrline)
arrlinehuge = rhino.ExtendCurveLength(arrline,0,1,40)
oct4 = rhino.ExtrudeSurface(oct2,arrlinehuge)


rhino.MoveObject oct4, arrnormend,arrct
arrel1 = (array(oct3))
arrel2 = (array(oct4))

rhino.BooleanDifference arrel1,arrel2

Call rhino.DeleteObject (arrline)
Call rhino.DeleteObject (oct1)
Call rhino.DeleteObject (oct2)

Next
Next

For i = 3 To upar-2 Step 4
For J=1 To vpar-2 Step 2
pt1 = matrix(i,j)
pt2 = matrix(i+1,j)
pt3 = matrix(i+2,j+1)
pt4 = matrix(i+1,j+2)
pt5 = matrix(i,j+2)
pt6 = matrix(i-1,j+1)
strcell = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt5,pt6,pt1),1)
arrct = array( (pt6(0)+pt3(0))/2,(pt6(1)+pt3(1))/2,(pt6(2)+pt3(2))/2)
arrptsurf = rhino.SurfaceClosestPoint(strsurf,arrct)
rn = rnd

strcell2 = rhino.ScaleObject(strcell,arrct,array(0.5,0.5,0.5),True)

arrnorm = rhino.SurfaceNormal(strsurf,arrptsurf)
arrnorm = rhino.VectorScale(arrnorm, dblheight)
arrnormend = rhino.PointAdd(arrct,arrnorm)
arrline = rhino.AddLine(arrct,arrnormend)


Call rhino.SelectObject (strcell)
rhino.Command("-patch " & "enter")
oct1=rhino.FirstObject
rhino.UnselectAllObjects

rhino.SelectObject (strcell2)
rhino.Command("-patch " & "enter")
oct2=rhino.FirstObject
rhino.UnselectAllObjects

oct3 = rhino.ExtrudeSurface(oct1,arrline)
arrlinehuge = rhino.ExtendCurveLength(arrline,0,1,40)
oct4 = rhino.ExtrudeSurface(oct2,arrlinehuge)


rhino.MoveObject oct4, arrnormend,arrct
arrel1 = (array(oct3))
arrel2 = (array(oct4))

rhino.BooleanDifference arrel1,arrel2

Call rhino.DeleteObject (arrline)
Call rhino.DeleteObject (oct1)
Call rhino.DeleteObject (oct2)
Next
Next

Call rhino.deleteobject(strsurf)
Call rhino.EnableRedraw(True)
End Sub
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 2 SURFHEXAGON -----

Sub SURFHEXAGON(strsurf,Intuint,Intvint)

Dim dblheight : dblheight = rhino.getreal("extrusion height",.3)
Intuint = IntUint*20
Intvint = Intvint*20
Call rhino.EnableRedraw (False)

Dim arrUdom, arrVdom
arrUdom = Rhino.SurfaceDomain(strsurf,0)
arrVdom = Rhino.SurfaceDomain(strsurf,1)

Dim i, j
Dim arrPt, upar, vpar
ReDim arrPt(intUint-1 , intVint-1)
For i = 0 To Intuint-1
For j = 0 To intvint-1

upar = arrudom(0) + i*(arrudom(1)-arrudom(0))/(intuint-1)
vpar = arrudom(0) + j*(arrvdom(1)-arrvdom(0))/(intvint-1)
arrpt (i,j) = rhino.EvaluateSurface(strsurf,array(upar,vpar))

Next
Next


Dim arrpanel, arrpanel2
Dim strcurvepanel, strcurvepanel2
Dim arrsurfpanel,arrsurfpanel2
Dim strcut, arrCP, dbldist1, dblscale
For i = 6 To Intuint-6 Step 6

For j = 0 To intvint-6 Step 18

arrpanel = array (arrpt(i,j),arrpt(i+3,j+6), arrpt(i-3,j+6),arrpt(i,j))
arrsurfpanel = rhino.addsrfpt(arrpanel)

Next
Next

For i = 0 To Intuint-6 Step 6

For j = 0 To intvint-6 Step 18

arrpanel = array (arrpt(i,j),arrpt(i+6,j), arrpt(i+3,j+6),arrpt(i,j))
arrsurfpanel = rhino.addsrfpt(arrpanel)

Next
Next

For i = 3 To Intuint-6 Step 12

For j = 6 To intvint-6 Step 18

arrpanel = array (arrpt(i,j),arrpt(i+6,j), arrpt(i+3,j+6),arrpt(i,j))
arrsurfpanel = rhino.addsrfpt(arrpanel)

Next
Next
For i = 12 To Intuint-12 Step 12

For j = 0 To intvint-12 Step 18

arrpanel2 = array (arrpt(i,j),arrpt(i-3,j+6), arrpt(i+3,j+6),arrpt(i,j))
strcurvepanel2 = rhino.addcurve(arrpanel2,1)
arrsurfpanel2 = rhino.addsrfpt(arrpanel2)

Next
Next

For i = 6 To Intuint-12 Step 12

For j = 12 To intvint-12 Step 18
arrpanel2 = array (arrpt(i,j),arrpt(i-3,j+6), arrpt(i+3,j+6),arrpt(i,j))
strcurvepanel2 = rhino.addcurve(arrpanel2,1)
arrsurfpanel2 = rhino.addsrfpt(arrpanel2)

Next
Next

Dim arrstrcurvepanel(), k
k =0
For i = 9 To Intuint-9 Step 12
For j = 6 To intvint-12 Step 18
ReDim Preserve arrstrcurvepanel (k)
arrpanel = array (arrpt(i,j),arrpt(i+6,j), arrpt(i+9,j+6),arrpt(i+6,j+12), arrpt(i,j+12),arrpt(i,j+12),arrpt(i-3,j+6),arrpt(i,j))
arrstrcurvepanel(k) = rhino.addcurve(arrpanel,1)
Dim arrct
arrct = array( (arrpt(i-3,j+6)(0)+arrpt(i+9,j+6)(0))/2,(arrpt(i-3,j+6)(1)+arrpt(i+9,j+6)(1))/2,(arrpt(i-3,j+6)(2)+arrpt(i+9,j+6)(2))/2)
Dim arrptsurf
arrptsurf = rhino.SurfaceClosestPoint(strsurf,arrct)
Dim strcell2
strcell2 = rhino.ScaleObject(arrstrcurvepanel(k),arrct,array(0.3,0.3,0.3),True)
Dim arrnorm, arrnormend, arrline
arrnorm = rhino.SurfaceNormal(strsurf,arrptsurf)
arrnorm = rhino.VectorScale(arrnorm, dblheight)
arrnormend = rhino.PointAdd(arrct,arrnorm)
arrline = rhino.AddLine(arrct,arrnormend)

rhino.MoveObject strcell2, arrct, arrnormend
Call rhino.AddLoftSrf(array(arrstrcurvepanel(k),strcell2),,,,,,False)
Call rhino.deleteobject (arrline)
k = k+1
Next
Next

Call rhino.deleteobject(strsurf)
Call rhino.enableredraw(True)
End Sub
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 3 SURFGRID -----

Sub surfgrid (strsurf,upar,vpar)

Dim radius : radius = rhino.getstring("pipe radius?" ,".1")
If isnull (radius) Then Exit Sub

Call rhino.enableredraw(False)
Dim i, j
Dim uvalone(1), uvaltwo
Dim arrUone, arrVone
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4
ReDim matrix (upar, vpar)
Dim tempt

arruone = array (0,0)
arrVone = array (0,0)

If rhino.IsSurface(strsurf) Then
arruone = rhino.surfacedomain(strsurf,0)
arrVone = rhino.surfacedomain(strsurf,1)
End If

For i=0 To upar
For j=0 To vpar
uvalone(0)= ((arruone(1)-arruone(0))/upar)*i
uvalone(1) = ((arrVone(1)-arrVone(0))/vpar)*j
arrpttemp = rhino.EvaluateSurface(strsurf,uvalone)
matrix(i,j) = arrpttemp
Next
Next

For i = 0 To upar-1

For J=0 To vpar-1
pt1 = matrix(i,j)
pt2 = matrix(i+1,j)
pt3 = matrix(i+1,j+1)
pt4 = matrix(i,j+1)

Call grid(pt1,pt2,pt3,pt4, radius)
Next
Next

Call rhino.deleteobject(strsurf)
Call rhino.EnableRedraw(True)
End Sub

Function grid(pt1,pt2,pt3,pt4,radius)



Dim lin12, lin23, lin34, lin41, lin13, lin24

lin12 = rhino.AddLine(pt1,pt2)
lin23 = rhino.AddLine(pt2, pt3)
lin34 = rhino.AddLine(pt3,pt4)
lin41 = rhino.AddLine(pt4, pt1)
lin13 = rhino.AddLine(pt1,pt3)
lin24 = rhino.AddLine(pt2, pt4)

Call rhino.selectobject (lin12)
rhino.Command "_pipe " & radius &" "& radius & " " & " _enter "
rhino.UnselectAllObjects

Call rhino.selectobject (lin23)
rhino.Command "_pipe " & ".1 " & ".1 " & " _enter " & " _enter "
rhino.UnselectAllObjects

Call rhino.selectobject (lin34)
rhino.Command "_pipe " & ".1 " & ".1 " & " _enter " & " _enter "
rhino.UnselectAllObjects

Call rhino.selectobject (lin41)
rhino.Command "_pipe " & ".1 " & ".1 " & " _enter " & " _enter "
rhino.UnselectAllObjects

Call rhino.selectobject (lin13)
rhino.Command "_pipe " & ".1 " & ".1 " & " _enter " & " _enter "
rhino.UnselectAllObjects

Call rhino.selectobject (lin24)
rhino.Command "_pipe " & ".1 " & ".1 " & " _enter " & " _enter "
rhino.UnselectAllObjects

End Function

' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 4 SURFRND -----

Sub surfrnd (strsurf,upar,vpar)

Dim dblheight : dblheight = rhino.getreal("elements height?" ,.3)

If isnull (dblheight) Then Exit Sub

Call rhino.enableredraw(False)
Dim i, j
Dim uvalone(1), uvaltwo
Dim arrUone, arrVone
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4, pt5, pt6
ReDim matrix (upar, vpar)
Dim tempt

arruone = array (0,0)
arrVone = array (0,0)
Dim strcell, arrct, arrptsurf, arrnorm, arrnormend, arrline, strcell2

If rhino.IsSurface(strsurf) Then
arruone = rhino.surfacedomain(strsurf,0)
arrVone = rhino.surfacedomain(strsurf,1)
End If

For i=0 To upar
For j=0 To vpar
uvalone(0)= ((arruone(1)-arruone(0))/upar)*i
uvalone(1) = ((arrVone(1)-arrVone(0))/vpar)*j
arrpttemp = rhino.EvaluateSurface(strsurf,uvalone)
matrix(i,j) = arrpttemp
Next
Next


Dim strcell3, strcell4

Dim rn


For i = 1 To upar-2 Step 4

For J=0 To vpar-2 Step 2
pt1 = matrix(i,j)
pt2 = matrix(i+1,j)
pt3 = matrix(i+2,j+1)
pt4 = matrix(i+1,j+2)
pt5 = matrix(i,j+2)
pt6 = matrix(i-1,j+1)

strcell = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt5,pt6,pt1),2)
arrct = array( (pt6(0)+pt3(0))/2,(pt6(1)+pt3(1))/2,(pt6(2)+pt3(2))/2)
arrptsurf = rhino.SurfaceClosestPoint(strsurf,arrct)
rn = rnd

strcell2 = rhino.ScaleObject(strcell,arrct,array(rn*0.7,rn*0.7,rn*0.7),True)

arrnorm = rhino.SurfaceNormal(strsurf,arrptsurf)
arrnorm = rhino.VectorScale(arrnorm, dblheight)
arrnormend = rhino.PointAdd(arrct,arrnorm)
arrline = rhino.AddLine(arrct,arrnormend)

rn = rnd
strcell3 = rhino.ScaleObject(strcell,arrct,array(rn*0.5,rn*0.5,rn*0.5),True)
strcell4 = rhino.ScaleObject(strcell,arrct,array(0.8,0.8,0.8),True)

rhino.MoveObject strcell3, arrct, arrnormend
rhino.MoveObject strcell4, arrct, arrnormend

Call rhino.AddLoftSrf(array(strcell,strcell2,strcell3,strcell4),,,,,,True)


Call rhino.DeleteObject (arrline)
Call rhino.DeleteObjects (array(strcell,strcell2,strcell3,strcell4))

Next
Next

For i = 3 To upar-2 Step 4
For J=1 To vpar-2 Step 2
pt1 = matrix(i,j)
pt2 = matrix(i+1,j)
pt3 = matrix(i+2,j+1)
pt4 = matrix(i+1,j+2)
pt5 = matrix(i,j+2)
pt6 = matrix(i-1,j+1)

strcell = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt5,pt6,pt1),2)
arrct = array( (pt6(0)+pt3(0))/2,(pt6(1)+pt3(1))/2,(pt6(2)+pt3(2))/2)
arrptsurf = rhino.SurfaceClosestPoint(strsurf,arrct)
rn = rnd

strcell2 = rhino.ScaleObject(strcell,arrct,array(rn*0.8,rn*0.8,rn*0.8),True)

arrnorm = rhino.SurfaceNormal(strsurf,arrptsurf)
arrnorm = rhino.VectorScale(arrnorm, dblheight)
arrnormend = rhino.PointAdd(arrct,arrnorm)
arrline = rhino.AddLine(arrct,arrnormend)
rn=rnd

strcell3 = rhino.ScaleObject(strcell,arrct,array(rn*0.8,rn*0.8,rn*0.8),True)
strcell4 = rhino.ScaleObject(strcell,arrct,array(0.9,0.9,0.9),True)

rhino.MoveObject strcell3, arrct, arrnormend
rhino.MoveObject strcell4, arrct, arrnormend

Call rhino.AddLoftSrf(array(strcell,strcell2,strcell3,strcell4),,,,,,True)


Call rhino.DeleteObject (arrline)
Call rhino.DeleteObjects (array(strcell,strcell2,strcell3,strcell4))

Next
Next

Call rhino.deleteobject(strsurf)
Call rhino.EnableRedraw(True)
End Sub
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 5 SURFBOX -----

Sub surfbox(strsurf,upar,vpar)

Call rhino.enableredraw(False)

Dim intposition: intposition = rhino.getreal ("maximum interposition?",0.4,0)
Dim intheight: intheight = rhino.getreal("maximum height?",0.6,0)

Dim i,j
Dim uvalone(1),uvaltwo
Dim arrudom, arrvdom
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4
Dim arrpts: arrpts = array(pt1,pt2,pt3,pt4)
ReDim arrpts (upar,vpar)
Dim temppt
arrudom = array(0,0)
arrvdom = array (0,0)

arrudom = rhino.SurfaceDomain(strsurf,0)
arrvdom = rhino.surfacedomain (strsurf,1)

For i = 0 To upar
For j= 0 To vpar
uvalone(0) = ((arrudom(1)-arrudom(0))/upar)*i
uvalone(1) = ((arrvdom(1)-arrvdom(0))/vpar) * (j)
arrpttemp = rhino.EvaluateSurface(strsurf, uvalone)
arrpts(i,j) = arrpttemp
Next
Next

For i = 0 To upar-1
For j=0 To vpar -1
pt1 = arrpts(i,j)
pt2 = arrpts(i+1,j)
pt3 = arrpts(i+1,j+1)
pt4 = arrpts (i,j+1)
Call boxes(pt1,pt2,pt3,pt4,intposition,intheight)

Next
Next

Call rhino.DeleteObject (strsurf)

Call rhino.enableredraw(True)

End Sub

Function boxes (pt1,pt2,pt3,pt4,intposition,intheight)
Dim tempsrf, arrdomainU, arrdomainv, arrdirection
Dim arrparam(1), arrnormal, linenormalsmall, linenormalbig, pt5
Dim linep1p4, linep1p4extend, linearray, linep1p2, linep1p4norm,linep1p2extend
Dim vertsurface1,vertsurface2, arrptdomain,arrptparam,pt6

tempsrf = rhino.AddSrfPt(array(pt1,pt2,pt3,pt4))

arrdomainU = rhino.surfacedomain(tempsrf,0)
arrdomainV = rhino.surfacedomain(tempsrf,1)
arrparam(0) = (arrdomainU(1)-arrdomainu(0))/2
arrparam(1) = (arrdomainV(1)-arrdomainV(0))/2
pt5 = rhino.EvaluateSurface(tempsrf, arrparam)


arrnormal = rhino.surfacenormal(tempsrf, arrparam)

Dim vector
vector = rhino.PointAdd(pt5,arrnormal)
linenormalsmall = rhino.AddLine(pt5, Rhino.VectorAdd(pt5,arrnormal))
linenormalbig = rhino.ExtendCurveLength(linenormalsmall, 0,1,intheight*rnd)

arrptdomain = rhino.CurveDomain(linenormalbig)
arrptparam = arrptdomain(1)
pt6 = rhino.EvaluateCurve(linenormalbig,arrptparam)


linep1p4 = rhino.AddLine(pt1,pt4)
linep1p2 = rhino.AddLine(pt1,pt2)
linep1p4norm = rhino.CopyObject(linep1p4,pt5,pt6)
linep1p4extend = rhino.ExtendCurveLength(linep1p4, 0,1,intposition)
linep1p2extend = rhino.ExtendCurveLength(linep1p2, 0,1,intposition)
linearray= (array(linep1p4extend,linep1p4norm))
vertsurface1 =rhino.AddEdgeSrf(linearray)
vertsurface2 = rhino.ExtrudeSurface(vertsurface1,linep1p2extend)

Call rhino.DeleteObject(tempsrf)
Call rhino.DeleteObjects(array(linep1p4norm,linep1p2extend,linep1p4extend,linep1p2,linep1p4))
rhino.UnselectAllObjects

End Function
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 9 SURFCURVES -----

Sub SURFCURVES(strsurf,upar,vpar)

Dim U,v, i,j,arrparam(1),arrpoint
Dim arrparamnormal, arrnormal, linenorm
Dim interpcurve
Dim strsurfloft, strinterpcurve, strinterpcurveonsurf, intheight, intloftfreq, intlofttype
Dim arrinterpcurve


upar = upar -1
vpar = vpar -1
intheight = rhino.getreal("maximum height?",1)
If isnull(intheight) Then Exit Sub
intloftfreq = rhino.getinteger("loft frequence?",2,2)
If intloftfreq < intlofttype =" rhino.getreal(">4 Then Exit Sub
intlofttype = intlofttype -1


U = rhino.SurfaceDomain(strsurf,0)
v = rhino.surfacedomain (strsurf,1)
If Not isarray(U) Or Not isarray (v) Then Exit Sub


For i = 0 To upar
arrparam(0) = u (0) + (((u(1)-u(0))/upar)*i)

For j = 0 To vpar
arrparam(1) = v (0) + (((v(1)-v(0))/vpar)*j)
arrpoint = rhino.evaluatesurface(strsurf,arrparam)
arrparamnormal = rhino.surfaceclosestpoint(strsurf,arrpoint)
arrnormal = rhino.surfacenormal(strsurf, arrparamnormal)
arrnormal = rhino.VectorScale(arrnormal,intheight)

Dim arrnvect
arrnvect = rhino.pointAdd(arrpoint,arrnormal)
' linenorm = rhino.AddLine(arrpoint,arrnvect)
' Call rhino.ObjectColor(linenorm,rgb(255,0,255))

ReDim Preserve arrnormptssurf(vpar)
arrnormptssurf(j)=arrpoint
ReDim Preserve arrnormptsEnd(vpar)
If i = 0 And i = upar And j=0 And j=vpar Then
arrnormptsEnd(j) = arrpoint
Else
arrnormptsEnd (j) = arrnvect
End If

Dim intcrossnpts: intcrossnpts = 2
Dim intstripefreq: intstripefreq = i+1
ReDim Preserve arrptwave(vpar)
Dim strWAVE
ReDim Preserve arrptwaveud(vpar)
Dim strwaveud

If intstripefreq Mod 2 Then
If intstripefreq <> 1 Then
If j Mod intcrossnpts Then

arrptwave(j) = arrnormptssurf(j)
arrptwaveud(j) = arrnormptssurf(j)
Else

arrptwave(j) = arrnormptssurfPr(j)
arrptwaveud(j) = arrnormptsEnd(j)
End If
If j = vpar Then

strWAVE = Rhino.AddInterpCrvOnSrf (strsurf,arrptwave)
strwaveud = Rhino.AddInterpCurve (arrptwaveud, 3)

arrInterpCurve = array(strWAVEp(i-1), strwaveudpr(i-1), strWAVE)
strsurfLoft = Rhino.AddLoftSrf (arrInterpCurve, , ,intLoftType,1,100, False)
Call Rhino.SurfaceIsocurveDensity (strsurfLoft, -1)
End If
End If
Else
If j Mod intcrossnpts Then
arrptwave(j) = arrnormptssurfPr(j)
arrptwaveud(j) = arrnormptsEnd(j)
Else
arrptwave(j) = arrnormptssurf(j)
arrptwaveud(j) = arrnormptssurf(j)
End If
If j = vpar Then
strWAVE = Rhino.AddInterpCrvOnSrf (strsurf,arrptwave)
strwaveud = Rhino.AddInterpCurve (arrptwaveud, 3)
If i>1 Then
arrInterpCurve = array(strWAVEp(i-1), strwaveudpr(i-1), strWAVE)
strsurfLoft = Rhino.AddLoftSrf (arrInterpCurve, , ,intLoftType,1,100, False)
Rhino.SurfaceIsocurveDensity strsurfLoft, -1


End If
End If

End If
ReDim Preserve strWAVEp(upar)
strWAVEp(i) = strWAVE
ReDim Preserve strwaveudpr(upar)
strwaveudpr(i) = strwaveud
ReDim Preserve arrnormptssurfPr(vpar)
arrnormptssurfPr(j) = arrnormptssurf(j)
ReDim Preserve arrnormptsEndpr(vpar)
arrnormptsEndpr(j) = arrnormptsEnd(j)


Next

Next

Call rhino.deleteobject (strsurf)


End Sub

' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 7 SURFBOXHOLE -----

Sub surfboxhole(strsurf,upar,vpar)
Call rhino.enableredraw(False)
Dim intposition: intposition = rhino.getreal ("maximum interposition?",0.05,0)
Dim intheight: intheight = rhino.getreal("maximum height?",0.4,0)

Dim i,j
Dim uvalone(1),uvaltwo
Dim arrudom, arrvdom
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4
Dim arrpts: arrpts = array(pt1,pt2,pt3,pt4)
ReDim arrpts (upar,vpar)
Dim temppt
arrudom = array(0,0)
arrvdom = array (0,0)

arrudom = rhino.SurfaceDomain(strsurf,0)
arrvdom = rhino.surfacedomain (strsurf,1)

For i = 0 To upar
For j= 0 To vpar
uvalone(0) = ((arrudom(1)-arrudom(0))/upar)*i
uvalone(1) = ((arrvdom(1)-arrvdom(0))/vpar) * (j)
arrpttemp = rhino.EvaluateSurface(strsurf, uvalone)
arrpts(i,j) = arrpttemp
Next
Next

For i = 0 To upar-1
For j=0 To vpar -1
pt1 = arrpts(i,j)
pt2 = arrpts(i+1,j)
pt3 = arrpts(i+1,j+1)
pt4 = arrpts (i,j+1)
Call drawbox2(pt1,pt2,pt3,pt4,intposition,intheight)

Next
Next

Call rhino.DeleteObject (strsurf)

Call rhino.enableredraw(True)

End Sub

Function drawbox2(pt1,pt2,pt3,pt4,intposition,intheight)
Dim tempsrf, arrdomainU, arrdomainv, arrdirection
Dim arrparam(1), arrnormal, linenormalsmall, linenormalbig, pt5
Dim linep1p4, linep1p4extend, linearray, linep1p2, linep1p4norm,linep1p2extend
Dim vertsurface1,vertsurface2, arrptdomain,arrptparam,pt6

tempsrf = rhino.AddSrfPt(array(pt1,pt2,pt3,pt4))

arrdomainU = rhino.surfacedomain(tempsrf,0)
arrdomainV = rhino.surfacedomain(tempsrf,1)
arrparam(0) = (arrdomainU(1)-arrdomainu(0))/2
arrparam(1) = (arrdomainV(1)-arrdomainV(0))/2
pt5 = rhino.EvaluateSurface(tempsrf, arrparam)


arrnormal = rhino.surfacenormal(tempsrf, arrparam)

Dim vector
vector = rhino.PointAdd(pt5,arrnormal)
linenormalsmall = rhino.AddLine(pt5, Rhino.VectorAdd(pt5,arrnormal))
linenormalbig = rhino.ExtendCurveLength(linenormalsmall, 0,1,intheight*rnd)

arrptdomain = rhino.CurveDomain(linenormalbig)
arrptparam = arrptdomain(1)
pt6 = rhino.EvaluateCurve(linenormalbig,arrptparam)


linep1p4 = rhino.AddLine(pt1,pt4)
linep1p2 = rhino.AddLine(pt1,pt2)
linep1p4norm = rhino.CopyObject(linep1p4,pt5,pt6)
linep1p4extend = rhino.ExtendCurveLength(linep1p4, 0,1,intposition)
linep1p2extend = rhino.ExtendCurveLength(linep1p2, 0,1,intposition)
linearray= (array(linep1p4extend,linep1p4norm))
vertsurface1 =rhino.AddEdgeSrf(linearray)
vertsurface2 = rhino.ExtrudeSurface(vertsurface1,linep1p2extend)

Dim linenormhuge
linenormhuge = rhino.ExtendCurveLength(linenormalsmall,0,1,40)
Dim ellipse1
ellipse1 = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt1))

rhino.SelectObject ellipse1
rhino.Command("-patch " & "enter")

Dim ellipse2

ellipse2=rhino.FirstObject

Dim ellipse3

ellipse3 = rhino.ExtrudeSurface(ellipse2,linenormhuge)

rhino.MoveObject ellipse3, pt6,pt5

Dim arrellipse, arrtrapezoid
arrellipse = (array(ellipse3))
arrtrapezoid = (array(vertsurface2))
rhino.BooleanDifference arrtrapezoid,arrellipse

Call rhino.DeleteObject(tempsrf)
Call rhino.DeleteObject(ellipse2)
Call rhino.DeleteObject(linenormhuge)
Call rhino.DeleteObjects(array(linep1p4norm,linep1p2extend,linep1p4extend,linep1p2,linep1p4))
rhino.UnselectAllObjects

End Function
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 8 SURFPYRAMID -----

Sub Surfpyramid(strsurf,upar,vpar)
Dim intheight: intheight = rhino.getreal("maximum height?",0.4,0)
Call rhino.enableredraw(False)

Dim i, j
Dim uvalone(1), uvaltwo
Dim arrudom, arrvdom
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4

Dim arrpts()
ReDim arrpts (upar, vpar)

arrudom = array(0,0)
arrvdom= array(0,0)

If rhino.IsSurface(strsurf) Then
arrudom = rhino.SurfaceDomain(strsurf, 0)
arrvdom = rhino.SurfaceDomain(strsurf, 1)

End If

For i=0 To upar
For j=0 To vpar
uvalone(0) = ((arrudom(1)-arrudom(0))/upar)*i
uvalone(1) = ((arrvdom(1)-arrvdom(0))/vpar)*j

arrpttemp = rhino.EvaluateSurface(strsurf,uvalone)
arrpts(i,j) = arrpttemp
Next
Next

For i =0 To upar-1
For j=0 To vpar-1
pt1 = arrpts (i,j)
pt2 = arrpts (i+1,j)
pt3 = arrpts (i+1,j+1)
pt4 = arrpts (i,j+1) 'rettangoli di base

Call pyramid (pt1,pt2,pt3,pt4,intheight)
Next

Next

Call rhino.EnableRedraw(True)
Call rhino.deleteobject (strsurf)

End Sub

Function pyramid(pt1,pt2,pt3,pt4,intheight)
Dim tempsrf, arrdomainU, arrdomainV, arrdirection
Dim arrparam(1), arrnormal, linenormalsmall, linenormalbig, arrptdomain, arrptparam
Dim pt5, pt6
Dim sideone, sidetwo, sidethree, sidefour
tempsrf = rhino.addsrfpt (array(pt1,pt2,pt3,pt4))

arrdomainU = rhino.SurfaceDomain(tempsrf,0)
arrdomainv= rhino.SurfaceDomain(tempsrf,1)
arrparam(0) = (arrdomainU(1)-arrdomainU(0))/2
arrparam(1) = (arrdomainv(1)-arrdomainV(0))/2
pt5 = rhino.EvaluateSurface(tempsrf, arrparam)

arrnormal = rhino.surfacenormal (tempsrf, arrparam)

Dim vector
vector = rhino.PointAdd(pt5,arrnormal)
linenormalsmall = rhino.AddLine(pt5, Rhino.VectorAdd(pt5,arrnormal))
linenormalbig = rhino.ExtendCurveLength(linenormalsmall, 0,1,intheight)'maybe rnd*height

rhino.selectobject (tempsrf)
rhino.Command "flip"
arrnormal = rhino.SurfaceNormal(tempsrf, arrparam)
vector = rhino.PointAdd(pt5,arrnormal)
linenormalsmall = rhino.AddLine(pt5, Rhino.VectorAdd(pt5,arrnormal))
'rhino.ExtrudeSurface tempsrf, linenormalsmall
arrptdomain = rhino.curvedomain(linenormalbig)
arrptparam = arrptdomain(1)
pt6 = rhino.EvaluateCurve(linenormalbig, arrptparam)

sideone = rhino.AddSrfPt (array(pt1,pt2,pt6))
sideone = rhino.AddSrfPt (array(pt2,pt3,pt6))
sideone = rhino.AddSrfPt (array(pt3,pt4,pt6))
sideone = rhino.AddSrfPt (array(pt4,pt1,pt6))

Call rhino.deleteobject(linenormalsmall)
Call rhino.deleteobject (linenormalbig)

End Function

' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 6 SURFWAVES -----

Sub Surfwaves (strsurf, nrows, ncolumns)
Dim u, v, i,j, arrparam(1), arrpoint
Dim arrparamnormal, arrnormal, normal, deltaheight
Dim vector, arrnormalnew
Dim strinterpcurve, strinterpcurveonsurf
Dim strsurfloft

nrows = nrows -1
ncolumns = ncolumns -1

deltaheight = rhino.GetReal("wave height?",5,1)
Call rhino.enableredraw(False)


U = RHino.SurfaceDomain(strsurf,0)
v = rhino.surfacedomain(strsurf,1)

If Not isarray(u) Or Not isarray(V) Then Exit Sub

For i = 0 To nrows
arrparam(0) = U(0) + ((U(1)-u(0))/nrows)*i

For j= 0 To ncolumns
arrparam(1) = V(0) + ((V(1)-V(0))/ncolumns)*j
arrpoint = rhino.evaluatesurface(strsurf, arrparam)

arrparamnormal = rhino.SurfaceNormal(strsurf,arrparam)
arrparamnormal= rhino.vectorscale(arrparamnormal, CDbl(deltaheight))
vector = rhino.PointAdd(arrpoint,arrparamnormal)
normal = rhino.AddLine(arrpoint, vector)

ReDim Preserve arrnormalendcollection(ncolumns)
If j = 0 And j = ncolumns Then
arrnormalendcollection(j)=arrpoint
Else
arrnormalendcollection(j) = vector
End If

ReDim Preserve arrnormaloriginecollection(ncolumns)
arrnormaloriginecollection(j) = arrpoint

Call rhino.deleteobject (normal)

Next


ReDim Preserve arrInterpcurve(nrows)
If i Mod 2 Then
arrinterpcurve(i) = rhino.addinterpcurve(arrnormalendcollection)
Else
arrinterpcurve(i) = rhino.AddInterpCrvOnSrf(strsurf,arrnormaloriginecollection)
End If

Next

strsurfloft = rhino.AddLoftSrf(arrinterpcurve, , ,3,1,100)
rhino.SurfaceIsocurveDensity strsurfloft, -1
rhino.ObjectColor strsurfloft, rgb(255,0,255)

Call rhino.DeleteObjects (arrinterpcurve)
Call rhino.deleteobject (strsurf)
Call rhino.deleteobjects (vector)
Call rhino.EnableRedraw(True)

End Sub

1 comment:

  1. After a long silence....someone's back!

    Good job Vink! ;-)

    ReplyDelete