Sun Position: fix error with Diurnal mode of Sun collection
[blender-addons.git] / amaranth / utils.py
blob029ee42ba844e43830b469f673ceabd7ce3cbffa
1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 import bpy
8 # FUNCTION: Checks if cycles is available
9 def cycles_exists():
10 return hasattr(bpy.types.Scene, "cycles")
13 # FUNCTION: Checks if cycles is the active renderer
14 def cycles_active(context):
15 return context.scene.render.engine == "CYCLES"
18 # FUNCTION: Check if material has Emission (for select and stats)
19 def cycles_is_emission(context, ob):
20 is_emission = False
22 if not ob.material_slots:
23 return is_emission
25 for ma in ob.material_slots:
26 if not ma.material:
27 continue
28 if ma.material.node_tree and ma.material.node_tree.nodes:
29 for no in ma.material.node_tree.nodes:
30 if not no.type in ("EMISSION", "GROUP"):
31 continue
32 for ou in no.outputs:
33 if not ou.links:
34 continue
35 if no.type == "GROUP" and no.node_tree and no.node_tree.nodes:
36 for gno in no.node_tree.nodes:
37 if gno.type != "EMISSION":
38 continue
39 for gou in gno.outputs:
40 if ou.links and gou.links:
41 is_emission = True
42 elif no.type == "EMISSION":
43 if ou.links:
44 is_emission = True
45 return is_emission
48 # FUNCTION: Check if object has keyframes for a specific frame
49 def is_keyframe(ob, frame):
50 if ob is not None and ob.animation_data is not None and ob.animation_data.action is not None:
51 for fcu in ob.animation_data.action.fcurves:
52 if frame in (p.co.x for p in fcu.keyframe_points):
53 return True
54 return False