1# Copyright 2018 The glTF-Blender-IO authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15from io_scene_gltf2.io.com.gltf2_io import from_dict, from_union, from_none, from_float, from_str, from_list 16from io_scene_gltf2.io.com.gltf2_io import to_float, to_class 17 18 19class LightSpot: 20 """light/spot""" 21 def __init__(self, inner_cone_angle, outer_cone_angle): 22 self.inner_cone_angle = inner_cone_angle 23 self.outer_cone_angle = outer_cone_angle 24 25 @staticmethod 26 def from_dict(obj): 27 assert isinstance(obj, dict) 28 inner_cone_angle = from_union([from_float, from_none], obj.get("innerConeAngle")) 29 outer_cone_angle = from_union([from_float, from_none], obj.get("outerConeAngle")) 30 return LightSpot(inner_cone_angle, outer_cone_angle) 31 32 def to_dict(self): 33 result = {} 34 result["innerConeAngle"] = from_union([from_float, from_none], self.inner_cone_angle) 35 result["outerConeAngle"] = from_union([from_float, from_none], self.outer_cone_angle) 36 return result 37 38 39class Light: 40 """defines a set of lights for use with glTF 2.0. Lights define light sources within a scene""" 41 def __init__(self, color, intensity, spot, type, range, name, extensions, extras): 42 self.color = color 43 self.intensity = intensity 44 self.spot = spot 45 self.type = type 46 self.range = range 47 self.name = name 48 self.extensions = extensions 49 self.extras = extras 50 51 @staticmethod 52 def from_dict(obj): 53 assert isinstance(obj, dict) 54 color = from_union([lambda x: from_list(from_float, x), from_none], obj.get("color")) 55 intensity = from_union([from_float, from_none], obj.get("intensity")) 56 spot = LightSpot.from_dict(obj.get("spot")) 57 type = from_str(obj.get("type")) 58 range = from_union([from_float, from_none], obj.get("range")) 59 name = from_union([from_str, from_none], obj.get("name")) 60 extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none], 61 obj.get("extensions")) 62 extras = obj.get("extras") 63 return Light(color, intensity, spot, type, range, name, extensions, extras) 64 65 def to_dict(self): 66 result = {} 67 result["color"] = from_union([lambda x: from_list(to_float, x), from_none], self.color) 68 result["intensity"] = from_union([from_float, from_none], self.intensity) 69 result["spot"] = from_union([lambda x: to_class(LightSpot, x), from_none], self.spot) 70 result["type"] = from_str(self.type) 71 result["range"] = from_union([from_float, from_none], self.range) 72 result["name"] = from_union([from_str, from_none], self.name) 73 result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none], 74 self.extensions) 75 result["extras"] = self.extras 76 return result 77