diff options
author | Peter Kim <pk15950@gmail.com> | 2022-09-08 07:00:43 +0300 |
---|---|---|
committer | Peter Kim <pk15950@gmail.com> | 2022-09-08 07:00:43 +0300 |
commit | e83f88c951e26b01893acee4f24b40a46062a41c (patch) | |
tree | 09f60bf7d4fc2ae1ef50668823e416fc675b252e /io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_transmission.py | |
parent | ec84e3294593e2e26475f18c81e847bf00dc201e (diff) | |
parent | 0cd92169d40ae1c7e103ff269e850eaf1b901646 (diff) |
Merge branch 'master' into xr-devxr-dev
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_transmission.py')
-rw-r--r-- | io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_transmission.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_transmission.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_transmission.py new file mode 100644 index 00000000..fdc5d8c7 --- /dev/null +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_transmission.py @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2018-2022 The glTF-Blender-IO authors. + +import bpy +from io_scene_gltf2.io.com.gltf2_io_extensions import Extension +from io_scene_gltf2.blender.exp import gltf2_blender_get +from io_scene_gltf2.blender.exp import gltf2_blender_gather_texture_info + +def export_transmission(blender_material, export_settings): + transmission_enabled = False + has_transmission_texture = False + + transmission_extension = {} + transmission_slots = () + + transmission_socket = gltf2_blender_get.get_socket(blender_material, 'Transmission') + + if isinstance(transmission_socket, bpy.types.NodeSocket) and not transmission_socket.is_linked: + transmission_extension['transmissionFactor'] = transmission_socket.default_value + transmission_enabled = transmission_extension['transmissionFactor'] > 0 + elif gltf2_blender_get.has_image_node_from_socket(transmission_socket): + fac = gltf2_blender_get.get_factor_from_socket(transmission_socket, kind='VALUE') + transmission_extension['transmissionFactor'] = fac if fac is not None else 1.0 + has_transmission_texture = True + transmission_enabled = True + + if not transmission_enabled: + return None, None + + # Pack transmission channel (R). + if has_transmission_texture: + transmission_slots = (transmission_socket,) + + use_actives_uvmaps = [] + + if len(transmission_slots) > 0: + combined_texture, use_active_uvmap, _ = gltf2_blender_gather_texture_info.gather_texture_info( + transmission_socket, + transmission_slots, + export_settings, + ) + if has_transmission_texture: + transmission_extension['transmissionTexture'] = combined_texture + if use_active_uvmap: + use_actives_uvmaps.append("transmissionTexture") + + return Extension('KHR_materials_transmission', transmission_extension, False), use_actives_uvmaps
\ No newline at end of file |