Skip to content

Commit

Permalink
Merge pull request #1173 from hummat/extend_light
Browse files Browse the repository at this point in the history
feat(light): add utility functions for managing light objects
  • Loading branch information
cornerfarmer authored Dec 12, 2024
2 parents 1f09fe4 + 46d7695 commit 06b190f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions blenderproc/api/lighting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from blenderproc.python.lighting.SuncgLighting import light_suncg_scene
from blenderproc.python.lighting.SurfaceLighting import light_surface
from blenderproc.python.lighting.IntersectingSpotLight import add_intersecting_spot_lights_to_camera_poses
from blenderproc.python.types.LightUtility import get_all_light_objects, convert_to_lights
20 changes: 19 additions & 1 deletion blenderproc/python/types/LightUtility.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
""" This class allows the creation and management of lights in the scene. """

from typing import Union, Optional
from typing import Union, Optional, List

import numpy as np
import bpy
from mathutils import Color

from blenderproc.python.types.EntityUtility import Entity
from blenderproc.python.utility.Utility import Utility, KeyFrame
from blenderproc.python.utility.BlenderUtility import get_all_blender_light_objects


class Light(Entity):
Expand Down Expand Up @@ -243,3 +244,20 @@ def get_type(self, frame: Optional[int] = None) -> str:
"""
with KeyFrame(frame):
return self.blender_obj.data.type


def convert_to_lights(blender_objects: List[bpy.types.Object]) -> List[Light]:
""" Converts a list of Blender light objects to a list of BlenderProc light objects.
:param blender_objects: A list of Blender light objects.
:return: A list of BlenderProc light objects.
"""
return [Light(blender_obj=obj) for obj in blender_objects]


def get_all_light_objects() -> List[Light]:
""" Retrieves all light objects in the current Blender scene and converts them to BlenderProc light objects.
:return: A list of all light objects in the current scene.
"""
return convert_to_lights(get_all_blender_light_objects())
8 changes: 8 additions & 0 deletions blenderproc/python/utility/BlenderUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ def get_all_blender_mesh_objects() -> List[bpy.types.Object]:
return [obj for obj in bpy.context.scene.objects if obj.type == 'MESH']


def get_all_blender_light_objects() -> List[bpy.types.Object]:
"""
Returns a list of all light objects in the scene
:return: a list of all light objects
"""
return [obj for obj in bpy.context.scene.objects if obj.type == 'LIGHT']


def get_all_materials() -> List[bpy.types.Material]:
"""
Returns a list of all materials used and unused
Expand Down

0 comments on commit 06b190f

Please sign in to comment.