Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TransparencyFactor not fully handled by FBXLoader #29439

Closed
BTT-GH opened this issue Sep 18, 2024 · 10 comments · Fixed by #29544
Closed

TransparencyFactor not fully handled by FBXLoader #29439

BTT-GH opened this issue Sep 18, 2024 · 10 comments · Fixed by #29544
Milestone

Comments

@BTT-GH
Copy link

BTT-GH commented Sep 18, 2024

Description

When importing a FBX object with a material using transparency factor as a value with FBXLoader, the model stay fully opaque.

We added a correspondance for transparency factor/Opacity wich solved the issues.

Example object attached

		if ( materialNode.TransparencyFactor ) {

			parameters.opacity = 1 - parseFloat( materialNode.TransparencyFactor.value );

		} 
		else if ( materialNode.Opacity ) 
		{

			parameters.opacity = parseFloat( materialNode.Opacity.value );

		}

		if ( parameters.opacity < 1.0 ) {

			parameters.transparent = true;

		}

exampleWindow.zip

Reproduction steps

  1. Use FBXLoader on a file with material using a transparency factor as a value

Code

	Material: 2219013623056, "Material::maskwindow", "" {
		Version: 102
		ShadingModel: "unknown"
		MultiLayer: 0
		Properties70:  {
			P: "ShadingModel", "KString", "", "", "unknown"
			P: "AmbientColor", "ColorRGB", "Color", "",0,0,0
			P: "DiffuseColor", "ColorRGB", "Color", "",0,0,0
			P: "SpecularColor", "ColorRGB", "Color", "",1,1,1
			P: "SpecularFactor", "double", "Number", "",2
			P: "ShininessExponent", "double", "Number", "",1024
			P: "TransparencyFactor", "double", "Number", "",0.600000023841858
			P: "EmissiveColor", "ColorRGB", "Color", "",0,0,0
			P: "EmissiveFactor", "double", "Number", "",0
			P: "3dsMax", "Compound", "", ""
			P: "3dsMax|ClassIDa", "int", "Integer", "",1030429932
			P: "3dsMax|ClassIDb", "int", "Integer", "",-559038463
			P: "3dsMax|SuperClassID", "int", "Integer", "",3072
			P: "3dsMax|Parameters", "Compound", "", ""
			P: "3dsMax|ORIGINAL_MTL", "KString", "", "", "PHYSICAL_MTL"
			P: "3dsMax|Parameters|material_mode", "Integer", "", "A",2
			P: "3dsMax|Parameters|base_weight", "Float", "", "A",0
			P: "3dsMax|Parameters|base_color", "ColorAndAlpha", "", "A",0.5,0.5,0.5,1
			P: "3dsMax|Parameters|reflectivity", "Float", "", "A",1
			P: "3dsMax|Parameters|roughness", "Float", "", "A",0
			P: "3dsMax|Parameters|roughness_inv", "Bool", "", "A",0
			P: "3dsMax|Parameters|metalness", "Float", "", "A",0
			P: "3dsMax|Parameters|refl_color", "ColorAndAlpha", "", "A",1,1,1,1
			P: "3dsMax|Parameters|diff_roughness", "Float", "", "A",0
			P: "3dsMax|Parameters|brdf_mode", "Bool", "", "A",1
			P: "3dsMax|Parameters|brdf_low", "Float", "", "A",0.05
			P: "3dsMax|Parameters|brdf_high", "Float", "", "A",1
			P: "3dsMax|Parameters|brdf_curve", "Float", "", "A",5
			P: "3dsMax|Parameters|anisotropy", "Float", "", "A",0
			P: "3dsMax|Parameters|anisoangle", "Float", "", "A",0.25
			P: "3dsMax|Parameters|aniso_mode", "Integer", "", "A",0
			P: "3dsMax|Parameters|aniso_channel", "Integer", "", "A",0
			P: "3dsMax|Parameters|transparency", "Float", "", "A",1
			P: "3dsMax|Parameters|trans_color", "ColorAndAlpha", "", "A",1,1,1,1
			P: "3dsMax|Parameters|trans_depth", "Float", "", "A",0
			P: "3dsMax|Parameters|trans_roughness", "Float", "", "A",0
			P: "3dsMax|Parameters|trans_roughness_inv", "Bool", "", "A",0
			P: "3dsMax|Parameters|trans_roughness_lock", "Bool", "", "A",1
			P: "3dsMax|Parameters|trans_ior", "Float", "", "A",1.52
			P: "3dsMax|Parameters|thin_walled", "Bool", "", "A",0
			P: "3dsMax|Parameters|dispersion", "Float", "", "A",0
			P: "3dsMax|Parameters|trans_scatter_color", "ColorAndAlpha", "", "A",0,0,0,1
			P: "3dsMax|Parameters|trans_scatter_aniso", "Float", "", "A",0
			P: "3dsMax|Parameters|scattering", "Float", "", "A",0
			P: "3dsMax|Parameters|sss_color", "ColorAndAlpha", "", "A",1,1,1,1
			P: "3dsMax|Parameters|sss_depth", "Float", "", "A",10
			P: "3dsMax|Parameters|sss_scale", "Float", "", "A",1
			P: "3dsMax|Parameters|sss_scatter_color", "ColorAndAlpha", "", "A",1000000,500000,250000,1
			P: "3dsMax|Parameters|emission", "Float", "", "A",1
			P: "3dsMax|Parameters|emit_color", "ColorAndAlpha", "", "A",0,0,0,1
			P: "3dsMax|Parameters|emit_luminance", "Float", "", "A",1500
			P: "3dsMax|Parameters|emit_kelvin", "Float", "", "A",6500
			P: "3dsMax|Parameters|coating", "Float", "", "A",0
			P: "3dsMax|Parameters|coat_color", "ColorAndAlpha", "", "A",1,1,1,1
			P: "3dsMax|Parameters|coat_roughness", "Float", "", "A",0
			P: "3dsMax|Parameters|coat_roughness_inv", "Bool", "", "A",0
			P: "3dsMax|Parameters|coat_affect_color", "Float", "", "A",0.5
			P: "3dsMax|Parameters|coat_affect_roughness", "Float", "", "A",0.5
			P: "3dsMax|Parameters|coat_ior", "Float", "", "A",1.52
			P: "3dsMax|Parameters|coat_anisotropy", "Float", "", "A",0
			P: "3dsMax|Parameters|coat_anisoangle", "Float", "", "A",0.25
			P: "3dsMax|Parameters|sheen", "Float", "", "A",0
			P: "3dsMax|Parameters|sheen_color", "ColorAndAlpha", "", "A",1,1,1,1
			P: "3dsMax|Parameters|sheen_roughness", "Float", "", "A",0.3
			P: "3dsMax|Parameters|thin_film", "Float", "", "A",0
			P: "3dsMax|Parameters|thin_film_thickness", "Float", "", "A",0
			P: "3dsMax|Parameters|thin_film_ior", "Float", "", "A",1.3
			P: "3dsMax|Parameters|base_weight_map", "Reference", "", "A"
			P: "3dsMax|Parameters|base_color_map", "Reference", "", "A"
			P: "3dsMax|Parameters|reflectivity_map", "Reference", "", "A"
			P: "3dsMax|Parameters|refl_color_map", "Reference", "", "A"
			P: "3dsMax|Parameters|roughness_map", "Reference", "", "A"
			P: "3dsMax|Parameters|metalness_map", "Reference", "", "A"
			P: "3dsMax|Parameters|diff_rough_map", "Reference", "", "A"
			P: "3dsMax|Parameters|anisotropy_map", "Reference", "", "A"
			P: "3dsMax|Parameters|aniso_angle_map", "Reference", "", "A"
			P: "3dsMax|Parameters|transparency_map", "Reference", "", "A"
			P: "3dsMax|Parameters|trans_color_map", "Reference", "", "A"
			P: "3dsMax|Parameters|trans_rough_map", "Reference", "", "A"
			P: "3dsMax|Parameters|trans_ior_map", "Reference", "", "A"
			P: "3dsMax|Parameters|scattering_map", "Reference", "", "A"
			P: "3dsMax|Parameters|sss_color_map", "Reference", "", "A"
			P: "3dsMax|Parameters|sss_scale_map", "Reference", "", "A"
			P: "3dsMax|Parameters|emission_map", "Reference", "", "A"
			P: "3dsMax|Parameters|emit_color_map", "Reference", "", "A"
			P: "3dsMax|Parameters|coat_map", "Reference", "", "A"
			P: "3dsMax|Parameters|coat_color_map", "Reference", "", "A"
			P: "3dsMax|Parameters|coat_rough_map", "Reference", "", "A"
			P: "3dsMax|Parameters|displacement_map", "Reference", "", "A"
			P: "3dsMax|Parameters|cutout_map", "Reference", "", "A"
			P: "3dsMax|Parameters|coat_aniso_map", "Reference", "", "A"
			P: "3dsMax|Parameters|coat_aniso_angle_map", "Reference", "", "A"
			P: "3dsMax|Parameters|sheen_map", "Reference", "", "A"
			P: "3dsMax|Parameters|sheen_color_map", "Reference", "", "A"
			P: "3dsMax|Parameters|sheen_rough_map", "Reference", "", "A"
			P: "3dsMax|Parameters|thin_film_map", "Reference", "", "A"
			P: "3dsMax|Parameters|thin_film_ior_map", "Reference", "", "A"
			P: "3dsMax|Parameters|base_weight_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|base_color_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|reflectivity_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|refl_color_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|roughness_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|metalness_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|diff_rough_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|anisotropy_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|aniso_angle_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|transparency_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|trans_color_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|trans_rough_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|trans_ior_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|scattering_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|sss_color_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|sss_scale_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|emission_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|emit_color_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|coat_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|coat_color_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|coat_rough_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|coat_aniso_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|coat_aniso_angle_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|sheen_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|sheen_color_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|sheen_rough_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|thin_film_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|thin_film_ior_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|displacement_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|cutout_map_on", "Bool", "", "A",1
			P: "3dsMax|Parameters|displacement_map_amt", "Float", "", "A",1
		}
	}

Live example

Screenshots

image
image

Version

168

Device

Desktop

Browser

Firefox

OS

Windows

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 18, 2024

Would you be willing to file a PR with the suggested change?

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 24, 2024

I have tested your proposed change and it unfortunately breaks the bot asset in webgl_loader_fbx. It renders completely transparent now which is obviously incorrect.

@WestLangley
Copy link
Collaborator

Does this hint still work?

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 24, 2024

Tried it in the editor but it has no effect.

@GitHubDragonFly
Copy link
Contributor

This code appears to work, not sure if it's universal but seems to be functional for FBX models I tried (can be tested in my FBX Viewer):

		if ( materialNode.TransparencyFactor && ( materialNode.TransparencyFactor.value < 1 || ! materialNode.Opacity ) ) {

			parameters.opacity = 1 - parseFloat( materialNode.TransparencyFactor.value );

		} else if ( materialNode.Opacity ) {

			parameters.opacity = parseFloat( materialNode.Opacity.value );

		}

		if ( parameters.opacity < 1.0 ) {

			parameters.transparent = true;

		}

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 2, 2024

I remember @looeee recommended to use the Blender source code as a reference in such cases. If you have the possibility, it would be great if you could check the transparency handling there.

@GitHubDragonFly
Copy link
Contributor

@Mugen87 if your suggestion was intended for me then just to say that I'm not much of a Blender user in any way.

I did log the materialNode in the console just to see what different models include for TransparencyFactor and Opacity properties and that's how I came up with the code posted in my previous post.

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 2, 2024

Below should be the relevant section. I actually like the initial comment 😁 .

https://github.com/sobotka/blender-addons/blob/7d80f2f97161fc8e353a657b179b9aa1f8e5280b/io_scene_fbx/import_fbx.py#L1444-L1459

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 2, 2024

@GitHubDragonFly Would this new transparency handling work for you?

parameters.opacity = 1 - ( materialNode.TransparencyFactor ? parseFloat( materialNode.TransparencyFactor.value ) : 0 );

if ( parameters.opacity === 1 || parameters.opacity === 0 ) {

	parameters.opacity = ( materialNode.Opacity ? parseFloat( materialNode.Opacity.value ) : null );

	if ( parameters.opacity === null ) {

		parameters.opacity = 1 - ( materialNode.TransparentColor ? parseFloat( materialNode.TransparentColor.value[ 0 ] ) : 0 );

	}

}

if ( parameters.opacity < 1.0 ) {

	parameters.transparent = true;

}

The code would replace the previous if ( materialNode.Opacity ) { block. This implementation would match Blender and Unity. The OP's asset as well as the bot from webgl_loader_fbx render as expected now.

@GitHubDragonFly
Copy link
Contributor

@Mugen87 if I just plug your code in there is no difference in the output that I could see.

That seems to be the way to go, since it matches Blender and Unity better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants