def gather_texture( blender_shader_sockets_or_texture_slots: typing.Union[ typing.Tuple[bpy.types.NodeSocket], typing.Tuple[typing.Any]], export_settings): """ Gather texture sampling information and image channels from a blender shader texture attached to a shader socket. :param blender_shader_sockets: The sockets of the material which should contribute to the texture :param export_settings: configuration of the export :return: a glTF 2.0 texture with sampler and source embedded (will be converted to references by the exporter) """ # TODO: extend to texture slots if not __filter_texture(blender_shader_sockets_or_texture_slots, export_settings): return None texture = gltf2_io.Texture( extensions=__gather_extensions(blender_shader_sockets_or_texture_slots, export_settings), extras=__gather_extras(blender_shader_sockets_or_texture_slots, export_settings), name=__gather_name(blender_shader_sockets_or_texture_slots, export_settings), sampler=__gather_sampler(blender_shader_sockets_or_texture_slots, export_settings), source=__gather_source(blender_shader_sockets_or_texture_slots, export_settings) ) # although valid, most viewers can't handle missing source properties if texture.source is None: return None export_user_extensions('gather_texture_hook', export_settings, texture, blender_shader_sockets_or_texture_slots) return texture
def gather_texture(blender_shader_sockets_or_texture_slots: typing.Union[ typing.Tuple[bpy.types.NodeSocket], typing.Tuple[bpy.types.MaterialTextureSlot]], export_settings): """ Gather texture sampling information and image channels from a blender shader textu re attached to a shader socket :param blender_shader_sockets: The sockets of the material which should contribute to the texture :param export_settings: configuration of the export :return: a glTF 2.0 texture with sampler and source embedded (will be converted to references by the exporter) """ # TODO: extend to texture slots if not __filter_texture(blender_shader_sockets_or_texture_slots, export_settings): return None return gltf2_io.Texture( extensions=__gather_extensions(blender_shader_sockets_or_texture_slots, export_settings), extras=__gather_extras(blender_shader_sockets_or_texture_slots, export_settings), name=__gather_name(blender_shader_sockets_or_texture_slots, export_settings), sampler=__gather_sampler(blender_shader_sockets_or_texture_slots, export_settings), source=__gather_source(blender_shader_sockets_or_texture_slots, export_settings))
def __gather_extensions(blender_material, export_settings): extensions = {} if bpy.app.version < (2, 80, 0): if blender_material.use_shadeless: extensions["KHR_materials_unlit"] = Extension( "KHR_materials_unlit", {}, False) else: if gltf2_blender_get.get_socket_or_texture_slot( blender_material, "Background") is not None: extensions["KHR_materials_unlit"] = Extension( "KHR_materials_unlit", {}, False) if blender_material.get("useVideoTextureExtension", False) == "True": image_name = blender_material.get( "videoTextureExtension_DiffuseImageName") if image_name is not None: image = bpy.data.images[image_name] if image is not None and image.source == "MOVIE": data = tmp_encode_movie(image) mime_type = __gather_mimetype(image) image_base_name, _extension = path.splitext(image_name) if mime_type is not None: # Create an image, either in a buffer view or in a separate file source = gltf2_io.Image(buffer_view=__gather_buffer_view( data, export_settings), extensions=None, extras=None, mime_type=mime_type, name=image_base_name, uri=__gather_uri( data, image_base_name, mime_type, export_settings)) # Create a texture to use the previous video image texture = gltf2_io.Texture(extensions=None, extras=None, name=None, sampler=None, source=source) extension = dict(diffuse=texture) extensions["SVRF_video_texture"] = Extension( "SVRF_video_texture", extension, False) # TODO specular glossiness extension return extensions if extensions else None