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

    Texture.use_alpha?

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 1.1k 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.
    • T Offline
      tomasz
      last edited by

      Hi,
      Is there way to find out if a texture has alpha channel?
      Texture class has no such a method. Material method relates to transparency (opacity).
      Will material.materialType help me?

      Tomasz

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

      1 Reply Last reply Reply Quote 0
      • tbdT Offline
        tbd
        last edited by

        @unknownuser said:

        Is there way to find out if a texture has alpha channel?

        nope 😢

        @unknownuser said:

        Will material.materialType help me?

        nope again - it returns the same value as for a non-alpha texture

        you can look for 'tRNS' chunk inside .png files - if present than it contains transparency

        SketchUp Ruby Consultant | Podium 1.x developer
        http://plugins.ro

        1 Reply Last reply Reply Quote 0
        • tbdT Offline
          tbd
          last edited by

          here some quick code to check for PNG transparency

          
          class ReadPNG
            def initialize(file)
              @pngfile = File.open(file,"rb+").read
              read_offset(8) #skip header
            end
            
            def transparent?
              ok = true
              while ok
                chunk_size  = read_offset(4).unpack("N")[0]
                section     = read_offset(4)
                case section
                when 'PLTE'
                  read_offset(chunk_size)
                when 'IDAT'
                  read_offset(chunk_size)
                when 'tRNS'
                  read_offset(chunk_size)
                  return true
                else
                  @offset += chunk_size
                end
                ok = section != "IEND"
                read_offset(4)  # skip CRC
              end
              return false
            end 
            
            def read_offset(length = 1, offset = nil)
              @offset ||= 0
              @offset = offset if offset
              begin
                ret = @pngfile[@offset, length]
              rescue
                p "error reading at #{@offset}"
              end
              @offset += length
              ret
            end  
          end
          
          p ReadPNG.new('texture.png').transparent?
          
          

          SketchUp Ruby Consultant | Podium 1.x developer
          http://plugins.ro

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

            Put the file opening and read to the "transparent?" method. Because this way you 1. can close the file from within the instance when you're ready with analyse and 2. can react on changed png file.

            azuby

            *error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

            Bad English? PM me, correct me. :smile:**

            1 Reply Last reply Reply Quote 0
            • tbdT Offline
              tbd
              last edited by

              azuby: true. thanks

              SketchUp Ruby Consultant | Podium 1.x developer
              http://plugins.ro

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

                Hi TBD,
                I am surprised there is no such a method.
                The PNG testing will be helpful for me.
                Thank you!
                Tomasz

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

                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