Option Explicit
'Script written by Luis Quinones
'Script copyrighted by [n]igma + studioBoom
'www.luisquinonesdesign.com
'www.cargocollective.com/studioboom
'Script version Sunday, March 20, 2011 8:08:03 PM
Call Main()
Sub Main()
'///////////////////////////////////////////////////////////////////////////////////////////////////
Call Rhino.MessageBox("Code Generates Mesh OffSets and Frames Based on Luminance Values coming from Geometry Painted with PaintVertex Tool in Maya")
'Declare Variables
Dim strMainLayer : strMainLayer = Rhino.AddLayer("MainMesh")
Dim strObject : strObject = Rhino.GetObject("Select mesh", 32)
Call Rhino.ObjectLayer(strObject,strMainLayer)
MeshFaces
Dim arrFaces : arrFaces = Rhino.MeshFaces(strObject, True)
Dim color : color = Rhino.MeshVertexColors(strObject)
Dim arrFace(3),arrHLS(3)
Dim arrFaceVertices2()
Dim strLayer6 : strLayer6 = Rhino.AddLayer("BaseCrvs",RGB(255,0,0))
Dim strLayer2 : strLayer2 = Rhino.AddLayer("OffsetCrv",RGB(255,0,0))
Dim strLayer : strLayer = Rhino.AddLayer("OffSetMesh",RGB(255,0,0))
Dim strLayer3 : strLayer3 = Rhino.AddLayer("FrameDog",RGB(255,255,255))
Dim strLayer5 : strLayer5 = Rhino.AddLayer("0_ValueOffSet",RGB(120,120,120))
Dim strLayer4 : strLayer4 = Rhino.AddLayer("Color_Vert_Info",RGB(255,255,0))
Dim i,j
'///////////////////////////////////////////////////////////////////////////////////////////////////
If IsArray(arrFaces) Then
Rhino.EnableRedraw False
i = 0
Do While i <= UBound(arrFaces)
arrFace(0) = arrFaces(i)
arrFace(1) = arrFaces(i+1)
arrFace(2) = arrFaces(i+2)
arrFace(3) = arrFaces(i+3)
arrHLS(0) = Rhino.ColorRGBToHLS(color(i))
'Call Rhino.Print(arrHLS(0)(1)/240)
arrHLS(1) = Rhino.ColorRGBToHLS(color(i+1))
'Call Rhino.Print(arrHLS(1)(1)/240)
arrHLS(2) = Rhino.ColorRGBToHLS(color(i+2))
'Call Rhino.Print(arrHLS(2)(1)/240)
arrHLS(3) = Rhino.ColorRGBToHLS(color(i+3))
'Call Rhino.Print(arrHLS(3)(1)/240)
'Call Rhino.AddTextDot("Vert 0" & "_" & arrHLS(0)(1)/240,arrface(0))
'Call Rhino.AddTextDot("Vert 1" & "_" & arrHLS(1)(1)/240,arrface(1))
'Call Rhino.AddTextDot("Vert 2" & "_" & arrHLS(2)(1)/240,arrface(2))
'Call Rhino.AddTextDot("Vert 3" & "_" & arrHLS(3)(1)/240,arrface(3))
Dim sum : sum = Rhino.Sum(Array(arrHLS(0)(1)/240,arrHLS(1)(1)/240,arrHLS(2)(1)/240,arrHLS(3)(1)/240))
Dim ave : ave = sum/4
'If ave < 0.015 Then
'ave = 0.015
'End If
'Call Rhino.Print(ave)
Dim line : line = Rhino.AddLine(arrFace(0),arrFace(2))
Dim midpt : midpt = Rhino.CurveMidPoint(line)
Call Rhino.DeleteObject(line)
'Dim dot1 : dot1 = Rhino.AddTextDot("Scale_Value = " & ave,midpt)
'Call Rhino.ObjectLayer(dot1,strLayer4)
Dim arrVertices : arrVertices = Array(arrFace(0),arrFace(1),arrFace(2),arrFace(3))
Dim arrVerticesNEW : arrVerticesNEW = Array(arrFace(0),arrFace(1),arrFace(2),arrFace(3),arrFace(0)) '///////////////////////////////////////////////////////////////////////////////////////////////////
For j = 0 To 3
ReDim Preserve arrFaceVertices2(j)
arrFaceVertices2(j) = Array(0,1,2,3)
Next
'///////////////////////////////////////////////////////////////////////////////////////////////////
Dim newMesh : newMesh = Rhino.AddMesh (arrVertices, arrFaceVertices2)
Call Rhino.ObjectLayer(newMesh,strLayer5)
Dim meshCent : meshCent = Rhino.MeshAreaCentroid(newMesh)
Dim strPoly : strPoly = Rhino.AddPolyline(arrVerticesNEW)
Call Rhino.ObjectLayer(strPoly,strLayer6)
Dim strPoly2 : strPoly2 = Rhino.AddPolyline(arrVerticesNEW)
Call Rhino.ObjectLayer(strPoly2,strLayer6)
'/////////////////////////////////////////////////////////////////////////////////////////////////
If ave > 0 And ave < 0.9 Then
Dim scaleMesh : scaleMesh = Rhino.ScaleObject(newMesh,meshCent,Array(ave,ave,ave))
Call Rhino.ObjectLayer(scaleMesh,strLayer)
Dim scaleSrf : scaleSrf = Rhino.ScaleObject(strPoly,meshCent,Array(ave,ave,ave))
Call Rhino.ObjectLayer(scaleSrf,strLayer2)
Dim strlofty : strlofty = Rhino.AddLoftSrf(Array(strPoly2,scaleSrf))
Call Rhino.ObjectLayer(strLofty,strLayer3)
Call Rhino.SurfaceIsocurveDensity(strlofty,-1)
'Call Rhino.DeleteObjects(join)
End If
'///////////////////////////////////////////////////////////////////////////////////////////////////
If ave >= 0.9 Then
Dim scaleMesh3 : scaleMesh3 = Rhino.ScaleObject(newMesh,meshCent,Array(ave-0.05,ave-0.05,ave-0.05))
Call Rhino.ObjectLayer(scaleMesh3,strLayer)
Dim scaleSrf3 : scaleSrf3 = Rhino.ScaleObject(strPoly,meshCent,Array(ave-0.05,ave-0.05,ave-0.05))
Call Rhino.ObjectLayer(scaleSrf3,strLayer2)
strlofty = Rhino.AddLoftSrf(Array(strPoly2,scaleSrf3))
Call Rhino.ObjectLayer(strLofty,strLayer3)
Call Rhino.SurfaceIsocurveDensity(strlofty,-1)
'Call Rhino.DeleteObjects(join3)
End If
i = i + 4
Erase arrFaceVertices2
Loop '///////////////////////////////////////////////////////////////////////////////////////////////////
Rhino.EnableRedraw True
End If
Call Rhino.LayerVisible(strLayer2,False)
Call Rhino.LayerVisible(strLayer4,False)
Call Rhino.LayerVisible(strMainLayer,False)
Call Rhino.LayerVisible(strLayer6,False)
End Sub
Update