Merge branch 'master' into extended-collider-spec-version

This commit is contained in:
ousttrue
2024-07-31 13:25:46 +09:00
committed by GitHub
127 changed files with 561 additions and 420 deletions

View File

@@ -109,11 +109,12 @@ namespace UniGLTF
{
var data = new ExportingGltfData();
using (var exporter = new gltfExporter(data, Settings,
progress: new EditorProgress(),
animationExporter: new EditorAnimationExporter()))
progress: new EditorProgress(),
animationExporter: new EditorAnimationExporter(),
textureSerializer: new EditorTextureSerializer()))
{
exporter.Prepare(State.ExportRoot);
exporter.Export(new EditorTextureSerializer());
exporter.Export();
}
if (isGlb)

View File

@@ -19,35 +19,7 @@ namespace UniGLTF
public ScriptedImporterAxes m_reverseAxis = default;
[SerializeField]
[Header("Experimental")]
public RenderPipelineTypes m_renderPipeline;
void OnValidate()
{
if (m_renderPipeline == UniGLTF.RenderPipelineTypes.UniversalRenderPipeline)
{
if (Shader.Find(UniGLTF.UrpGltfPbrMaterialImporter.ShaderName) == null)
{
Debug.LogWarning("URP is not installed. Force to BuiltinRenderPipeline");
m_renderPipeline = UniGLTF.RenderPipelineTypes.BuiltinRenderPipeline;
}
}
}
static IMaterialDescriptorGenerator GetMaterialGenerator(RenderPipelineTypes renderPipeline)
{
switch (renderPipeline)
{
case RenderPipelineTypes.BuiltinRenderPipeline:
return new BuiltInGltfMaterialDescriptorGenerator();
case RenderPipelineTypes.UniversalRenderPipeline:
return new UrpGltfMaterialDescriptorGenerator();
default:
throw new System.NotImplementedException();
}
}
public ImporterRenderPipelineTypes m_renderPipeline;
/// <summary>
/// glb をパースして、UnityObject化、さらにAsset化する
@@ -55,7 +27,8 @@ namespace UniGLTF
/// <param name="scriptedImporter"></param>
/// <param name="context"></param>
/// <param name="reverseAxis"></param>
protected static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, Axes reverseAxis, RenderPipelineTypes renderPipeline)
/// <param name="renderPipeline"></param>
protected static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, Axes reverseAxis, ImporterRenderPipelineTypes renderPipeline)
{
UniGLTFLogger.Log("OnImportAsset to " + scriptedImporter.assetPath);
@@ -68,7 +41,7 @@ namespace UniGLTF
.Where(x => x.Value != null)
.ToDictionary(kv => new SubAssetKey(kv.Value.GetType(), kv.Key.name), kv => kv.Value);
IMaterialDescriptorGenerator materialGenerator = GetMaterialGenerator(renderPipeline);
var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline);
using (var data = new AutoGltfFileParser(scriptedImporter.assetPath).Parse())
using (var loader = new ImporterContext(data, extractedObjects, materialGenerator: materialGenerator))
@@ -94,5 +67,16 @@ namespace UniGLTF
context.SetMainObject(root);
}
}
private static IMaterialDescriptorGenerator GetMaterialDescriptorGenerator(ImporterRenderPipelineTypes renderPipeline)
{
return renderPipeline switch
{
ImporterRenderPipelineTypes.Auto => MaterialDescriptorGeneratorUtility .GetValidGltfMaterialDescriptorGenerator(),
ImporterRenderPipelineTypes.BuiltinRenderPipeline => MaterialDescriptorGeneratorUtility .GetGltfMaterialDescriptorGenerator(RenderPipelineTypes.BuiltinRenderPipeline),
ImporterRenderPipelineTypes.UniversalRenderPipeline => MaterialDescriptorGeneratorUtility .GetGltfMaterialDescriptorGenerator(RenderPipelineTypes.UniversalRenderPipeline),
_ => MaterialDescriptorGeneratorUtility.GetValidGltfMaterialDescriptorGenerator(),
};
}
}
}

View File

