Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

don't bring in emissive properties with FBX as they can create issues with how they are set

Scott Petrovic782212d26b4e
diff --git a/src/lib/io/fbx/FBXTreeParser.ts b/src/lib/io/fbx/FBXTreeParser.ts
index 03c0bf1..cdcd2ba 100644
--- a/src/lib/io/fbx/FBXTreeParser.ts
+++ b/src/lib/io/fbx/FBXTreeParser.ts
@@ -446,20 +446,17 @@ class FBXTreeParser {
}
- if (materialNode.Emissive) {
-
- parameters.emissive = ColorManagement.colorSpaceToWorking(new Color().fromArray(materialNode.Emissive.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);
+ // Emissive is deliberately not read from the FBX (Emissive / EmissiveColor /
+ // EmissiveFactor). FBX files very often carry an emissive color that was
+ // never meant to light anything up, and it cannot survive a round trip:
+ // the viewport dims it by EmissiveFactor, but a GLB export writes the color
+ // into emissiveFactor and only keeps the intensity for standard (PBR)
+ // materials - FBX loads as Phong, so the intensity is dropped and the
+ // exported model glows far brighter than it did on screen. Leaving these
+ // parameters unset keeps three's default of a black (no glow) emissive.
+ if (materialNode.Emissive || materialNode.EmissiveColor || materialNode.EmissiveFactor) {
+
+ console.warn('THREE.FBXLoader: ignoring the emissive settings on material "%s". Emissive from an FBX cannot be exported correctly, so it is treated as no glow.', materialNode.attrName);
}
@@ -543,12 +540,14 @@ class FBXTreeParser {
break;
case 'EmissiveColor':
- parameters.emissiveMap = scope.getTexture(textureMap, child.ID);
- if (parameters.emissiveMap !== undefined) {
-
- parameters.emissiveMap.colorSpace = SRGBColorSpace;
-
- }
+ // skipped along with the emissive color above - an emissive map
+ // with no emissive color to tint it does nothing except add an
+ // unused texture to whatever the model is exported to
+
+ // parameters.emissiveMap = scope.getTexture(textureMap, child.ID);
+ // if (parameters.emissiveMap !== undefined) {
+ // parameters.emissiveMap.colorSpace = SRGBColorSpace;
+ // }
break;
diff --git a/src/lib/processes/load-model/ModelAnalysisReport.test.ts b/src/lib/processes/load-model/ModelAnalysisReport.test.ts
index 812c508..6bef1cf 100644
--- a/src/lib/processes/load-model/ModelAnalysisReport.test.ts
+++ b/src/lib/processes/load-model/ModelAnalysisReport.test.ts
@@ -134,63 +134,33 @@ describe('ModelAnalysisReport.snapshot_scene', () => {
expect(analyzed.materials[0].texture_slots).toEqual([])
})
- it('flags an emissive material, which is what makes a GLB export glow', () => {
+ it('records the emissive values that decide whether an export glows', () => {
const scene = new Scene()
const mesh = make_mesh('lamp')
const material = mesh.material as MeshStandardMaterial
- material.name = 'lamp_mat'
material.emissive.set(0xffffff)
- material.emissiveIntensity = 1
+ material.emissiveIntensity = 0.1
scene.add(mesh)
const analyzed = ModelAnalysisReport.snapshot_scene(scene).objects[0]
+ // intensity is deliberately not folded into the strength - an export writes
+ // the color on its own, which is what makes a dim looking model glow later
expect(analyzed.materials[0].emissive_hex).toBe('#ffffff')
+ expect(analyzed.materials[0].emissive_intensity).toBeCloseTo(0.1)
expect(analyzed.materials[0].emissive_strength).toBeCloseTo(1)
- expect(analyzed.warnings.some((entry) => entry.includes('emissive (glow) color'))).toBe(true)
- })
-
- it('does not flag a material whose emissive color is black', () => {
- const scene = new Scene()
- const mesh = make_mesh('body')
- const material = mesh.material as MeshStandardMaterial
- material.emissive.set(0x000000)
- scene.add(mesh)
-
- const analyzed = ModelAnalysisReport.snapshot_scene(scene).objects[0]
-
- expect(analyzed.materials[0].emissive_strength).toBe(0)
- expect(analyzed.warnings).toEqual([])
+ expect(analyzed.materials[0].exports_emissive_intensity).toBe(true)
})
- it('flags a phong material whose emissive intensity is dropped on export', () => {
+ it('knows a phong material cannot carry emissive intensity through an export', () => {
const scene = new Scene()
const mesh = new Mesh(new BoxGeometry(1, 1, 1), new MeshPhongMaterial())
mesh.name = 'lamp'
- const material = mesh.material as MeshPhongMaterial
- material.emissive.set(0xffffff)
- // a dim glow on screen here, but a GLB export keeps the color and loses this
- material.emissiveIntensity = 0.1
scene.add(mesh)
const analyzed = ModelAnalysisReport.snapshot_scene(scene).objects[0]
expect(analyzed.materials[0].exports_emissive_intensity).toBe(false)
- expect(analyzed.warnings.some((entry) => entry.includes('drops the intensity'))).toBe(true)
- })
-
- it('does not flag dropped intensity on a standard material, which can export it', () => {
- const scene = new Scene()
- const mesh = make_mesh('lamp')
- const material = mesh.material as MeshStandardMaterial
- material.emissive.set(0xffffff)
- material.emissiveIntensity = 0.1
- scene.add(mesh)
-
- const analyzed = ModelAnalysisReport.snapshot_scene(scene).objects[0]
-
- expect(analyzed.materials[0].exports_emissive_intensity).toBe(true)
- expect(analyzed.warnings.some((entry) => entry.includes('drops the intensity'))).toBe(false)
})
it('does not flag a mesh that is already baked at the origin', () => {
@@ -215,9 +185,32 @@ describe('ModelAnalysisReport.build_html', () => {
expect(html).not.toContain('<img src=x')
expect(html).toContain('&lt;img src=x')
})
+
+ it('warns about a glow that is still there after import', () => {
+ const scene = new Scene()
+ const mesh = make_mesh('lamp')
+ const material = mesh.material as MeshStandardMaterial
+ material.name = 'lamp_mat'
+ material.emissive.set(0xffffff)
+ scene.add(mesh)
+ const snapshot: SceneSnapshot = ModelAnalysisReport.snapshot_scene(scene)
+
+ const html: string = ModalAnalysisHtml(snapshot)
+
+ expect(html).toContain('emissive (glow) color')
+ expect(html).toContain('lamp_mat')
+ })
+
+ it('does not warn about a material with no glow', () => {
+ const scene = new Scene()
+ scene.add(make_mesh('body'))
+ const snapshot: SceneSnapshot = ModelAnalysisReport.snapshot_scene(scene)
+
+ expect(ModalAnalysisHtml(snapshot)).not.toContain('emissive (glow) color')
+ })
})
-/** Small helper so the escaping test reads clearly. */
+/** Small helper so the html tests read clearly. */
function ModalAnalysisHtml (snapshot: SceneSnapshot): string {
return ModelAnalysisReport.build_html({
source_name: 'test.glb',
diff --git a/src/lib/processes/load-model/ModelAnalysisReport.ts b/src/lib/processes/load-model/ModelAnalysisReport.ts
index d59c458..1900696 100644
--- a/src/lib/processes/load-model/ModelAnalysisReport.ts
+++ b/src/lib/processes/load-model/ModelAnalysisReport.ts
@@ -361,10 +361,9 @@ export class ModelAnalysisReport {
}
/**
- * Material problems that carry through to the export. Emissive is the one that
- * bites most often: FBX files frequently set an emissive color without meaning
- * to, and the GLB export writes that color into emissiveFactor, so the model
- * comes out glowing even though it looked fine in the tool that authored it.
+ * Material problems that follow the model out to an export. The FBX loader
+ * already drops emissive on the way in, since it cannot round trip, so what is
+ * left here is a glow that a GLB or GLTF file asked for on purpose.
*/
private static collect_material_warnings (material: MaterialInfo): string[] {
const warnings: string[] = []
@@ -374,13 +373,13 @@ export class ModelAnalysisReport {
return warnings
}
- warnings.push(`${label} has an emissive (glow) color of ${material.emissive_hex ?? '-'}. GLB export writes that color out as emissiveFactor, so the model glows regardless of lighting. Emissive should usually be black (#000000) unless the part is meant to light up.`)
+ warnings.push(`${label} has an emissive (glow) color of ${material.emissive_hex ?? '-'}. A GLB export writes that color into emissiveFactor, so the model glows no matter how it is lit. Emissive should usually be black (#000000) unless the part is meant to light up.`)
// the case that catches people out: the viewport dims the glow by the
- // intensity, the export does not, so the GLB comes back brighter than what
- // was on screen here. FBX materials load as Phong, which is exactly this case
+ // intensity, the export does not, so the exported model comes back brighter
+ // than what was on screen here
if (!material.exports_emissive_intensity && Math.abs(material.emissive_intensity - 1) > this.EMISSIVE_EPSILON) {
- warnings.push(`${label} dims its glow with an emissive intensity of ${this.format_number(material.emissive_intensity)}, but only standard (PBR) materials can store intensity in a GLB. This one is a ${material.type}, so the export keeps the full emissive color and drops the intensity - the exported model will glow more than it does here.`)
+ warnings.push(`${label} dims that glow with an emissive intensity of ${this.format_number(material.emissive_intensity)}, but only standard (PBR) materials can store intensity in a GLB. This one is a ${material.type}, so the export keeps the full emissive color and drops the intensity - the exported model will glow more than it does here.`)
}
return warnings