Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix glTFPbrMetallicRoughness init. #403

Merged
merged 1 commit into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ public void MaterialTest()
};

var json = model.ToJson();
Assert.AreEqual(@"{""name"":""a"",""emissiveFactor"":[0.5,0.5,0.5],""doubleSided"":false}", json);
Assert.AreEqual(@"{""name"":""a"",""pbrMetallicRoughness"":{""baseColorFactor"":[1,1,1,1],""metallicFactor"":1,""roughnessFactor"":1},""emissiveFactor"":[0.5,0.5,0.5],""doubleSided"":false}", json);
Debug.Log(json);

var c = new JsonSchemaValidationContext("")
{
EnableDiagnosisForNotRequiredFields = true,
};
var json2 = JsonSchema.FromType<glTFMaterial>().Serialize(model, c);
Assert.AreEqual(@"{""name"":""a"",""emissiveFactor"":[0.5,0.5,0.5],""doubleSided"":false}", json2);
Assert.AreEqual(@"{""name"":""a"",""pbrMetallicRoughness"":{""baseColorFactor"":[1,1,1,1],""metallicFactor"":1,""roughnessFactor"":1},""emissiveFactor"":[0.5,0.5,0.5],""doubleSided"":false}", json2);
}

[Test]
Expand All @@ -297,7 +297,7 @@ public void MaterialAlphaTest()
EnableDiagnosisForNotRequiredFields = true,
};
var json = JsonSchema.FromType<glTFMaterial>().Serialize(model, c);
Assert.AreEqual(@"{""name"":""a"",""emissiveFactor"":[0.5,0.5,0.5],""alphaMode"":""MASK"",""alphaCutoff"":0.5,""doubleSided"":false}", json);
Assert.AreEqual(@"{""name"":""a"",""pbrMetallicRoughness"":{""baseColorFactor"":[1,1,1,1],""metallicFactor"":1,""roughnessFactor"":1},""emissiveFactor"":[0.5,0.5,0.5],""alphaMode"":""MASK"",""alphaCutoff"":0.5,""doubleSided"":false}", json);
}

[Test]
Expand Down
9 changes: 6 additions & 3 deletions Assets/VRM/UniGLTF/Scripts/Format/glTFMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ protected override void SerializeMembers(GLTFJsonFormatter f)
public class glTFMaterial : JsonSerializableBase
{
public string name;
public glTFPbrMetallicRoughness pbrMetallicRoughness;
public glTFPbrMetallicRoughness pbrMetallicRoughness = new glTFPbrMetallicRoughness
{
baseColorFactor = new float[] { 1.0f, 1.0f, 1.0f, 1.0f },
};
public glTFMaterialNormalTextureInfo normalTexture = null;

public glTFMaterialOcclusionTextureInfo occlusionTexture = null;
Expand Down Expand Up @@ -214,8 +217,8 @@ public glTFTextureInfo[] GetTextures()
{
return new glTFTextureInfo[]
{
pbrMetallicRoughness.baseColorTexture,
pbrMetallicRoughness.metallicRoughnessTexture,
(pbrMetallicRoughness != null)?pbrMetallicRoughness.baseColorTexture:null,
(pbrMetallicRoughness != null)?pbrMetallicRoughness.metallicRoughnessTexture:null,
normalTexture,
occlusionTexture,
emissiveTexture
Expand Down