0
$\begingroup$

So, basically I have textures that are transparent PNGs and need to display as such on the model. But no matter what I do, when I export it as .dae and re-import it, it loses the transparency and becomes a black square around the texture. Is there any way to force the .dae file to have the relevant data in it to avoid this, or at least a script that I can use to instantly fix this on all materials after re-importing it? Here is a visual of my problem:

Intended effect (using a Princess Peach sprite for simplicity's sake): Before DAE export (the intended appearance)

How this looks after exporting as a DAE and re-importing:After re-importing the file

My render engine is Eevee. If storing this data in the DAE is impossible, I will also settle for a script that fixes this on every material after it initially loads with the missing transparency. The models I'm working with have a LOT of different materials that all need proper transparency and I need to export them as Collada files, so I need some way to either address this issue or fix it efficiently (not one by one, as some of the models I'm working with have close to 100 materials)

I hope I've explained this problem and what I need as clearly as possible. It's hard to explain, so let me know if anything is unclear.

$\endgroup$
4
  • $\begingroup$ I think this is just Eevee transparency option that is not set when the material is imported. So the dae should be ok $\endgroup$
    – lemon
    Commented May 7, 2023 at 10:42
  • $\begingroup$ I also just tried importing the dae with the render engine set to Cycles, and it still imports with a black box around it. If it is an issue with how it re-imports using the available render modes, is there a script that can fix this so I don't have to manually edit 50+ materials every time I want to use one of these dae files? $\endgroup$
    – Fawful
    Commented May 7, 2023 at 11:30
  • $\begingroup$ ok, just checked that dae does not seem to save alpha channel from the principled bsdf. $\endgroup$
    – lemon
    Commented May 7, 2023 at 11:34
  • $\begingroup$ So is there any solution to this like a script? All I can find are scripts that set the alpha value to a number, none that set it to the associated texture. The old Blender Internal render engine used to make this easy, but it's phased out and even if I exported a .dae from an older version of Blender, it doesn't open in 3.0+ for some reason. This is what forced me to start working in newer versions to begin with. Just for reference, this is what I'm dealing with, I want to be able to use these .daes in Blender without a ton of manual editing: i.imgur.com/nXPxxu2.png $\endgroup$
    – Fawful
    Commented May 7, 2023 at 11:55

1 Answer 1

1
$\begingroup$

Using a sprite sprite for simplicity's sake:

enter image description here

This script will go through all materials and test if a link to the principled alpha channel is possible and/or needed, as commented in the code:

import bpy

for mat in bpy.data.materials:
    # we don't want materials without node tree
    if not mat.node_tree: continue

    nodes = mat.node_tree.nodes
    principled = next(node for node in nodes if node.type == 'BSDF_PRINCIPLED')
    # we need a principled
    if not principled: continue

    color = principled.inputs[0]
    alpha = principled.inputs[21]    
    # color input should have links
    if not (color and color.links): continue

    from_node = color.links[0].from_node    
    # and this link should be an image texture
    if not (from_node and from_node.type == 'TEX_IMAGE'): continue

    # also if alpha is already linked, do nothing
    if alpha.links: continue

    # finally, make the link
    mat.node_tree.links.new(from_node.outputs[1], alpha)
    # and, for the eevee case set the blend method
    mat.blend_method = 'BLEND' # or 'HASHED
$\endgroup$
1
  • $\begingroup$ Thank you so much, this was exactly the solution I was looking for ^^ $\endgroup$
    – Fawful
    Commented May 7, 2023 at 12:32

You must log in to answer this question.

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