-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into Santarh-patch-1
- Loading branch information
Showing
42 changed files
with
713 additions
and
742 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
36 changes: 36 additions & 0 deletions
36
...UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.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,36 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace UniGLTF | ||
{ | ||
/// <summary> | ||
/// フォールバック目的で最低限なにかをエクスポートする。 | ||
/// | ||
/// メインカラーとメインテクスチャをエクスポートする。 | ||
/// </summary> | ||
public class UrpFallbackMaterialExporter | ||
{ | ||
public glTFMaterial ExportMaterial(Material src, ITextureExporter textureExporter) | ||
{ | ||
var dst = new glTFMaterial | ||
{ | ||
name = src.name, | ||
pbrMetallicRoughness = new glTFPbrMetallicRoughness(), | ||
}; | ||
|
||
dst.pbrMetallicRoughness.baseColorFactor = src.color.ToFloat4(ColorSpace.sRGB, ColorSpace.Linear); | ||
var index = textureExporter.RegisterExportingAsSRgb(src.mainTexture, false); | ||
if (index >= 0) | ||
{ | ||
dst.pbrMetallicRoughness.baseColorTexture = new glTFMaterialBaseColorTextureInfo | ||
{ | ||
index = index, | ||
texCoord = 0, | ||
}; | ||
GltfMaterialExportUtils.ExportTextureTransform(src.mainTextureOffset, src.mainTextureScale, dst.pbrMetallicRoughness.baseColorTexture); | ||
} | ||
|
||
return dst; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...TF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.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
79 changes: 79 additions & 0 deletions
79
...UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.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,79 @@ | ||
using System; | ||
using UniGLTF.UniUnlit; | ||
using UnityEngine; | ||
|
||
namespace UniGLTF | ||
{ | ||
public class UrpUniUnlitMaterialExporter | ||
{ | ||
public Shader Shader { get; set; } | ||
|
||
/// <summary> | ||
/// "UniGLTF/UniUnlit" シェーダのマテリアルをエクスポートする。 | ||
/// | ||
/// プロパティに互換性がある他のシェーダを指定することもできる。 | ||
/// </summary> | ||
public UrpUniUnlitMaterialExporter(Shader shader = null) | ||
{ | ||
Shader = shader != null ? shader : Shader.Find("UniGLTF/UniUnlit"); | ||
} | ||
|
||
public bool TryExportMaterial(Material src, ITextureExporter textureExporter, out glTFMaterial dst) | ||
{ | ||
try | ||
{ | ||
if (src == null) throw new ArgumentNullException(nameof(src)); | ||
if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); | ||
if (src.shader != Shader || Shader == null) throw new UniGLTFShaderNotMatchedInternalException(src.shader); | ||
|
||
dst = glTF_KHR_materials_unlit.CreateDefault(); | ||
dst.name = src.name; | ||
|
||
var context = new UniUnlitContext(src); | ||
|
||
dst.alphaMode = context.RenderMode switch | ||
{ | ||
UniUnlitRenderMode.Opaque => glTFBlendMode.OPAQUE.ToString(), | ||
UniUnlitRenderMode.Cutout => glTFBlendMode.MASK.ToString(), | ||
UniUnlitRenderMode.Transparent => glTFBlendMode.BLEND.ToString(), | ||
_ => throw new ArgumentOutOfRangeException(), | ||
}; | ||
dst.alphaCutoff = context.Cutoff; | ||
dst.doubleSided = context.CullMode != UniUnlitCullMode.Back; | ||
|
||
dst.pbrMetallicRoughness.baseColorFactor = context.MainColorSrgb | ||
.ToFloat4(ColorSpace.sRGB, ColorSpace.Linear); | ||
if (context.MainTexture != null) | ||
{ | ||
var needsAlpha = context.RenderMode != UniUnlitRenderMode.Opaque; | ||
var index = textureExporter.RegisterExportingAsSRgb(context.MainTexture, needsAlpha); | ||
if (index >= 0) | ||
{ | ||
dst.pbrMetallicRoughness.baseColorTexture = new glTFMaterialBaseColorTextureInfo | ||
{ | ||
index = index, | ||
texCoord = 0, | ||
}; | ||
GltfMaterialExportUtils.ExportTextureTransform( | ||
context.MainTextureOffset, | ||
context.MainTextureScale, | ||
dst.pbrMetallicRoughness.baseColorTexture); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
catch (UniGLTFShaderNotMatchedInternalException) | ||
{ | ||
dst = default; | ||
return false; | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogException(e); | ||
dst = default; | ||
return false; | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...TF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
...ts/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.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,50 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace UniGLTF | ||
{ | ||
public class UrpUnlitMaterialExporter | ||
{ | ||
public Shader Shader { get; set; } | ||
|
||
/// <summary> | ||
/// "Universal Render Pipeline/Unlit" シェーダのマテリアルをエクスポートする。 | ||
/// | ||
/// プロパティに互換性がある他のシェーダを指定することもできる。 | ||
/// </summary> | ||
public UrpUnlitMaterialExporter(Shader shader = null) | ||
{ | ||
Shader = shader != null ? shader : Shader.Find("Universal Render Pipeline/Unlit"); | ||
} | ||
|
||
public bool TryExportMaterial(Material src, ITextureExporter textureExporter, out glTFMaterial dst) | ||
{ | ||
try | ||
{ | ||
if (src == null) throw new ArgumentNullException(nameof(src)); | ||
if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); | ||
if (src.shader != Shader || Shader == null) throw new UniGLTFShaderNotMatchedInternalException(src.shader); | ||
|
||
dst = glTF_KHR_materials_unlit.CreateDefault(); | ||
dst.name = src.name; | ||
|
||
var context = new UrpUnlitContext(src); | ||
UrpLitMaterialExporter.ExportSurfaceSettings(context, dst, textureExporter); | ||
UrpLitMaterialExporter.ExportBaseColor(context, dst, textureExporter); | ||
|
||
return true; | ||
} | ||
catch (UniGLTFShaderNotMatchedInternalException) | ||
{ | ||
dst = default; | ||
return false; | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogException(e); | ||
dst = default; | ||
return false; | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...iGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.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
Oops, something went wrong.