forked from mcneel/rhino-developer-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalysisMeshSlope.rvb
62 lines (51 loc) · 2.17 KB
/
AnalysisMeshSlope.rvb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' AnalysisMeshSlope.rvb -- February 2010
' If this code works, it was written by Dale Fugier.
' If not, I don't know who wrote it.
' Works with Rhino 4.0.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' First, download and install the Analysis Tools
' plug-in from Rhino Labs:
'
' http://wiki.mcneel.com/labs/labsanalysistools
'
' This plug-in allows you to view meshes that have custom analysis data, such
' as slope.
'
' After you have installed this plug-in, drag and drop the attached
' RhinoScript on top of Rhino and then run the AnalysisMeshSlope command on
' some mesh. If all you have is a surface, then use either the Mesh or
' ExtractRenderMesh commands to produce a mesh from your surface. Finally, use
' the AnalyzeMesh command to make adjustments to the color scale.
'
' In a nutshell, the AnalysisMeshSlope script calculates the slope (angle) at
' each mesh vertex. These angles are then assigned to the mesh as analysis
' data. The Analysis Tools plug-in takes the analysis data (angles) and
' calculate color values using an algorithm similar to what is presented here:
'
' http://wiki.mcneel.com/developer/scriptsamples/hotcoldcolor
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub AnalysisMeshSlope()
Dim objAnalysis, strMesh, arrNormals, arrAngles(), arrDir, i
On Error Resume Next
Set objAnalysis = Rhino.GetPluginObject("Analysis Tools")
If Err Then
Rhino.Print "Unable to connect to AnalysisTools plug-in."
Exit Sub
End If
strMesh = Rhino.GetObject("Select mesh", 32, True)
If IsNull(strMesh) Then Exit Sub
arrNormals = Rhino.MeshVertexNormals(strMesh)
If IsNull(arrNormals) Then
Rhino.Print "The strMesh does not have vertex arrNormals."
Exit Sub
End If
arrDir = Array(0,0,1)
ReDim arrAngles(UBound(arrNormals))
For i = 0 To UBound(arrNormals)
arrAngles(i) = Rhino.VectorAngle(arrNormals(i), arrDir)
Next
Call objAnalysis.AnalysisMeshData(strMesh, arrAngles)
End Sub