@@ -0,0 +1,9 @@
namespace UniGLTF
{
public enum ImporterRenderPipelineTypes
{
Auto = 0,
BuiltinRenderPipeline = 1,
UniversalRenderPipeline = 2,
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d4f38213d6e442ef986fd3e633991ba7
timeCreated: 1722347490

View File

@@ -307,7 +307,7 @@ namespace UniGLTF
using (MeasureTime("BuildMesh"))
{
var meshWithMaterials = await MeshUploader.BuildMeshAndUploadAsync(awaitCaller, meshData,
(int? materialIndex) =>
async materialIndex =>
{
if (materialIndex.HasValidIndex())
{
@@ -315,7 +315,7 @@ namespace UniGLTF
}
else
{
return MaterialFactory.DefaultMaterial;
return await MaterialFactory.GetDefaultMaterialAsync(awaitCaller);
}
});
var mesh = meshWithMaterials.Mesh;

View File

@@ -0,0 +1,15 @@
namespace UniGLTF
{
public static class MaterialExporterUtility
{
public static IMaterialExporter GetValidGltfMaterialExporter()
{
return RenderPipelineUtility.GetRenderPipelineType() switch
{
RenderPipelineTypes.UniversalRenderPipeline => throw new System.NotImplementedException(),
RenderPipelineTypes.BuiltinRenderPipeline => new BuiltInGltfMaterialExporter(),
_ => new BuiltInGltfMaterialExporter(),
};
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ce72b16c8b374add909ab887c14a0f44
timeCreated: 1722257666

View File

@@ -0,0 +1,21 @@
namespace UniGLTF
{
public static class MaterialDescriptorGeneratorUtility
{
public static IMaterialDescriptorGenerator GetValidGltfMaterialDescriptorGenerator()
{
return GetGltfMaterialDescriptorGenerator(RenderPipelineUtility.GetRenderPipelineType());
}
public static IMaterialDescriptorGenerator GetGltfMaterialDescriptorGenerator(RenderPipelineTypes renderPipelineType)
{
return renderPipelineType switch
{
RenderPipelineTypes.UniversalRenderPipeline => new UrpGltfMaterialDescriptorGenerator(),
RenderPipelineTypes.BuiltinRenderPipeline => new BuiltInGltfMaterialDescriptorGenerator(),
_ => new BuiltInGltfMaterialDescriptorGenerator(),
};
}
}
}

View File

@@ -11,28 +11,17 @@ namespace UniGLTF
{
private readonly IReadOnlyDictionary<SubAssetKey, Material> m_externalMap;
MaterialDescriptor m_defaultMaterialParams;
/// <summary>
/// デフォルトマテリアルの MaterialDescriptor は IMaterialDescriptorGenerator の実装によって異なるので外から渡す
/// </summary>
private readonly MaterialDescriptor m_defaultMaterialParams;
/// <summary>
/// gltfPritmitive.material が無い場合のデフォルトマテリアル
/// https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#default-material
///
/// </summary>
Material m_defaultMaterial;
public Material DefaultMaterial
{
get
{
if (m_defaultMaterial == null)
{
// default material にバリエーションがある?
var task = LoadAsync(m_defaultMaterialParams, (_x, _y) => Task.FromResult<Texture>(null), new ImmediateCaller());
task.Wait();
m_defaultMaterial = task.Result;
}
return m_defaultMaterial;
}
}
private Material m_defaultMaterial;
public MaterialFactory(IReadOnlyDictionary<SubAssetKey, Material> externalMaterialMap, MaterialDescriptor defaultMaterialParams)
{
@@ -110,6 +99,16 @@ namespace UniGLTF
return m_materials[index].Asset;
}
public async Task<Material> GetDefaultMaterialAsync(IAwaitCaller awaitCaller)
{
if (m_defaultMaterial == null)
{
m_defaultMaterial = await LoadAsync(m_defaultMaterialParams, (_, _) => null, awaitCaller);
}
return m_defaultMaterial;
}
public async Task<Material> LoadAsync(MaterialDescriptor matDesc, GetTextureAsyncFunc getTexture, IAwaitCaller awaitCaller)
{
if (m_externalMap.TryGetValue(matDesc.SubAssetKey, out Material material))

View File

@@ -1,8 +1,8 @@
using UnityEngine.Rendering;
using UnityEngine.Rendering;
namespace UniGLTF
{
public static class MaterialDescriptorGeneratorUtility
public static class RenderPipelineUtility
{
public static RenderPipelineTypes GetRenderPipelineType()
{
@@ -25,16 +25,5 @@ namespace UniGLTF
return RenderPipelineTypes.Unknown;
}
public static IMaterialDescriptorGenerator GetValidGltfMaterialDescriptorGenerator()
{
return GetRenderPipelineType() switch
{
RenderPipelineTypes.UniversalRenderPipeline => new UrpGltfMaterialDescriptorGenerator(),
RenderPipelineTypes.BuiltinRenderPipeline => new BuiltInGltfMaterialDescriptorGenerator(),
_ => new BuiltInGltfMaterialDescriptorGenerator(),
};
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0fd29db9c49145cd9f56f92e6153c8db
timeCreated: 1722257774

View File

@@ -89,7 +89,7 @@ namespace UniGLTF
public static async Task<MeshWithMaterials> BuildMeshAndUploadAsync(
IAwaitCaller awaitCaller,
MeshData data,
Func<int?, Material> materialFromIndex)
Func<int?, Task<Material>> materialFromIndex)
{
//Debug.Log(prims.ToJson());
@@ -117,10 +117,16 @@ namespace UniGLTF
mesh.RecalculateTangents();
await awaitCaller.NextFrame();
var materials = new Material[data.MaterialIndices.Count];
for (var idx = 0; idx < data.MaterialIndices.Count; ++idx)
{
materials[idx] = await materialFromIndex(data.MaterialIndices[idx]);
}
var result = new MeshWithMaterials
{
Mesh = mesh,
Materials = data.MaterialIndices.Select(materialFromIndex).ToArray(),
Materials = materials,
ShouldSetRendererNodeAsBone = data.ShouldSetRendererNodeAsBone,
};
await awaitCaller.NextFrame();

View File

@@ -45,11 +45,6 @@ namespace UniGLTF
private set;
}
protected virtual IMaterialExporter CreateMaterialExporter()
{
return new BuiltInGltfMaterialExporter();
}
protected ITextureExporter TextureExporter => _textureExporter;
private TextureExporter _textureExporter;
@@ -66,10 +61,18 @@ namespace UniGLTF
m_progress.Report(new ExportProgress("gltfExporter", msg, progress));
}
IAnimationExporter m_animationExporter;
private readonly IAnimationExporter m_animationExporter;
private readonly IMaterialExporter m_materialExporter;
private readonly ITextureSerializer m_textureSerializer;
public gltfExporter(ExportingGltfData data, GltfExportSettings settings, IProgress<ExportProgress> progress = null,
IAnimationExporter animationExporter = null)
public gltfExporter(
ExportingGltfData data,
GltfExportSettings settings,
IProgress<ExportProgress> progress = null,
IAnimationExporter animationExporter = null,
IMaterialExporter materialExporter = null,
ITextureSerializer textureSerializer = null
)
{
_data = data;
@@ -87,6 +90,8 @@ namespace UniGLTF
}
m_animationExporter = animationExporter;
m_materialExporter = materialExporter ?? MaterialExporterUtility.GetValidGltfMaterialExporter();
m_textureSerializer = textureSerializer ?? new RuntimeTextureSerializer();
}
GameObject m_tmpParent = null;
@@ -224,7 +229,7 @@ namespace UniGLTF
// do nothing
}
public virtual void Export(ITextureSerializer textureSerializer)
public virtual void Export()
{
if (m_settings.FreezeMesh)
{
@@ -249,10 +254,9 @@ namespace UniGLTF
ReportProgress("Materials and Textures", 0.2f);
Materials = uniqueUnityMeshes.GetUniqueMaterials().ToList();
_textureExporter = new TextureExporter(textureSerializer);
_textureExporter = new TextureExporter(m_textureSerializer);
var materialExporter = CreateMaterialExporter();
_gltf.materials = Materials.Select(x => materialExporter.ExportMaterial(x, TextureExporter, m_settings)).ToList();
_gltf.materials = Materials.Select(x => m_materialExporter.ExportMaterial(x, TextureExporter, m_settings)).ToList();
#endregion
#region Meshes
@@ -346,14 +350,14 @@ namespace UniGLTF
m_animationExporter.Export(_data, Copy, Nodes);
}
ExportExtensions(textureSerializer);
ExportExtensions(m_textureSerializer);
// Extension で Texture が増える場合があるので最後に呼ぶ
var exported = _textureExporter.Export();
for (var exportedTextureIdx = 0; exportedTextureIdx < exported.Count; ++exportedTextureIdx)
{
var (unityTexture, colorSpace) = exported[exportedTextureIdx];
GltfTextureExporter.PushGltfTexture(_data, unityTexture, colorSpace, textureSerializer);
GltfTextureExporter.PushGltfTexture(_data, unityTexture, colorSpace, m_textureSerializer);
}
FixName(_gltf);

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 6cf41692967c5544b8ceeb148cad87b3
guid: 257f9efac603801459934018928760de
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

Before

Width:  |  Height:  |  Size: 79 B

After

Width:  |  Height:  |  Size: 79 B

View File

@@ -3,7 +3,7 @@ guid: fc1ba24d4a4141d4d9e9ae0a0d3ecd0a
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
@@ -24,6 +24,7 @@ TextureImporter:
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
@@ -62,6 +63,7 @@ TextureImporter:
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
@@ -99,6 +101,18 @@ TextureImporter:
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
@@ -112,6 +126,7 @@ TextureImporter:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0

View File

Before

Width:  |  Height:  |  Size: 79 B

After

Width:  |  Height:  |  Size: 79 B

View File

@@ -3,7 +3,7 @@ guid: b5d17df8d14f2324692a7c69f24cf658
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 1
@@ -24,6 +24,7 @@ TextureImporter:
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
@@ -62,6 +63,7 @@ TextureImporter:
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
@@ -99,6 +101,18 @@ TextureImporter:
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
@@ -112,6 +126,7 @@ TextureImporter:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0

View File

Before

Width:  |  Height:  |  Size: 79 B

After

Width:  |  Height:  |  Size: 79 B

View File

@@ -3,7 +3,7 @@ guid: 0f7acf68f1798ae48a5505519abac457
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
@@ -24,6 +24,7 @@ TextureImporter:
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
@@ -62,6 +63,7 @@ TextureImporter:
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
@@ -99,6 +101,18 @@ TextureImporter:
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
@@ -112,6 +126,7 @@ TextureImporter:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0

View File

Before

Width:  |  Height:  |  Size: 560 B

After

Width:  |  Height:  |  Size: 560 B

View File

@@ -33,6 +33,8 @@ namespace UniGLTF
var tmp = AssetDatabase.LoadAssetAtPath<Mesh>(assetPath);
Assert.Null(tmp);
AssetDatabase.DeleteAsset(assetPath);
}
AssetDatabase.Refresh();

View File

@@ -1,13 +1,10 @@
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
namespace UniGLTF
{
public sealed class CopyTextureTests
{
private static string AssetPath = "Assets/VRMShaders/GLTF/IO/Tests";
private static readonly Color32 Black = new Color32(0, 0, 0, 255);
private static readonly Color32 Gray = new Color32(127, 127, 127, 255);
private static readonly Color32 White = new Color32(255, 255, 255, 255);
@@ -32,7 +29,7 @@ namespace UniGLTF
[Test]
public void CopyFromNonReadableSRgbPng()
{
var nonReadableTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/4x4_non_readable.png");
var nonReadableTex = TestAssets.LoadAsset<Texture2D>("4x4_non_readable.png");
Assert.False(nonReadableTex.isReadable);
var copiedTex = TextureConverter.CopyTexture(nonReadableTex, ColorSpace.sRGB, true, null);
var pixels = copiedTex.GetPixels32(miplevel: 0);
@@ -46,7 +43,7 @@ namespace UniGLTF
[Test]
public void CopyFromNonReadableSRgbDds()
{
var compressedTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/4x4_non_readable_compressed.dds");
var compressedTex = TestAssets.LoadAsset<Texture2D>("4x4_non_readable_compressed.dds");
Assert.False(compressedTex.isReadable);
var copiedTex = TextureConverter.CopyTexture(compressedTex, ColorSpace.sRGB, true, null);
var pixels = copiedTex.GetPixels32(miplevel: 0);
@@ -60,7 +57,7 @@ namespace UniGLTF
[Test]
public void CopyAttributes()
{
var src = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/4x4_non_readable.png");
var src = TestAssets.LoadAsset<Texture2D>("4x4_non_readable.png");
var dst = TextureConverter.CopyTexture(src, ColorSpace.sRGB, false, null);
Assert.AreEqual(src.name, dst.name);
Assert.AreEqual(src.anisoLevel, dst.anisoLevel);

View File

@@ -1,18 +1,16 @@
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
namespace UniGLTF
{
public sealed class EditorTextureSerializerTests
{
private static readonly string AssetPath = "Assets/UniGLTF/Tests/UniGLTF";
private static readonly string SrgbGrayImageName = "4x4_gray_import_as_srgb";
private static readonly string LinearGrayImageName = "4x4_gray_import_as_linear";
private static readonly string NormalMapGrayImageName = "4x4_gray_import_as_normal_map";
private static readonly Texture2D SrgbGrayTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/{SrgbGrayImageName}.png");
private static readonly Texture2D LinearGrayTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/{LinearGrayImageName}.png");
private static readonly Texture2D NormalMapGrayTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/{NormalMapGrayImageName}.png");
private static readonly Texture2D SrgbGrayTex = TestAssets.LoadAsset<Texture2D>($"{SrgbGrayImageName}.png");
private static readonly Texture2D LinearGrayTex = TestAssets.LoadAsset<Texture2D>($"{LinearGrayImageName}.png");
private static readonly Texture2D NormalMapGrayTex = TestAssets.LoadAsset<Texture2D>($"{NormalMapGrayImageName}.png");
private static readonly Color32 JustGray = new Color32(127, 127, 127, 255);
private static readonly Color32 SrgbGrayInSrgb = JustGray;
private static readonly Color32 SrgbGrayInLinear = ((Color)SrgbGrayInSrgb).linear;
@@ -113,23 +111,28 @@ namespace UniGLTF
{
// Prepare
var root = GameObject.CreatePrimitive(PrimitiveType.Cube);
var mat = new Material(Shader.Find("Standard"));
var mat = new Material(Shader.Find(BuiltInStandardMaterialExporter.TargetShaderName));
mat.SetTexture(propertyName, srcTex);
root.GetComponentOrThrow<MeshRenderer>().sharedMaterial = mat;
// Export glTF
var data = new ExportingGltfData();
using (var exporter = new gltfExporter(data, new GltfExportSettings
{
InverseAxis = Axes.X,
ExportOnlyBlendShapePosition = false,
UseSparseAccessorForMorphTarget = false,
DivideVertexBuffer = false,
}))
{
exporter.Prepare(root);
exporter.Export(new EditorTextureSerializer());
}
using var exporter = new gltfExporter(
data,
new GltfExportSettings
{
InverseAxis = Axes.X,
ExportOnlyBlendShapePosition = false,
UseSparseAccessorForMorphTarget = false,
DivideVertexBuffer = false,
},
materialExporter: new BuiltInGltfMaterialExporter(),
textureSerializer: new EditorTextureSerializer()
);
exporter.Prepare(root);
exporter.Export();
var gltf = data.Gltf;
Assert.AreEqual(1, gltf.images.Count);
var exportedImage = gltf.images[0];

View File

@@ -68,7 +68,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
{
exporter.Prepare(root);
exporter.Export(new EditorTextureSerializer());
exporter.Export();
}
return data.ToGlbBytes();
}

View File

@@ -0,0 +1,12 @@
namespace UniGLTF
{
public static class TestAssets
{
public static readonly string AssetPath = "Assets/UniGLTF/Tests/Objects";
public static T LoadAsset<T>(string filename) where T : UnityEngine.Object
{
return UnityEditor.AssetDatabase.LoadAssetAtPath<T>($"{AssetPath}/{filename}");
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8519ebb2f0f84833a752bb564b59c47c
timeCreated: 1722263712

View File

@@ -0,0 +1,52 @@
using UnityEngine;
namespace UniGLTF
{
public static class TestGltf
{
public static RuntimeGltfInstance LoadBytesAsBuiltInRP(byte[] bytes)
{
return GltfUtility.LoadBytesAsync(
"",
bytes,
awaitCaller: new ImmediateCaller(),
materialGenerator: new BuiltInGltfMaterialDescriptorGenerator()
).Result;
}
public static RuntimeGltfInstance LoadPathAsBuiltInRP(string path)
{
return GltfUtility.LoadAsync(
path,
awaitCaller: new ImmediateCaller(),
materialGenerator: new BuiltInGltfMaterialDescriptorGenerator()
).Result;
}
public static ExportingGltfData ExportAsBuiltInRP(GameObject gameObject, GltfExportSettings exportSettings = null)
{
var data = new ExportingGltfData();
using var exporter = new gltfExporter(
data,
exportSettings ?? new GltfExportSettings(),
progress: new EditorProgress(),
animationExporter: new EditorAnimationExporter(),
materialExporter: new BuiltInGltfMaterialExporter(),
textureSerializer: new EditorTextureSerializer()
);
exporter.Prepare(gameObject);
exporter.Export();
return data;
}
public static GameObject CreatePrimitiveAsBuiltInRP(PrimitiveType primitiveType)
{
var go = GameObject.CreatePrimitive(primitiveType);
var shader = Shader.Find("Standard");
var material = new Material(shader);
go.GetComponent<Renderer>().sharedMaterial = material;
return go;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 11719ab072944cc2b7c0eaafa0cdff2e
timeCreated: 1722267047

View File

@@ -1,17 +1,14 @@
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
namespace UniGLTF
{
public class TextureBytesTests
{
static string AssetPath = "Assets/VRMShaders/GLTF/IO/Tests";
[Test]
public void NonReadablePng()
{
var nonReadableTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/4x4_non_readable.png");
var nonReadableTex = TestAssets.LoadAsset<Texture2D>("4x4_non_readable.png");
Assert.False(nonReadableTex.isReadable);
var (bytes, mime) = new EditorTextureSerializer().ExportBytesWithMime(nonReadableTex, ColorSpace.sRGB);
Assert.NotNull(bytes);
@@ -20,7 +17,7 @@ namespace UniGLTF
[Test]
public void NonReadableDds()
{
var readonlyTexture = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/4x4_non_readable_compressed.dds");
var readonlyTexture = TestAssets.LoadAsset<Texture2D>("4x4_non_readable_compressed.dds");
Assert.False(readonlyTexture.isReadable);
var (bytes, mime) = new EditorTextureSerializer().ExportBytesWithMime(readonlyTexture, ColorSpace.sRGB);
Assert.NotNull(bytes);

View File

@@ -100,18 +100,17 @@ namespace UniGLTF
// export
var data = new ExportingGltfData();
using var exporter = new gltfExporter(
data,
new GltfExportSettings(),
materialExporter: new BuiltInGltfMaterialExporter());
exporter.Prepare(go);
exporter.Export();
string json = null;
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
{
exporter.Prepare(go);
exporter.Export(new EditorTextureSerializer());
// remove empty buffer
data.Gltf.buffers.Clear();
// remove empty buffer
data.Gltf.buffers.Clear();
json = data.Gltf.ToJson();
}
var json = data.Gltf.ToJson();
// parse
using (var parsed = GltfData.CreateFromExportForTest(data))
@@ -353,12 +352,7 @@ namespace UniGLTF
[Test]
public void GlTFToJsonTest()
{
var data = new ExportingGltfData();
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
{
exporter.Prepare(CreateSimpleScene());
exporter.Export(new EditorTextureSerializer());
}
var data = TestGltf.ExportAsBuiltInRP(CreateSimpleScene());
var expected = data.Gltf.ToJson().ParseAsJson();
expected.AddKey(Utf8String.From("meshes"));
@@ -565,7 +559,7 @@ namespace UniGLTF
{
var shader = Shader.Find("Unlit/Color");
var cubeA = GameObject.CreatePrimitive(PrimitiveType.Cube);
var cubeA = TestGltf.CreatePrimitiveAsBuiltInRP(PrimitiveType.Cube);
{
cubeA.transform.SetParent(go.transform);
var material = new Material(shader);
@@ -586,16 +580,8 @@ namespace UniGLTF
}
// export
var data = new ExportingGltfData();
var data = TestGltf.ExportAsBuiltInRP(go);
var gltf = data.Gltf;
var json = default(string);
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
{
exporter.Prepare(go);
exporter.Export(new EditorTextureSerializer());
json = gltf.ToJson();
}
Assert.AreEqual(2, gltf.meshes.Count);
@@ -658,22 +644,14 @@ namespace UniGLTF
try
{
{
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
var cube = TestGltf.CreatePrimitiveAsBuiltInRP(PrimitiveType.Cube);
cube.transform.SetParent(go.transform);
UnityEngine.Object.DestroyImmediate(cube.GetComponent<MeshRenderer>());
}
// export
var data = new ExportingGltfData();
var data = TestGltf.ExportAsBuiltInRP(go);
var gltf = data.Gltf;
string json;
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
{
exporter.Prepare(go);
exporter.Export(new EditorTextureSerializer());
json = gltf.ToJson();
}
Assert.AreEqual(0, gltf.meshes.Count);
Assert.AreEqual(1, gltf.nodes.Count);
@@ -682,7 +660,7 @@ namespace UniGLTF
// import
using (var parsed = GltfData.CreateFromExportForTest(data))
{
using (var context = new ImporterContext(parsed))
using (var context = new ImporterContext(parsed, materialGenerator: new BuiltInGltfMaterialDescriptorGenerator()))
using (var loaded = context.Load())
{
Assert.AreEqual(1, loaded.transform.GetChildren().Count());
@@ -708,14 +686,14 @@ namespace UniGLTF
try
{
{
var child = GameObject.CreatePrimitive(PrimitiveType.Cube);
var child = TestGltf.CreatePrimitiveAsBuiltInRP(PrimitiveType.Cube);
child.transform.SetParent(root.transform);
// remove MeshFilter
Component.DestroyImmediate(child.GetComponent<MeshFilter>());
}
{
var child = GameObject.CreatePrimitive(PrimitiveType.Cube);
var child = TestGltf.CreatePrimitiveAsBuiltInRP(PrimitiveType.Cube);
child.transform.SetParent(root.transform);
// set null
child.GetComponent<MeshFilter>().sharedMesh = null;
@@ -727,16 +705,9 @@ namespace UniGLTF
Assert.True(vs.All(x => x.CanExport));
// export
var data = new ExportingGltfData();
var data = TestGltf.ExportAsBuiltInRP(root);
var gltf = data.Gltf;
string json;
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
{
exporter.Prepare(root);
exporter.Export(new EditorTextureSerializer());
json = gltf.ToJson();
}
var json = gltf.ToJson();
Assert.AreEqual(0, gltf.meshes.Count);
Assert.AreEqual(2, gltf.nodes.Count);

View File

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

View File

@@ -16,12 +16,17 @@ namespace VRM
/// </summary>
/// <param name="path">出力先</param>
/// <param name="settings">エクスポート設定</param>
public static byte[] Export(GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings)
public static byte[] Export(
GameObject exportRoot,
VRMMetaObject meta,
VRMExportSettings settings,
IMaterialExporter materialExporter = null
)
{
List<GameObject> destroy = new List<GameObject>();
try
{
return Export(exportRoot, meta, settings, destroy);
return Export(exportRoot, meta, settings, materialExporter, destroy);
}
finally
{
@@ -143,9 +148,12 @@ namespace VRM
/// <param name="path"></param>
/// <param name="settings"></param>
/// <param name="destroy">作業が終わったらDestoryするべき一時オブジェクト</param>
static byte[] Export(GameObject exportRoot, VRMMetaObject meta,
VRMExportSettings settings,
List<GameObject> destroy)
private static byte[] Export(
GameObject exportRoot,
VRMMetaObject meta,
VRMExportSettings settings,
IMaterialExporter materialExporter,
List<GameObject> destroy)
{
var target = exportRoot;
@@ -226,10 +234,12 @@ namespace VRM
var data = new UniGLTF.ExportingGltfData();
var gltfExportSettings = settings.GltfExportSettings;
using (var exporter = new VRMExporter(data, gltfExportSettings,
settings.KeepAnimation ? new EditorAnimationExporter() : null))
animationExporter: settings.KeepAnimation ? new EditorAnimationExporter() : null,
materialExporter: materialExporter,
textureSerializer: new EditorTextureSerializer()))
{
exporter.Prepare(target);
exporter.Export(new EditorTextureSerializer());
exporter.Export();
}
var bytes = data.ToGlbBytes();
Debug.LogFormat("Export elapsed {0}", sw.Elapsed);

View File

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

View File

@@ -6,7 +6,12 @@ namespace VRM
{
public static IMaterialDescriptorGenerator GetValidVrmMaterialDescriptorGenerator(glTF_VRM_extensions vrm)
{
return MaterialDescriptorGeneratorUtility.GetRenderPipelineType() switch
return GetVrmMaterialDescriptorGenerator(vrm, RenderPipelineUtility.GetRenderPipelineType());
}
public static IMaterialDescriptorGenerator GetVrmMaterialDescriptorGenerator(glTF_VRM_extensions vrm, RenderPipelineTypes renderPipelineType)
{
return renderPipelineType switch
{
RenderPipelineTypes.UniversalRenderPipeline => new UrpVrmMaterialDescriptorGenerator(vrm),
RenderPipelineTypes.BuiltinRenderPipeline => new BuiltInVrmMaterialDescriptorGenerator(vrm),

View File

@@ -0,0 +1,17 @@
using UniGLTF;
namespace VRM
{
public static class VrmMaterialExporterUtility
{
public static IMaterialExporter GetValidVrmMaterialExporter()
{
return RenderPipelineUtility.GetRenderPipelineType() switch
{
RenderPipelineTypes.UniversalRenderPipeline => throw new System.NotImplementedException(),
RenderPipelineTypes.BuiltinRenderPipeline => new BuiltInVrmMaterialExporter(),
_ => new BuiltInVrmMaterialExporter(),
};
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c195ef8334f647febbfc517181117548
timeCreated: 1722258234

View File

@@ -14,18 +14,29 @@ namespace VRM
public static ExportingGltfData Export(GltfExportSettings configuration, GameObject go, ITextureSerializer textureSerializer)
{
var data = new ExportingGltfData();
using (var exporter = new VRMExporter(data, configuration))
using (var exporter = new VRMExporter(data, configuration, textureSerializer: textureSerializer))
{
exporter.Prepare(go);
exporter.Export(textureSerializer);
exporter.Export();
}
return data;
}
public readonly VRM.glTF_VRM_extensions VRM = new glTF_VRM_extensions();
public VRMExporter(ExportingGltfData data, GltfExportSettings exportSettings, IAnimationExporter animationExporter = null) : base(
data, exportSettings, animationExporter: animationExporter)
public VRMExporter(
ExportingGltfData data,
GltfExportSettings exportSettings,
IAnimationExporter animationExporter = null,
IMaterialExporter materialExporter = null,
ITextureSerializer textureSerializer = null
) : base(
data,
exportSettings,
animationExporter: animationExporter,
materialExporter: materialExporter ?? VrmMaterialExporterUtility.GetValidVrmMaterialExporter(),
textureSerializer: textureSerializer
)
{
if (exportSettings == null)
{
@@ -40,11 +51,6 @@ namespace VRM
_gltf.extensionsUsed.Add(glTF_VRM_extensions.ExtensionName);
}
protected override IMaterialExporter CreateMaterialExporter()
{
return new BuiltInVrmMaterialExporter();
}
public override void ExportExtensions(ITextureSerializer textureSerializer)
{
var getBone = UniHumanoid.Humanoid.Get_GetBoneTransform(Copy);

View File

@@ -1,19 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!200 &20000000
ShaderVariantCollection:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: VRMShaders
m_Shaders:
- first: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
second:
variants: []
- first: {fileID: 4800000, guid: 1a97144e4ad27a04aafd70f7b915cedb, type: 3}
second:
variants: []
- first: {fileID: 4800000, guid: 8c17b56f4bf084c47872edcb95237e4a, type: 3}
second:
variants: []

View File

@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 486ebb794ada0de41be4f35c56876f82
timeCreated: 1520840003
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 20000000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -33,9 +33,11 @@ namespace VRM.Samples
public void ImportExportTest()
{
var path = AliciaPath;
using (var data = new GlbFileParser(path).Parse())
using (var context = new VRMImporterContext(new VRMData(data)))
using (var loaded = context.Load())
using var data = new GlbFileParser(path).Parse();
var vrmData = new VRMData(data);
var materialGenerator = new BuiltInVrmMaterialDescriptorGenerator(vrmData.VrmExtension);
using var context = new VRMImporterContext(vrmData, materialGenerator: materialGenerator);
using var loaded = context.Load();
{
loaded.ShowMeshes();
loaded.EnableUpdateWhenOffscreen();
@@ -126,9 +128,11 @@ namespace VRM.Samples
public void MeshCopyTest()
{
var path = AliciaPath;
using (var data = new GlbFileParser(path).Parse())
using (var context = new VRMImporterContext(new VRMData(data)))
using (var loaded = context.Load())
using var data = new GlbFileParser(path).Parse();
var vrmData = new VRMData(data);
var materialGenerator = new BuiltInVrmMaterialDescriptorGenerator(vrmData.VrmExtension);
using var context = new VRMImporterContext(vrmData, materialGenerator: materialGenerator);
using var loaded = context.Load();
{
loaded.ShowMeshes();
loaded.EnableUpdateWhenOffscreen();
@@ -147,8 +151,10 @@ namespace VRM.Samples
// Aliciaを古いデシリアライザでロードする
var path = AliciaPath;
using (var data = new GlbFileParser(path).Parse())
using (var context = new VRMImporterContext(new VRMData(data)))
using var data = new GlbFileParser(path).Parse();
var vrmData = new VRMData(data);
var materialGenerator = new BuiltInVrmMaterialDescriptorGenerator(vrmData.VrmExtension);
using var context = new VRMImporterContext(vrmData, materialGenerator: materialGenerator);
{
var oldJson = context.GLTF.ToJson().ParseAsJson().ToString(" ");

View File

@@ -0,0 +1,32 @@
using UniGLTF;
using UnityEngine;
namespace VRM
{
public static class TestVrm0X
{
public static RuntimeGltfInstance LoadBytesAsBuiltInRP(byte[] bytes)
{
return VrmUtility.LoadBytesAsync(
"",
bytes,
awaitCaller: new ImmediateCaller(),
materialGeneratorCallback: x => new BuiltInVrmMaterialDescriptorGenerator(x)
).Result;
}
public static RuntimeGltfInstance LoadPathAsBuiltInRP(string path)
{
return VrmUtility.LoadAsync(
path,
awaitCaller: new ImmediateCaller(),
materialGeneratorCallback: x => new BuiltInVrmMaterialDescriptorGenerator(x)
).Result;
}
public static byte[] ExportAsBuiltInRP(GameObject gameObject, VRMExportSettings exportSettings)
{
return VRMEditorExporter.Export(gameObject, null, exportSettings, new BuiltInVrmMaterialExporter());
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 47b1209d83114ccbaa0bf02436b8eb04
timeCreated: 1722265572

View File

@@ -21,11 +21,8 @@ namespace VRM
[Test]
public void VRMLookAtTest()
{
var data = new GlbFileParser(AliciaPath).Parse();
byte[] bytes = default;
using (data)
using (var loader = new VRMImporterContext(new VRMData(data)))
using (var loaded = loader.Load())
using var loaded = TestVrm0X.LoadPathAsBuiltInRP(AliciaPath);
{
loaded.ShowMeshes();
@@ -35,12 +32,12 @@ namespace VRM
var lookAt = go.AddComponent<VRMLookAtBlendShapeApplyer>();
var settings = (VRMExportSettings)ScriptableObject.CreateInstance<VRMExportSettings>();
settings.PoseFreeze = true;
bytes = VRMEditorExporter.Export(go, null, settings);
}
bytes = TestVrm0X.ExportAsBuiltInRP(go, settings);
}
using (var data2 = new GlbLowLevelParser(AliciaPath, bytes).Parse())
using (var loader2 = new VRMImporterContext(new VRMData(data2)))
{
using var data2 = new GlbLowLevelParser(AliciaPath, bytes).Parse();
using var loader2 = new VRMImporterContext(new VRMData(data2));
Assert.AreEqual(LookAtType.BlendShape, loader2.VRM.firstPerson.lookAtType);
}
}
@@ -48,13 +45,10 @@ namespace VRM
[Test]
public void VRMLookAtCurveMapWithFreezeTest()
{
var data = new GlbFileParser(AliciaPath).Parse();
byte[] bytes = default;
byte[] bytes;
CurveMapper horizontalInner = default;
using (data)
using (var loader = new VRMImporterContext(new VRMData(data)))
using (var loaded = loader.Load())
{
using var loaded = TestVrm0X.LoadPathAsBuiltInRP(AliciaPath);
loaded.ShowMeshes();
var go = loaded.gameObject;
@@ -63,13 +57,11 @@ namespace VRM
horizontalInner = lookAt.HorizontalInner;
var settings = ScriptableObject.CreateInstance<VRMExportSettings>();
settings.PoseFreeze = true;
bytes = VRMEditorExporter.Export(go, null, settings);
bytes = TestVrm0X.ExportAsBuiltInRP(go, settings);
}
using (var data2 = new GlbLowLevelParser(AliciaPath, bytes).Parse())
using (var loader = new VRMImporterContext(new VRMData(data2)))
using (var loaded = loader.Load())
{
using var loaded = TestVrm0X.LoadBytesAsBuiltInRP(bytes);
loaded.ShowMeshes();
var lookAt = loaded.GetComponent<VRMLookAtBoneApplyer>();
@@ -81,13 +73,10 @@ namespace VRM
[Test]
public void VRMLookAtCurveMapTest()
{
var data = new GlbFileParser(AliciaPath).Parse();
byte[] bytes = default;
byte[] bytes;
CurveMapper horizontalInner = default;
using (data)
using (var loader = new VRMImporterContext(new VRMData(data)))
using (var loaded = loader.Load())
{
using var loaded = TestVrm0X.LoadPathAsBuiltInRP(AliciaPath);
loaded.ShowMeshes();
var go = loaded.gameObject;
@@ -96,13 +85,11 @@ namespace VRM
horizontalInner = lookAt.HorizontalInner;
var settings = (VRMExportSettings)ScriptableObject.CreateInstance<VRMExportSettings>();
settings.PoseFreeze = false;
bytes = VRMEditorExporter.Export(go, null, settings);
bytes = TestVrm0X.ExportAsBuiltInRP(go, settings);
}
using (var data2 = new GlbLowLevelParser(AliciaPath, bytes).Parse())
using (var loader = new VRMImporterContext(new VRMData(data2)))
using (var loaded = loader.Load())
{
using var loaded = TestVrm0X.LoadBytesAsBuiltInRP(bytes);
loaded.ShowMeshes();
var lookAt = loaded.GetComponent<VRMLookAtBoneApplyer>();

View File

@@ -67,13 +67,21 @@ namespace VRM
var path = AliciaPath;
var loaded = Load(File.ReadAllBytes(path), path);
var exported = VRMExporter.Export(new UniGLTF.GltfExportSettings
var exportSettings = new GltfExportSettings
{
DivideVertexBuffer = true, // test this
ExportOnlyBlendShapePosition = true,
ExportTangents = false,
UseSparseAccessorForMorphTarget = true,
}, loaded, new EditorTextureSerializer());
};
var exported = new ExportingGltfData();
using var exporter = new VRMExporter(
exported,
exportSettings,
textureSerializer: new EditorTextureSerializer(),
materialExporter: new BuiltInVrmMaterialExporter());
exporter.Prepare(loaded);
exporter.Export();
var bytes = exported.ToGlbBytes();
var divided = Load(bytes, path);

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using UniGLTF;
using UnityEngine;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
@@ -15,23 +16,11 @@ namespace UniVRM10
public bool MigrateToVrm1 = default;
[SerializeField]
public UniGLTF.RenderPipelineTypes RenderPipeline = default;
public ImporterRenderPipelineTypes RenderPipeline = default;
public override void OnImportAsset(AssetImportContext ctx)
{
VrmScriptedImporterImpl.Import(this, ctx, MigrateToVrm1, RenderPipeline);
}
void OnValidate()
{
if (RenderPipeline == UniGLTF.RenderPipelineTypes.UniversalRenderPipeline)
{
if (Shader.Find(UniGLTF.UrpGltfPbrMaterialImporter.ShaderName) == null)
{
Debug.LogWarning("URP is not installed. Force to BuiltinRenderPipeline");
RenderPipeline = UniGLTF.RenderPipelineTypes.BuiltinRenderPipeline;
}
}
}
}
}

View File

@@ -15,23 +15,7 @@ namespace UniVRM10
{
public static class VrmScriptedImporterImpl
{
static IMaterialDescriptorGenerator GetMaterialDescriptorGenerator(RenderPipelineTypes renderPipeline)
{
var settings = Vrm10ProjectEditorSettings.instance;
if (settings.MaterialDescriptorGeneratorFactory != null)
{
return settings.MaterialDescriptorGeneratorFactory.Create();
}
return renderPipeline switch
{
RenderPipelineTypes.BuiltinRenderPipeline => new BuiltInVrm10MaterialDescriptorGenerator(),
RenderPipelineTypes.UniversalRenderPipeline => new UrpVrm10MaterialDescriptorGenerator(),
_ => throw new NotImplementedException()
};
}
static void Process(Vrm10Data result, ScriptedImporter scriptedImporter, AssetImportContext context, RenderPipelineTypes renderPipeline)
static void Process(Vrm10Data result, ScriptedImporter scriptedImporter, AssetImportContext context, ImporterRenderPipelineTypes renderPipeline)
{
//
// Import(create unity objects)
@@ -73,7 +57,7 @@ namespace UniVRM10
/// <param name="doMigrate">vrm0 だった場合に vrm1 化する</param>
/// <param name="renderPipeline"></param>
/// <param name="doNormalize">normalize する</param>
public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool doMigrate, RenderPipelineTypes renderPipeline)
public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool doMigrate, ImporterRenderPipelineTypes renderPipeline)
{
if (Symbols.VRM_DEVELOP)
{
@@ -113,5 +97,22 @@ namespace UniVRM10
return;
}
}
private static IMaterialDescriptorGenerator GetMaterialDescriptorGenerator(ImporterRenderPipelineTypes renderPipeline)
{
var settings = Vrm10ProjectEditorSettings.instance;
if (settings.MaterialDescriptorGeneratorFactory != null)
{
return settings.MaterialDescriptorGeneratorFactory.Create();
}
return renderPipeline switch
{
ImporterRenderPipelineTypes.Auto => Vrm10MaterialDescriptorGeneratorUtility.GetValidVrm10MaterialDescriptorGenerator(),
ImporterRenderPipelineTypes.BuiltinRenderPipeline => Vrm10MaterialDescriptorGeneratorUtility.GetVrm10MaterialDescriptorGenerator(RenderPipelineTypes.BuiltinRenderPipeline),
ImporterRenderPipelineTypes.UniversalRenderPipeline => Vrm10MaterialDescriptorGeneratorUtility.GetVrm10MaterialDescriptorGenerator(RenderPipelineTypes.UniversalRenderPipeline),
_ => Vrm10MaterialDescriptorGeneratorUtility.GetValidVrm10MaterialDescriptorGenerator(),
};
}
}
}

View File

@@ -311,7 +311,10 @@ namespace UniVRM10
model.ConvertCoordinate(VrmLib.Coordinates.Vrm1, ignoreVrm: false);
// export vrm-1.0
var exporter = new UniVRM10.Vrm10Exporter(new EditorTextureSerializer(), m_settings.MeshExportSettings);
var exporter = new Vrm10Exporter(
m_settings.MeshExportSettings,
textureSerializer: new EditorTextureSerializer()
);
var option = new VrmLib.ExportArgs
{
sparse = m_settings.MorphTargetUseSparse,

View File

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

Some files were not shown because too many files have changed in this diff Show More