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

MetallicRoughnessOcclusion テクスチャーの取り廻しを中心に改修 #780

Merged
merged 28 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
27f9a99
fix normal use original texture
ousttrue Mar 11, 2021
f35a51b
fix roughnessConversion
ousttrue Mar 11, 2021
d589f6b
OcclusionMetallicRoughnessConverter
ousttrue Mar 12, 2021
4413128
remove ITextureConverter.GetImportTexture
ousttrue Mar 12, 2021
3d85986
MetallicFactor and RoughnessFactor
ousttrue Mar 12, 2021
dba9460
not catch
ousttrue Mar 12, 2021
d2e560a
OcclusionMetallicRoughnessConverter.Convert
ousttrue Mar 12, 2021
fd12e0d
remove ITextureConverter. static class OcclusionMetallicRoughnessConv…
ousttrue Mar 12, 2021
07afd49
static class NormalConverter
ousttrue Mar 12, 2021
fd2650f
rename
ousttrue Mar 12, 2021
59d84cb
glTFTextureTypes, Export_PBR
ousttrue Mar 12, 2021
bb60768
TextureExportManager.GetTextureIndex
ousttrue Mar 12, 2021
da86ba4
UnitTest
ousttrue Mar 12, 2021
be204ad
WIP TextureExportManager
ousttrue Mar 15, 2021
a8dcec0
static class TextureIO
ousttrue Mar 15, 2021
755c907
rename
ousttrue Mar 15, 2021
f6aeef3
rename
ousttrue Mar 15, 2021
83ac944
rename
ousttrue Mar 15, 2021
18fd381
TextureImporterConfigurator
ousttrue Mar 15, 2021
6b3856a
fix PBRMaterialItem null check
ousttrue Mar 15, 2021
13e43bd
return -1
ousttrue Mar 15, 2021
558f651
fix normalMap extract
ousttrue Mar 15, 2021
b474ca3
NotVrm0Exception
ousttrue Mar 15, 2021
377d512
fix MToon export
ousttrue Mar 15, 2021
2c9bb63
impl
ousttrue Mar 15, 2021
1d38656
fix rebase
ousttrue Mar 17, 2021
6d211f2
test
ousttrue Mar 17, 2021
25b70b9
TextureExporter.ExportLinear place holder
ousttrue Mar 17, 2021
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
8 changes: 3 additions & 5 deletions Assets/UniGLTF/Editor/UniGLTF/AssetTextureLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ public static class AssetTextureLoader
public static Task<Texture2D> LoadTaskAsync(UnityPath m_assetPath,
glTF gltf, int textureIndex)
{
var textureType = TextureIO.GetglTFTextureType(gltf, textureIndex);
var colorSpace = TextureIO.GetColorSpace(textureType);
var isLinear = colorSpace == RenderTextureReadWrite.Linear;
var sampler = gltf.GetSamplerFromTextureIndex(textureIndex);
var colorSpace = gltf.GetColorSpace(textureIndex);

//
// texture from assets
Expand All @@ -25,7 +22,7 @@ public static Task<Texture2D> LoadTaskAsync(UnityPath m_assetPath,
else
{
importer.maxTextureSize = 8192;
importer.sRGBTexture = !isLinear;
importer.sRGBTexture = colorSpace == RenderTextureReadWrite.sRGB;
importer.SaveAndReimport();
}

Expand All @@ -50,6 +47,7 @@ public static Task<Texture2D> LoadTaskAsync(UnityPath m_assetPath,
importer.SaveAndReimport();
}

var sampler = gltf.GetSamplerFromTextureIndex(textureIndex);
if (sampler != null)
{
TextureSamplerUtil.SetSampler(Texture, sampler);
Expand Down
16 changes: 13 additions & 3 deletions Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public void Dispose()
}
}

static bool s_foldMaterials;
static bool s_foldTextures;
static bool s_foldMaterials = true;
static bool s_foldTextures = true;

public static void OnGUIMaterial(ScriptedImporter importer, GltfParser parser)
{
Expand All @@ -51,7 +51,17 @@ public static void OnGUIMaterial(ScriptedImporter importer, GltfParser parser)
s_foldTextures = EditorGUILayout.Foldout(s_foldTextures, "Remapped Textures");
if (s_foldTextures)
{
DrawRemapGUI<UnityEngine.Texture2D>(importer, GltfTextureEnumerator.Enumerate(parser.GLTF).Select(x => x.ConvertedName));
DrawRemapGUI<UnityEngine.Texture2D>(importer, GltfTextureEnumerator.Enumerate(parser.GLTF).Select(x =>
{
switch (x.TextureType)
{
case GetTextureParam.TextureTypes.NormalMap:
return x.GltflName;

default:
return x.ConvertedName;
}
}));
}

if (GUILayout.Button("Clear"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ public class GlbScriptedImporter : ScriptedImporter

public override void OnImportAsset(AssetImportContext ctx)
{
try
{
ScriptedImporterImpl.Import(this, ctx, m_reverseAxis);
}
catch (System.Exception ex)
{
Debug.LogError(ex);
}
ScriptedImporterImpl.Import(this, ctx, m_reverseAxis);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ public class GltfScriptedImporter : ScriptedImporter

public override void OnImportAsset(AssetImportContext ctx)
{
try
{
ScriptedImporterImpl.Import(this, ctx, m_reverseAxis);
}
catch (System.Exception ex)
{
Debug.LogError(ex);
}
ScriptedImporterImpl.Import(this, ctx, m_reverseAxis);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
Expand Down Expand Up @@ -35,6 +36,12 @@ public static void Import(ScriptedImporter scriptedImporter, AssetImportContext
externalObjectMap.Where(x => x.Value != null).Select(x => (x.Value.name, x.Value)).Concat(
EnumerateTexturesFromUri(externalObjectMap, parser, UnityPath.FromUnityPath(scriptedImporter.assetPath).Parent))))
{
// settings TextureImporters
foreach (var textureInfo in GltfTextureEnumerator.Enumerate(parser.GLTF))
{
TextureImporterConfigurator.Configure(textureInfo, loaded.TextureFactory.ExternalMap);
}

loaded.InvertAxis = reverseAxis;
loaded.Load();
loaded.ShowMeshes();
Expand Down Expand Up @@ -64,8 +71,7 @@ public static void Import(ScriptedImporter scriptedImporter, AssetImportContext
{
switch (texParam.TextureType)
{
case GetTextureParam.METALLIC_GLOSS_PROP:
case GetTextureParam.OCCLUSION_PROP:
case GetTextureParam.TextureTypes.StandardMap:
break;

default:
Expand Down
34 changes: 3 additions & 31 deletions Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public void Extract(GetTextureParam param, bool hasUri)

switch (param.TextureType)
{
case GetTextureParam.METALLIC_GLOSS_PROP:
case GetTextureParam.OCCLUSION_PROP:
case GetTextureParam.TextureTypes.StandardMap:
{
// write converted texture
targetPath = $"{m_path}/{param.ConvertedName}.png";
Expand Down Expand Up @@ -130,40 +129,13 @@ public static void ExtractTextures(string assetPath, TextureEnumerator textureEn

EditorApplication.delayCall += () =>
{
// Wait for the texture assets to be imported

foreach (var kv in extractor.Textures)
{
var targetPath = kv.Key;
var param = kv.Value;

// TextureImporter
var targetTextureImporter = AssetImporter.GetAtPath(targetPath) as TextureImporter;
if (targetTextureImporter != null)
{
switch (param.TextureType)
{
case GetTextureParam.OCCLUSION_PROP:
case GetTextureParam.METALLIC_GLOSS_PROP:
#if VRM_DEVELOP
Debug.Log($"{targetPath} => linear");
#endif
targetTextureImporter.sRGBTexture = false;
targetTextureImporter.SaveAndReimport();
break;

case GetTextureParam.NORMAL_PROP:
#if VRM_DEVELOP
Debug.Log($"{targetPath} => normalmap");
#endif
targetTextureImporter.textureType = TextureImporterType.NormalMap;
targetTextureImporter.SaveAndReimport();
break;
}
}
else
{
throw new FileNotFoundException(targetPath);
}

// remap
var externalObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Texture2D>(targetPath);
if (externalObject != null)
Expand Down
74 changes: 74 additions & 0 deletions Assets/UniGLTF/Editor/UniGLTF/TextureImporterConfigurator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace UniGLTF
{
public static class TextureImporterConfigurator
{
public static void ConfigureNormalMap(Texture2D texture)
{
var path = UnityPath.FromAsset(texture);
if (AssetImporter.GetAtPath(path.Value) is TextureImporter textureImporter)
{
#if VRM_DEVELOP
Debug.Log($"{path} => normalmap");
#endif
textureImporter.textureType = TextureImporterType.NormalMap;
textureImporter.SaveAndReimport();
}
else
{
throw new System.IO.FileNotFoundException($"{path}");
}
}

public static void ConfigureLinear(Texture2D texture)
{
var path = UnityPath.FromAsset(texture);
if (AssetImporter.GetAtPath(path.Value) is TextureImporter textureImporter)
{
#if VRM_DEVELOP
Debug.Log($"{path} => linear");
#endif
textureImporter.sRGBTexture = false;
textureImporter.SaveAndReimport();
}
else
{
throw new System.IO.FileNotFoundException($"{path}");
}
}

public static void Configure(GetTextureParam textureInfo, IDictionary<string, Texture2D> ExternalMap)
{
switch (textureInfo.TextureType)
{
case GetTextureParam.TextureTypes.NormalMap:
{
if (ExternalMap.TryGetValue(textureInfo.GltflName, out Texture2D external))
{
ConfigureNormalMap(external);
}
}
break;

case GetTextureParam.TextureTypes.StandardMap:
{
if (ExternalMap.TryGetValue(textureInfo.ConvertedName, out Texture2D external))
{
ConfigureLinear(external);
}
}
break;

case GetTextureParam.TextureTypes.sRGB:
break;

default:
throw new NotImplementedException();
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 7 additions & 21 deletions Assets/UniGLTF/Runtime/UniGLTF/Format/glTFMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ namespace UniGLTF
{
public enum glTFTextureTypes
{
BaseColor,
Metallic,
OcclusionMetallicRoughness,
Normal,
Occlusion,
Emissive,
Unknown
SRGB,
Linear,
}

public interface IglTFTextureinfo
Expand Down Expand Up @@ -38,19 +36,13 @@ public abstract class glTFTextureInfo : IglTFTextureinfo
[Serializable]
public class glTFMaterialBaseColorTextureInfo : glTFTextureInfo
{
public override glTFTextureTypes TextureType
{
get { return glTFTextureTypes.BaseColor; }
}
public override glTFTextureTypes TextureType => glTFTextureTypes.SRGB;
}

[Serializable]
public class glTFMaterialMetallicRoughnessTextureInfo : glTFTextureInfo
{
public override glTFTextureTypes TextureType
{
get { return glTFTextureTypes.Metallic; }
}
public override glTFTextureTypes TextureType => glTFTextureTypes.OcclusionMetallicRoughness;
}

[Serializable]
Expand All @@ -70,19 +62,13 @@ public class glTFMaterialOcclusionTextureInfo : glTFTextureInfo
[JsonSchema(Minimum = 0.0, Maximum = 1.0)]
public float strength = 1.0f;

public override glTFTextureTypes TextureType
{
get { return glTFTextureTypes.Occlusion; }
}
public override glTFTextureTypes TextureType => glTFTextureTypes.OcclusionMetallicRoughness;
}

[Serializable]
public class glTFMaterialEmissiveTextureInfo : glTFTextureInfo
{
public override glTFTextureTypes TextureType
{
get { return glTFTextureTypes.Emissive; }
}
public override glTFTextureTypes TextureType => glTFTextureTypes.SRGB;
}

[Serializable]
Expand Down
16 changes: 0 additions & 16 deletions Assets/UniGLTF/Runtime/UniGLTF/IO/ITextureExporter.cs

This file was deleted.

1 change: 1 addition & 0 deletions Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public ImporterContext(GltfParser parser,
};
#endif
}

m_textureFactory = new TextureFactory(loadTextureAsync, externalObjectMap);
m_materialFactory = new MaterialFactory(GLTF, Storage, externalObjectMap);
}
Expand Down
12 changes: 0 additions & 12 deletions Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialExporter.cs.meta

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading