mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-13 22:09:53 -05:00
153 lines
4.0 KiB
C#
153 lines
4.0 KiB
C#
using System;
|
|
using UniJSON;
|
|
|
|
namespace UniGLTF
|
|
{
|
|
public enum glTFTextureTypes
|
|
{
|
|
BaseColor,
|
|
Metallic,
|
|
Normal,
|
|
Occlusion,
|
|
Emissive,
|
|
Unknown
|
|
}
|
|
|
|
public interface IglTFTextureinfo
|
|
{
|
|
glTFTextureTypes TextureType { get; }
|
|
}
|
|
|
|
[Serializable]
|
|
public abstract class glTFTextureInfo : IglTFTextureinfo
|
|
{
|
|
[JsonSchema(Required = true, Minimum = 0)]
|
|
public int index = -1;
|
|
|
|
[JsonSchema(Minimum = 0)]
|
|
public int texCoord;
|
|
|
|
// empty schemas
|
|
public object extensions;
|
|
public object extras;
|
|
|
|
public abstract glTFTextureTypes TextureType { get; }
|
|
}
|
|
|
|
|
|
[Serializable]
|
|
public class glTFMaterialBaseColorTextureInfo : glTFTextureInfo
|
|
{
|
|
public override glTFTextureTypes TextureType
|
|
{
|
|
get { return glTFTextureTypes.BaseColor; }
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class glTFMaterialMetallicRoughnessTextureInfo : glTFTextureInfo
|
|
{
|
|
public override glTFTextureTypes TextureType
|
|
{
|
|
get { return glTFTextureTypes.Metallic; }
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class glTFMaterialNormalTextureInfo : glTFTextureInfo
|
|
{
|
|
public float scale = 1.0f;
|
|
|
|
public override glTFTextureTypes TextureType
|
|
{
|
|
get { return glTFTextureTypes.Normal; }
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class glTFMaterialOcclusionTextureInfo : glTFTextureInfo
|
|
{
|
|
[JsonSchema(Minimum = 0.0, Maximum = 1.0)]
|
|
public float strength = 1.0f;
|
|
|
|
public override glTFTextureTypes TextureType
|
|
{
|
|
get { return glTFTextureTypes.Occlusion; }
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class glTFMaterialEmissiveTextureInfo : glTFTextureInfo
|
|
{
|
|
public override glTFTextureTypes TextureType
|
|
{
|
|
get { return glTFTextureTypes.Emissive; }
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class glTFPbrMetallicRoughness
|
|
{
|
|
public glTFMaterialBaseColorTextureInfo baseColorTexture = null;
|
|
|
|
[JsonSchema(MinItems = 4, MaxItems = 4)]
|
|
[ItemJsonSchema(Minimum = 0.0, Maximum = 1.0)]
|
|
public float[] baseColorFactor;
|
|
|
|
public glTFMaterialMetallicRoughnessTextureInfo metallicRoughnessTexture = null;
|
|
|
|
[JsonSchema(Minimum = 0.0, Maximum = 1.0)]
|
|
public float metallicFactor = 1.0f;
|
|
|
|
[JsonSchema(Minimum = 0.0, Maximum = 1.0)]
|
|
public float roughnessFactor = 1.0f;
|
|
|
|
// empty schemas
|
|
public object extensions;
|
|
public object extras;
|
|
}
|
|
|
|
[Serializable]
|
|
public class glTFMaterial
|
|
{
|
|
public string name;
|
|
public glTFPbrMetallicRoughness pbrMetallicRoughness = new glTFPbrMetallicRoughness
|
|
{
|
|
baseColorFactor = new float[] { 1.0f, 1.0f, 1.0f, 1.0f },
|
|
};
|
|
public glTFMaterialNormalTextureInfo normalTexture = null;
|
|
|
|
public glTFMaterialOcclusionTextureInfo occlusionTexture = null;
|
|
|
|
public glTFMaterialEmissiveTextureInfo emissiveTexture = null;
|
|
|
|
[JsonSchema(MinItems = 3, MaxItems = 3)]
|
|
[ItemJsonSchema(Minimum = 0.0, Maximum = 1.0)]
|
|
public float[] emissiveFactor;
|
|
|
|
[JsonSchema(EnumValues = new object[] { "OPAQUE", "MASK", "BLEND" }, EnumSerializationType = EnumSerializationType.AsUpperString)]
|
|
public string alphaMode;
|
|
|
|
[JsonSchema(Dependencies = new string[] { "alphaMode" }, Minimum = 0.0)]
|
|
public float alphaCutoff = 0.5f;
|
|
|
|
public bool doubleSided;
|
|
|
|
[JsonSchema(SkipSchemaComparison = true)]
|
|
public object extensions;
|
|
public object extras;
|
|
|
|
public glTFTextureInfo[] GetTextures()
|
|
{
|
|
return new glTFTextureInfo[]
|
|
{
|
|
(pbrMetallicRoughness != null)?pbrMetallicRoughness.baseColorTexture:null,
|
|
(pbrMetallicRoughness != null)?pbrMetallicRoughness.metallicRoughnessTexture:null,
|
|
normalTexture,
|
|
occlusionTexture,
|
|
emissiveTexture
|
|
};
|
|
}
|
|
}
|
|
}
|