Module: AMS::RayUtil
- Defined in:
- ray_util.rb
Overview
Ray utility adds more options to the
Sketchup.active_model.raytest method.
Class Method Summary (collapse)
-
+ (Array<Geom::Point3d>) deepray_t1(point, vector, chg = false)
Get an array of points intersecting the ray.
-
+ (Array<Geom::Point3d>) deepray_t2(ents, point, vector, chg = false)
Get an array of points intersecting the ray.
-
+ (Array<Geom::Point3d>) deepray_t3(ents, point, vector, chg = false)
Get an array of points intersecting the ray.
-
+ (Array?) raytest_t1(ents, point, vector, chg = false)
Cast a ray through the model and get the first thing that the ray hits.
-
+ (Array?) raytest_t2(ents, point, vector, chg = false)
Cast a ray through the model and get the first thing that the ray hits.
-
+ (Array?) raytest_t3(point, vector, chg = false)
Cast a ray through the model and get the first thing that the ray hits.
Class Method Details
+ (Array<Geom::Point3d>) deepray_t1(point, vector, chg = false)
Get an array of points intersecting the ray. T1 : type 1 checks all model entities.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'ray_util.rb', line 12 def deepray_t1(point, vector, chg = false) chg = chg ? true : false pts = [] hit = nil while true hit = Sketchup.active_model.raytest(point, vector, !chg) break unless hit x = hit[0] pts.push x point = x end pts end |
+ (Array<Geom::Point3d>) deepray_t2(ents, point, vector, chg = false)
Get an array of points intersecting the ray. T2 : type 2 checks all the given entities.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'ray_util.rb', line 34 def deepray_t2(ents, point, vector, chg = false) chg = chg ? true : false unless ents.is_a?(Array) ents = ents.respond_to?(:to_a) ? ents.to_a : [ents] end entIDs = Hash[ents.map {|e| [e.entityID, 1]}] pts = [] hit = nil while true hit = Sketchup.active_model.raytest(point, vector, !chg) break unless hit x = hit[0] pts.push x if entIDs[hit[1][0].entityID] point = x end pts end |
+ (Array<Geom::Point3d>) deepray_t3(ents, point, vector, chg = false)
Get an array of points intersecting the ray. T3 : type 3 checks all, but the given entities.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'ray_util.rb', line 60 def deepray_t3(ents, point, vector, chg = false) chg = chg ? true : false unless ents.is_a?(Array) ents = ents.respond_to?(:to_a) ? ents.to_a : [ents] end entIDs = Hash[ents.map {|e| [e.entityID, 1]}] pts = [] hit = nil while true hit = Sketchup.active_model.raytest(point, vector, !chg) break unless hit x = hit[0] pts.push x unless entIDs[hit[1][0].entityID] point = x end pts end |
+ (Array?) raytest_t1(ents, point, vector, chg = false)
Cast a ray through the model and get the first thing that the ray hits. T1 : type 1 checks all the given entities.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'ray_util.rb', line 87 def raytest_t1(ents, point, vector, chg = false) chg = chg ? true : false unless ents.is_a?(Array) ents = ents.respond_to?(:to_a) ? ents.to_a : [ents] end entIDs = Hash[ents.map {|e| [e.entityID, 1]}] hit = nil while true hit = Sketchup.active_model.raytest(point, vector, !chg) break unless hit return hit if entIDs[hit[1][0].entityID] point = hit[0] end nil end |
+ (Array?) raytest_t2(ents, point, vector, chg = false)
Cast a ray through the model and get the first thing that the ray hits. T2 : type 2 checks all, but the given entities.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'ray_util.rb', line 112 def raytest_t2(ents, point, vector, chg = false) chg = chg ? true : false unless ents.is_a?(Array) ents = ents.respond_to?(:to_a) ? ents.to_a : [ents] end entIDs = Hash[ents.map {|e| [e.entityID, 1]}] hit = nil while true hit = Sketchup.active_model.raytest(point, vector, !chg) break unless hit return hit unless entIDs[hit[1][0].entityID] point = hit[0] end nil end |
+ (Array?) raytest_t3(point, vector, chg = false)
Cast a ray through the model and get the first thing that the ray hits. T3 : type 3 passes through transparent faces and stops until it hits a solid face.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'ray_util.rb', line 137 def raytest_t3(point, vector, chg = false) chg = chg ? true : false hit = nil model = Sketchup.active_model cam = model.active_view.camera while true hit = model.raytest(point, vector, !chg) break unless hit ent = hit[1].last return hit unless ent.is_a?(Sketchup::Face) angle = ent.normal.angle_between(cam.direction) mat = nil normal = ent.normal for i in 0...(hit[1].size-1) e = hit[1][i] normal.transform!(e.transformation) mat = e.material if e.material != nil end fmat = angle < 90.degrees ? ent.back_material : ent.material mat = fmat if fmat != nil return hit if mat.nil? or mat.alpha == 1.0 point = hit[0] end nil end |