1
$\begingroup$

I am working on upgrading a 2.79 plugin to 2.8.

The plugin was using the Material.use_transparency and Material.alpha fields, which got both removed in the 2.8 api change.

I am new to this, and I wonder what is the new equivalent of these fields, or if there is a new way to get these information.

Thanks a lot!

$\endgroup$

1 Answer 1

1
$\begingroup$

This is more complex because materials now almost always use nodes.

Whether to use alpha is controlled by the Blend Method. As a replacement for reading material.use_transparency, try using material.blend_method != 'OPAQUE'.

To fetch the actual alpha value is harder since it now flows down an arbitrarily-complex node graph. But for simple graphs you can try this

from bpy_extras.node_shader_utils import PrincipledBSDFWrapper
ma_wrap = PrincipledBSDFWrapper(material)
ma_wrap.alpha  # use this instead of material.alpha
ma_wrap.alpha_texture.image  # use this if you want the alpha texture image

This wrapper is used by the OBJ/FBX exporter. See Import & Export of Node Shaders in the manual for more about it.

$\endgroup$
1
  • $\begingroup$ Thanks a lot! I'll study the method used by the official exporters then. $\endgroup$
    – Nemo Zhang
    Sep 20, 2020 at 10:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .