sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    [code] Is there a way to know if cursor on top of shadow?

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 4 Posters 441 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • renderizaR Offline
      renderiza
      last edited by

      Thanks TIG for the fast replay!

      Your suggestion seems like the right way so I will try to make it work...again thanks!

      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

      1 Reply Last reply Reply Quote 0
      • TIGT Online
        TIG Moderator
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • renderizaR Offline
          renderiza
          last edited by

          @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=peye

          Of 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!

          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

          1 Reply Last reply Reply Quote 0
          • renderizaR Offline
            renderiza
            last edited by

            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

            [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

            1 Reply Last reply Reply Quote 0
            • renderizaR Offline
              renderiza
              last edited by

              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!

              [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                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?

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • TIGT Online
                  TIG Moderator
                  last edited by

                  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 ??

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    True that. Just didn't expect it.

                    Thomas Thomassen β€” SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • renderizaR Offline
                      renderiza
                      last edited by

                      Thanks thomthom for pointing out that "!= nil" was not needed.

                      cheers!

                      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        ... because in a boolean expression nil (and false,) eval falsely.

                        Everything else including true, [] (an empty array), and 0 (the integer zero,) evaluate truthfully.

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement