petrbroz / svf-utils

Utilities for working with the SVF file format used by Autodesk Platform Services.
https://petrbroz.github.io/svf-utils/
MIT License
131 stars 56 forks source link

Bad Texture Unit-scale, missing Transparency and Metal for Fusion360 Materials #51

Open wallabyway opened 2 years ago

wallabyway commented 2 years ago

prism-materials-wrong

Markers:

Right: Fusion(F3D) in LMV Left: LGLTracer with glTF

Source F3D: https://developer.api.autodesk.com/oss/v2/signedresources/8982cad5-0eda-4beb-96fb-6244062d21aa?region=US

wallabyway commented 2 years ago

Missing Metals

The metal issue is related to using the wrong materials json file.

The Materials.json.gz file maps the f0 base color into the specular value, but the metallic-roughness value is gone. The ProteinMaterials.json.gz file contains both the f0 base color of metals, as well as it's metallic roughness. The ProteinMaterials.json.gz has more information needed for glTF's PBR materials, than Materials.json.gz. You may want to switch over to that. Note: fixing metals will also fix this issue... https://github.com/petrbroz/forge-convert-utils/issues/23

Texture Scale

Looks like LGLTracer is missing support for KHR_texture_transform, causing the texture scale issue. Nothing to do with forge-convert-utils. https://github.com/LGL-Tracer-Renderer/LGL-Tracer-Renderer.github.io/issues/15

wallabyway commented 2 years ago

The fix:

divide glossiness by 20 and by 60, depending on isMetal, like so...

at line 126 in reader.ts

            roughness: _mat?.glossiness ? ( 20.0/ _mat.glossiness ) : 1.0, // TODO: how to map glossiness to roughness properly?
            scale: {x: _mat?.maps?.diffuse?.scale.texture_UScale ?? 1.0 , y: _mat?.maps?.diffuse?.scale.texture_VScale ?? 1.0}
        };
        if (_mat?.diffuse) {
            mat.diffuse.x = _mat.diffuse[0];
            mat.diffuse.y = _mat.diffuse[1];
            mat.diffuse.z = _mat.diffuse[2];
        }
        if (_mat?.metal && _mat.specular && _mat.glossiness) {
            mat.diffuse.x = _mat.specular[0];
            mat.diffuse.y = _mat.specular[1];
            mat.diffuse.z = _mat.specular[2];
            mat.roughness = 60/_mat.glossiness;
        }        

Reference (LMV)

Screen Shot 2022-02-17 at 7 22 16 PM

Results ( Three.js, Babylon.js, LGLTracer ):

Screen Shot 2022-02-17 at 7 20 02 PM

petrbroz commented 2 years ago

Thanks @wallabyway, I've just merged the PR. Next week we can test it out and publish a new version if everything looks correct.