-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
Add support for mayas openPBRsurface shader when using the fbx-loader #32584
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
Changes from 2 commits
95b0533
b0f9a82
0951f6e
18cb0b0
b4d4a2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,12 +41,14 @@ | |
| Vector2, | ||
| Vector3, | ||
| Vector4, | ||
| VectorKeyframeTrack | ||
| VectorKeyframeTrack, | ||
| MeshStandardMaterial | ||
| } from 'three'; | ||
|
|
||
| import * as fflate from '../libs/fflate.module.js'; | ||
| import { NURBSCurve } from '../curves/NURBSCurve.js'; | ||
|
|
||
|
|
||
| let fbxTree; | ||
| let connections; | ||
| let sceneGraph; | ||
|
|
@@ -168,11 +170,9 @@ | |
|
|
||
| } | ||
|
|
||
| // console.log( fbxTree ); | ||
|
|
||
| const textureLoader = new TextureLoader( this.manager ).setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin ); | ||
|
|
||
| return new FBXTreeParser( textureLoader, this.manager ).parse( fbxTree ); | ||
| return new FBXTreeParser( textureLoader, this.manager ).parse(); // Parse the fbxTree | ||
|
|
||
| } | ||
|
|
||
|
|
@@ -259,7 +259,6 @@ | |
|
|
||
| const images = {}; | ||
| const blobs = {}; | ||
|
|
||
| if ( 'Video' in fbxTree.Objects ) { | ||
|
|
||
| const videoNodes = fbxTree.Objects.Video; | ||
|
|
@@ -297,8 +296,7 @@ | |
| const filename = images[ id ]; | ||
|
|
||
| if ( blobs[ filename ] !== undefined ) images[ id ] = blobs[ filename ]; | ||
| else images[ id ] = images[ id ].split( '\\' ).pop(); | ||
|
|
||
| else images[ id ] = images[ id ].replace(/^.*[\\/]|[?#].*$/g, ''); // Split on / or ?# as well as \ | ||
| } | ||
|
|
||
| return images; | ||
|
|
@@ -514,7 +512,6 @@ | |
| // Materials are connected to texture maps in FBXTree.Objects.Textures | ||
| // FBX format currently only supports Lambert and Phong shading models | ||
| parseMaterial( materialNode, textureMap ) { | ||
|
|
||
| const ID = materialNode.id; | ||
| const name = materialNode.attrName; | ||
| let type = materialNode.ShadingModel; | ||
|
|
@@ -541,6 +538,9 @@ | |
| case 'lambert': | ||
| material = new MeshLambertMaterial(); | ||
| break; | ||
| case 'openpbrsurface': | ||
| material = new MeshStandardMaterial(); | ||
| break; | ||
| default: | ||
| console.warn( 'THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.', type ); | ||
| material = new MeshPhongMaterial(); | ||
|
|
@@ -561,15 +561,12 @@ | |
|
|
||
| const parameters = {}; | ||
|
|
||
| if ( materialNode.BumpFactor ) { | ||
|
|
||
| parameters.bumpScale = materialNode.BumpFactor.value; | ||
|
|
||
| if ( materialNode.BumpFactor || materialNode['Maya|normalCameraFactor']) { | ||
| parameters.bumpScale = materialNode.BumpFactor?.value ?? materialNode['Maya|normalCameraFactor'].value; | ||
| } | ||
|
|
||
| if ( materialNode.Diffuse ) { | ||
|
|
||
| parameters.color = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.Diffuse.value ), SRGBColorSpace ); | ||
| if ( materialNode.Diffuse || materialNode['Maya|baseColor'] ) { | ||
| parameters.color = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.Diffuse?.value || materialNode['Maya|baseColor'].value ), SRGBColorSpace ); | ||
|
|
||
| } else if ( materialNode.DiffuseColor && ( materialNode.DiffuseColor.type === 'Color' || materialNode.DiffuseColor.type === 'ColorRGB' ) ) { | ||
|
|
||
|
|
@@ -584,45 +581,48 @@ | |
|
|
||
| } | ||
|
|
||
| if ( materialNode.Emissive ) { | ||
| if ( materialNode.Emissive || materialNode['Maya|emissionColor'] ) { | ||
|
|
||
| parameters.emissive = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.Emissive.value ), SRGBColorSpace ); | ||
| parameters.emissive = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.Emissive?.value || materialNode['Maya|emissionColor'].value ), SRGBColorSpace ); | ||
|
|
||
| } else if ( materialNode.EmissiveColor && ( materialNode.EmissiveColor.type === 'Color' || materialNode.EmissiveColor.type === 'ColorRGB' ) ) { | ||
|
|
||
| // The blender exporter exports emissive color here instead of in materialNode.Emissive | ||
| parameters.emissive = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.EmissiveColor.value ), SRGBColorSpace ); | ||
|
|
||
| } | ||
|
|
||
| if ( materialNode.EmissiveFactor ) { | ||
|
|
||
| parameters.emissiveIntensity = parseFloat( materialNode.EmissiveFactor.value ); | ||
| } | ||
|
|
||
| if ( materialNode.EmissiveFactor || materialNode['Maya|emissionLuminance']) { | ||
|
|
||
| parameters.emissiveIntensity = parseFloat( materialNode.EmissiveFactor?.value ?? materialNode['Maya|emissionLuminance'].value ); | ||
| } | ||
|
|
||
| // the transparency handling is implemented based on Blender/Unity's approach: https://github.com/sobotka/blender-addons/blob/7d80f2f97161fc8e353a657b179b9aa1f8e5280b/io_scene_fbx/import_fbx.py#L1444-L1459 | ||
|
|
||
| parameters.opacity = 1 - ( materialNode.TransparencyFactor ? parseFloat( materialNode.TransparencyFactor.value ) : 0 ); | ||
| if(materialNode.TransparencyFactor){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if ( materialNode[ 'Maya|transmissionWeight' ] ) {
parameters.opacity = 1 - materialNode[ 'Maya|transmissionWeight' ].value;
}
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. I will look into that. |
||
| parameters.opacity = 1 - (materialNode.TransparencyFactor.value ? parseFloat( materialNode.TransparencyFactor.value ) : 0); | ||
|
|
||
| if ( parameters.opacity === 1 || parameters.opacity === 0 ) { | ||
| if ( parameters.opacity === 1 || parameters.opacity === 0 ) { | ||
|
|
||
| parameters.opacity = ( materialNode.Opacity ? parseFloat( materialNode.Opacity.value ) : null ); | ||
| parameters.opacity = ( materialNode.Opacity ? parseFloat( materialNode.Opacity.value ) : null ); | ||
|
|
||
| if ( parameters.opacity === null ) { | ||
| if ( parameters.opacity === null ) { | ||
|
|
||
| parameters.opacity = 1 - ( materialNode.TransparentColor ? parseFloat( materialNode.TransparentColor.value[ 0 ] ) : 0 ); | ||
| parameters.opacity = 1 - ( materialNode.TransparentColor ? parseFloat( materialNode.TransparentColor.value[ 0 ] ) : 0 ); | ||
|
|
||
| } | ||
| } | ||
|
|
||
| } | ||
| }else if(materialNode['Maya|transmissionWeight']){ | ||
| parameters.opacity = 1 - materialNode['Maya|transmissionWeight'].value; | ||
| } | ||
|
|
||
| if ( parameters.opacity < 1.0 ) { | ||
|
|
||
| parameters.transparent = true; | ||
|
|
||
| } | ||
|
|
||
| if ( materialNode.ReflectionFactor ) { | ||
|
|
||
| parameters.reflectivity = materialNode.ReflectionFactor.value; | ||
|
|
@@ -645,10 +645,14 @@ | |
| parameters.specular = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.SpecularColor.value ), SRGBColorSpace ); | ||
|
|
||
| } | ||
|
|
||
| if ( materialNode['Maya|baseMetalness'] ){ | ||
| parameters.metalness = materialNode['Maya|baseMetalness'].value; | ||
| } | ||
|
|
||
| const scope = this; | ||
| connections.get( ID ).children.forEach( function ( child ) { | ||
|
|
||
| const type = child.relationship; | ||
|
|
||
| switch ( type ) { | ||
|
|
@@ -660,7 +664,7 @@ | |
| case 'Maya|TEX_ao_map': | ||
| parameters.aoMap = scope.getTexture( textureMap, child.ID ); | ||
| break; | ||
|
|
||
| case 'DiffuseColor': | ||
| case 'Maya|TEX_color_map': | ||
| parameters.map = scope.getTexture( textureMap, child.ID ); | ||
|
|
@@ -669,7 +673,15 @@ | |
| parameters.map.colorSpace = SRGBColorSpace; | ||
|
|
||
| } | ||
| break; | ||
|
|
||
| case 'Maya|baseColor': | ||
| parameters.map = scope.getTexture( textureMap, child.ID ); | ||
| if ( parameters.map !== undefined ) { | ||
| parameters.color = ColorManagement.colorSpaceToWorking( new Color("white") ) // MATERIAL COLOR GETS SET TO BLACK BY MAYA WHEN A COLOR MAP IS APPLIED, SO SETTING IT TO WHITE TO RESOLVE THAT PROBLEM | ||
Check noticeCode scanning / CodeQL Semicolon insertion Note
Avoid automated semicolon insertion (94% of all statements in
the enclosing function Error loading related location Loading |
||
| parameters.map.colorSpace = SRGBColorSpace; | ||
|
|
||
| } | ||
| break; | ||
|
|
||
| case 'DisplacementColor': | ||
|
|
@@ -683,10 +695,18 @@ | |
| parameters.emissiveMap.colorSpace = SRGBColorSpace; | ||
|
|
||
| } | ||
| break; | ||
|
|
||
| case 'Maya|emissionColor': | ||
| parameters.emissiveMap = scope.getTexture( textureMap, child.ID ); | ||
| if ( parameters.emissiveMap !== undefined ) { | ||
| parameters.emissive = ColorManagement.colorSpaceToWorking( new Color("white") ) // MATERIAL COLOR GETS SET TO BLACK BY MAYA WHEN A COLOR MAP IS APPLIED, SO SETTING IT TO WHITE TO RESOLVE THAT PROBLEM | ||
Check noticeCode scanning / CodeQL Semicolon insertion Note
Avoid automated semicolon insertion (94% of all statements in
the enclosing function Error loading related location Loading
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your PR breaks the formatting and linter rules. Please make sure your editor properly supports ESLint so the file is correctly formatted when you save it.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you @Mugen87 for the feedback about the PR breaks and linter rules. Will look into that. |
||
| parameters.emissiveMap.colorSpace = SRGBColorSpace; | ||
| } | ||
| break; | ||
|
|
||
| case 'NormalMap': | ||
| case 'Maya|normalCamera': | ||
| case 'Maya|TEX_normal_map': | ||
| parameters.normalMap = scope.getTexture( textureMap, child.ID ); | ||
| break; | ||
|
|
@@ -744,7 +764,6 @@ | |
| id = connections.get( id ).children[ 0 ].ID; | ||
|
|
||
| } | ||
|
|
||
| return textureMap.get( id ); | ||
|
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding this change. I can see that my comment was a bit unclear as to why this is necassary. When I work in maya, forward slashes has to be used for paths. The loader did only account for backslashes, making the path invalid. The regex (shamefully admitting it being AI-generated) takes both and back and forward slash into account. I also noticed it that it would consider ? and #. Which at first seemed uncessary. But then I thought: "if one for some reason would like to read an image from a web-URL, then query parameters may be included... oh now that I think about it again. Maybe that part was unnecssary. Anyway forward slashes is still causing problems.