Skip to content

Commit

Permalink
GLTF: Use updated spec for material extension
Browse files Browse the repository at this point in the history
This is now using the structure from
KhronosGroup/glTF#947 (comment),
though perhaps liable to change soon this is what's currently used by
Three.js.
  • Loading branch information
jamesgk committed Jul 3, 2017
1 parent 3f48540 commit b1366e5
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions code/glTFAssetWriter.inl
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,12 @@ namespace glTF {
namespace {
inline void WriteColorOrTex(Value& obj, TexProperty& prop, const char* propName, MemoryPoolAllocator<>& al)
{
if (prop.texture)
obj.AddMember(StringRef(propName), prop.texture->index, al);
else {
if (prop.texture) {
Value tex;
tex.SetObject();
tex.AddMember("index", prop.texture->index, al);
obj.AddMember(StringRef(propName), tex, al);
} else {
Value col;
obj.AddMember(StringRef(propName), MakeValue(col, prop.color, al), al);
}
Expand All @@ -229,24 +232,20 @@ namespace glTF {
Value v;
v.SetObject();
{
WriteColorOrTex(v, m.ambient, "ambient", w.mAl);
WriteColorOrTex(v, m.diffuse, "diffuse", w.mAl);
WriteColorOrTex(v, m.specular, "specular", w.mAl);
WriteColorOrTex(v, m.emission, "emission", w.mAl);
WriteColorOrTex(v, m.ambient, m.ambient.texture ? "ambientTexture" : "ambientFactor", w.mAl);
WriteColorOrTex(v, m.diffuse, m.diffuse.texture ? "diffuseTexture" : "diffuseFactor", w.mAl);
WriteColorOrTex(v, m.specular, m.specular.texture ? "specularTexture" : "specularFactor", w.mAl);
WriteColorOrTex(v, m.emission, m.emission.texture ? "emissionTexture" : "emissionFactor", w.mAl);

if (m.transparent)
v.AddMember("transparency", m.transparency, w.mAl);

v.AddMember("shininess", m.shininess, w.mAl);
v.AddMember("shininessFactor", m.shininess, w.mAl);
}

Value khr;
khr.SetObject();
khr.AddMember("technique", "PHONG", w.mAl);
khr.AddMember("values", v, w.mAl);
v.AddMember("type", "commonPhong", w.mAl);
Value ext;
ext.SetObject();
ext.AddMember("KHR_materials_common", khr, w.mAl);
ext.AddMember("KHR_materials_common", v, w.mAl);
obj.AddMember("extensions", ext, w.mAl);
}

Expand Down

0 comments on commit b1366e5

Please sign in to comment.