sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🔌 Smart Spline | Fluid way to handle splines for furniture design and complex structures. Download

    Reading and drawing textures

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    22 貼文 7 Posters 1.5k 瀏覽 7 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • tt_suT 離線
      tt_su
      最後由 編輯

      @marc477 said:

      And how can I get texture's data loaded in SketchUp memory with an external tool ?
      Do you mean that I should write every texture with the TextureWriter and then load them with an external tool ?

      I'm confused - when you say "external tool" - you mean a custom Ruby Tool? Or some third party software?
      And "load in memory" you mean for reading the bitmap data? ... I guess you want the bitmap data - since you talked about this earlier.
      With SketchUp 2014 you now have the standard Ruby library and the gem system - you might be able to find some ruby gem you can install and use.

      1 條回覆 最後回覆 回覆 引用 0
      • Dan RathbunD 離線
        Dan Rathbun
        最後由 編輯

        Thomas he was responding to my use of "external tool", and I meant external utility library.

        ImageMagick DOES have a gem, and is available for both PC and Mac.

        Download the Ruby RMagick Gem: http://rubyforge.org/frs/?group_id=12%26amp;release_id=42049
        (Use the MajikCore C API library.)

        The ImageMagick site: http://www.imagemagick.org/
        With 4 choices to use the libraries under Ruby: http://www.imagemagick.org/script/api.php#ruby

        Here's the doc page on the view class.
        http://studio.imagemagick.org/RMagick/doc/struct.html#view
        (you can also use the Image.view instance method.
        See: http://studio.imagemagick.org/RMagick/doc/image3.html#view

        You need to install the ImageMagick libraries separately for the gem.
        I have not gotten the gem to install to my system Ruby install... yet.
        I get an errors.

        I'm not here much anymore.

        1 條回覆 最後回覆 回覆 引用 0
        • M 離線
          Marc477
          最後由 編輯

          @tt_su said:

          I'm confused - when you say "external tool" - you mean a custom Ruby Tool? Or some third party software?
          And "load in memory" you mean for reading the bitmap data? ... I guess you want the bitmap data - since you talked about this earlier.

          Yes sorry I meant "external third party library" and yes I want to read bitmap data.

          Ok so there is absolutely no way to read bitmap data of loaded textures in Sketchup!?

          Does that mean I need to double memory usage by reloading textures with an external library (probably OpenCv since I am working with a C extension).

          1 條回覆 最後回覆 回覆 引用 0
          • Dan RathbunD 離線
            Dan Rathbun
            最後由 編輯

            You can also use the ImageMagick libraries. (It is Open Source.) .. or maybe GIMP libraries ?

            OR... FreeImage which SketchUp uses, and may already be loaded.
            http://freeimage.sourceforge.net/

            I'm not here much anymore.

            1 條回覆 最後回覆 回覆 引用 0
            • tt_suT 離線
              tt_su
              最後由 編輯

              @marc477 said:

              Ok so there is absolutely no way to read bitmap data of loaded textures in Sketchup!?

              Does that mean I need to double memory usage by reloading textures with an external library (probably OpenCv since I am working with a C extension).

              Correct. I think we have a feature request to access the DIB data - but right now it's not possible.

              1 條回覆 最後回覆 回覆 引用 0
              • A 離線
                Aerilius
                最後由 編輯

                The Ruby gem creates a wrapper around the almost complete ImageMagick API. For use with SketchUp, the major (and time&resource consuming) task is to export the texture image to a file in a temporary location, read it again and clean it up when not needed anymore. To improve performance, you would even need a caching mechanism.

                All this is not provided by the Ruby gem.

                For long image manipulations you would also want to run ImageMagick asynchronously, including the Ruby code that you run afterwards. Since I usually use only one or two ImageMagick commands (not the whole API) I once made a library that does the caching and asynchronous stuff.

                Still, calling an external program is not ideal if you want to do a very interactive tool (see here). Then you would rather nudge Thomthom to include some more pixel reading/manipulation methods to the API. They could already be designing for the next version.

                1 條回覆 最後回覆 回覆 引用 0
                • Dan RathbunD 離線
                  Dan Rathbun
                  最後由 編輯

                  @Andreas: I got an error, trying to compile the latest RMagick gem, under Windows, using the latest 32bit Ruby Devkit, for Ruby 2.0, against the latest 32bit ImageMagick (installed in "C:/ImageMagick".)

                  Were you able to compile such a so file ? If so can ya share it ?

                  I'm not here much anymore.

                  1 條回覆 最後回覆 回覆 引用 0
                  • Dan RathbunD 離線
                    Dan Rathbun
                    最後由 編輯

                    @tt: For a Ruby C extension, is it possible to get a handle on the FreeImage library that SketchUp has loaded ?

                    Or.. is it better to just re-load it when needed, and free it when done ?

                    I'm not here much anymore.

                    1 條回覆 最後回覆 回覆 引用 0
                    • N 離線
                      nick9111
                      最後由 編輯

                      Hi, I am new to the community and also have a thing I don't understand how it should be done. For example, I can get filename of texture which is saved inside .skp file using

                      Sketchup.active_model.materials[0].texture.filename
                      

                      Is there a way to rename it? (and keep reference of associated material to it)

                      1 條回覆 最後回覆 回覆 引用 0
                      • Dan RathbunD 離線
                        Dan Rathbun
                        最後由 編輯

                        The texture is a property of the Material.

                        Save the material's size (if width and height differ,) so you can restore that.
                        Then re-assign the material's texture using:
                        matl.texture="new/path/to/renamed/imagefile"
                        Lastly restore the size needed.

                        I'm not here much anymore.

                        1 條回覆 最後回覆 回覆 引用 0
                        • TIGT 離線
                          TIG Moderator
                          最後由 編輯

                          I've answered this in your parallel thread http://sketchucation.com/forums/viewtopic.php?p=524826#p524826

                          TIG

                          1 條回覆 最後回覆 回覆 引用 0
                          • M 離線
                            Marc477
                            最後由 編輯

                            Thank you all, now I know how to do the first step (Reading texture data) but now I still wonder how to do the second step: drawing textures.

                            As discussed above it doesn't seem to be possible to draw them in the viewport so I tought I could create a new window and display an image in it. I found that there is a WebDialog class that could be useful to create the new window, but now does anyone know how I can draw an image in those dialogs? I would like to avoid reloading the texture from Hard Drive everytime I refresh the image (since the image will be edited).

                            I could load the texture only one time from the Hard Drive using ImageMajik (Thanks Dan), then update the "in memory" buffer directly and display it in the WebDialog. Is it possible to do that ? How do I draw in a web dialog an image loaded with ImageMajik ?

                            1 條回覆 最後回覆 回覆 引用 0
                            • fredo6F 離線
                              fredo6
                              最後由 編輯

                              Not sure I understand what you mean by reading textures, but you can at least extract them from Sketchup and show them as images in a web dialog.
                              TIG's method is the right one to go.

                              Here is a screenshot of my plugin ReportLabelArea

                              Report on Areas.png

                              Fredo

                              1 條回覆 最後回覆 回覆 引用 0
                              • Dan RathbunD 離線
                                Dan Rathbun
                                最後由 編輯

                                @marc477 said:

                                I could load the texture only one time from the Hard Drive using ImageMajik (Thanks Dan), then update the "in memory" buffer directly and display it in the WebDialog. Is it possible to do that ? How do I draw in a web dialog an image loaded with ImageMajik ?

                                I do not think anyone has ever done it.

                                The HTML5 Canvas element will not work well on PC yet because SketchUp uses the MSIE WebBrowser control for WebDialogs. Microsoft is lagging behind in their IE support of the specification.

                                You CAN use the RMagick gem to draw, and save the edits to disk, and MSIE knows how to natively render image file formats, but you'll need to refresh the web dialog, to re-render the imagefile. (or have a html IMG element within a HTML file.)
                                See the doc: http://studio.imagemagick.org/RMagick/doc/
                                Also note there IS a RVG class that is based upon SVG.

                                I'm not here much anymore.

                                1 條回覆 最後回覆 回覆 引用 0
                                • Dan RathbunD 離線
                                  Dan Rathbun
                                  最後由 編輯

                                  @dan rathbun said:

                                  The HTML5 Canvas element will not work well on PC yet because SketchUp uses the MSIE WebBrowser control for WebDialogs. Microsoft is lagging behind in their IE support of the specification.

                                  You can test by loading the HTML5 Bejeweled game into a WebDialog.

                                  It most likely will not run under XP. But runs fine under Win7 with MSIE v11 installed.

                                  Bejeweled.rb

                                  I'm not here much anymore.

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • 1
                                  • 2
                                  • 1 / 2
                                  • 第一個貼文
                                    最後的貼文
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement