[code] Is there a way to know if cursor on top of shadow?
-
Thanks TIG for the fast replay!
Your suggestion seems like the right way so I will try to make it work...again thanks!
-
If you do manage to get a working method perhaps you could share just that part of your new tool on the open forum ?
-
@tig said:
If you do manage to get a working method perhaps you could share just that part of your new tool on the open forum ?
Hi, I am currently doing some little research before making the final code and I stumbled on a post you made that might be useful to understand.
Here is what you coded on this thread...http://sketchucation.com/forums/viewtopic.php?f=323&t=35887&start=0
@tig said:
model=Sketchup.active_model
svec=model.shadow_info["SunDirection"]
peye=model.active_view.camera.eye
clin=model.active_entities.add_cline(peye, svec)
clin.end=nil
clin.start=peyeOf course if I am able to make working code I will share it with forum.
By the way the basic idea for this was to add a feature to a plugin I am making called "Canvas" where you make a group or component plane that has material opacity to about 5% and this will allow you to "paint" groups or comp to only faces that have shadow on them.
But thinking of others ideas on how else this can be useful is fun...cheers!
-
WIP
Hi, here is a what I have done so far...
@@model = Sketchup.active_model ; def onLButtonDown(flags,x,y,view) ip1 = view.inputpoint x,y ; point = ip1.position ; svec = @@model.shadow_info["SunDirection"] ; peye = @@model.active_view.camera.eye ; clin = @@model.active_entities.add_cline(point, svec) ; clin.end = peye ; clin.start = point ; end #def
I started with add_cline to test but soon I will add the model.raytest to evaluate if it returns nill or not.
Again thanks and will keep you posted on the progress
Note: Here is the Canvas Plugin just in case someone is interested...
http://sketchucation.com/forums/viewtopic.php?f=323&t=51655 -
Here is the final code to detect if the cursor is on a shadow...
@@model = Sketchup.active_model ; def onLButtonDown(flags,x,y,view) ip1 = view.inputpoint x,y ; point = ip1.position ; svec = @@model.shadow_info["SunDirection"] ; hit_path = Sketchup.active_model.raytest [point,svec] if hit_path != nil UI.messagebox("On Shadow") ; end #if end #def
Thanks TIG!
-
Is sun direction pointing to the sun? Not from the sun?
Btw, no need to compare against nil. (
!= nil
or== nil
)if hit_path != nil
is the same as
if hit_path
If you want to check if an value is
nil
- then you can use.nil?
-
The 'SunDirection' gives something like:
Vector3d(-0.424437, -0.772256, 0.47273)
When the sun is 'in the south' so that suggests the returned vector is towards the sun.
Otherwise its Z would be negative - i.e. downwards ?? -
True that. Just didn't expect it.
-
Thanks thomthom for pointing out that "!= nil" was not needed.
cheers!
-
... because in a boolean expression
nil
(andfalse
,) eval falsely.Everything else including
true
,[]
(an empty array), and0
(the integer zero,) evaluate truthfully.
Advertisement