Import images as planes: use Principled BSDF for emission mode
[blender-addons.git] / amaranth / utils.py
blobf63678751a62d73faa8c320c77b187b8c4aba63d
1 # This program is free software; you can redistribute it and/or
2 # modify it under the terms of the GNU General Public License
3 # as published by the Free Software Foundation; either version 2
4 # of the License, or (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software Foundation,
13 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 import bpy
18 # FUNCTION: Checks if cycles is available
19 def cycles_exists():
20 return hasattr(bpy.types.Scene, "cycles")
23 # FUNCTION: Checks if cycles is the active renderer
24 def cycles_active(context):
25 return context.scene.render.engine == "CYCLES"
28 # FUNCTION: Check if material has Emission (for select and stats)
29 def cycles_is_emission(context, ob):
30 is_emission = False
32 if not ob.material_slots:
33 return is_emission
35 for ma in ob.material_slots:
36 if not ma.material:
37 continue
38 if ma.material.node_tree and ma.material.node_tree.nodes:
39 for no in ma.material.node_tree.nodes:
40 if not no.type in ("EMISSION", "GROUP"):
41 continue
42 for ou in no.outputs:
43 if not ou.links:
44 continue
45 if no.type == "GROUP" and no.node_tree and no.node_tree.nodes:
46 for gno in no.node_tree.nodes:
47 if gno.type != "EMISSION":
48 continue
49 for gou in gno.outputs:
50 if ou.links and gou.links:
51 is_emission = True
52 elif no.type == "EMISSION":
53 if ou.links:
54 is_emission = True
55 return is_emission
58 # FUNCTION: Check if object has keyframes for a specific frame
59 def is_keyframe(ob, frame):
60 if ob is not None and ob.animation_data is not None and ob.animation_data.action is not None:
61 for fcu in ob.animation_data.action.fcurves:
62 if frame in (p.co.x for p in fcu.keyframe_points):
63 return True
64 return False