def gather_material(blender_material, mesh_double_sided, 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 orm_texture = __gather_orm_texture(blender_material, export_settings) 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, mesh_double_sided, export_settings), emissive_factor=__gather_emissive_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, orm_texture, export_settings), pbr_metallic_roughness=__gather_pbr_metallic_roughness(blender_material, orm_texture, export_settings) ) return material
def __gather_material_unlit(blender_material, export_settings): gltf2_unlit = gltf2_blender_gather_materials_unlit info = gltf2_unlit.detect_shadeless_material(blender_material, export_settings) if info is None: 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), extensions={"KHR_materials_unlit": Extension("KHR_materials_unlit", {}, required=False)}, extras=__gather_extras(blender_material, export_settings), name=__gather_name(blender_material, export_settings), emissive_factor=None, emissive_texture=None, normal_texture=None, occlusion_texture=None, pbr_metallic_roughness=gltf2_io.MaterialPBRMetallicRoughness( base_color_factor=gltf2_unlit.gather_base_color_factor(info, export_settings), base_color_texture=gltf2_unlit.gather_base_color_texture(info, export_settings), metallic_factor=0.0, roughness_factor=0.9, metallic_roughness_texture=None, extensions=None, extras=None, ) ) export_user_extensions('gather_material_unlit_hook', export_settings, material, blender_material) return material
def __gather_material_unlit(blender_material, active_uvmap_index, export_settings): gltf2_unlit = gltf2_blender_gather_materials_unlit info = gltf2_unlit.detect_shadeless_material(blender_material, export_settings) if info is None: return None base_color_texture, use_active_uvmap = gltf2_unlit.gather_base_color_texture( info, export_settings) base_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), extensions={ "KHR_materials_unlit": Extension("KHR_materials_unlit", {}, required=False) }, extras=__gather_extras(blender_material, export_settings), name=__gather_name(blender_material, export_settings), emissive_factor=None, emissive_texture=None, normal_texture=None, occlusion_texture=None, pbr_metallic_roughness=gltf2_io.MaterialPBRMetallicRoughness( base_color_factor=gltf2_unlit.gather_base_color_factor( info, export_settings), base_color_texture=base_color_texture, metallic_factor=0.0, roughness_factor=0.9, metallic_roughness_texture=None, extensions=None, extras=None, )) if use_active_uvmap is not None: # Because some part of material are shared (eg pbr_metallic_roughness), we must copy the material # Texture must be shared, but not TextureInfo material = deepcopy(base_material) __get_new_material_texture_shared(base_material, material) material.pbr_metallic_roughness.base_color_texture.tex_coord = active_uvmap_index elif use_active_uvmap is None and active_uvmap_index != -1: # If material is not using active UVMap, we need to return the same material, # Even if multiples meshes are using different active UVMap material = gather_material(blender_material, -1, export_settings) else: material = base_material export_user_extensions('gather_material_unlit_hook', export_settings, material, blender_material) return material
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 mat_unlit = __gather_material_unlit(blender_material, export_settings) if mat_unlit is not None: return mat_unlit orm_texture = __gather_orm_texture(blender_material, export_settings) 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_emissive_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, orm_texture, export_settings), pbr_metallic_roughness=__gather_pbr_metallic_roughness( blender_material, orm_texture, export_settings)) # If emissive is set, from an emissive node (not PBR) # We need to set manually default values for # pbr_metallic_roughness.baseColor if material.emissive_factor is not None and gltf2_blender_get.get_node_socket( blender_material, bpy.types.ShaderNodeBsdfPrincipled, "Base Color") is None: material.pbr_metallic_roughness = gltf2_blender_gather_materials_pbr_metallic_roughness.get_default_pbr_for_emissive_node( ) export_user_extensions('gather_material_hook', export_settings, material, blender_material) return material
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=None, alpha_mode=None, double_sided=None, emissive_factor=None, emissive_texture=None, extensions=None, extras=None, name=None, normal_texture=None, occlusion_texture=None, pbr_metallic_roughness=None) return material
def gather_material(blender_material, active_uvmap_index, 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 mat_unlit = __gather_material_unlit(blender_material, active_uvmap_index, export_settings) if mat_unlit is not None: export_user_extensions('gather_material_hook', export_settings, mat_unlit, blender_material) return mat_unlit orm_texture = __gather_orm_texture(blender_material, export_settings) emissive_texture, uvmap_actives_emissive_texture = __gather_emissive_texture( blender_material, export_settings) extensions, uvmap_actives_extensions = __gather_extensions( blender_material, export_settings) normal_texture, uvmap_actives_normal_texture = __gather_normal_texture( blender_material, export_settings) occlusion_texture, uvmap_actives_occlusion_texture = __gather_occlusion_texture( blender_material, orm_texture, export_settings) pbr_metallic_roughness, uvmap_actives_pbr_metallic_roughness = __gather_pbr_metallic_roughness( blender_material, orm_texture, export_settings) base_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_emissive_factor(blender_material, export_settings), emissive_texture=emissive_texture, extensions=extensions, extras=__gather_extras(blender_material, export_settings), name=__gather_name(blender_material, export_settings), normal_texture=normal_texture, occlusion_texture=occlusion_texture, pbr_metallic_roughness=pbr_metallic_roughness) # merge all uvmap_actives uvmap_actives = [] if uvmap_actives_emissive_texture: uvmap_actives.extend(uvmap_actives_emissive_texture) if uvmap_actives_extensions: uvmap_actives.extend(uvmap_actives_extensions) if uvmap_actives_normal_texture: uvmap_actives.extend(uvmap_actives_normal_texture) if uvmap_actives_occlusion_texture: uvmap_actives.extend(uvmap_actives_occlusion_texture) if uvmap_actives_pbr_metallic_roughness: uvmap_actives.extend(uvmap_actives_pbr_metallic_roughness) # Because some part of material are shared (eg pbr_metallic_roughness), we must copy the material # Texture must be shared, but not TextureInfo material = deepcopy(base_material) __get_new_material_texture_shared(base_material, material) active_uvmap_index = active_uvmap_index if active_uvmap_index != 0 else None for tex in uvmap_actives: if tex == "emissiveTexture": material.emissive_texture.tex_coord = active_uvmap_index elif tex == "normalTexture": material.normal_texture.tex_coord = active_uvmap_index elif tex == "occlusionTexture": material.occlusion_texture.tex_coord = active_uvmap_index elif tex == "baseColorTexture": material.pbr_metallic_roughness.base_color_texture.tex_coord = active_uvmap_index elif tex == "metallicRoughnessTexture": material.pbr_metallic_roughness.metallic_roughness_texture.tex_coord = active_uvmap_index elif tex == "clearcoatTexture": material.extensions["KHR_materials_clearcoat"].extension[ 'clearcoatTexture'].tex_coord = active_uvmap_index elif tex == "clearcoatRoughnessTexture": material.extensions["KHR_materials_clearcoat"].extension[ 'clearcoatRoughnessTexture'].tex_coord = active_uvmap_index elif tex == "clearcoatNormalTexture": #TODO not tested yet material.extensions["KHR_materials_clearcoat"].extension[ 'clearcoatNormalTexture'].tex_coord = active_uvmap_index elif tex == "transmissionTexture": #TODO not tested yet material.extensions["KHR_materials_transmission"].extension[ 'transmissionTexture'].tex_coord = active_uvmap_index # If material is not using active UVMap, we need to return the same material, # Even if multiples meshes are using different active UVMap if len(uvmap_actives) == 0 and active_uvmap_index != -1: material = gather_material(blender_material, -1, export_settings) # If emissive is set, from an emissive node (not PBR) # We need to set manually default values for # pbr_metallic_roughness.baseColor if material.emissive_factor is not None and gltf2_blender_get.get_node_socket( blender_material, bpy.types.ShaderNodeBsdfPrincipled, "Base Color") is None: material.pbr_metallic_roughness = gltf2_blender_gather_materials_pbr_metallic_roughness.get_default_pbr_for_emissive_node( ) export_user_extensions('gather_material_hook', export_settings, material, blender_material) return material