Seçilen mesh nesneleri yüzeyleri kamera yönünde olacak şekilde döndüren rhinoscript.
Kodu:
-
Option Explicit
-
‘Script written by AM
-
‘Script version Tuesday, 17 March 2009 22:00:34
-
‘Use in conjunction with RotateObjectsToCamera-Refresh
-
‘Rotates objects to face camera (typically for rendering). Only meshes for now.
-
‘Initiates AddObjectsToGroup sub and creates group.
-
‘***FLAWED*** RotateObjectsToCamera function sometimes must be run up to 5 times to affect all objects correctly. CW/CCW fail
-
-
Call AddObjectsToGroup()
-
Sub AddObjectsToGroup()
-
-
Dim strObjects
-
Dim strGroupID
-
Dim strGroupObjects
-
-
strObjects = Rhino.GetObjects(“Select meshes to add to rotate group”, 32, True, True)
-
If IsNull(strObjects) Then
-
Rhino.Print “No valid objects selected.”
-
Exit Sub
-
End If
-
-
strGroupID = “RotateToCamera”
-
-
If Not IsGroup(strGroupID) Then Rhino.AddGroup(strGroupID)
-
Rhino.AddObjectsToGroup strObjects, strGroupID
-
strGroupObjects = Rhino.ObjectsByGroup(strGroupID)
-
-
RotateObjectsToCamera(strGroupObjects)
-
-
End Sub
-
-
Function RotateObjectsToCamera(strGroupObjects)
-
-
Dim strObjects : strObjects = strGroupObjects
-
Dim arrCam, arrVertices, arrVertex, strBottomLine, arrMid
-
Dim arrLine1, arrLine2, arrAngle, dblRotateAngle
-
Dim arrNormals, arrPlane, arrVecCamToMid, arrNormalAngle
-
Dim i
-
-
arrCam = Rhino.ViewCamera
-
-
Rhino.EnableRedraw(False)
-
For i=0 To UBound(strObjects)
-
-
‘OBJECT TYPE
-
Select Case Rhino.ObjectType(strObjects(i))
-
Case 8
-
arrNormals = Rhino.SurfaceNormal(strObjects(i))
-
arrVertices = Rhino.SurfacePoints(strObjects(i))
-
Case 32
-
arrNormals = Rhino.MeshVertexNormals(strObjects(i))
-
arrVertices = Rhino.MeshVertices(strObjects(i))
-
End Select
-
-
If IsNull(arrNormals) Then Exit For
-
If IsNull(arrVertices) Then Exit For
-
-
‘CONSTRUCTION LINES
-
arrVertex = arrVertices(2)
-
strBottomLine = Rhino.AddLine(arrVertices(0), arrVertex)
-
arrMid = Rhino.CurveMidPoint(strBottomLine)
-
-
arrLine1 = Array(Array(arrCam(0),arrCam(1)), Array(arrMid(0),arrMid(1)))
-
arrLine2 = Array(Array(arrVertices(0)(0),arrVertices(0)(1)), Array(arrVertex(0),arrVertex(1)))
-
arrAngle = Rhino.Angle2(arrLine1, arrLine2)
-
If Not IsArray(arrAngle) Then Exit For
-
-
‘NORMAL ANALYSIS. FRONT VS BACK, CW VS CCW
-
arrPlane = Rhino.PlaneFromNormal(arrVertices(0), arrNormals(0))
-
arrVecCamToMid = Rhino.VectorCreate(Array(arrCam(0),arrCam(1)), Array(arrMid(0),arrMid(1)))
-
-
Dim u0 : u0 = Rhino.VectorUnitize(arrVecCamToMid)
-
Dim u1 : u1 = Rhino.VectorUnitize(arrPlane(0))
-
Dim cross : cross = Rhino.VectorCrossProduct(u0, u1)
-
‘Rhino.Print Rhino.Pt2Str(cross)
-
-
‘ALREADY PERPENDICULAR
-
If cross(2) = 0 Then Exit For
-
-
‘FRONT
-
If cross(2) < 0 Then
-
‘Rhino.Print “Angle: ” & CStr(arrAngle(0))
-
dblRotateAngle = (CDbl(arrAngle(0)))-90
-
Rhino.RotateObject strObjects(i), arrMid, dblRotateAngle
-
End If
-
-
‘BACK
-
If cross(2) > 0 Then
-
‘Rhino.Print “Angle: ” & CStr(arrAngle(0))
-
dblRotateAngle = 90-(CDbl(arrAngle(0)))
-
Rhino.RotateObject strObjects(i), arrMid, dblRotateAngle
-
End If
-
-
Rhino.DeleteObjects Array(strBottomLine)
-
-
Next
-
Rhino.EnableRedraw(True)
-
End Function
Dosyayı indirmek için tıklayın.
Kaynak: http://www.rhinoscript.org/scripts/65
