VRMShaders.TextureExporter, AssetTextureUtil

This commit is contained in:
ousttrue
2021-04-02 18:35:02 +09:00
parent d28f700997
commit 27fa5dbc60
20 changed files with 59 additions and 32 deletions

View File

@@ -4,7 +4,8 @@
"UniGLTF",
"MeshUtility",
"MeshUtility.Editor",
"VRMShaders"
"VRMShaders",
"VRMShaders.Editor"
],
"optionalUnityReferences": [],
"includePlatforms": [

View File

@@ -5,6 +5,7 @@ using System.Reflection;
using UniGLTF.Animation;
using UnityEditor;
using UnityEngine;
using VRMShaders;
namespace UniGLTF
{

View File

@@ -3,7 +3,8 @@
"references": [
"UniGLTF",
"UniGLTF.Editor",
"VRMShaders"
"VRMShaders",
"VRMShaders.Editor"
],
"optionalUnityReferences": [
"TestAssemblies"

View File

@@ -50,28 +50,5 @@ namespace UniGLTF
var (bytes, mime) = GltfTextureExporter.GetBytesWithMime(readonlyTexture);
Assert.NotNull(bytes);
}
[Test]
public void ExportMetallicSmoothnessOcclusion_Test()
{
var metallic = new Texture2D(4, 4, TextureFormat.ARGB32, false, true);
var occlusion = new Texture2D(4, 4, TextureFormat.ARGB32, false, true);
{
var exporter = new TextureExporter(AssetTextureUtil.UseAsset);
Assert.AreEqual(-1, exporter.ExportMetallicSmoothnessOcclusion(null, 0, null));
}
{
var exporter = new TextureExporter(AssetTextureUtil.UseAsset);
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(null, 0, occlusion));
Assert.AreEqual(1, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, null));
}
{
var exporter = new TextureExporter(AssetTextureUtil.UseAsset);
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, occlusion));
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(null, 0, occlusion));
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, null));
}
}
}
}

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using UniJSON;
using UnityEngine;
using VRMShaders;
namespace UniGLTF
{

View File

@@ -8,7 +8,7 @@
"UniVRM.Editor",
"VRM.Tests",
"VRMShaders",
"UniGLTF.Editor"
"VRMShaders.Editor"
],
"optionalUnityReferences": [
"TestAssemblies"

View File

@@ -5,6 +5,7 @@ using UniJSON;
using UnityEngine;
using MeshUtility;
using System;
using VRMShaders;
namespace VRM.Samples
{

View File

@@ -6,6 +6,7 @@ using System.Text;
using UniGLTF;
using UnityEditor;
using UnityEngine;
using VRMShaders;
namespace VRM
{

View File

@@ -8,7 +8,8 @@
"UniUnlit",
"UniGLTF",
"UniGLTF.Editor",
"VRMShaders"
"VRMShaders",
"VRMShaders.Editor"
],
"optionalUnityReferences": [],
"includePlatforms": [

View File

@@ -6,7 +6,7 @@
"MeshUtility",
"MeshUtility.Editor",
"VRMShaders",
"UniGLTF.Editor"
"VRMShaders.Editor"
],
"optionalUnityReferences": [
"TestAssemblies"

View File

@@ -4,6 +4,7 @@ using System.IO;
using NUnit.Framework;
using UniGLTF;
using UnityEngine;
using VRMShaders;
namespace VRM
{

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 58204522f08a6fe4f846a5817a37f902
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,7 +2,7 @@ using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace UniGLTF
namespace VRMShaders
{
public static class AssetTextureUtil
{
@@ -13,7 +13,8 @@ namespace UniGLTF
/// <returns></returns>
public static bool CopyIfMaxTextureSizeIsSmaller(Texture src)
{
var textureImporter = AssetImporter.GetAtPath(UnityPath.FromAsset(src).Value) as TextureImporter;
var path = AssetDatabase.GetAssetPath(src);
var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
// private メソッド TextureImporter.GetWidthAndHeight を無理やり呼ぶ
var getSizeMethod = typeof(TextureImporter).GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance);

View File

@@ -0,0 +1,3 @@
{
"name": "VRMShaders.Editor"
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7da8a75dcade2144aab699032d7d7987
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -89,5 +89,28 @@ namespace VRMShaders
Is.EqualTo(new Color32(255, 0, 0, 255)));
}
}
[Test]
public void ExportMetallicSmoothnessOcclusion_Test()
{
var metallic = new Texture2D(4, 4, TextureFormat.ARGB32, false, true);
var occlusion = new Texture2D(4, 4, TextureFormat.ARGB32, false, true);
{
var exporter = new TextureExporter(AssetTextureUtil.UseAsset);
Assert.AreEqual(-1, exporter.ExportMetallicSmoothnessOcclusion(null, 0, null));
}
{
var exporter = new TextureExporter(AssetTextureUtil.UseAsset);
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(null, 0, occlusion));
Assert.AreEqual(1, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, null));
}
{
var exporter = new TextureExporter(AssetTextureUtil.UseAsset);
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, occlusion));
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(null, 0, occlusion));
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, null));
}
}
}
}

View File

@@ -1,7 +1,8 @@
{
"name": "VRMShaders.Tests",
"references": [
"VRMShaders"
"VRMShaders",
"VRMShaders.Editor"
],
"optionalUnityReferences": [
"TestAssemblies"