• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

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.
  • L Offline
    lbsswu
    last edited by 29 Jan 2015, 06:35

    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
    • S Offline
      sdmitch
      last edited by 29 Jan 2015, 14:19

      @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 29 Jan 2015, 14:28

        @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
        • S Offline
          sdmitch
          last edited by 29 Jan 2015, 14:38

          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 29 Jan 2015, 14:49

            @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
            • L Offline
              lbsswu
              last edited by 29 Jan 2015, 22:37

              @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
              1 / 1
              • First post
                1/6
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement