sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Reverse operation of view.screen_coords

    Scheduled Pinned Locked Moved Developers' Forum
    30 Posts 5 Posters 744 Views 5 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      How about https://developers.google.com/sketchup/docs/ourdoc/inputpoint#position ?

      TIG

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

        @tig said:

        How about https://developers.google.com/sketchup/docs/ourdoc/inputpoint#position ?

        Doesn't that risk it snapping to nearby geometry? That's why I was thinking a raytest would be safest as it would not be affected by inference.

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

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

          He can specify the view's inputpoint by using screen-coordinates (x,y) ?
          And then get the inputpoint's position as a 3dPoint ??

          That way he can get the screen width as with y at 0, and x at 0 and screen-width, gives two points - he can get the distance between them, then that's the amount to shunt the camera's eye/target across to pan a whole screen in the x-direction ?

          TIG

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

            This 'proof of concept' pans the whole screen to the right [in plan is easiest to see...]

            def pan_whole_screen_to_the_right()
              model=Sketchup.active_model
              view=model.active_view
              ip0=view.inputpoint(0,0)
              ip1=view.inputpoint(view.vpwidth,0)
              p0=ip0.position
              p1=ip1.position
              dis=p0.distance(p1)
              cam=view.camera
              eye=cam.eye
              tar=cam.target
              upp=cam.up
              eye.x=eye.x+dis
              tar.x=tar.x+dis
              cam.set(eye,tar,upp)
            end
            

            Obviously you can make a more flexible method which could pan right/left and up/down as desired...

            TIG

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

              @tig said:

              He can specify the view's inputpoint by using screen-coordinates (x,y) ?
              And then get the inputpoint's position as a 3dPoint ??

              But my concern was that InputPoint will return a 3D point affected by inference, ie it snaps to mid points or something, based onthe 2D point.

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

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

                I see the point. πŸ˜’
                Here's a fuller version that avoids that [can you think of a better way?]

                def pan_whole_screen_to_the_right()
                  model=Sketchup.active_model
                  ents=model.entities
                  ants=model.active_entities
                  pants=ents.to_a+ants.to_a
                  hidn=pants.uniq.find_all{|e|not e.hidden?}
                  model.start_operation('pants')
                  hidn.each{|e|e.hidden=true}
                  hgeo=model.rendering_options["DrawHidden"]
                  model.rendering_options["DrawHidden"]=false
                  view=model.active_view
                  ip0=view.inputpoint(0,0)
                  ip1=view.inputpoint(view.vpwidth,0)
                  p0=ip0.position
                  p1=ip1.position
                  dis=p0.distance(p1)
                  cam=view.camera
                  eye=cam.eye
                  tar=cam.target
                  upp=cam.up
                  eye.x=eye.x+dis
                  tar.x=tar.x+dis
                  cam.set(eye,tar,upp)
                  hidn.each{|e|e.hidden=false}
                  model.rendering_options["DrawHidden"]=hgeo
                  model.commit_operation
                end
                

                TIG

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

                  @tig said:

                  Here's a fuller version that avoids that [can you think of a better way?] [code]def pan_whole_screen_to_the_right()

                  http://forums.sketchucation.com/viewtopic.php?f=180&t=44290#p394956

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

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

                    Therefore we can substitute
                    p0=view.pickray(0,0)[0] p1=view.pickray(view.vpwidth,0)[0]
                    and get a simpler method because the ray's point doesn't get influenced by inferences and is made on the picture-plane, as it were...

                    def pan_whole_screen_to_the_right()
                      model=Sketchup.active_model
                      view=model.active_view
                      p0=view.pickray(0,0)[0]
                      p1=view.pickray(view.vpwidth,0)[0]
                      dis=p0.distance(p1)
                      cam=view.camera
                      eye=cam.eye
                      tar=cam.target
                      upp=cam.up
                      eye.x=eye.x+dis
                      tar.x=tar.x+dis
                      cam.set(eye,tar,upp)
                    end
                    

                    πŸ˜„

                    TIG

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

                      Ah, yes! Of course - no need to pick anything. I forgot that the ray contained a point that could be used directly.

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

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

                        Two brains are better than one [at least our combined IQs add up to around the average!!]
                        πŸ˜†

                        TIG

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

                          I've already determined that my brain is on timeshare lease... πŸ˜’

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

                          1 Reply Last reply Reply Quote 0
                          • J Offline
                            jpark
                            last edited by

                            TIG and thomthom,

                            Do you guys ever sleep!!??
                            You gave me a plenty of assignment for the weekend; to digest all that you posted.

                            For your info, I am attempting to model a 'plan viewer' for blueprints which will become framework for architectural components

                            Thanks guys

                            John

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

                              "Sl-eep"..? πŸ˜•

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

                              1 Reply Last reply Reply Quote 0
                              • J Offline
                                jpark
                                last edited by

                                Just finished reading up on view.pickray method and ran TIG's sample code. At first glance it should have worked but does not. In executing each line, I find that p0 and p1 return same value as camera eye position. See Ruby Console responses below:

                                p0=view.pickray(0,0)[0] Point3d(3255.11, 1479.16, 8761.61) p1=view.pickray(view.vpwidth,0)[0] Point3d(3255.11, 1479.16, 8761.61) p2=view.pickray(0,view.vpheight)[0] Point3d(3255.11, 1479.16, 8761.61) p3=view.pickray(view.vpwidth,view.vpheight)[0] Point3d(3255.11, 1479.16, 8761.61) cam=Sketchup.active_model.active_view.camera #<Sketchup::Camera:0x7ce5de0> cam.eye Point3d(3255.11, 1479.16, 8761.61) cam.target Point3d(3255.11, 1479.16, 127.281) cam.up Vector3d(0, 1, 0)

                                How could this be? I thought I understood pickray method but NOT

                                Off the topic note: where can I find instruction on how to annotate posting w/ codes, images, smiles, etc ...

                                John

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

                                  I added some 'ruby' tags to make it clearer...

                                  I hope this is not ALL of the code...
                                  Have you set the view and so on earlier ?
                                  IF so... you don't use
                                  cam=Sketchup.active_model.active_view.camera
                                  but
                                  cam=view.camera
                                  ???
                                  My code is a working example.......

                                  TIG

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

                                    @jpark said:

                                    Off the topic note: where can I find instruction on how to annotate posting w/ codes, images, smiles, etc ...

                                    There is a "hard to find" link on each message "POST A REPLY" page, in the right column, beneath the "Smilies" list.

                                    Notice how the line "BBCode is ON" has a link ??

                                    It leads you to a user guide for the code tags.

                                    Most of these usable tags have toolbar button "inserters" already set up for you to use. You just click the button, it inserts the tag. and positions the cursor between the tags so you can type text (or paste text,) into them.

                                    I'm not here much anymore.

                                    1 Reply Last reply Reply Quote 0
                                    • J Offline
                                      jpark
                                      last edited by

                                      @dan rathbun said:

                                      There is a "hard to find" link on each message "POST A REPLY" page, in the right column, beneath the "Smilies" list.

                                      Now I'm enlightened 😍 Thanks Dan

                                      @tig said:

                                      I hope this is not ALL of the code...

                                      No this is an output of individual Ruby Console execution. This is my attempt to debug each line of your sample code to check each variable's current value. Programming is my hobby and I just picked up Sketchup and Ruby couple of months ago so I have a lot to learn.

                                      Back to pickray method - All screen postions (ie p0, p1, p2, and p3) return different value yet pickray method of these points return identical 3D point as camera eye position but with different vector. How come?

                                      John

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

                                        eh.. TIG, I think we both did a brain-fart. We have to do a raytest - otherwise the ray will return a point which is based on the camera eye... because all pickray origin from the camera eye.

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

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

                                          Though, at 2:30 it's hard to process these thigns...

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

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

                                            Here's a much better version that uses planes, lines, vectors, and takes arguments to change panning from right/left and up/down etc - allowing a toolbar button set to be easily made...

                                            require 'sketchup.rb'
                                            ### Usage TIG.screenpan(1), where the argument can be either 1, -1, 2 or -2
                                            ### 1=right, -1=left, 2=up, -2=down
                                            ### make 4 'arrow' buttons in a toolbar using the 4 alternative commands.
                                            module TIG
                                                def self.screenpan(direction=1)
                                                    m = Sketchup.active_model
                                                    v = m.active_view
                                                    c0 = v.corner(0)
                                                    c1 = v.corner(1)
                                                    c2 = v.corner(2)
                                                    c = v.camera
                                                    e = c.eye
                                                    t = c.target
                                                    up = c.up
                                                    di = c.direction
                                                    pa = [e, di]
                                                    i0 = v.inputpoint(c0[0],c0[1]).position
                                                    i1 = v.inputpoint(c1[0],c1[1]).position
                                                    i2 = v.inputpoint(c2[0],c2[1]).position
                                                    p0 = Geom.intersect_line_plane([i0,di], pa)
                                                    p1 = Geom.intersect_line_plane([i1,di], pa)
                                                    p2 = Geom.intersect_line_plane([i2,di], pa)
                                                    vx = p0.vector_to(p1)
                                                    vy = p0.vector_to(p2)
                                                    case direction
                                                      when 1
                                                        c.set(e.offset(vx), t.offset(vx), up)
                                                      when -1
                                                        c.set(e.offset(vx.reverse), t.offset(vx.reverse), up)
                                                      when 2
                                                        c.set(e.offset(vy.reverse), t.offset(vy.reverse), up)
                                                      when -2
                                                        c.set(e.offset(vy), t.offset(vy), up)
                                                   end
                                                end
                                            end
                                            

                                            TIG

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

                                            Advertisement