diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2018-11-27 22:59:55 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2018-11-27 22:59:55 +0300 |
commit | 74dbec774ef5e10f1b3475682efe286da8fed4cc (patch) | |
tree | 88ae822fee83f7188deeb0774b131d6300037fa5 /io_scene_gltf2/io | |
parent | a12a93cbdffe78998b494175d5012fb1a79e2826 (diff) |
glTF addon: updates from upstream
* invalidate cache for multiple exports
* exporter: support KHR_lights_punctual
* fixed lights
* disable export all layers
* fixed texture slot images stalling export
* option to enable exporting more than 4 influences
from upsteam commit 26699c476211add92d13df0a284b8df2f08acb3e
to upstream commit 7a8f733fc446cfb3880a8c1658bccf94bcfd456c
Diffstat (limited to 'io_scene_gltf2/io')
-rw-r--r-- | io_scene_gltf2/io/com/gltf2_io_extensions.py | 38 | ||||
-rw-r--r-- | io_scene_gltf2/io/com/gltf2_io_lights_punctual.py | 76 |
2 files changed, 114 insertions, 0 deletions
diff --git a/io_scene_gltf2/io/com/gltf2_io_extensions.py b/io_scene_gltf2/io/com/gltf2_io_extensions.py new file mode 100644 index 00000000..2422d205 --- /dev/null +++ b/io_scene_gltf2/io/com/gltf2_io_extensions.py @@ -0,0 +1,38 @@ +# 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 typing import List, Dict, Any + + +class Extension: + """Container for extensions. Allows to specify requiredness""" + def __init__(self, name: str, extension: Dict[str, Any], required: bool = True): + self.name = name + self.extension = extension + self.required = required + + +class ChildOfRootExtension(Extension): + """Container object for extensions that should be appended to the root extensions""" + def __init__(self, path: List[str], name: str, extension: Dict[str, Any], required: bool = True): + """ + Wrap a local extension entity into an object that will later be inserted into a root extension and converted + to a reference. + :param path: The path of the extension object in the root extension. E.g. ['lights'] for + KHR_lights_punctual. Must be a path to a list in the extensions dict. + :param extension: The data that should be placed into the extension list + """ + self.path = path + super().__init__(name, extension, required) + diff --git a/io_scene_gltf2/io/com/gltf2_io_lights_punctual.py b/io_scene_gltf2/io/com/gltf2_io_lights_punctual.py new file mode 100644 index 00000000..3dc8704c --- /dev/null +++ b/io_scene_gltf2/io/com/gltf2_io_lights_punctual.py @@ -0,0 +1,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 * + + +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 + |