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

FBXLoader: Partial transparent maps doesn't work #12625

Closed
2 tasks done
cnspaha opened this issue Nov 10, 2017 · 16 comments
Closed
2 tasks done

FBXLoader: Partial transparent maps doesn't work #12625

cnspaha opened this issue Nov 10, 2017 · 16 comments

Comments

@cnspaha
Copy link
Contributor

cnspaha commented Nov 10, 2017

Description of the problem

When loading a FBX file ( succubus.zip, it is the original file, no export ) via FBXLoader transparent parts of a map isn't taken into account.

The map, opened in Gimp so you can see the transparent parts, hair + feathers:
unbenannt3

What it should look like Sketchfab
unbenannt

What it really looks like (my viewer):
unbenannt2

The problem can be worked around with when applying following code on every mesh the FBXLoader creates:

            ((obj as THREE.Mesh).material as THREE.Material).transparent = true;
            ((obj as THREE.Mesh).material as THREE.Material).side = THREE.DoubleSide;
            ((obj as THREE.Mesh).material as THREE.Material).alphaTest = 0.5;

But of course I don't want this code to be applied on every mesh because AFAIK transparency and alpha testing costs quite a bit of performance, especially if it isn't needed...

I am willingly to make a PR if I would know how to fix this.

One possible solution is that we would have to check ONLY the PART of the image being used per mesh if there is any transparency and if there is some then setting the transparent parameter on the material.

@Kyle-Larson @takahirox since you both wrote this Loader, do you have any idea?
@Mugen87 @donmccurdy you both are pretty active on loader issues/PRs probably you could help here too? ;)

Three.js version
  • [ x ] r88
Browser
  • All of them
OS
  • All of them
@donmccurdy
Copy link
Collaborator

Since the model is on Sketchfab already, you can download the glTF version there. It looks correct with r88 GLTFLoader, other than some transparency artifacts that aren't loader-related.

Preview on https://gltf-viewer.donmccurdy.com/:

screen shot 2017-11-10 at 7 09 06 am

Issue in the FBX file looks similar to #11598

@WestLangley
Copy link
Collaborator

If you are setting alphaTest, and your textures are cut-outs (no semi-transparency), there is no need to set material.transparent = true. And therefore, you should see no "transparency artifacts".

@donmccurdy
Copy link
Collaborator

That's good to know, thanks 🙂

the glTF asset from sketchfab doesn't set alphaTest but perhaps it should... trying a quick test after dragging the glTF into https://gltf-viewer.donmccurdy.com/ ...

content.traverse((node) => {
  if (node.isMesh) {
    node.material.transparent = false;
    node.material.alphaTest = 0.5;
  }
});

i'm not getting the right result:

screen shot 2017-11-10 at 8 39 58 am

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 12, 2017

If a load the FBX file with FBXLoader and set alphaTest to 0.5, the result looks okay.

image

Uploading the FBX file back to Sketchfab, i have the following result. It looks like that manual adjustments by the user are also necessary when using Sketchfab.

image

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 12, 2017

I guess we can close this issue.

@cnspaha
Copy link
Contributor Author

cnspaha commented Nov 13, 2017

If a load the FBX file with FBXLoader and set alphaTest to 0.5, the result looks okay.

can you provide me with your example code?
Because in my case it looks quite different... got some nasty white silhuettes around the feathers but don't know why.
I set the side to DoubleSide and the alphaTest to 0.5, don't do anything more with the material.
image

If you are setting alphaTest, and your textures are cut-outs (no semi-transparency), there is no need to set material.transparent = true. And therefore, you should see no "transparency artifacts".

Thanks :)

So the only option is to set alphaTest to 0.5 for every model and part I load? Because there is no possibility to check if I need to?

@donmccurdy
Copy link
Collaborator

donmccurdy commented Nov 13, 2017

So the only option is to set alphaTest to 0.5 for every model and part I load? Because there is no possibility to check if I need to?

