Skip to content

Commit

Permalink
Adding SpotLight to Lighting kit (#219)
Browse files Browse the repository at this point in the history
* Adding Spotlight requirements

Added the spot_blend and spot_size parameters into the lights.py file.

Spot Blend is the roughness of the beam
Spot Size is the radius in deg 0 - 180

Blender.py was changed to add the needed parameters inside the blender handler. I think I added the correct identifiers and what not. I just copied the standard implementation as it was written.

The SpotLight was added in with the other forms of Lights

----------
Still need to look at the colors of the lights. Maybe refer to the issue in the main github of Kubric regarding the Color Class and its implementation.

* Update as per notes

Awesome notes from Qwlouse! can be found at PR #219

* As per #225

As per #225 fix implemented

* Update kubric/renderer/blender.py

Co-authored-by: Klaus Greff <[email protected]>

* Import Numpy

Bug Fix noted by Qwlouse

Co-authored-by: Klaus Greff <[email protected]>
  • Loading branch information
MrXandbadas and Qwlouse authored May 6, 2022
1 parent fe85bc6 commit 09e4047
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions kubric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from kubric.core.lights import DirectionalLight
from kubric.core.lights import PointLight
from kubric.core.lights import RectAreaLight
from kubric.core.lights import SpotLight

from kubric.core.materials import Material
from kubric.core.materials import UndefinedMaterial
Expand Down
6 changes: 6 additions & 0 deletions kubric/core/lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
"""Kubric lights module."""

import numpy as np
import traitlets as tl

from kubric.core import traits as ktl
Expand All @@ -31,6 +32,11 @@ def get_background_default(self):
return True


class SpotLight(Light):
spot_blend = tl.Float(1.)
spot_size = tl.Float(np.pi / 4)


class UndefinedLight(Light, UndefinedAsset):
pass

Expand Down
18 changes: 18 additions & 0 deletions kubric/renderer/blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,24 @@ def _add_asset(self, obj: core.DirectionalLight): # pylint: disable=function-re
obj.observe(KeyframeSetter(sun, "energy"), "intensity", type="keyframe")
return sun_obj

#@add_asset.register(core.SpotLight) # I think these are needed... ~MrX
#@blender_utils.prepare_blender_object
def _add_asset(self, obj: core.SpotLight): # pylint: disable=function-redefined
spotlight = bpy.data.lights.new(obj.uid, "SPOT")
spotlight_obj = bpy.data.objects.new(obj.uid, core.SpotLight)

register_object3d_setters(obj, spotlight_obj)
obj.observe(AttributeSetter(spotlight, "color"), "color")
obj.observe(KeyframeSetter(spotlight, "color"), "color", type="keyframe")
obj.observe(AttributeSetter(spotlight, "energy"), "intensity")
obj.observe(KeyframeSetter(spotlight, "energy"), "intensity", type="keyframe")
obj.observe(AttributeSetter(spotlight, "spot_blend"), "spot_blend")
obj.observe(KeyframeSetter(spotlight, "spot_blend"), "spot_blend", type="keyframe")
obj.observe(AttributeSetter(spotlight, "spot_size"), "spot_size")
obj.observe(KeyframeSetter(spotlight, "spot_size"), "spot_size", type="keyframe")
return spotlight_obj


@add_asset.register(core.RectAreaLight)
@blender_utils.prepare_blender_object
def _add_asset(self, obj: core.RectAreaLight):
Expand Down
2 changes: 1 addition & 1 deletion shapenet2kubric/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def stage5(object_folder: Path, logger=_DEFAULT_LOGGER):
tar.add(object_folder / 'kubric' / 'collision_geometry.obj',
arcname='collision_geometry.obj')
tar.add(object_folder / 'kubric' / 'model_watertight.obj',
arcname='collision_geometry.obj')
arcname='model_watertight.obj')
tar.add(object_folder / 'kubric' / 'object.urdf',
arcname='object.urdf')
tar.add(object_folder / 'kubric' / 'data.json',
Expand Down

0 comments on commit 09e4047

Please sign in to comment.