Texture.use_alpha?
-
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
-
@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
-
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?
-
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
-
azuby: true. thanks
-
Hi TBD,
I am surprised there is no such a method.
The PNG testing will be helpful for me.
Thank you!
Tomasz
Advertisement