surface Components-2 [class 20091215]

this script includes functions that add X-braces and triangular surfaces as surface components

Option Explicit
'Script written by onur yuce gun
'Script copyrighted by
'Script version Tuesday, December 15, 2009 10:28:40 AM
Dim uNum
Dim vNum

Call Main()
Sub Main()
	Dim mySrf
	uNum = Rhino.GetInteger ("enter u division number",10)
	vNum = Rhino.GetInteger ("enter v division number",10)
	mySrf = rhino.GetObject("select surface")
	rhino.EnableRedraw False
	'get the surface points from the first function
	Dim srfPt
	srfPt =	uvPts(mySrf,uNum,vNum)
	'create xBrace on the uv grid
	Dim xBr
	xBr = xBrace(srfPt)
	'create sub syrface
	Dim sSrf
	sSrf = subSrf(srfPt)
	rhino.EnableReDraw True
End Sub
Function uvPts(srf, uDiv, vDiv)
	'find the surface domain
	Dim srfDomU
	Dim srfDomV
	srfDomU = Rhino.SurfaceDomain(srf,0)
	srfDomV = Rhino.SurfaceDomain(srf,1)
	'define parameter variables
	Dim parU
	Dim parV
	Dim parUV
	'all points array
	Dim allPt
	ReDim allPt (uDiv,vDiv)
	'counters
	Dim i,j
	For i = 0 To uDiv
		For j = 0 To vDiv
			parU = (srfDomU(1)/uDiv)*i
			parV = (srfDomV(1)/vDiv)*j
			parUV = Array(parU,parV)
			allPt(i,j) = Rhino.EvaluateSurface (srf, parUV)
			rhino.AddPoint allPt(i,j)
		Next
	Next
	uvPts = allPt
End Function
Function xBrace(ptArray)
	rhino.AddLayer "xBrace"
	Dim m
	Dim n
	Dim a1
	Dim a2
	For m = 0 To uNum-1
		For n = 0 To vNum-1
			a1 = rhino.AddLine (ptArray(m,n), ptArray(m+1,n+1))
			a2 = rhino.AddLine (ptArray(m+1,n), ptArray(m,n+1))
			rhino.ObjectLayer a1, "xBrace"
			rhino.ObjectLayer a2, "xBrace"
		Next
	Next
End Function
Function subSrf(ptArray)
	rhino.AddLayer "subSrf",RGB(20,210,200)
	rhino.AddLayer "subSrf_Off", RGB(100,10,200)
	Dim m
	Dim n
	Dim allSubSrf
	ReDim allSubSrf(uNum-1,vNum-1)
	For m = 0 To uNum-1
		For n = 0 To vNum-1
			allSubSrf(m,n) = rhino.AddSrfPt (Array(ptArray(m,n), ptArray(m+1,n),ptArray(m+1,n+1)))
			rhino.ObjectLayer allSubSrf(m,n),"subSrf"
			rhino.OffsetSurface allSubSrf(m,n),-1.5
			rhino.ObjectLayer rhino.firstObject,"subSrf_off" 'the last object created in the scene.
		Next
	Next
	subSrf = allSubSrf
End Function
Advertisement

~ by onuryucegun on 2009/12/17.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.