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-24 18:28:33 +0300
committerJulien Duroure <julien.duroure@gmail.com>2018-11-24 18:28:33 +0300
commitb1f2133fa2849da272e9d8404f371220226ddaf1 (patch)
tree25db56e0f2211bd1059fe0e04e78430a6156e021 /io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
parent8959f1798cfc86924493347304118c61bd5c7f7a (diff)
Initial commit of glTF 2.0 importer/exporter
Official Khronos Group Blender glTF 2.0 importer and exporter. glTF specification: https://github.com/KhronosGroup/glTF The upstream repository can be found here: https://github.com/KhronosGroup/glTF-Blender-IO Reviewed By: Bastien, Campbell Differential Revision: https://developer.blender.org/D3929
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py138
1 files changed, 138 insertions, 0 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
new file mode 100755
index 00000000..d801eca7
--- /dev/null
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
@@ -0,0 +1,138 @@
+# 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
+
+from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
+from io_scene_gltf2.io.com import gltf2_io
+from io_scene_gltf2.blender.exp import gltf2_blender_gather_texture_info
+from io_scene_gltf2.blender.exp import gltf2_blender_gather_material_normal_texture_info_class
+from io_scene_gltf2.blender.exp import gltf2_blender_gather_material_occlusion_texture_info_class
+
+from io_scene_gltf2.blender.exp import gltf2_blender_gather_materials_pbr_metallic_roughness
+from io_scene_gltf2.blender.exp import gltf2_blender_get
+
+
+@cached
+def gather_material(blender_material, export_settings):
+ """
+ Gather the material used by the blender primitive.
+
+ :param blender_material: the blender material used in the glTF primitive
+ :param export_settings:
+ :return: a glTF material
+ """
+ if not __filter_material(blender_material, export_settings):
+ return None
+
+ material = gltf2_io.Material(
+ alpha_cutoff=__gather_alpha_cutoff(blender_material, export_settings),
+ alpha_mode=__gather_alpha_mode(blender_material, export_settings),
+ double_sided=__gather_double_sided(blender_material, export_settings),
+ emissive_factor=__gather_emmissive_factor(blender_material, export_settings),
+ emissive_texture=__gather_emissive_texture(blender_material, export_settings),
+ extensions=__gather_extensions(blender_material, export_settings),
+ extras=__gather_extras(blender_material, export_settings),
+ name=__gather_name(blender_material, export_settings),
+ normal_texture=__gather_normal_texture(blender_material, export_settings),
+ occlusion_texture=__gather_occlusion_texture(blender_material, export_settings),
+ pbr_metallic_roughness=__gather_pbr_metallic_roughness(blender_material, export_settings)
+ )
+
+ return material
+ # material = blender_primitive['material']
+ #
+ # if get_material_requires_texcoords(glTF, material) and not export_settings['gltf_texcoords']:
+ # material = -1
+ #
+ # if get_material_requires_normals(glTF, material) and not export_settings['gltf_normals']:
+ # material = -1
+ #
+ # # Meshes/primitives without material are allowed.
+ # if material >= 0:
+ # primitive.material = material
+ # else:
+ # print_console('WARNING', 'Material ' + internal_primitive[
+ # 'material'] + ' not found. Please assign glTF 2.0 material or enable Blinn-Phong material in export.')
+
+
+def __filter_material(blender_material, export_settings):
+ # if not blender_material.use_nodes:
+ # return False
+ # if not blender_material.node_tree:
+ # return False
+ return True
+
+
+def __gather_alpha_cutoff(blender_material, export_settings):
+ return None
+
+
+def __gather_alpha_mode(blender_material, export_settings):
+ return None
+
+
+def __gather_double_sided(blender_material, export_settings):
+ return None
+
+
+def __gather_emmissive_factor(blender_material, export_settings):
+ emissive = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Emissive")
+ if isinstance(emissive, bpy.types.NodeSocket):
+ return emissive.default_value
+ return None
+
+
+def __gather_emissive_texture(blender_material, export_settings):
+ emissive = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Emissive")
+ return gltf2_blender_gather_texture_info.gather_texture_info((emissive,), export_settings)
+
+
+def __gather_extensions(blender_material, export_settings):
+ extensions = {}
+
+
+ # TODO specular glossiness extension
+
+ return extensions if extensions else None
+
+
+def __gather_extras(blender_material, export_setttings):
+ return None
+
+
+def __gather_name(blender_material, export_settings):
+
+ return None
+
+
+def __gather_normal_texture(blender_material, export_settings):
+ normal = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Normal")
+ return gltf2_blender_gather_material_normal_texture_info_class.gather_material_normal_texture_info_class(
+ (normal,),
+ export_settings)
+
+
+def __gather_occlusion_texture(blender_material, export_settings):
+ emissive = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Occlusion")
+ return gltf2_blender_gather_material_occlusion_texture_info_class.gather_material_occlusion_texture_info_class(
+ (emissive,),
+ export_settings)
+
+
+def __gather_pbr_metallic_roughness(blender_material, export_settings):
+ return gltf2_blender_gather_materials_pbr_metallic_roughness.gather_material_pbr_metallic_roughness(
+ blender_material,
+ export_settings)
+