|
@@ -28,6 +28,8 @@
|
|
|
|
|
|
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
|
|
|
|
|
|
+ this.sRGBTextureEncoding = false;
|
|
|
+
|
|
|
};
|
|
|
|
|
|
Object.assign( THREE.FBXLoader.prototype, {
|
|
@@ -107,7 +109,7 @@
|
|
|
var connections = parseConnections( FBXTree );
|
|
|
var images = parseImages( FBXTree );
|
|
|
var textures = parseTextures( FBXTree, textureLoader, images, connections );
|
|
|
- var materials = parseMaterials( FBXTree, textures, connections );
|
|
|
+ var materials = parseMaterials( FBXTree, textures, connections, this.sRGBTextureEncoding );
|
|
|
var deformers = parseDeformers( FBXTree, connections );
|
|
|
var geometryMap = parseGeometries( FBXTree, connections, deformers );
|
|
|
var sceneGraph = parseScene( FBXTree, connections, deformers, geometryMap, materials );
|
|
@@ -388,7 +390,7 @@
|
|
|
}
|
|
|
|
|
|
// Parse nodes in FBXTree.Objects.Material
|
|
|
- function parseMaterials( FBXTree, textureMap, connections ) {
|
|
|
+ function parseMaterials( FBXTree, textureMap, connections, sRGBTextureEncoding ) {
|
|
|
|
|
|
var materialMap = new Map();
|
|
|
|
|
@@ -398,7 +400,7 @@
|
|
|
|
|
|
for ( var nodeID in materialNodes ) {
|
|
|
|
|
|
- var material = parseMaterial( FBXTree, materialNodes[ nodeID ], textureMap, connections );
|
|
|
+ var material = parseMaterial( FBXTree, materialNodes[ nodeID ], textureMap, connections, sRGBTextureEncoding );
|
|
|
|
|
|
if ( material !== null ) materialMap.set( parseInt( nodeID ), material );
|
|
|
|
|
@@ -413,7 +415,7 @@
|
|
|
// Parse single node in FBXTree.Objects.Material
|
|
|
// Materials are connected to texture maps in FBXTree.Objects.Textures
|
|
|
// FBX format currently only supports Lambert and Phong shading models
|
|
|
- function parseMaterial( FBXTree, materialNode, textureMap, connections ) {
|
|
|
+ function parseMaterial( FBXTree, materialNode, textureMap, connections, sRGBTextureEncoding ) {
|
|
|
|
|
|
var ID = materialNode.id;
|
|
|
var name = materialNode.attrName;
|
|
@@ -429,7 +431,7 @@
|
|
|
// Ignore unused materials which don't have any connections.
|
|
|
if ( ! connections.has( ID ) ) return null;
|
|
|
|
|
|
- var parameters = parseParameters( FBXTree, materialNode, textureMap, ID, connections );
|
|
|
+ var parameters = parseParameters( FBXTree, materialNode, textureMap, ID, connections, sRGBTextureEncoding );
|
|
|
|
|
|
var material;
|
|
|
|
|
@@ -457,7 +459,7 @@
|
|
|
|
|
|
// Parse FBX material and return parameters suitable for a three.js material
|
|
|
// Also parse the texture map and return any textures associated with the material
|
|
|
- function parseParameters( FBXTree, properties, textureMap, ID, connections ) {
|
|
|
+ function parseParameters( FBXTree, properties, textureMap, ID, connections, sRGBTextureEncoding ) {
|
|
|
|
|
|
var parameters = {};
|
|
|
|
|
@@ -538,7 +540,9 @@
|
|
|
break;
|
|
|
|
|
|
case 'DiffuseColor':
|
|
|
+
|
|
|
parameters.map = getTexture( FBXTree, textureMap, child.ID, connections );
|
|
|
+ if ( sRGBTextureEncoding ) parameters.map.encoding = THREE.sRGBEncoding;
|
|
|
break;
|
|
|
|
|
|
case 'DisplacementColor':
|
|
@@ -548,6 +552,7 @@
|
|
|
|
|
|
case 'EmissiveColor':
|
|
|
parameters.emissiveMap = getTexture( FBXTree, textureMap, child.ID, connections );
|
|
|
+ if ( sRGBTextureEncoding ) parameters.emissiveMap.encoding = THREE.sRGBEncoding;
|
|
|
break;
|
|
|
|
|
|
case 'NormalMap':
|
|
@@ -561,6 +566,7 @@
|
|
|
|
|
|
case 'SpecularColor':
|
|
|
parameters.specularMap = getTexture( FBXTree, textureMap, child.ID, connections );
|
|
|
+ if ( sRGBTextureEncoding ) parameters.specularMap.encoding = THREE.sRGBEncoding;
|
|
|
break;
|
|
|
|
|
|
case 'TransparentColor':
|