CesiumGS/obj2gltf

load .obj mtl material data

HappyKuTou opened this issue · 2 comments

Describe the issue

I have to convert obj to gltf by c++
data in obj mtl file is not pbr data
how can I fill the tinygltf material struct after load obj mtl file

To Reproduce

  • OS win10
  • Compiler vs2019

Expected behaviour

I need to write mtl data in tinygltf material struct

Screenshots
this is tinygltf material struct
image

this is obj mtl file
image

@HappyKuTou this area of the code is how obj2gltf converts .mtl to glTF PBR materials:

obj2gltf/lib/loadMtl.js

Lines 733 to 755 in 79848fe

function convertTraditionalToMetallicRoughness(material) {
// Translate the blinn-phong model to the pbr metallic-roughness model
// Roughness factor is a combination of specular intensity and shininess
// Metallic factor is 0.0
// Textures are not converted for now
const specularIntensity = luminance(material.specularColor);
// Transform from 0-1000 range to 0-1 range. Then invert.
let roughnessFactor = material.specularShininess;
roughnessFactor = roughnessFactor / 1000.0;
roughnessFactor = 1.0 - roughnessFactor;
roughnessFactor = CesiumMath.clamp(roughnessFactor, 0.0, 1.0);
// Low specular intensity values should produce a rough material even if shininess is high.
if (specularIntensity < 0.1) {
roughnessFactor *= (1.0 - specularIntensity);
}
const metallicFactor = 0.0;
material.specularColor = [metallicFactor, metallicFactor, metallicFactor, 1.0];
material.specularShininess = roughnessFactor;
}

Ultimately there's not a perfect conversion from the blinn/phong model to metallic-roughness so we approximated it as best we could. Hopefully this is enough to get started with your converter. I'm going to close the issue since there's no action here for obj2gltf.