Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(light): add utility functions for managing light objects #1173

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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