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

    Textures in model slow down ruby?

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 4 Posters 516 Views 4 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
      wawmsey7
      last edited by

      Hi,

      I've written various script for drawing various parts of a cabinet, so just generally drawing shapes pushpull-ing followme etc... I'm finding that that scripts all run really nice and fast- for example one of them completes in 0.06 seconds! Which is perfect... However as soon as I bring a texture into the model, not into the script just import it into the model not even applied to anything. Then when I run the script exactly the same as before it takes 0.5 seconds to complete the same tasks!! Which is nearly 10 times as long to do the same things, the only difference being that there is a texture loaded in the materials box. The texture in this case isn't particularly large - 600kb JPEG.

      Is there anything I could be doing wrong or is there a setting to change that could help this? Or is this just how it goes??
      ('use maximum texture size' in openGL settings is set to off)

      Thanks for your help
      Matt

      ** just tried adding 3 materials to the material toolbar all with textures of about 1mb each and the same script now takes 7 seconds to complete!!! Surely this isn't just how it is??

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

        @wawmsey7 said:

        loaded in the materials box. The texture in this case isn't particularly large - 600kb JPEG.

        File size doesn't say much about the texture size when we are talking about compressed file formats. How many pixels and what's the color depth?

        Also, do you have any sample code? Sample texture? Without it's very hard to say what is going on.
        Like, are you using start_operation with the second argument (disable_ui) set to true?

        And what OS and SketchUp version are you using?

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

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

          After a bit of trial and error I have found that the problem only occurs on scripts where I am pulling an external component into the model as part of the script, like this...

          
            shelfpin = Sketchup.active_model.definitions.load ("filename")
            ents.add_instance shelfpin, (Geom;;Transformation.new [posx,posy,posz])
          
          

          doing this works fine when no textures are loaded in the model and runs just as fast as the other scripts, however if there are textured materials in the model (as described previously) then it really slows down the script?? it doesn't slow down any other scripts...

          The components I am pulling in don't have any materials already applied...

          Anyone got any ideas? Is there a way around this??

          Thanks again
          Matt

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

            thanks, yes I am wrapping all the code with the start and end operation commands

            
            @model.start_operation('Leg',true)
            
            ...code...
            
            @model.commit_operation      
            
            

            I am using a new 15" macbook pro OSX yosemite with the latest sketchup pro version

            this is one of the smaller textures i am using...
            (the others exceeded the pixel limit for uploading to sketchucation (3000x2000-ish))


            Estate_Harvest_Oak21_extractedTex2366 copy.jpg

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

              I've worked out that textures in the model only make the script run slowly when it is pulling/importing the component definitions into the model like so...

              shelfpin = Sketchup.active_model.definitions.load ("filename")

              and in one of my scripts I had this as part of a defined function which I was looping 50+ times to cut shelf holes and add a shelf pin for various positions on a panel - so was in affect importing the shelf pin component 50+ times completely unnecessarily.

              So as soon as I took out this out of the code completely (given that the component is already loaded in the model) and ran the same code again, it ran at the same fast speed as it does when there isn't any textures in the model!

              So my solution is to run the code to load the components needed for all my scripts once and then it's all done only once and I'm free to run any of my scripts after it.

              However it would be easier if I could have code before the code for loading the component to check if it's already loaded or not into the model and then load it if it's not already there? Is that do-able?

              **the following code just tagged on the end seemed to work fine

                 magd = Sketchup.active_model.definitions.load (file) if magd.class != Sketchup;;ComponentDefinition
              

              theres probably a tonne of ways to do this but that seemed to do the job

              Thanks

              1 Reply Last reply Reply Quote 0
              • D Offline
                driven
                last edited by

                I wondering if you still use Vray, and is it active or disabled during these 'slow' tests?
                john

                learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                  I do use vray, but it was disabled throughout all of this... just to be on the safe side!

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

                    @wawmsey7 said:

                    (the others exceeded the pixel limit for uploading to sketchucation (3000x2000-ish))

                    That certainly qualify for a large texture. SU will by default render textures in max 1024x1024 (double if you enable maximum texture)

                    So - I'm a little confused. You add textures by loading components containing them?

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

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

                      No, I'm adding materials the normal way. Adding the materials isn't the problem. I was having a problem whereby adding component definitions is slower if I simply have materials with textures in the model, and the the more there are the slower it goes... but i've managed to nullify this problem by writing my code better so that I only define each component that I need to load for my scripts once.

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

                        @wawmsey7 said:

                        However it would be easier if I could have code before the code for loading the component to check if it's already loaded or not into the model and then load it if it's not already there? Is that do-able?

                        You need to search the DefinitionList collection properly.
                        This class, like many of the API collection classes, has the Enumerable library module mixed in.

                        The following method should be wrapped within your plugin module:

                        
                        def self.get_component(
                          filepath = "some/path/to/component.skp"
                        )
                          # Warning, on MS Windows the definition paths are
                          # returned with backslashes not forward slashes !
                          filepath = filepath.tr("\\",'/')
                          dlist = Sketchup.active_model.definitions
                          found = dlist.find {|cdef|
                            if cdef.path.nil?
                              false
                            elsif cdef.path.tr("\\",'/') == filepath
                              true
                            else
                              false
                            end
                          }
                          return found if found
                          if File.exist?(filepath)
                            dlist.load(filepath)
                          else
                            return false
                          end
                        end
                        
                        

                        I'm not here much anymore.

                        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