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

    Model.raytest and Entity visibillity

    Scheduled Pinned Locked Moved Developers' Forum
    28 Posts 6 Posters 1.8k Views 6 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.
    • thomthomT Offline
      thomthom
      last edited by

      There is something about model.raytest's behaviour that I'm not expecting.

      Here's a test setup:
      01 - Setup.png
      A set for Cpoints, a ground terrain shape. And an assortment of faces, grouped/ungrouped, hidden. The purple faces are on Layer1. Layer1 is turned of so the complete setup looks like this:
      02 - The Scene.png

      If one takes all the CPoints and perform a model.raytest downwards, along Z_AXIS.reverse, the results are such:
      03 - Native Raytest.png
      Notice that the rays pass through hidden entities, but stops at entities located on hidden layers. Why is this behaviour not consistent? Why ignore one type of visibility, but not another? (Why not have that as an argument?)
      Is it some kind of bug?
      ( To replicate, download the sample model and script and run TT_Raytrace.drop_cpoints(true) )

      This is what I expected:
      04 - Custom Raytest.png
      ( To replicate, download the sample model and script and run TT_Raytrace.drop_cpoints )
      To achieve this result I had to write a proxy method that recast the ray if it stopped on an entity not really visible.

      
        def self.raytest(ray)
          model = Sketchup.active_model
          vector = ray[1]
          while true
            # Shot ray
            test = model.raytest(ray)
            return nil if test.nil?
            # Verify visibility
            point, path = test
            if path.all? { |e| e.visible? && e.layer.visible? }
              return test
            else
              # raytest stopped on a hidden entity - create a new ray from that point
              # and let the loop continue until it hits something visible, or nothing.
              ray = [ point, vector ]
            end
          end
        end
      
      

      raytrace.rb


      DropTest.skp

      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

        @unknownuser said:

        Thomas, I am surprised that your rays go through a hidden faces. In my experience they stop on such entities.

        That is what I thought they would do. Maybe there's been a change in some SU version? I'll see if I can make a run on SU6 and SU5.

        @unknownuser said:

        I have to do same check as you do and recast the ray further from the point the previous ray met hidden entity in the script.

        It would hit itself if it was on the entity itself?

        hmmm... this made me wonder, some times SU messes up and creates multiple faces overlapping. Maybe that could cause problem in my recasting loop. Potential for a never ending loop? 😕

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

        1 Reply Last reply Reply Quote 0
        • T Offline
          tomasz
          last edited by

          I am casting next ray from the intersection point and haven't experienced closed loop - the method doesn't return the face the point is located on.

          Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

          1 Reply Last reply Reply Quote 0
          • T Offline
            tomasz
            last edited by

            Thomas, I am surprised that your rays go through a hidden faces. In my experience they stop on such entities.
            You say that when a layer and object is hidden a ray goes through. It is weird.

            I have to do same check as you do and recast the ray further from the point the previous ray met hidden entity in the script.

            I have reported it already in 2008.

            Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

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

              But in your tests, model.raytest stops at hidden entities?
              You are testing SU6? SU7?
              PC or Mac?

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

              1 Reply Last reply Reply Quote 0
              • T Offline
                tomasz
                last edited by

                @thomthom said:

                But in your tests, model.raytest stops at hidden entities?

                Yes. It was stopping on hidden entities.
                It was a while ago. I was testing under Win on SU7. Maybe there were some improvements\fixes in 7.1 related to the bug report.

                Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

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

                  hm... I just tested the same scene on SU6 and SU5. Same behaviour as my test in SU 7.1.

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

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    AlexMozg
                    last edited by

                    thomthom,
                    I confirm that in some scenes, model.raytest don't stops at hidden layer entities. So wrote the following method, which has successfully been using.

                    
                    module Enumerable
                    	def each_element_satisfies?(&block)
                    		self.each{ |v| return false unless yield(v) }
                    		true
                    	end#def
                    end#def
                    class Sketchup;;Model
                    	def real_raytest(ray, depth=nil)
                    		depth = nil if depth == 0
                    		path = self.raytest(ray)
                    		if not path or (path[1].each_element_satisfies?{|e| e.layer.visible?} &&
                    			(depth ? path[1].length == depth ; true))
                    			return path
                    		else
                    			real_raytest [path[0], ray[1]], depth
                    		end
                    	end#def
                    end#class
                    
                    

                    depth = InputPoint.depth in tool

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

                      @Alex: your each_element_satisfies?(&block) does the same as the native Enumerable.all?

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

                      1 Reply Last reply Reply Quote 0
                      • K Offline
                        kwalkerman
                        last edited by

                        I've been using model.raytest on SU 7.1 pro. It has not seen hidden entities (which I like!)

                        Sounds like in SU 8, things are all messed up. Maybe a new raytest method could be developed where you can specify whether the ray is allowed to return something hidden or not?

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

                          @kwalkerman said:

                          I've been using model.raytest on SU 7.1 pro. It has not seen hidden entities (which I like!)

                          Sounds like in SU 8, things are all messed up. Maybe a new raytest method could be developed where you can specify whether the ray is allowed to return something hidden or not?

                          In SU7 and older model.raytest stopped on hidden layers, but not on hidden entities.
                          In SU8 it stops on hidden layers and entities, but there is a bug where some rays fail.

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

                          1 Reply Last reply Reply Quote 0
                          • K Offline
                            kwalkerman
                            last edited by

                            Weird. Are they homing in on anything consistent?

                            --
                            Karen

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

                              @kwalkerman said:

                              Weird. Are they homing in on anything consistent?

                              Seems that they made it stop on any entity regardless of visibility - which mean we need to check that our selves and recast the ray.
                              But also managed to introduce a new nasty bug. 😕

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

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                tomasz
                                last edited by

                                @thomthom said:

                                Seems that they made it stop on any entity regardless of visibility - which mean we need to check that our selves and recast the ray.

                                EDIT: In my experience it was always the case.

                                @thomthom said:

                                But also managed to introduce a new nasty bug. 😕

                                😕 😡

                                Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                                1 Reply Last reply Reply Quote 0
                                • Al HartA Offline
                                  Al Hart
                                  last edited by

                                  OOf...

                                  Glad to find this thread. Several of our placement tools have started failing in SU 8.

                                  We were using raytest to try to find a specific object behind the cursor, and then hiding anything we did not want to locate.

                                  In this example, we are placing a component, and want raytest to ignore the component we are placing (We make it visible so the user can see it). This is from our "spray paint" tool which is trying to place trees randomly on the ground, but not on other trees which we just placed.

                                  
                                              item = model.raytest ray
                                  
                                              #Ignore any elements of the same type we are placing
                                              hidden_ents = Array.new
                                              while(item != nil && item[1].at(0).kind_of?(Sketchup;;ComponentInstance) && item[1].at(0).definition == definition)
                                                  hidden_ents.push(item[1][0])
                                                  item[1][0].hidden = true
                                                  item = model.raytest ray
                                              end
                                              hidden_ents.each {
                                                  |ent|
                                                  ent.hidden = false
                                              }
                                  

                                  However, in SU 8, hiding the component instance, when it is under the cursor - does not leave it out of the ray test. (We also discovered a nasty bug where we were looping forever if we are over the component being placed)

                                  Can anyone think of a way to place components at the end of a ray, but ignore certain elements. Apparently .hidden will not work, and not even placing them on a temporary hidden layer. I haven't tried deleting them, (and then aborting the delete operation), yet. But it seems pretty painful.

                                  Al Hart

                                  http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                                  IRender nXt from Render Plus

                                  1 Reply Last reply Reply Quote 0
                                  • Al HartA Offline
                                    Al Hart
                                    last edited by

                                    @unknownuser said:

                                    @thomthom said:

                                    Seems that they made it stop on any entity regardless of visibility - which mean we need to check that our selves and recast the ray.

                                    EDIT: In my experience it was always the case.

                                    @thomthom said:

                                    But also managed to introduce a new nasty bug. 😕

                                    😕 😡

                                    In reference to my previous post. Can I just move the ray itself past the point returned and "recast" it. Still, while trying to ignore an entire tree, or other component, this could be painful.

                                    Al Hart

                                    http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                                    IRender nXt from Render Plus

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

                                      @al hart said:

                                      In reference to my previous post. Can I just move the ray itself past the point returned and "recast" it. Still, while trying to ignore an entire tree, or other component, this could be painful.

                                      It's what I do in my wrapper method that ensures the ray doesn't stop on hidden entities.

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

                                      1 Reply Last reply Reply Quote 0
                                      • Al HartA Offline
                                        Al Hart
                                        last edited by

                                        @thomthom said:

                                        @al hart said:

                                        It's what I do in my wrapper method that ensures the ray doesn't stop on hidden entities.

                                        [EDIT: I see some code in a previous post. I will try it out]

                                        Thanks,

                                        Is there some code here in this thread already, or can you show me what you are doing to skip hidden geometry?

                                        Al Hart

                                        http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                                        IRender nXt from Render Plus

                                        1 Reply Last reply Reply Quote 0
                                        • Al HartA Offline
                                          Al Hart
                                          last edited by

                                          Thanks tons, ThomThom, by tool is working again! ☀

                                          Al Hart

                                          http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                                          IRender nXt from Render Plus

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

                                            @al hart said:

                                            @thomthom said:

                                            @al hart said:

                                            It's what I do in my wrapper method that ensures the ray doesn't stop on hidden entities.

                                            [EDIT: I see some code in a previous post. I will try it out]

                                            Thanks,

                                            Is there some code here in this thread already, or can you show me what you are doing to skip hidden geometry?

                                            Bottom of first post:
                                            http://forums.sketchucation.com/viewtopic.php?f=180&t=28059#p243311

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

                                            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