GLTFLoader could be altered to do this automatically, assuming it shows the right result (currently it isn't for me; see above). Not sure whether the FBX format provides clear indicators of when alphaTest should be changed or not though, to enable FBXLoader to do it automatically.

@cnspaha
Copy link
Contributor Author

cnspaha commented Nov 13, 2017

GLTFLoader could be altered to do this automatically, see above, assuming it shows the right result (currently it isn't for me). Not sure whether the FBX format provides clear indicators of when alphaTest should be changed or not though, to enable FBXLoader to do it automatically.

haven't used the GLTFLoader yet.
Regarding the indicator for alpha in the FBX format I will do some researching, but don't know if it will provide good results :/ But when I do, I will post in this issue and let you know

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 13, 2017

@cnspaha I've just done this:

loader.load( 'models/fbx/succubus.fbx', function( object ) {

	object.traverse( function( o ) {

		if ( o.isMesh === true ) {

			o.material.alphaTest = 0.5;
		
		}

	} );
           
	scene.add( object );

} );

@cnspaha
Copy link
Contributor Author

cnspaha commented Nov 13, 2017

@Mugen87
I do the same as you. But just found the culprit... it is the "alpha" property on the WebGLRenderer.
If it is set to "true" the white silhuette appears...

@cnspaha
Copy link
Contributor Author

cnspaha commented Nov 13, 2017

close this, since it doesn't seem possible to check if there such parts contains alpha.

@cnspaha cnspaha closed this as completed Nov 13, 2017
@donmccurdy
Copy link
Collaborator

I followed up about why the glTF version doesn't render correctly; there is an unexpected case in the format spec. Will post more updates here: KhronosGroup/glTF#1158

@looeee
Copy link
Collaborator

looeee commented Nov 20, 2017

GLTFLoader could be altered to do this automatically, assuming it shows the right result (currently it isn't for me; see above). Not sure whether the FBX format provides clear indicators of when alphaTest should be changed or not though, to enable FBXLoader to do it automatically.

@donmccurdy how is this indicated in GLTF? I'll take a look and see if there is anything similar in FBX.

@donmccurdy
Copy link
Collaborator

donmccurdy commented Nov 20, 2017

@looeee glTF sets alphaMode as one of BLEND, MASK, or OPAQUE. Another property, alphaCutoff, corresponds to three.js's alphaTest. But (per KhronosGroup/glTF#1158) alphaCutoff is only used in MASK mode, not BLEND, and so the format technically does not allow what Sketchfab is trying to do here. That may be an oversight that needs to be corrected in a future glTF version...

https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#alpha-coverage

@looeee
Copy link
Collaborator

looeee commented Nov 20, 2017

There's an enum AlphaSource in FBX, unfortunately the documentation is as usual pretty sparse (documentation as comments here):

{ 
    eNone, // no alpha         
    eRGBIntensity,  //RGB Intensity (computed).
    eBlack // Alpha channel. Black is 100% transparency, white is opaque          
};

I wonder if eBlack could be used to indicate alpha test is needed?

EDIT: tested with a few models including this one, and I can't find any where this enum is actually set... so I guess we are stuck with doing it manually.

@yazancash
Copy link

i have same problem.
in FBX file, textures are defined as below:

Texture: 123, "Texture::texmap123", "" {
	Type: "TextureVideoClip"
	Version: 202
	TextureName: "Texture::texmap123"
	Properties70:  {
		P: "UseMaterial", "bool", "", "",1
	}
	FileName: "123.png"
	ModelUVTranslation: 0,0
	ModelUVScaling: 1,1
	Texture_Alpha_Source: "RGBIntensity"
	Cropping: 0,0,0,0
}

i can see Texture_Alpha_Source: "RGBIntensity"
but model is appearing with no transparency. even when i set AlphaTest = 0.5

is there any solution for this?

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

No branches or pull requests

6 participants