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

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2018-11-27 22:59:55 +0300
committerJulien Duroure <julien.duroure@gmail.com>2018-11-27 22:59:55 +0300
commit74dbec774ef5e10f1b3475682efe286da8fed4cc (patch)
tree88ae822fee83f7188deeb0774b131d6300037fa5 /io_scene_gltf2/blender/exp/gltf2_blender_gather_lights.py
parenta12a93cbdffe78998b494175d5012fb1a79e2826 (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/blender/exp/gltf2_blender_gather_lights.py')
-rw-r--r--io_scene_gltf2/blender/exp/gltf2_blender_gather_lights.py131
1 files changed, 131 insertions, 0 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_lights.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_lights.py
new file mode 100644
index 00000000..5cc3dc62
--- /dev/null
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_lights.py
@@ -0,0 +1,131 @@
+# 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.
+
+import bpy
+import math
+from typing import Optional, List, Dict, Any
+
+from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
+
+from io_scene_gltf2.io.com import gltf2_io_lights_punctual
+from io_scene_gltf2.io.com import gltf2_io_debug
+
+from io_scene_gltf2.blender.exp import gltf2_blender_gather_light_spots
+from io_scene_gltf2.blender.exp import gltf2_blender_search_node_tree
+
+@cached
+def gather_lights_punctual(blender_lamp, export_settings) -> Optional[Dict[str, Any]]:
+ if not __filter_lights_punctual(blender_lamp, export_settings):
+ return None
+
+ light = gltf2_io_lights_punctual.Light(
+ color=__gather_color(blender_lamp, export_settings),
+ intensity=__gather_intensity(blender_lamp, export_settings),
+ spot=__gather_spot(blender_lamp, export_settings),
+ type=__gather_type(blender_lamp, export_settings),
+ range=__gather_range(blender_lamp, export_settings),
+ name=__gather_name(blender_lamp, export_settings),
+ extensions=__gather_extensions(blender_lamp, export_settings),
+ extras=__gather_extras(blender_lamp, export_settings)
+ )
+
+ return light.to_dict()
+
+
+def __filter_lights_punctual(blender_lamp, export_settings) -> bool:
+ if blender_lamp.type in ["HEMI", "AREA"]:
+ gltf2_io_debug.print_console("WARNING", "Unsupported light source {}".format(blender_lamp.type))
+ return False
+
+ return True
+
+
+def __gather_color(blender_lamp, export_settings) -> Optional[List[float]]:
+ emission_node = __get_cycles_emission_node(blender_lamp)
+ if emission_node is not None:
+ return emission_node.inputs["Color"].default_value
+
+ return list(blender_lamp.color)
+
+
+def __gather_intensity(blender_lamp, _) -> Optional[float]:
+ emission_node = __get_cycles_emission_node(blender_lamp)
+ if emission_node is not None:
+ if blender_lamp.type != 'SUN':
+ # When using cycles, the strength should be influenced by a LightFalloff node
+ result = gltf2_blender_search_node_tree.from_socket(
+ emission_node.get("Strength"),
+ gltf2_blender_search_node_tree.FilterByType(bpy.types.ShaderNodeLightFalloff)
+ )
+ if result:
+ quadratic_falloff_node = result[0].shader_node
+ emission_strength = quadratic_falloff_node.inputs["Strength"].default_value / (math.pi * 4.0)
+ else:
+ gltf2_io_debug.print_console('WARNING',
+ 'No quadratic light falloff node attached to emission strength property')
+ emission_strength = blender_lamp.energy
+ else:
+ emission_strength = emission_node.inputs["Strength"].default_value
+ return emission_strength
+
+ return blender_lamp.energy
+
+
+def __gather_spot(blender_lamp, export_settings) -> Optional[gltf2_io_lights_punctual.LightSpot]:
+ if blender_lamp.type == "SPOT":
+ return gltf2_blender_gather_light_spots.gather_light_spot(blender_lamp, export_settings)
+ return None
+
+
+def __gather_type(blender_lamp, _) -> str:
+ return {
+ "POINT": "point",
+ "SUN": "directional",
+ "SPOT": "spot"
+ }[blender_lamp.type]
+
+
+def __gather_range(blender_lamp, export_settings) -> Optional[float]:
+ # TODO: calculate range from
+ # https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual#range-property
+ return None
+
+
+def __gather_name(blender_lamp, export_settings) -> Optional[str]:
+ return blender_lamp.name
+
+
+def __gather_extensions(blender_lamp, export_settings) -> Optional[dict]:
+ return None
+
+
+def __gather_extras(blender_lamp, export_settings) -> Optional[Any]:
+ return None
+
+
+def __get_cycles_emission_node(blender_lamp) -> Optional[bpy.types.ShaderNodeEmission]:
+ if blender_lamp.use_nodes and blender_lamp.node_tree:
+ for currentNode in blender_lamp.node_tree.nodes:
+ if isinstance(currentNode, bpy.types.ShaderNodeOutputLamp):
+ if not currentNode.is_active_output:
+ continue
+ result = gltf2_blender_search_node_tree.from_socket(
+ currentNode.inputs.get("Surface"),
+ gltf2_blender_search_node_tree.FilterByType(bpy.types.ShaderNodeEmission)
+ )
+ if not result:
+ continue
+ return result[0].shader_node
+ return None
+