-
Notifications
You must be signed in to change notification settings - Fork 437
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
VRM1.0 MToon の Texture をすべて Import できる #934
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
14151cb
Rename
Santarh db33697
Separate Vrm10 Texture Enumerator
Santarh 877d611
GetTextureOffsetAndScale can get from transform ext object.
Santarh c082bb0
Remove unused definition.
Santarh e872884
Define Vrm10MToon Texture importer
Santarh 65973e2
Can import TextureImportTypes.Linear.
Santarh c6a0540
Import all of VRM10 MToon textures.
Santarh a7ac5cc
revert
Santarh 4bdfd3e
Add comment.
Santarh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
153 changes: 153 additions & 0 deletions
153
Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.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,153 @@ | ||
using System; | ||
using UniGLTF; | ||
using UniGLTF.Extensions.VRMC_materials_mtoon; | ||
using UnityEngine; | ||
using VRMShaders; | ||
|
||
namespace UniVRM10 | ||
{ | ||
public static class Vrm10MToonMaterialImporter | ||
{ | ||
public static bool TryGetBaseColorTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair) | ||
{ | ||
try | ||
{ | ||
pair = GltfPBRMaterial.BaseColorTexture(parser, src); | ||
return true; | ||
} | ||
catch (NullReferenceException) | ||
{ | ||
pair = default; | ||
return false; | ||
} | ||
catch (ArgumentOutOfRangeException) | ||
{ | ||
pair = default; | ||
return false; | ||
} | ||
} | ||
|
||
public static bool TryGetNormalTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair) | ||
{ | ||
try | ||
{ | ||
pair = GltfPBRMaterial.NormalTexture(parser, src); | ||
return true; | ||
} | ||
catch (NullReferenceException) | ||
{ | ||
pair = default; | ||
return false; | ||
} | ||
catch (ArgumentOutOfRangeException) | ||
{ | ||
pair = default; | ||
return false; | ||
} | ||
} | ||
|
||
public static bool TryGetShadeMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair) | ||
{ | ||
return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.ShadeMultiplyTexture), out pair); | ||
} | ||
|
||
public static bool TryGetShadingShiftTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair) | ||
{ | ||
return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.ShadingShiftTexture), out pair); | ||
} | ||
|
||
public static bool TryGetMatcapTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair) | ||
{ | ||
return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.ShadingShiftTexture), out pair); | ||
} | ||
|
||
public static bool TryGetRimMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair) | ||
{ | ||
return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.RimMultiplyTexture), out pair); | ||
} | ||
|
||
public static bool TryGetOutlineWidthMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair) | ||
{ | ||
return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.OutlineWidthMultiplyTexture), out pair); | ||
} | ||
|
||
public static bool TryGetUvAnimationMaskTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair) | ||
{ | ||
return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.UvAnimationMaskTexture), out pair); | ||
} | ||
|
||
private static bool TryGetSRGBTexture(GltfParser parser, Vrm10TextureInfo info, out (SubAssetKey, TextureImportParam) pair) | ||
{ | ||
try | ||
{ | ||
var (offset, scale) = GetTextureOffsetAndScale(info); | ||
pair = GltfTextureImporter.CreateSRGB(parser, info.index, offset, scale); | ||
return true; | ||
} | ||
catch (NullReferenceException) | ||
{ | ||
pair = default; | ||
return false; | ||
} | ||
catch (ArgumentOutOfRangeException) | ||
{ | ||
pair = default; | ||
return false; | ||
} | ||
} | ||
private static bool TryGetLinearTexture(GltfParser parser, Vrm10TextureInfo info, out (SubAssetKey, TextureImportParam) pair) | ||
{ | ||
try | ||
{ | ||
var (offset, scale) = GetTextureOffsetAndScale(info); | ||
pair = GltfTextureImporter.CreateLinear(parser, info.index, offset, scale); | ||
return true; | ||
} | ||
catch (NullReferenceException) | ||
{ | ||
pair = default; | ||
return false; | ||
} | ||
catch (ArgumentOutOfRangeException) | ||
{ | ||
pair = default; | ||
return false; | ||
} | ||
} | ||
|
||
private static (Vector2, Vector2) GetTextureOffsetAndScale(Vrm10TextureInfo textureInfo) | ||
{ | ||
if (glTF_KHR_texture_transform.TryGet(textureInfo, out var textureTransform)) | ||
{ | ||
return GltfMaterialImporter.GetTextureOffsetAndScale(textureTransform); | ||
} | ||
return (new Vector2(0, 0), new Vector2(1, 1)); | ||
} | ||
|
||
/// <summary> | ||
/// MToon 定義内の TextureInfo を glTFTextureInfo として扱う入れ物 | ||
/// </summary> | ||
private sealed class Vrm10TextureInfo : glTFTextureInfo | ||
{ | ||
public Vrm10TextureInfo(TextureInfo info) | ||
{ | ||
if (info == null) return; | ||
|
||
index = info.Index ?? -1; | ||
texCoord = info.TexCoord ?? -1; | ||
extensions = info.Extensions as glTFExtension; | ||
extras = info.Extras as glTFExtension; | ||
} | ||
|
||
public Vrm10TextureInfo(ShadingShiftTextureInfo info) | ||
{ | ||
if (info == null) return; | ||
|
||
index = info.Index ?? -1; | ||
texCoord = info.TexCoord ?? -1; | ||
extensions = info.Extensions as glTFExtension; | ||
extras = info.Extras as glTFExtension; | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glTF の Linear は、metallic_roughness_occlusion もしくは normal として扱うので無かった。