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

    How to judge whether a 3D point is visible or not

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 374 Views 3 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.
    • lbsswuL Offline
      lbsswu
      last edited by

      Hi everyone,

      Suppose I have opened the Sketchup software, I want to know whether a 3D point is visible or not in current view.
      For example, the 3D point may locate on the back of a person, thus we can't see it when the person facing to us.

      This should be done by Sketchup ruby code.Could anyone help me?

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        @lbsswu said:

        Hi everyone,

        Suppose I have opened the Sketchup software, I want to know whether a 3D point is visible or not in current view.
        For example, the 3D point may locate on the back of a person, thus we can't see it when the person facing to us.

        This should be done by Sketchup ruby code.Could anyone help me?

        I placed a construction point, the little black dot just below the horizon, and "Nancy" in the model. I then used the following code to test if the point was visible.

        mod = Sketchup.active_model
        ent = mod.active_entities
        sel = mod.selection
        vue = mod.active_view
        eye = vue.camera.eye
        cp = ent.grep(Sketchup;;ConstructionPoint)[0]
        pt = cp.position
        vec = pt.vector_to(eye)
        hit = mod.raytest([pt,vec])
        if hit
         puts "pt is not visible"
        else
         puts "pt is visible"
        end
        
        

        visiability1.jpg


        visiability2.jpg

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • S Offline
          slbaumgartner
          last edited by

          @sdmitch, is the logic reversed in your test on hit? I think raytest returns nil if the point is not visible.

          OK, I'm confused...unfortunately, the Ruby API site is not responding right now (server issues?) so I can't look at the documentation for raytest.

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            if the ray "hits" something then that means that that object must be between the point and the camera. If there are no obstructions then raytest will return nil.

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • S Offline
              slbaumgartner
              last edited by

              @sdmitch said:

              if the ray "hits" something then that means that that object must be between the point and the camera. If there are no obstructions then raytest will return nil.

              Yeah, I figured that out by experimentation since I can't get to the docs. Thanks!

              1 Reply Last reply Reply Quote 0
              • lbsswuL Offline
                lbsswu
                last edited by

                @sdmitch said:

                @lbsswu said:

                Hi everyone,

                Suppose I have opened the Sketchup software, I want to know whether a 3D point is visible or not in current view.
                For example, the 3D point may locate on the back of a person, thus we can't see it when the person facing to us.

                This should be done by Sketchup ruby code.Could anyone help me?

                I placed a construction point, the little black dot just below the horizon, and "Nancy" in the model. I then used the following code to test if the point was visible.

                mod = Sketchup.active_model
                > ent = mod.active_entities
                > sel = mod.selection
                > vue = mod.active_view
                > eye = vue.camera.eye
                > cp = ent.grep(Sketchup;;ConstructionPoint)[0]
                > pt = cp.position
                > vec = pt.vector_to(eye)
                > hit = mod.raytest([pt,vec])
                > if hit
                >  puts "pt is not visible"
                > else
                >  puts "pt is visible"
                > end
                > 
                

                Hi, sdmitch. Thank you very much. It works!

                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