1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2018-2021 The glTF-Blender-IO authors.
7 from ..com
.gltf2_blender_extras
import set_extras
8 from io_scene_gltf2
.io
.imp
.gltf2_io_user_extensions
import import_user_extensions
13 def __new__(cls
, *args
, **kwargs
):
14 raise RuntimeError("%s should not be instantiated" % cls
)
17 def create(gltf
, vnode
, light_id
):
19 pylight
= gltf
.data
.extensions
['KHR_lights_punctual']['lights'][light_id
]
21 import_user_extensions('gather_import_light_before_hook', gltf
, vnode
, pylight
)
23 if pylight
['type'] == "directional":
24 light
= BlenderLight
.create_directional(gltf
, light_id
)
25 elif pylight
['type'] == "point":
26 light
= BlenderLight
.create_point(gltf
, light_id
)
27 elif pylight
['type'] == "spot":
28 light
= BlenderLight
.create_spot(gltf
, light_id
)
30 if 'color' in pylight
.keys():
31 light
.color
= pylight
['color']
33 if 'intensity' in pylight
.keys():
34 light
.energy
= pylight
['intensity']
38 set_extras(light
, pylight
.get('extras'))
43 def create_directional(gltf
, light_id
):
44 pylight
= gltf
.data
.extensions
['KHR_lights_punctual']['lights'][light_id
]
46 if 'name' not in pylight
.keys():
47 pylight
['name'] = "Sun"
49 sun
= bpy
.data
.lights
.new(name
=pylight
['name'], type="SUN")
53 def create_point(gltf
, light_id
):
54 pylight
= gltf
.data
.extensions
['KHR_lights_punctual']['lights'][light_id
]
56 if 'name' not in pylight
.keys():
57 pylight
['name'] = "Point"
59 point
= bpy
.data
.lights
.new(name
=pylight
['name'], type="POINT")
63 def create_spot(gltf
, light_id
):
64 pylight
= gltf
.data
.extensions
['KHR_lights_punctual']['lights'][light_id
]
66 if 'name' not in pylight
.keys():
67 pylight
['name'] = "Spot"
69 spot
= bpy
.data
.lights
.new(name
=pylight
['name'], type="SPOT")
72 if 'spot' in pylight
.keys() and 'outerConeAngle' in pylight
['spot']:
73 spot
.spot_size
= pylight
['spot']['outerConeAngle'] * 2
75 spot
.spot_size
= pi
/ 2
77 if 'spot' in pylight
.keys() and 'innerConeAngle' in pylight
['spot']:
78 spot
.spot_blend
= 1 - ( pylight
['spot']['innerConeAngle'] / pylight
['spot']['outerConeAngle'] )