Material Transparency

Hi guys, i want to check if one material use transparency or not.I have alredy used material.use_alpha? and material.color.alpha > 0 but not works , maybe i am doing something wrong or i dont understand how theese works

This is my code, i hope in your help

if(material.use_alpha? == false || material.color.alpha > 0)
      UI.messagebox " NO material is NOT transparent"
elsif(material.use_alpha? == true || material.color.alpha == 0)
      UI.messagebox " OH material is transparent"
end

edit:

material.use_alpha? || material.color.alpha > 0 are both true

unless it’s the ‘default color’, it either has it or not…

so you can simply test for that…

material = Sketchup.active_model.materials.current
if !material.nil? && material.use_alpha?
 UI.messagebox " OH material is transparent"
else
 UI.messagebox " NO material is NOT transparent"
end

john

2 Likes

Thank you, it works. you saved me a lot of time, can i ask you how to get material’s tiling and offset

You can obtain the UV data either via Sketchup::UVHelper or Geom::PolygonMesh.

Thank you but,i dont need to retrieve the mesh’s uvs but, i need to get the texture’s width and height.

Cattura

The problem is that the measue unit is variable from model to model

material = Sketchup.active_model.materials.current
if !material.nil? && material.respond_to?(:texture)
 p [material.texture.width, material.texture.image_width, material.texture.height, material.texture.image_height] 
else
 p " NO material has no texture"
end

width, height are in inches and image_width, image_height are in pixels…

john

1 Like

From Sketchup::Texture - using the width and height properties.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.