-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add KHR_materials_specular, clean up
- Loading branch information
1 parent
39f7f34
commit 47a8673
Showing
11 changed files
with
3,397 additions
and
694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...F/Assets/UnityGLTF/Runtime/Plugins/GLTFSerialization/Extensions/KHR_materials_specular.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using GLTF.Extensions; | ||
using Newtonsoft.Json.Linq; | ||
using Color = GLTF.Math.Color; | ||
|
||
namespace GLTF.Schema | ||
{ | ||
// https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_specular/README.md | ||
[Serializable] | ||
public class KHR_materials_specular : IExtension | ||
{ | ||
public float specularFactor = 1f; | ||
public TextureInfo specularTexture; // A channel | ||
public Color specularColorFactor = COLOR_DEFAULT; | ||
public TextureInfo specularColorTexture; // RGB channel | ||
|
||
public static readonly Color COLOR_DEFAULT = Color.White; | ||
|
||
public JProperty Serialize() | ||
{ | ||
var jo = new JObject(); | ||
JProperty jProperty = new JProperty(KHR_materials_specular_Factory.EXTENSION_NAME, jo); | ||
|
||
if (specularFactor != 1) jo.Add(new JProperty(nameof(specularFactor), specularFactor)); | ||
if (specularColorFactor != COLOR_DEFAULT) jo.Add(new JProperty(nameof(specularColorFactor), specularColorFactor)); | ||
if (specularTexture != null) { | ||
jo.Add(new JProperty(nameof(specularTexture), | ||
new JObject( | ||
new JProperty(TextureInfo.INDEX, specularTexture.Index.Id), | ||
new JProperty(TextureInfo.TEXCOORD, specularTexture.TexCoord) | ||
) | ||
) | ||
); | ||
} | ||
if (specularColorTexture != null) { | ||
jo.Add(new JProperty(nameof(specularColorTexture), | ||
new JObject( | ||
new JProperty(TextureInfo.INDEX, specularColorTexture.Index.Id), | ||
new JProperty(TextureInfo.TEXCOORD, specularColorTexture.TexCoord) | ||
) | ||
) | ||
); | ||
} | ||
return jProperty; | ||
} | ||
|
||
public IExtension Clone(GLTFRoot root) | ||
{ | ||
return new KHR_materials_specular() | ||
{ | ||
specularFactor = specularFactor, specularTexture = specularTexture, | ||
specularColorFactor = specularColorFactor, specularColorTexture = specularColorTexture, | ||
}; | ||
} | ||
} | ||
|
||
public class KHR_materials_specular_Factory : ExtensionFactory | ||
{ | ||
public const string EXTENSION_NAME = "KHR_materials_specular"; | ||
|
||
public KHR_materials_specular_Factory() | ||
{ | ||
ExtensionName = EXTENSION_NAME; | ||
} | ||
|
||
public override IExtension Deserialize(GLTFRoot root, JProperty extensionToken) | ||
{ | ||
if (extensionToken != null) | ||
{ | ||
var extension = new KHR_materials_specular(); | ||
extension.specularFactor = extensionToken.Value[nameof(KHR_materials_specular.specularFactor)]?.Value<float>() ?? 0; | ||
extension.specularColorFactor = extensionToken.Value[nameof(KHR_materials_specular.specularColorFactor)]?.DeserializeAsColor() ?? Color.White; | ||
extension.specularTexture = extensionToken.Value[nameof(KHR_materials_specular.specularTexture)]?.DeserializeAsTexture(root); | ||
extension.specularColorTexture = extensionToken.Value[nameof(KHR_materials_specular.specularColorTexture)]?.DeserializeAsTexture(root); | ||
return extension; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ets/UnityGLTF/Runtime/Plugins/GLTFSerialization/Extensions/KHR_materials_specular.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.