-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathex_mesh.rb
135 lines (116 loc) · 3.35 KB
/
ex_mesh.rb
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#####################################################
# ex_mesh.rb
# by Brad Denniston Copyright (c) 2014
#
# Demonstrate PolygonMesh methods
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#####################################################
module Mesh
# create global variables
#
def self.reset
$inst1 = nil
$inst2 = nil
$inst3 = nil
$face = nil
$mesh = nil
$mesh2 = nil
$pts = Array.new
end
# cubecomp - build 3 cubes
#
def self.cubecomp
points = Array.new
points[0] = ORIGIN
points[1] = [10,0,0]
points[2] = [10,10,0]
points[3] = [0,10,0]
# create a component definition for the cube
new_comp_def = Sketchup.active_model.definitions.add("Cube size 10")
# create a face instance
newface = new_comp_def.entities.add_face(points)
# extend the face in the component definition into a cube
# If the z face is pointing up, reverse it.
newface.reverse! if newface.normal.z < 0
newface.pushpull 10 # now this is the cube is defined
# an instance must be placed at some location, transform it
trans0 = Geom::Transformation.new # an empty, default transformation.
# Create an instance of the Cube component.
act_ents = Sketchup.active_model.active_entities
new_inst_index = act_ents.size - 1
act_ents.add_instance(new_comp_def, trans0)
$inst1 = act_ents[new_inst_index]
trans1 = Geom::Transformation.new([4,4,4])
$inst2 = act_ents.add_instance(new_comp_def, trans1)
$inst3 = act_ents.add_instance(new_comp_def, trans1)
end
# makeAface
#
def self.makeAface
$mesh1 = Geom::PolygonMesh.new
$mesh2 = Geom::PolygonMesh.new
$pts[0] = ORIGIN
$pts[1] = [10,0,0]
$pts[2] = [10,10,0]
$pts[3] = [0,10,0]
# Add the face to the entities in the model
entities = Sketchup.active_model.active_entities
$face = entities.add_face($pts)
p "The face is #{$face}" # shows all 4 edges
# to_s is no different
# to_a is not defined
print "\n"
end
# all_connected
#
def self.all_connected
connected = $face.all_connected
p "connected is #{connected}" # shows all edges
# to_a same as just connected.
print "\n"
end
# makePolyMesh
#
def self.makePolyMesh
index = $mesh1.add_polygon( $pts )
p "mesh1 index is #{index}"
# p "Mesh1 is #{$mesh1[index]}" so what does the index mean?
print "\n"
end
# count_points
#
def self.count_points
index = $mesh2.add_polygon( $pts )
$pts[4] = [15,15,0]
$mesh2.add_point($pts[4]) # 5 sided
num = $mesh2.count_points
p "mesh2 point count is #{num}"
print "\n"
end
# faceToMesh
#
def self.faceToMesh
$mesh1 = $face.mesh(7)
p "mesh1 is now #{$mesh1}"
print "\n"
end
# point_at
#
def self.point_at
p "$mesh1 point at index 1 is #{$mesh1.point_at(1)}"
p "$mesh1 point at index 2 is #{$mesh1.point_at(2)}"
p "$mesh1 point at index 3 is #{$mesh1.point_at(3)}"
p "$mesh1 index of point at [0,10,0] is #{$mesh1.point_index($pts[3])}"
p "and $mesh1 points are #{$mesh1.points}"
print "\n"
end
self.reset
self.makeAface
self.all_connected
self.makePolyMesh
self.count_points
self.point_at
end #module