You're absolutely correct...I pulled the code out of context of a longer section of code, re-(mis-)labeled a few things, all in an effort to minimize the reading required by anyone attempting to help me out, since RAYTEST seems to be the crux of the problem (I think).
In case you care to read my entire code, it is below, though I've added a big comment block with #RAYTEST SECTION# if you want to skip to that.
The test point array is '@suns'
Thank you for trying to help me
module MC_sun_tools
@model = Sketchup.active_model
@ents = @model.entities
@sel = @model.selection
def MC_sun_tools.generate_suns
# Initialize some variables
tz = -5.0
altitude = 1000.m #We'll generate points 1km away
@suns = [] # An array to hold our "suns"
si = @model.shadow_info
ct = si["ShadowTime"] #the class of ct is Time
yr = ct.year
mon = 9 #ct.month
day = ct.day
# The points we add will be part of a new group
#my_verts = @sel[0].vertices
new_ent = @ents.add_group
new_ent.name = "{mon}-{day}"
0.upto(24*4-1) {|hour|
t = Time.local(yr, mon, day, hour/4, (hour.to_f/4 % 1)*60)
si['ShadowTime'] = t
v = si["SunDirection"]
v.length = altitude
pt = ORIGIN + v
new_ent.entities.add_cpoint(pt)
new_ent.entities.add_text(((hour/4-tz) % 24).to_i.to_s, pt)
@suns << pt #if pt.is_a? Sketchup;;Point3d
}
end
def MC_sun_tools.get_faces
my_faces = []
@sel.each {|e|
if e.is_a? Sketchup;;Face
my_faces << e
end
}
my_faces.each {|e|
MC_sun_tools.test_suns(e)
}
puts my_faces.length
end
######################################################
#########RAYTEST SECTION##############################
def MC_sun_tools.test_suns(face)
center = face.bounds.center
normal = face.normal
face.material= @color_hash[1]
counter = 1
0.upto(@suns.length-1) {|s|
ray = [center,@suns[s]]
item = @model.raytest(ray,false)
#puts item
if item == nil
sun_vector = center.vector_to @suns[s]
an = normal.angle_between sun_vector
counter = counter + Math.cos(an)*0.8
#puts cos(an)
#@ents.add_cline(center, @suns[s])
end
}
face.material = @color_hash[[counter.to_i, 25].min]
end
########################################################
@color_hash = [[0, 0, 180],
[0, 30, 180],
[0, 60, 180],
[0, 90, 180],
[0, 120, 180],
[0, 150, 180],
[0, 180, 180],
[0, 180, 150],
[0, 180, 120],
[0, 180, 90],
[0, 180, 60],
[0, 180, 30],
[0, 180, 0],
[30, 180, 0],
[60, 180, 0],
[90, 180, 0],
[120, 180, 0],
[150, 180, 0],
[180, 180, 0],
[180, 150, 0],
[180, 120, 0],
[180, 90, 0],
[180, 60, 0],
[180, 30, 0],
[180, 0, 0]]
end
plug_menu = UI.menu("Plugins")
plug_menu.add_item("Generate Suns") {MC_sun_tools.generate_suns}
plug_menu.add_item("Test Suns") {MC_sun_tools.test_suns}
plug_menu.add_item("Get Faces") {MC_sun_tools.get_faces}