Skip to content
Snippets Groups Projects
import_fbx.py 130 KiB
Newer Older
  • Learn to ignore specific revisions
  •                     elif lnk_type in {b'SpecularColor', b'SpecularFactor'}:
    
                            # Intensity actually, not color...
                            ma_wrap.specular_texture.image = image
                            texture_mapping_set(fbx_lnk, ma_wrap.specular_texture)
    
                        elif lnk_type in {b'ReflectionColor', b'ReflectionFactor', b'3dsMax|maps|texmap_reflection'}:
    
                            # Intensity actually, not color...
                            ma_wrap.metallic_texture.image = image
                            texture_mapping_set(fbx_lnk, ma_wrap.metallic_texture)
    
                        elif lnk_type in {b'TransparentColor', b'TransparentFactor'}:
    
                            ma_wrap.alpha_texture.image = image
                            texture_mapping_set(fbx_lnk, ma_wrap.alpha_texture)
    
                            if use_alpha_decals:
                                material_decals.add(material)
                        elif lnk_type == b'ShininessExponent':
    
                            # That is probably reversed compared to expected results? TODO...
                            ma_wrap.roughness_texture.image = image
                            texture_mapping_set(fbx_lnk, ma_wrap.roughness_texture)
    
                        # XXX, applications abuse bump!
                        elif lnk_type in {b'NormalMap', b'Bump', b'3dsMax|maps|texmap_bump'}:
    
                            ma_wrap.normalmap_texture.image = image
                            texture_mapping_set(fbx_lnk, ma_wrap.normalmap_texture)
    
                            """
                        elif lnk_type == b'Bump':
    
                            # TODO displacement...
    
                            """
                        else:
                            print("WARNING: material link %r ignored" % lnk_type)
    
                        material_images.setdefault(material, {})[lnk_type] = image
    
    
            # Check if the diffuse image has an alpha channel,
            # if so, use the alpha channel.
    
            # Note: this could be made optional since images may have alpha but be entirely opaque
            for fbx_uuid, fbx_item in fbx_table_nodes.items():
                fbx_obj, blen_data = fbx_item
                if fbx_obj.id != b'Material':
                    continue
    
                material = fbx_table_nodes.get(fbx_uuid, (None, None))[1]
    
                image = material_images.get(material, {}).get(b'DiffuseColor', None)
    
                # do we have alpha?
                if image and image.depth == 32:
                    if use_alpha_decals:
                        material_decals.add(material)
    
                    ma_wrap = nodal_material_wrap_map[material]
    
                    ma_wrap.alpha_texture.use_alpha = True
                    ma_wrap.alpha_texture.copy_from(ma_wrap.base_color_texture)
    
                # Propagate mapping from diffuse to all other channels which have none defined.
                # XXX Commenting for now, I do not really understand the logic here, why should diffuse mapping
                #     be applied to all others if not defined for them???
                # ~ ma_wrap = nodal_material_wrap_map[material]
                # ~ ma_wrap.mapping_set_from_diffuse()
    
        perfmon.step("FBX import: Cycles z-offset workaround...")
    
    
        def _():
            # Annoying workaround for cycles having no z-offset
            if material_decals and use_alpha_decals:
                for fbx_uuid, fbx_item in fbx_table_nodes.items():
                    fbx_obj, blen_data = fbx_item
                    if fbx_obj.id != b'Geometry':
                        continue
                    if fbx_obj.props[-1] == b'Mesh':
                        mesh = fbx_item[1]
    
                        if decal_offset != 0.0:
                            for material in mesh.materials:
                                if material in material_decals:
                                    for v in mesh.vertices:
                                        v.co += v.normal * decal_offset
                                    break
    
    
                        for obj in (obj for obj in bpy.data.objects if obj.data == mesh):
                            obj.cycles_visibility.shadow = False