Skip to content

Commit 06b190f

Browse files
authored
Merge pull request #1173 from hummat/extend_light
feat(light): add utility functions for managing light objects
2 parents 1f09fe4 + 46d7695 commit 06b190f

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

blenderproc/api/lighting/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from blenderproc.python.lighting.SuncgLighting import light_suncg_scene
22
from blenderproc.python.lighting.SurfaceLighting import light_surface
33
from blenderproc.python.lighting.IntersectingSpotLight import add_intersecting_spot_lights_to_camera_poses
4+
from blenderproc.python.types.LightUtility import get_all_light_objects, convert_to_lights

blenderproc/python/types/LightUtility.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
""" This class allows the creation and management of lights in the scene. """
22

3-
from typing import Union, Optional
3+
from typing import Union, Optional, List
44

55
import numpy as np
66
import bpy
77
from mathutils import Color
88

99
from blenderproc.python.types.EntityUtility import Entity
1010
from blenderproc.python.utility.Utility import Utility, KeyFrame
11+
from blenderproc.python.utility.BlenderUtility import get_all_blender_light_objects
1112

1213

1314
class Light(Entity):
@@ -243,3 +244,20 @@ def get_type(self, frame: Optional[int] = None) -> str:
243244
"""
244245
with KeyFrame(frame):
245246
return self.blender_obj.data.type
247+
248+
249+
def convert_to_lights(blender_objects: List[bpy.types.Object]) -> List[Light]:
250+
""" Converts a list of Blender light objects to a list of BlenderProc light objects.
251+
252+
:param blender_objects: A list of Blender light objects.
253+
:return: A list of BlenderProc light objects.
254+
"""
255+
return [Light(blender_obj=obj) for obj in blender_objects]
256+
257+
258+
def get_all_light_objects() -> List[Light]:
259+
""" Retrieves all light objects in the current Blender scene and converts them to BlenderProc light objects.
260+
261+
:return: A list of all light objects in the current scene.
262+
"""
263+
return convert_to_lights(get_all_blender_light_objects())

blenderproc/python/utility/BlenderUtility.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ def get_all_blender_mesh_objects() -> List[bpy.types.Object]:
117117
return [obj for obj in bpy.context.scene.objects if obj.type == 'MESH']
118118

119119

120+
def get_all_blender_light_objects() -> List[bpy.types.Object]:
121+
"""
122+
Returns a list of all light objects in the scene
123+
:return: a list of all light objects
124+
"""
125+
return [obj for obj in bpy.context.scene.objects if obj.type == 'LIGHT']
126+
127+
120128
def get_all_materials() -> List[bpy.types.Material]:
121129
"""
122130
Returns a list of all materials used and unused

0 commit comments

Comments
 (0)