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

    [Info] Ambient Occlusion -> Simple Rays

    Scheduled Pinned Locked Moved Plugins
    66 Posts 22 Posters 75.5k Views 22 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.
    • W Offline
      Wacov
      last edited by

      This is really amazing. I mean, if you could do the raytesting separately with a faster language, it'd be really useful.

      http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

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

        The .raytest method is running in SU's C. Not calculated using Ruby. Ruby just calls the C method.

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

        1 Reply Last reply Reply Quote 0
        • Q Offline
          qpik
          last edited by

          Does that mean that model.raytest algorithm is inherently slow?
          So I would need to write my own in C.

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

            What I meant was that the .raytest is probably written in C already.

            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
              Jim
              last edited by

              Yeah, to make it faster wouldn't you need to export the geometry so an external routine could both loop and perform the raytest?

              Hi

              1 Reply Last reply Reply Quote 0
              • Q Offline
                qpik
                last edited by

                But I would have to export geometry for that one external routine.
                Is there other way?

                @thomthom said:

                What I meant was that the .raytest is probably written in C already.

                I've got that, I just wonder what makes it slow then and how to write a faster one.

                I guess I have to prepare myself for switching to C. Even for my simple use, which is lately sunlight exposure analysis, it's simply too slow, when run on part of the city centre model.

                Kuba

                ps. Many thanks for all the help so far.

                1 Reply Last reply Reply Quote 0
                • W Offline
                  Wacov
                  last edited by

                  @thomthom said:

                  The .raytest method is running in SU's C. Not calculated using Ruby. Ruby just calls the C method.

                  Ok.

                  I guess I don't know what I'm talking about, but doesn't SU's raytest method extract more information than you need for your plugin? Maybe that's why it's so (comparatively) slow.

                  http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

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

                    Possibly. I guess it depends on what you need it for.

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

                    1 Reply Last reply Reply Quote 0
                    • Q Offline
                      qpik
                      last edited by

                      @wacov said:

                      I guess I don't know what I'm talking about, but doesn't SU's raytest method extract more information than you need for your plugin? Maybe that's why it's so (comparatively) slow.

                      I thought exactly the same, as it returns "the first thing that the ray hits". I suppose it means "the closest thing". For my purpose it's enough to get first-on-the-list hit end exit.
                      That might do the trick.

                      1 Reply Last reply Reply Quote 0
                      • Q Offline
                        qpik
                        last edited by

                        I quickly wrote this, but it worked MUCH slower than original method.

                        def raytest2 ray
                         hit = false
                         entities = self.entities
                         entities.each { |face|
                           if face.kind_of?(Sketchup;;Face) and face.classify_point(ray[0]) > 4
                            plane = [face.vertices[0].position, face.normal]
                            intersection = Geom.intersect_line_plane(ray, plane)
                            if intersection and face.classify_point(intersection) < 8
                             hit = true
                             break
                           end
                          end
                         }
                         return hit
                        end
                        

                        This could be optimized by passing pre-sorted face array (based on results from previous tests) instead of browsing entities array, but I doubt it would speed it up much.
                        What do you think?

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

                          @qpik said:

                          plane = [face.vertices[0].position, face.normal]

                          You can use face.plane instead

                          @qpik said:

                          This could be optimized by passing pre-sorted face array (based on results from previous tests) instead of browsing entities array, but I doubt it would speed it up much.
                          What do you think?

                          hmm... If you only iterate the entities collection once then it won't help to pre-process to filter out only faces. Infact, that would mean more iterations. But if you need to iterate the face multiple times, then you will save time on pre-filtering.

                          @qpik said:

                          I thought exactly the same, as it returns "the first thing that the ray hits". I suppose it means "the closest thing". For my purpose it's enough to get first-on-the-list hit end exit.

                          Isn't that the same thing?

                          @qpik said:

                          I quickly wrote this, but it worked MUCH slower than original method.

                          You're writing a ruby method to be faster than a C method - that C method must be doing a lot of extra processing in order to be able to out-perform it in Ruby.

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

                          1 Reply Last reply Reply Quote 0
                          • Q Offline
                            qpik
                            last edited by

                            @thomthom said:

                            You can use face.plane instead

                            Somehow I didn't notice that one in the API 😄

                            @thomthom said:

                            hmm... If you only iterate the entities collection once then it won't help to pre-process to filter out only faces. Infact, that would mean more iterations. But if you need to iterate the face multiple times, then you will save time on pre-filtering.

                            I meant to sort the collection before proceeding to the next testing point. The faces that got hit before might as well be the first to get hit by rays cast from adjacent point.

                            @thomthom said:

                            @qpik said:

                            I thought exactly the same, as it returns "the first thing that the ray hits". I suppose it means "the closest thing". For my purpose it's enough to get first-on-the-list hit end exit.

                            Isn't that the same thing?

                            I suppose model.raytest doesn't break after first positive ray hit, but returns the closest one from an array of all.

                            @thomthom said:

                            @qpik said:

                            I quickly wrote this, but it worked MUCH slower than original method.

                            You're writing a ruby method to be faster than a C method - that C method must be doing a lot of extra processing in order to be able to out-perform it in Ruby.

                            That is certainly true. That is why I managed to connect with a DLL using Win32api.call (BTW thanks to TBD for his SUDLL example).
                            Now I'm on my way to moving everything to C. I hope this will finally give a speed boost.

                            I'm looking into Ruby-OpenGL as well for another approach.
                            Here is an example - http://forums.sketchucation.com/viewtopic.php?f=180&t=20893&p=209966#p209966

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

                              @qpik said:

                              I suppose model.raytest doesn't break after first positive ray hit, but returns the closest one from an array of all.

                              that would be very odd. if it did produce a full array before returning I think it should return the full array.

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

                              1 Reply Last reply Reply Quote 0
                              • Q Offline
                                qpik
                                last edited by

                                But then how would it find out the closest intersection?

                                ps. I write all this out of my head, I'm not familiar with 3d algorithms.

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

                                  @qpik said:

                                  I suppose model.raytest doesn't break after first positive ray hit, but returns the closest one from an array of all.

                                  I think it does break after first positive hit. Make sure you check if the object is not hidden or on a hidden layer, otherwise your rays will stop too early when hidden layer present in a model.

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

                                  1 Reply Last reply Reply Quote 0
                                  • Q Offline
                                    qpik
                                    last edited by

                                    Yeah, but how would the method know if the first hit is the closest?
                                    It could be for example some distant face that got hit first, because it was first in the collection.

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

                                      Did you ever find any improvements that could be made?

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

                                      1 Reply Last reply Reply Quote 0
                                      • Q Offline
                                        qpik
                                        last edited by

                                        I planned writing new method in C and calling it via Win32api... but I never find time and enough determination to do it. I wish somebody else did it instead 😄, someone who knows C, unlike me.

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

                                          I'm also an C ignorant... 😞

                                          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
                                            KiraNL
                                            last edited by

                                            Any chance this ever might come out which works for round shapes?
                                            Love to use this as subtile shadows over the textures, sort of lighting baking.

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

                                            Advertisement