Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gltf2_io_lights_punctual.py « com « io « io_scene_gltf2 - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b1c48db08db3f9afc47dde15d67f81ed3fdea6a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright 2018 The glTF-Blender-IO authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from io_scene_gltf2.io.com.gltf2_io import from_dict, from_union, from_none, from_float, from_str, from_list
from io_scene_gltf2.io.com.gltf2_io import to_float, to_class


class LightSpot:
    """light/spot"""
    def __init__(self, inner_cone_angle, outer_cone_angle):
        self.inner_cone_angle = inner_cone_angle
        self.outer_cone_angle = outer_cone_angle

    @staticmethod
    def from_dict(obj):
        assert isinstance(obj, dict)
        inner_cone_angle = from_union([from_float, from_none], obj.get("innerConeAngle"))
        outer_cone_angle = from_union([from_float, from_none], obj.get("outerConeAngle"))
        return LightSpot(inner_cone_angle, outer_cone_angle)

    def to_dict(self):
        result = {}
        result["innerConeAngle"] = from_union([from_float, from_none], self.inner_cone_angle)
        result["outerConeAngle"] = from_union([from_float, from_none], self.outer_cone_angle)
        return result


class Light:
    """defines a set of lights for use with glTF 2.0. Lights define light sources within a scene"""
    def __init__(self, color, intensity, spot, type, range, name, extensions, extras):
        self.color = color
        self.intensity = intensity
        self.spot = spot
        self.type = type
        self.range = range
        self.name = name
        self.extensions = extensions
        self.extras = extras

    @staticmethod
    def from_dict(obj):
        assert isinstance(obj, dict)
        color = from_union([lambda x: from_list(from_float, x), from_none], obj.get("color"))
        intensity = from_union([from_float, from_none], obj.get("intensity"))
        spot = LightSpot.from_dict(obj.get("spot"))
        type = from_str(obj.get("type"))
        range = from_union([from_float, from_none], obj.get("range"))
        name = from_union([from_str, from_none], obj.get("name"))
        extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
                                obj.get("extensions"))
        extras = obj.get("extras")
        return Light(color, intensity, spot, type, range, name, extensions, extras)

    def to_dict(self):
        result = {}
        result["color"] = from_union([lambda x: from_list(to_float, x), from_none], self.color)
        result["intensity"] = from_union([from_float, from_none], self.intensity)
        result["spot"] = from_union([lambda x: to_class(LightSpot, x), from_none], self.spot)
        result["type"] = from_str(self.type)
        result["range"] = from_union([from_float, from_none], self.range)
        result["name"] = from_union([from_str, from_none], self.name)
        result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
                                          self.extensions)
        result["extras"] = self.extras
        return result