From 7ad405acd2e77bc7c1ac5389299a8f7e9c3d8704 Mon Sep 17 00:00:00 2001 From: MrXandbadas Date: Tue, 5 Apr 2022 23:54:48 +1000 Subject: [PATCH 1/5] 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. --- kubric/__init__.py | 1 + kubric/core/lights.py | 5 +++++ kubric/renderer/blender.py | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/kubric/__init__.py b/kubric/__init__.py index 6c5db4ae..31c29a55 100644 --- a/kubric/__init__.py +++ b/kubric/__init__.py @@ -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 diff --git a/kubric/core/lights.py b/kubric/core/lights.py index d4bd7899..27bc910b 100644 --- a/kubric/core/lights.py +++ b/kubric/core/lights.py @@ -31,6 +31,11 @@ def get_background_default(self): return True +class SpotLight(Light): + spot_blend = tl.Float(1.) + spot_size = tl.Float(*(0.00, 180.00)) + + class UndefinedLight(Light, UndefinedAsset): pass diff --git a/kubric/renderer/blender.py b/kubric/renderer/blender.py index 6e83c118..de69bc98 100644 --- a/kubric/renderer/blender.py +++ b/kubric/renderer/blender.py @@ -474,6 +474,22 @@ def _add_asset(self, obj: core.DirectionalLight): # pylint: disable=function-re obj.observe(KeyframeSetter(sun, "energy"), "intensity", type="keyframe") return sun_obj + 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, 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): From d036c227a207a0ffa2bef6254674d75ccc82e496 Mon Sep 17 00:00:00 2001 From: MrXandbadas Date: Mon, 25 Apr 2022 09:08:49 +1000 Subject: [PATCH 2/5] Update as per notes Awesome notes from Qwlouse! can be found at PR #219 --- kubric/core/lights.py | 2 +- kubric/renderer/blender.py | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/kubric/core/lights.py b/kubric/core/lights.py index 27bc910b..ca008750 100644 --- a/kubric/core/lights.py +++ b/kubric/core/lights.py @@ -33,7 +33,7 @@ def get_background_default(self): class SpotLight(Light): spot_blend = tl.Float(1.) - spot_size = tl.Float(*(0.00, 180.00)) + spot_size = tl.Float(np.pi / 4) class UndefinedLight(Light, UndefinedAsset): diff --git a/kubric/renderer/blender.py b/kubric/renderer/blender.py index de69bc98..9788860d 100644 --- a/kubric/renderer/blender.py +++ b/kubric/renderer/blender.py @@ -474,20 +474,22 @@ 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, 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 + spotlight = bpy.data.lights.new(obj.uid, "SPOT") + spotlight_obj = bpy.data.objects.new(obj.uid, 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) From 675324e98620f2fb908954355fa7e1fee96224cb Mon Sep 17 00:00:00 2001 From: MrXandbadas Date: Wed, 27 Apr 2022 02:20:29 +1000 Subject: [PATCH 3/5] As per #225 As per #225 fix implemented --- shapenet2kubric/convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shapenet2kubric/convert.py b/shapenet2kubric/convert.py index 8c6ad112..1444eb0a 100644 --- a/shapenet2kubric/convert.py +++ b/shapenet2kubric/convert.py @@ -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', From 8af14ec1635f9abee767bf0937e6492527d3b7ef Mon Sep 17 00:00:00 2001 From: MrXandbadas Date: Sat, 7 May 2022 01:02:24 +1000 Subject: [PATCH 4/5] Update kubric/renderer/blender.py Co-authored-by: Klaus Greff --- kubric/renderer/blender.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubric/renderer/blender.py b/kubric/renderer/blender.py index 9788860d..fc09d2e6 100644 --- a/kubric/renderer/blender.py +++ b/kubric/renderer/blender.py @@ -478,7 +478,7 @@ def _add_asset(self, obj: core.DirectionalLight): # pylint: disable=function-re #@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, SpotLight) + spotlight_obj = bpy.data.objects.new(obj.uid, core.SpotLight) register_object3d_setters(obj, spotlight_obj) obj.observe(AttributeSetter(spotlight, "color"), "color") From aca3bb602c71d15a019195ef435375b00e00f55f Mon Sep 17 00:00:00 2001 From: MrXandbadas Date: Sat, 7 May 2022 01:06:18 +1000 Subject: [PATCH 5/5] Import Numpy Bug Fix noted by Qwlouse --- kubric/core/lights.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kubric/core/lights.py b/kubric/core/lights.py index ca008750..c98cc0d4 100644 --- a/kubric/core/lights.py +++ b/kubric/core/lights.py @@ -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