From 786541e7357a2e252af68f8b4c3647434f668f6a Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 2 Aug 2024 19:46:48 +0900 Subject: [PATCH 01/11] breaking ! --- .../UniGLTF/Runtime/UniGLTF/PackageVersion.cs | 6 +- .../UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs | 6 +- .../UniGLTF/Samples~/GltfViewer/GltfViewer.cs | 2 +- .../OpenFileDialog/OpenFileDialog.cs | 4 +- .../Samples~/UniHumanoid/HumanBuilderTest.cs | 9 +- Assets/UniGLTF/package.json | 2 +- .../FirstPersonSample/VRMRuntimeLoader.cs | 3 +- .../VRMRuntimeExporter.cs | 3 +- Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs | 2 - Assets/VRM/package.json | 4 +- .../VRM10/Samples~/SimpleVrma/SimpleVrma.cs | 9 +- .../Samples~/URPSample/Runtime/UrpSampleUI.cs | 2 +- .../VRM10RuntimeLoader.cs | 11 +- .../VRM10RuntimeExporter.cs | 8 +- .../Samples~/VRM10Viewer/Motions/BvhMotion.cs | 5 +- .../Samples~/VRM10Viewer/VRM10TargetMover.cs | 1 - .../Samples~/VRM10Viewer/VRM10Viewer.unity | 528 +++--------------- .../Samples~/VRM10Viewer/VRM10ViewerUI.cs | 8 +- .../VRM10Viewer/VRM10VisualPrimitive.cs | 27 + .../VRM10Viewer/VRM10VisualPrimitive.cs.meta | 3 + Assets/VRM10/package.json | 4 +- ProjectSettings/UnityConnectSettings.asset | 18 +- 22 files changed, 160 insertions(+), 505 deletions(-) create mode 100644 Assets/VRM10/Samples~/VRM10Viewer/VRM10VisualPrimitive.cs create mode 100644 Assets/VRM10/Samples~/VRM10Viewer/VRM10VisualPrimitive.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/PackageVersion.cs b/Assets/UniGLTF/Runtime/UniGLTF/PackageVersion.cs index 3c4d84a63..ca987f215 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/PackageVersion.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/PackageVersion.cs @@ -4,8 +4,8 @@ namespace UniGLTF public static partial class PackageVersion { public const int MAJOR = 0; - public const int MINOR = 124; - public const int PATCH = 2; - public const string VERSION = "0.124.2"; + public const int MINOR = 125; + public const int PATCH = 0; + public const string VERSION = "0.125.0"; } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs b/Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs index e329b4d15..8e1140f1f 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs @@ -4,8 +4,8 @@ namespace UniGLTF public static partial class UniGLTFVersion { public const int MAJOR = 2; - public const int MINOR = 60; - public const int PATCH = 2; - public const string VERSION = "2.60.2"; + public const int MINOR = 61; + public const int PATCH = 0; + public const string VERSION = "2.61.0"; } } diff --git a/Assets/UniGLTF/Samples~/GltfViewer/GltfViewer.cs b/Assets/UniGLTF/Samples~/GltfViewer/GltfViewer.cs index fcdc21b31..dc8596b53 100644 --- a/Assets/UniGLTF/Samples~/GltfViewer/GltfViewer.cs +++ b/Assets/UniGLTF/Samples~/GltfViewer/GltfViewer.cs @@ -31,7 +31,7 @@ namespace UniGLTF.GltfViewer LoadPathAsync(path); } - async void LoadPathAsync(VRMShaders.PathObject path) + async void LoadPathAsync(PathObject path) { if (_instance) { diff --git a/Assets/UniGLTF/Samples~/GltfViewer/OpenFileDialog/OpenFileDialog.cs b/Assets/UniGLTF/Samples~/GltfViewer/OpenFileDialog/OpenFileDialog.cs index 2da319a5b..47695f73c 100644 --- a/Assets/UniGLTF/Samples~/GltfViewer/OpenFileDialog/OpenFileDialog.cs +++ b/Assets/UniGLTF/Samples~/GltfViewer/OpenFileDialog/OpenFileDialog.cs @@ -2,10 +2,10 @@ namespace UniGLTF.GltfViewer { public static class OpenFileDialog { - public static VRMShaders.PathObject Show(string title, params string[] extensions) + public static PathObject Show(string title, params string[] extensions) { #if UNITY_STANDALONE_WIN - return VRMShaders.PathObject.FromFullPath(FileDialogForWindows.FileDialog(title, extensions)); + return PathObject.FromFullPath(FileDialogForWindows.FileDialog(title, extensions)); #else UnityEngine.Debug.LogWarning("Non-Windows runtime file dialogs are not yet implemented."); return default; diff --git a/Assets/UniGLTF/Samples~/UniHumanoid/HumanBuilderTest.cs b/Assets/UniGLTF/Samples~/UniHumanoid/HumanBuilderTest.cs index b517b14dc..188eb73f3 100644 --- a/Assets/UniGLTF/Samples~/UniHumanoid/HumanBuilderTest.cs +++ b/Assets/UniGLTF/Samples~/UniHumanoid/HumanBuilderTest.cs @@ -119,7 +119,11 @@ namespace UniHumanoid builder.AddLeg(0.1f, 0.3f, 0.4f, 0.1f, 0.1f); var description = AvatarDescription.Create(builder.Skeleton); - var animator = GetComponentOrThrow(); + var animator = GetComponent(); + if (animator == null) + { + throw new System.ArgumentException("no animator"); + } animator.avatar = description.CreateAvatar(root); // create SkinnedMesh for bone visualize @@ -132,7 +136,8 @@ namespace UniHumanoid renderer.sharedMaterial = m_material; //root.gameObject.AddComponent(); - if (TryGetComponent(out var transfer)) + var transfer = GetComponent(); + if (transfer != null) { transfer.Avatar = animator.avatar; transfer.Setup(); diff --git a/Assets/UniGLTF/package.json b/Assets/UniGLTF/package.json index e4822d40d..a717e6305 100644 --- a/Assets/UniGLTF/package.json +++ b/Assets/UniGLTF/package.json @@ -1,6 +1,6 @@ { "name": "com.vrmc.gltf", - "version": "0.124.2", + "version": "0.125.0", "displayName": "UniGLTF", "description": "GLTF importer and exporter", "unity": "2021.3", diff --git a/Assets/VRM/Samples~/FirstPersonSample/VRMRuntimeLoader.cs b/Assets/VRM/Samples~/FirstPersonSample/VRMRuntimeLoader.cs index 3e19933bc..8ca9f94e0 100644 --- a/Assets/VRM/Samples~/FirstPersonSample/VRMRuntimeLoader.cs +++ b/Assets/VRM/Samples~/FirstPersonSample/VRMRuntimeLoader.cs @@ -3,7 +3,6 @@ using System.IO; using UniGLTF; using UnityEngine; - namespace VRM.FirstPersonSample { public class VRMRuntimeLoader : MonoBehaviour @@ -114,7 +113,7 @@ namespace VRM.FirstPersonSample var loaded = default(RuntimeGltfInstance); if (m_loadAsync) { - loaded = await context.LoadAsync(new VRMShaders.RuntimeOnlyAwaitCaller()); + loaded = await context.LoadAsync(new RuntimeOnlyAwaitCaller()); } else { diff --git a/Assets/VRM/Samples~/RuntimeExporterSample/VRMRuntimeExporter.cs b/Assets/VRM/Samples~/RuntimeExporterSample/VRMRuntimeExporter.cs index 7eaf769bc..5744a3b55 100644 --- a/Assets/VRM/Samples~/RuntimeExporterSample/VRMRuntimeExporter.cs +++ b/Assets/VRM/Samples~/RuntimeExporterSample/VRMRuntimeExporter.cs @@ -1,7 +1,6 @@ using System.IO; +using UniGLTF; using UnityEngine; -using VRMShaders; - namespace VRM.RuntimeExporterSample { diff --git a/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs b/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs index d227bf369..1093736e7 100644 --- a/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs +++ b/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs @@ -7,8 +7,6 @@ using UniGLTF; using UniHumanoid; using UnityEngine; using UnityEngine.UI; -using VRMShaders; - namespace VRM.SimpleViewer { diff --git a/Assets/VRM/package.json b/Assets/VRM/package.json index 4a527ae19..9740d2d5d 100644 --- a/Assets/VRM/package.json +++ b/Assets/VRM/package.json @@ -1,6 +1,6 @@ { "name": "com.vrmc.univrm", - "version": "0.124.2", + "version": "0.125.0", "displayName": "VRM", "description": "VRM importer", "unity": "2021.3", @@ -14,7 +14,7 @@ "name": "VRM Consortium" }, "dependencies": { - "com.vrmc.gltf": "0.124.2", + "com.vrmc.gltf": "0.125.0", "com.unity.ugui": "1.0.0" }, "samples": [ diff --git a/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.cs b/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.cs index 5db457913..cc8c2f25b 100644 --- a/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.cs +++ b/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.cs @@ -1,8 +1,7 @@ using UniGLTF; using UnityEngine; using UniVRM10; -using UniVRM10.VRM10Viewer; -using VRMShaders; + #if UNITY_EDITOR using UnityEditor; #endif @@ -47,7 +46,7 @@ public class SimpleVrma : MonoBehaviour showMeshes: false, awaitCaller: new ImmediateCaller()); - var instance = Vrm.GetComponentOrThrow(); + var instance = Vrm.GetComponent(); instance.ShowMeshes(); } @@ -58,11 +57,11 @@ public class SimpleVrma : MonoBehaviour using var loader = new VrmAnimationImporter(data); var instance = await loader.LoadAsync(new ImmediateCaller()); - Vrma = instance.GetComponentOrThrow(); + Vrma = instance.GetComponent(); Vrm.Runtime.VrmAnimation = Vrma; Debug.Log(Vrma); - var animation = Vrma.GetComponentOrThrow(); + var animation = Vrma.GetComponent(); animation.Play(); } } diff --git a/Assets/VRM10/Samples~/URPSample/Runtime/UrpSampleUI.cs b/Assets/VRM10/Samples~/URPSample/Runtime/UrpSampleUI.cs index 47d7a08f3..b952b4786 100644 --- a/Assets/VRM10/Samples~/URPSample/Runtime/UrpSampleUI.cs +++ b/Assets/VRM10/Samples~/URPSample/Runtime/UrpSampleUI.cs @@ -46,7 +46,7 @@ namespace UniVRM10.URPSample return; } - var instance = _loadedVrm.GetComponentOrThrow(); + var instance = _loadedVrm.GetComponent(); instance.ShowMeshes(); instance.EnableUpdateWhenOffscreen(); diff --git a/Assets/VRM10/Samples~/VRM10FirstPersonSample/VRM10RuntimeLoader.cs b/Assets/VRM10/Samples~/VRM10FirstPersonSample/VRM10RuntimeLoader.cs index 2ecba4ef7..d0b498891 100644 --- a/Assets/VRM10/Samples~/VRM10FirstPersonSample/VRM10RuntimeLoader.cs +++ b/Assets/VRM10/Samples~/VRM10FirstPersonSample/VRM10RuntimeLoader.cs @@ -33,7 +33,8 @@ namespace UniVRM10.FirstPersonSample m_target.Source = m_source; m_target.SourceType = UniHumanoid.HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer; - if (m_target.TryGetComponent(out var animator)) + var animator = m_target.GetComponent(); + if (animator != null) { if (m_faceCamera != null) { @@ -68,7 +69,7 @@ namespace UniVRM10.FirstPersonSample return; } - var instance = await LoadAsync(path, new VRMShaders.RuntimeOnlyAwaitCaller()); + var instance = await LoadAsync(path, new RuntimeOnlyAwaitCaller()); var root = instance.gameObject; root.transform.SetParent(transform, false); @@ -83,14 +84,14 @@ namespace UniVRM10.FirstPersonSample SetupTarget(m_target); } - async Task LoadAsync(string path, VRMShaders.IAwaitCaller awaitCaller) + async Task LoadAsync(string path, IAwaitCaller awaitCaller) { var instance = await Vrm10.LoadPathAsync(path, awaitCaller: awaitCaller, showMeshes: false); // VR用 FirstPerson 設定 await instance.Vrm.FirstPerson.SetupAsync(instance.gameObject, awaitCaller); - instance.GetComponentOrThrow().ShowMeshes(); + instance.GetComponent().ShowMeshes(); return instance; } @@ -126,7 +127,7 @@ namespace UniVRM10.FirstPersonSample { GameObject.Destroy(m_source.gameObject); } - m_source = context.Root.GetComponentOrThrow(); + m_source = context.Root.GetComponent(); SetupTarget(m_target); } diff --git a/Assets/VRM10/Samples~/VRM10RuntimeExporterSample/VRM10RuntimeExporter.cs b/Assets/VRM10/Samples~/VRM10RuntimeExporterSample/VRM10RuntimeExporter.cs index b99ce3bf9..f76da8c6b 100644 --- a/Assets/VRM10/Samples~/VRM10RuntimeExporterSample/VRM10RuntimeExporter.cs +++ b/Assets/VRM10/Samples~/VRM10RuntimeExporterSample/VRM10RuntimeExporter.cs @@ -1,7 +1,6 @@ using System.IO; using UniGLTF; using UnityEngine; -using VRMShaders; namespace UniVRM10.RuntimeExporterSample { @@ -47,7 +46,7 @@ namespace UniVRM10.RuntimeExporterSample } var vrm10 = await Vrm10.LoadPathAsync(path); - var loaded = vrm10.GetComponentOrThrow(); + var loaded = vrm10.GetComponent(); loaded.ShowMeshes(); loaded.EnableUpdateWhenOffscreen(); @@ -143,10 +142,7 @@ namespace UniVRM10.RuntimeExporterSample model.ConvertCoordinate(VrmLib.Coordinates.Vrm1, ignoreVrm: false); // export vrm-1.0 - var exporter = new UniVRM10.Vrm10Exporter(new RuntimeTextureSerializer(), new GltfExportSettings - { - - }); + var exporter = new Vrm10Exporter(new GltfExportSettings()); exporter.Export(root, model, converter, new VrmLib.ExportArgs { }, meta); diff --git a/Assets/VRM10/Samples~/VRM10Viewer/Motions/BvhMotion.cs b/Assets/VRM10/Samples~/VRM10Viewer/Motions/BvhMotion.cs index ffb925bb9..0cdac4631 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/Motions/BvhMotion.cs +++ b/Assets/VRM10/Samples~/VRM10Viewer/Motions/BvhMotion.cs @@ -28,7 +28,10 @@ namespace UniVRM10.VRM10Viewer // create SkinnedMesh for bone visualize var animator = m_context.Root.GetComponent(); m_boxMan = SkeletonMeshUtility.CreateRenderer(animator); - var material = new Material(Shader.Find("Standard")); + var tmpPrimitive = GameObject.CreatePrimitive(PrimitiveType.Quad); + var defaultMaterial = tmpPrimitive.GetComponent().sharedMaterial; + var material = new Material(defaultMaterial); + GameObject.Destroy(tmpPrimitive); BoxMan.sharedMaterial = material; var mesh = BoxMan.sharedMesh; mesh.name = "box-man"; diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10TargetMover.cs b/Assets/VRM10/Samples~/VRM10Viewer/VRM10TargetMover.cs index 7a37f1349..9311c436f 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/VRM10TargetMover.cs +++ b/Assets/VRM10/Samples~/VRM10Viewer/VRM10TargetMover.cs @@ -1,5 +1,4 @@ using System.Collections; -using System.Collections.Generic; using UnityEngine; diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10Viewer.unity b/Assets/VRM10/Samples~/VRM10Viewer/VRM10Viewer.unity index 54855ea3b..8e51e00c9 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/VRM10Viewer.unity +++ b/Assets/VRM10/Samples~/VRM10Viewer/VRM10Viewer.unity @@ -867,82 +867,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &251940583 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 251940584} - - component: {fileID: 251940586} - - component: {fileID: 251940585} - m_Layer: 5 - m_Name: Checkmark - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &251940584 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 251940583} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 452923209} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 20, y: 20} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!114 &251940585 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 251940583} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 - m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_Sprite: {fileID: 10901, guid: 0000000000000000f000000000000000, type: 0} - m_Type: 0 - m_PreserveAspect: 0 - m_FillCenter: 1 - m_FillMethod: 4 - m_FillAmount: 1 - m_FillClockwise: 1 - m_FillOrigin: 0 - m_UseSpriteMesh: 0 - m_PixelsPerUnitMultiplier: 1 ---- !u!222 &251940586 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 251940583} - m_CullTransparentMesh: 0 --- !u!1 &284921870 GameObject: m_ObjectHideFlags: 0 @@ -1113,11 +1037,9 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 322182885} - - component: {fileID: 322182888} - - component: {fileID: 322182887} - component: {fileID: 322182886} m_Layer: 0 - m_Name: Plane + m_Name: Floor m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -1138,70 +1060,19 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!23 &322182886 -MeshRenderer: +--- !u!114 &322182886 +MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 322182884} m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 1 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} ---- !u!64 &322182887 -MeshCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 322182884} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 4 - m_Convex: 0 - m_CookingOptions: 30 - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} ---- !u!33 &322182888 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 322182884} - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1e6b73d090be404cad1a0e9839366ce2, type: 3} + m_Name: + m_EditorClassIdentifier: + _primitiveType: 4 --- !u!1 &339774396 GameObject: m_ObjectHideFlags: 0 @@ -1250,7 +1121,6 @@ RectTransform: - {fileID: 634488421} - {fileID: 1767738854} - {fileID: 103723704} - - {fileID: 1438613464} - {fileID: 602093298} m_Father: {fileID: 124675794} m_RootOrder: 0 @@ -1480,83 +1350,6 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 20, y: 20} m_Pivot: {x: 0.5, y: 0.5} ---- !u!1 &452923208 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 452923209} - - component: {fileID: 452923211} - - component: {fileID: 452923210} - m_Layer: 5 - m_Name: Background - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &452923209 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 452923208} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: - - {fileID: 251940584} - m_Father: {fileID: 1438613464} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 1} - m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 10, y: -10} - m_SizeDelta: {x: 20, y: 20} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!114 &452923210 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 452923208} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 - m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} - m_Type: 1 - m_PreserveAspect: 0 - m_FillCenter: 1 - m_FillMethod: 4 - m_FillAmount: 1 - m_FillClockwise: 1 - m_FillOrigin: 0 - m_UseSpriteMesh: 0 - m_PixelsPerUnitMultiplier: 1 ---- !u!222 &452923211 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 452923208} - m_CullTransparentMesh: 0 --- !u!1 &488934504 GameObject: m_ObjectHideFlags: 0 @@ -1905,7 +1698,7 @@ RectTransform: - {fileID: 154330168} - {fileID: 1954133885} m_Father: {fileID: 339774397} - m_RootOrder: 18 + m_RootOrder: 17 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -2533,10 +2326,8 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 802105004} - - component: {fileID: 802105003} - - component: {fileID: 802105002} - - component: {fileID: 802105001} - component: {fileID: 802105005} + - component: {fileID: 802105006} m_Layer: 5 m_Name: LookAtTarget m_TagString: Untagged @@ -2544,69 +2335,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!23 &802105001 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 802105000} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 1 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} ---- !u!135 &802105002 -SphereCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 802105000} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Radius: 0.5 - m_Center: {x: 0, y: 0, z: 0} ---- !u!33 &802105003 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 802105000} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} --- !u!4 &802105004 Transform: m_ObjectHideFlags: 0 @@ -2638,6 +2366,19 @@ MonoBehaviour: m_angularVelocity: 40 m_y: 1.5 m_height: 3 +--- !u!114 &802105006 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 802105000} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1e6b73d090be404cad1a0e9839366ce2, type: 3} + m_Name: + m_EditorClassIdentifier: + _primitiveType: 0 --- !u!1 &806723448 GameObject: m_ObjectHideFlags: 0 @@ -5617,93 +5358,6 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1434602808} m_CullTransparentMesh: 0 ---- !u!1 &1438613463 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1438613464} - - component: {fileID: 1438613465} - m_Layer: 5 - m_Name: UseUrpMaterial - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &1438613464 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1438613463} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: - - {fileID: 452923209} - - {fileID: 2090837017} - m_Father: {fileID: 339774397} - m_RootOrder: 17 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 162, y: 20} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!114 &1438613465 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1438613463} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9085046f02f69544eb97fd06b6048fe2, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Navigation: - m_Mode: 3 - m_WrapAround: 0 - m_SelectOnUp: {fileID: 0} - m_SelectOnDown: {fileID: 0} - m_SelectOnLeft: {fileID: 0} - m_SelectOnRight: {fileID: 0} - m_Transition: 1 - m_Colors: - m_NormalColor: {r: 1, g: 1, b: 1, a: 1} - m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} - m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} - m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} - m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} - m_ColorMultiplier: 1 - m_FadeDuration: 0.1 - m_SpriteState: - m_HighlightedSprite: {fileID: 0} - m_PressedSprite: {fileID: 0} - m_SelectedSprite: {fileID: 0} - m_DisabledSprite: {fileID: 0} - m_AnimationTriggers: - m_NormalTrigger: Normal - m_HighlightedTrigger: Highlighted - m_PressedTrigger: Pressed - m_SelectedTrigger: Highlighted - m_DisabledTrigger: Disabled - m_Interactable: 1 - m_TargetGraphic: {fileID: 452923210} - toggleTransition: 1 - graphic: {fileID: 251940585} - m_Group: {fileID: 0} - onValueChanged: - m_PersistentCalls: - m_Calls: [] - m_IsOn: 0 --- !u!1 &1476033060 GameObject: m_ObjectHideFlags: 0 @@ -6033,6 +5687,7 @@ GameObject: - component: {fileID: 1629460661} - component: {fileID: 1629460658} - component: {fileID: 1629460657} + - component: {fileID: 1629460663} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -6121,6 +5776,39 @@ Transform: m_Father: {fileID: 241398689} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1629460663 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1629460656} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3} + m_Name: + m_EditorClassIdentifier: + m_RenderShadows: 1 + m_RequiresDepthTextureOption: 2 + m_RequiresOpaqueTextureOption: 2 + m_CameraType: 0 + m_Cameras: [] + m_RendererIndex: -1 + m_VolumeLayerMask: + serializedVersion: 2 + m_Bits: 1 + m_VolumeTrigger: {fileID: 0} + m_VolumeFrameworkUpdateModeOption: 2 + m_RenderPostProcessing: 0 + m_Antialiasing: 0 + m_AntialiasingQuality: 2 + m_StopNaN: 0 + m_Dithering: 0 + m_ClearDepth: 1 + m_AllowXRRendering: 1 + m_RequiresDepthTexture: 0 + m_RequiresColorTexture: 0 + m_Version: 2 --- !u!1 &1633219307 GameObject: m_ObjectHideFlags: 0 @@ -6828,7 +6516,6 @@ MonoBehaviour: m_enableLipSync: {fileID: 935566650} m_enableAutoBlink: {fileID: 634488422} m_enableAutoExpression: {fileID: 1767738855} - m_useUrpMaterial: {fileID: 1438613465} m_useAsync: {fileID: 602093299} m_target: {fileID: 802105000} m_motion: {fileID: 4900000, guid: 08df5151e71aed748b13547492fb8b9a, type: 3} @@ -7771,86 +7458,6 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2055567528} m_CullTransparentMesh: 1 ---- !u!1 &2090837016 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 2090837017} - - component: {fileID: 2090837019} - - component: {fileID: 2090837018} - m_Layer: 5 - m_Name: Label - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &2090837017 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2090837016} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 1438613464} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 9, y: -0.5} - m_SizeDelta: {x: -28, y: -3} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!114 &2090837018 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2090837016} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} - m_RaycastTarget: 1 - m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_FontData: - m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} - m_FontSize: 14 - m_FontStyle: 0 - m_BestFit: 0 - m_MinSize: 10 - m_MaxSize: 40 - m_Alignment: 0 - m_AlignByGeometry: 0 - m_RichText: 1 - m_HorizontalOverflow: 0 - m_VerticalOverflow: 0 - m_LineSpacing: 1 - m_Text: Use URP Material ---- !u!222 &2090837019 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2090837016} - m_CullTransparentMesh: 0 --- !u!1 &2105159131 GameObject: m_ObjectHideFlags: 0 @@ -7942,6 +7549,7 @@ GameObject: m_Component: - component: {fileID: 2141451818} - component: {fileID: 2141451817} + - component: {fileID: 2141451819} m_Layer: 0 m_Name: Directional Light m_TagString: Untagged @@ -8026,3 +7634,23 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 50, y: -210, z: 0} +--- !u!114 &2141451819 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2141451816} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 474bcb49853aa07438625e644c072ee6, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Version: 1 + m_UsePipelineSettings: 1 + m_AdditionalLightsShadowResolutionTier: 2 + m_LightLayerMask: 1 + m_CustomShadowLayers: 0 + m_ShadowLayerMask: 1 + m_LightCookieSize: {x: 1, y: 1} + m_LightCookieOffset: {x: 0, y: 0} diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs index f0f842ae2..91595b59f 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs @@ -5,7 +5,6 @@ using System.Threading; using UniGLTF; using UnityEngine; using UnityEngine.UI; -using VRMShaders; namespace UniVRM10.VRM10Viewer { @@ -42,9 +41,6 @@ namespace UniVRM10.VRM10Viewer [SerializeField] Toggle m_enableAutoExpression = default; - [SerializeField] - Toggle m_useUrpMaterial = default; - [SerializeField] Toggle m_useAsync = default; @@ -270,7 +266,6 @@ namespace UniVRM10.VRM10Viewer m_enableLipSync = toggles.First(x => x.name == "EnableLipSync"); m_enableAutoBlink = toggles.First(x => x.name == "EnableAutoBlink"); m_enableAutoExpression = toggles.First(x => x.name == "EnableAutoExpression"); - m_useUrpMaterial = toggles.First(x => x.name == "UseUrpMaterial"); m_useAsync = toggles.First(x => x.name == "UseAsync"); #if UNITY_2022_3_OR_NEWER @@ -545,8 +540,7 @@ namespace UniVRM10.VRM10Viewer var vrm10Instance = await Vrm10.LoadPathAsync(path, canLoadVrm0X: true, showMeshes: false, - awaitCaller: m_useAsync.enabled ? (IAwaitCaller)new RuntimeOnlyAwaitCaller() : (IAwaitCaller)new ImmediateCaller(), - materialGenerator: GetVrmMaterialDescriptorGenerator(m_useUrpMaterial.isOn), + awaitCaller: m_useAsync.enabled ? new RuntimeOnlyAwaitCaller() : new ImmediateCaller(), vrmMetaInformationCallback: m_texts.UpdateMeta, ct: cancellationToken); if (cancellationToken.IsCancellationRequested) diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10VisualPrimitive.cs b/Assets/VRM10/Samples~/VRM10Viewer/VRM10VisualPrimitive.cs new file mode 100644 index 000000000..05ea35def --- /dev/null +++ b/Assets/VRM10/Samples~/VRM10Viewer/VRM10VisualPrimitive.cs @@ -0,0 +1,27 @@ +using UnityEngine; + +namespace UniVRM10.VRM10Viewer +{ + /// + /// Built-in RP と URP の差異を楽に吸収してプリミティブを表示するためのクラス + /// + public class VRM10VisualPrimitive : MonoBehaviour + { + [SerializeField] private PrimitiveType _primitiveType; + + public PrimitiveType PrimitiveType + { + get => _primitiveType; + set => _primitiveType = value; + } + + private void Start() + { + var visual = GameObject.CreatePrimitive(_primitiveType); + visual.transform.SetParent(transform); + visual.transform.localPosition = Vector3.zero; + visual.transform.localRotation = Quaternion.identity; + visual.transform.localScale = Vector3.one; + } + } +} \ No newline at end of file diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10VisualPrimitive.cs.meta b/Assets/VRM10/Samples~/VRM10Viewer/VRM10VisualPrimitive.cs.meta new file mode 100644 index 000000000..d99639d67 --- /dev/null +++ b/Assets/VRM10/Samples~/VRM10Viewer/VRM10VisualPrimitive.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1e6b73d090be404cad1a0e9839366ce2 +timeCreated: 1721736320 \ No newline at end of file diff --git a/Assets/VRM10/package.json b/Assets/VRM10/package.json index 3e977bd0d..a53cda1ba 100644 --- a/Assets/VRM10/package.json +++ b/Assets/VRM10/package.json @@ -1,6 +1,6 @@ { "name": "com.vrmc.vrm", - "version": "0.124.2", + "version": "0.125.0", "displayName": "VRM-1.0", "description": "VRM-1.0 importer", "unity": "2021.3", @@ -14,7 +14,7 @@ "name": "VRM Consortium" }, "dependencies": { - "com.vrmc.gltf": "0.124.2" + "com.vrmc.gltf": "0.125.0" }, "samples": [ { diff --git a/ProjectSettings/UnityConnectSettings.asset b/ProjectSettings/UnityConnectSettings.asset index ec1ab2929..a88bee0f1 100644 --- a/ProjectSettings/UnityConnectSettings.asset +++ b/ProjectSettings/UnityConnectSettings.asset @@ -3,30 +3,34 @@ --- !u!310 &1 UnityConnectSettings: m_ObjectHideFlags: 0 + serializedVersion: 1 m_Enabled: 0 m_TestMode: 0 - m_TestEventUrl: - m_TestConfigUrl: + m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events + m_EventUrl: https://cdp.cloud.unity3d.com/v1/events + m_ConfigUrl: https://config.uca.cloud.unity3d.com + m_DashboardUrl: https://dashboard.unity3d.com m_TestInitMode: 0 CrashReportingSettings: - m_EventUrl: https://perf-events.cloud.unity3d.com/api/events/crashes + m_EventUrl: https://perf-events.cloud.unity3d.com m_Enabled: 0 + m_LogBufferSize: 10 m_CaptureEditorExceptions: 1 UnityPurchasingSettings: m_Enabled: 0 m_TestMode: 0 UnityAnalyticsSettings: m_Enabled: 0 - m_InitializeOnStartup: 1 m_TestMode: 0 - m_TestEventUrl: - m_TestConfigUrl: + m_InitializeOnStartup: 1 + m_PackageRequiringCoreStatsPresent: 0 UnityAdsSettings: m_Enabled: 0 m_InitializeOnStartup: 1 m_TestMode: 0 - m_EnabledPlatforms: 4294967295 m_IosGameId: m_AndroidGameId: + m_GameIds: {} + m_GameId: PerformanceReportingSettings: m_Enabled: 0 From 182fdbe8b046b50b3384f23dbd26d07d672ee69c Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Sat, 3 Aug 2024 01:00:21 +0900 Subject: [PATCH 02/11] Implements UrpUniUnlitMaterialExporter --- .../Materials/UrpUniUnlitMaterialExporter.cs | 74 +++++++++++++++++ .../UrpUniUnlitMaterialExporter.cs.meta | 3 + .../UniUnlit/Runtime/UniUnlitContext.cs | 80 +++++++++++++++++++ .../UniUnlit/Runtime/UniUnlitContext.cs.meta | 3 + 4 files changed, 160 insertions(+) create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs.meta create mode 100644 Assets/UniGLTF/UniUnlit/Runtime/UniUnlitContext.cs create mode 100644 Assets/UniGLTF/UniUnlit/Runtime/UniUnlitContext.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs new file mode 100644 index 000000000..5a34299dd --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs @@ -0,0 +1,74 @@ +using System; +using UniGLTF.UniUnlit; +using UnityEngine; + +namespace UniGLTF +{ + public class UrpUniUnlitMaterialExporter + { + public Shader Shader { get; set; } + + /// + /// "UniGLTF/UniUnlit" シェーダのマテリアルをエクスポートする。 + /// + /// プロパティに互換性がある他のシェーダを指定することもできる。 + /// + 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 (src.shader != Shader) throw new ArgumentException(nameof(src)); + if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); + + 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 (Exception e) + { + Debug.LogException(e); + dst = default; + return false; + } + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs.meta new file mode 100644 index 000000000..1c986fd4f --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5b17f3928c684fc1a9beda10797b0e76 +timeCreated: 1722613258 \ No newline at end of file diff --git a/Assets/UniGLTF/UniUnlit/Runtime/UniUnlitContext.cs b/Assets/UniGLTF/UniUnlit/Runtime/UniUnlitContext.cs new file mode 100644 index 000000000..5f3573aba --- /dev/null +++ b/Assets/UniGLTF/UniUnlit/Runtime/UniUnlitContext.cs @@ -0,0 +1,80 @@ +using UnityEngine; + +namespace UniGLTF.UniUnlit +{ + public class UniUnlitContext + { + public Material Material { get; } + public bool UnsafeEditMode { get; set; } = false; + + public UniUnlitContext(Material material) + { + Material = material; + } + + public UniUnlitRenderMode RenderMode + { + get => UniUnlitUtil.GetRenderMode(Material); + set + { + UniUnlitUtil.SetRenderMode(Material, value); + if (!UnsafeEditMode) UniUnlitUtil.ValidateProperties(Material, isRenderModeChangedByUser: true); + } + } + + public UniUnlitCullMode CullMode + { + get => UniUnlitUtil.GetCullMode(Material); + set + { + UniUnlitUtil.SetCullMode(Material, value); + if (!UnsafeEditMode) UniUnlitUtil.ValidateProperties(Material); + } + } + + public UniUnlitVertexColorBlendOp VColBlendMode + { + get => UniUnlitUtil.GetVColBlendMode(Material); + set + { + UniUnlitUtil.SetVColBlendMode(Material, value); + if (!UnsafeEditMode) UniUnlitUtil.ValidateProperties(Material); + } + } + + public Color MainColorSrgb + { + get => Material.GetColor(UniUnlitUtil.PropNameColor); + set => Material.SetColor(UniUnlitUtil.PropNameColor, value); + } + + public Texture MainTexture + { + get => Material.GetTexture(UniUnlitUtil.PropNameMainTex); + set => Material.SetTexture(UniUnlitUtil.PropNameMainTex, value); + } + + public Vector2 MainTextureOffset + { + get => Material.GetTextureOffset(UniUnlitUtil.PropNameMainTex); + set => Material.SetTextureOffset(UniUnlitUtil.PropNameMainTex, value); + } + + public Vector2 MainTextureScale + { + get => Material.GetTextureScale(UniUnlitUtil.PropNameMainTex); + set => Material.SetTextureScale(UniUnlitUtil.PropNameMainTex, value); + } + + public float Cutoff + { + get => Material.GetFloat(UniUnlitUtil.PropNameCutoff); + set => Material.SetFloat(UniUnlitUtil.PropNameCutoff, value); + } + + public void Validate() + { + UniUnlitUtil.ValidateProperties(Material, isRenderModeChangedByUser: true); + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/UniUnlit/Runtime/UniUnlitContext.cs.meta b/Assets/UniGLTF/UniUnlit/Runtime/UniUnlitContext.cs.meta new file mode 100644 index 000000000..77c89e884 --- /dev/null +++ b/Assets/UniGLTF/UniUnlit/Runtime/UniUnlitContext.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 57963fbf465047bf83ed829f8a0022d3 +timeCreated: 1722613449 \ No newline at end of file From d3439abc528abe8563ac1b1a4ce950d3717aa77b Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Sat, 3 Aug 2024 01:00:53 +0900 Subject: [PATCH 03/11] Implements UrpFallbackMaterialExporter --- .../Materials/UrpFallbackMaterialExporter.cs | 36 +++++++++++++++++++ .../UrpFallbackMaterialExporter.cs.meta | 3 ++ 2 files changed, 39 insertions(+) create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs new file mode 100644 index 000000000..c590d4e93 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs @@ -0,0 +1,36 @@ +using System; +using UnityEngine; + +namespace UniGLTF +{ + /// + /// フォールバック目的で最低限なにかをエクスポートする。 + /// + /// メインカラーとメインテクスチャをエクスポートする。 + /// + 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; + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs.meta new file mode 100644 index 000000000..908fd8446 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpFallbackMaterialExporter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c0269be076674f5988895ecd61b8d316 +timeCreated: 1722612454 \ No newline at end of file From ee1bdc701f079e1f79c8d95e1a613115f9457a46 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Sat, 3 Aug 2024 01:02:12 +0900 Subject: [PATCH 04/11] add exporting support UniUnlit in URP --- .../MaterialIO/URP/Export/UrpGltfMaterialExporter.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs index 01391fe22..f15cc756d 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs @@ -4,15 +4,17 @@ namespace UniGLTF { public class UrpGltfMaterialExporter : IMaterialExporter { - private readonly UrpLitMaterialExporter _litExporter = new(); + public UrpLitMaterialExporter UrpLitExporter { get; set; } = new(); + public UrpUniUnlitMaterialExporter UrpUniUnlitExporter { get; set; } = new(); + public UrpFallbackMaterialExporter FallbackExporter { get; set; } = new(); public glTFMaterial ExportMaterial(Material m, ITextureExporter textureExporter, GltfExportSettings settings) { - glTFMaterial dst; + if (UrpLitExporter.TryExportMaterial(m, textureExporter, out var dst)) return dst; + if (UrpUniUnlitExporter.TryExportMaterial(m, textureExporter, out dst)) return dst; - if (_litExporter.TryExportMaterial(m, textureExporter, out dst)) return dst; - - return dst; + Debug.Log($"Material `{m.name}` fallbacks."); + return FallbackExporter.ExportMaterial(m, textureExporter); } } } \ No newline at end of file From 39c01b2966bc1da05be8670904f4babd513f77af Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Sat, 3 Aug 2024 01:02:33 +0900 Subject: [PATCH 05/11] Refactoring --- .../Export/Materials/UrpLitMaterialExporter.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs index 98563c555..96faa86e5 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs @@ -7,18 +7,16 @@ namespace UniGLTF { public class UrpLitMaterialExporter { - public string TargetShaderName { get; } + public Shader Shader { get; set; } /// /// "Universal Render Pipeline/Lit" シェーダのマテリアルをエクスポートする。 /// - /// targetShaderName に、プロパティに互換性がある他のシェーダを指定することもできる。 + /// プロパティに互換性がある他のシェーダを指定することもできる。 /// - public UrpLitMaterialExporter(string targetShaderName = null) + public UrpLitMaterialExporter(Shader shader = null) { - TargetShaderName = string.IsNullOrEmpty(targetShaderName) - ? "Universal Render Pipeline/Lit" - : targetShaderName; + Shader = shader != null ? shader : Shader.Find("Universal Render Pipeline/Lit"); } public bool TryExportMaterial(Material src, ITextureExporter textureExporter, out glTFMaterial dst) @@ -26,7 +24,7 @@ namespace UniGLTF try { if (src == null) throw new ArgumentNullException(nameof(src)); - if (src.shader.name != TargetShaderName) throw new ArgumentException(nameof(src)); + if (src.shader != Shader) throw new ArgumentException(nameof(src)); if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); dst = new glTFMaterial @@ -54,8 +52,9 @@ namespace UniGLTF return true; } - catch (Exception) + catch (Exception e) { + Debug.LogException(e); dst = default; return false; } From 5f7a38989c922b7ba3f564efe7326fae8e6053ae Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Sat, 3 Aug 2024 01:12:54 +0900 Subject: [PATCH 06/11] Implements Universal Render Pipeline/Unlit Material Exporter --- .../Materials/UrpUnlitMaterialExporter.cs | 46 +++++++++++++++++++ .../UrpUnlitMaterialExporter.cs.meta | 3 ++ .../URP/Export/UrpGltfMaterialExporter.cs | 2 + 3 files changed, 51 insertions(+) create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs new file mode 100644 index 000000000..93d9a4996 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs @@ -0,0 +1,46 @@ +using System; +using UnityEngine; + +namespace UniGLTF +{ + public class UrpUnlitMaterialExporter + { + public Shader Shader { get; set; } + + /// + /// "Universal Render Pipeline/Unlit" シェーダのマテリアルをエクスポートする。 + /// + /// プロパティに互換性がある他のシェーダを指定することもできる。 + /// + 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 (src.shader != Shader) throw new ArgumentException(nameof(src)); + if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); + + dst = glTF_KHR_materials_unlit.CreateDefault(); + dst.name = src.name; + + var context = new UrpLitContext(src); + + UrpLitMaterialExporter.ExportSurfaceSettings(context, dst, textureExporter); + UrpLitMaterialExporter.ExportBaseColor(context, dst, textureExporter); + + return true; + } + catch (Exception e) + { + Debug.LogException(e); + dst = default; + return false; + } + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs.meta new file mode 100644 index 000000000..9924e9e80 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a90bb1e911744bbab916950324c70e52 +timeCreated: 1722614768 \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs index f15cc756d..e1f1d5921 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs @@ -5,12 +5,14 @@ namespace UniGLTF public class UrpGltfMaterialExporter : IMaterialExporter { public UrpLitMaterialExporter UrpLitExporter { get; set; } = new(); + public UrpUnlitMaterialExporter UrpUnlitExporter { get; set; } = new(); public UrpUniUnlitMaterialExporter UrpUniUnlitExporter { get; set; } = new(); public UrpFallbackMaterialExporter FallbackExporter { get; set; } = new(); public glTFMaterial ExportMaterial(Material m, ITextureExporter textureExporter, GltfExportSettings settings) { if (UrpLitExporter.TryExportMaterial(m, textureExporter, out var dst)) return dst; + if (UrpUnlitExporter.TryExportMaterial(m, textureExporter, out dst)) return dst; if (UrpUniUnlitExporter.TryExportMaterial(m, textureExporter, out dst)) return dst; Debug.Log($"Material `{m.name}` fallbacks."); From 0e0455f7d8fff797c04492a4ebe8bae35ba67100 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Sat, 3 Aug 2024 01:38:34 +0900 Subject: [PATCH 07/11] Implements UrpUnlitContext --- .../ShaderUtil/Lit/UrpBaseShaderContext.cs | 163 ++++++++++++ .../Lit/UrpBaseShaderContext.cs.meta | 3 + .../URP/ShaderUtil/Lit/UrpLitContext.cs | 245 ++++-------------- .../URP/ShaderUtil/Lit/UrpUnlitContext.cs | 12 + .../ShaderUtil/Lit/UrpUnlitContext.cs.meta | 3 + 5 files changed, 231 insertions(+), 195 deletions(-) create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpBaseShaderContext.cs create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpBaseShaderContext.cs.meta create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpUnlitContext.cs create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpUnlitContext.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpBaseShaderContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpBaseShaderContext.cs new file mode 100644 index 000000000..241203156 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpBaseShaderContext.cs @@ -0,0 +1,163 @@ +using UnityEngine; +using UnityEngine.Rendering; + +namespace UniGLTF +{ + public abstract class UrpBaseShaderContext + { + private static readonly int Surface = Shader.PropertyToID("_Surface"); + private static readonly int AlphaClip = Shader.PropertyToID("_AlphaClip"); + private static readonly int Blend = Shader.PropertyToID("_Blend"); + private static readonly int Cull = Shader.PropertyToID("_Cull"); + private static readonly int BaseColorProp = Shader.PropertyToID("_BaseColor"); + private static readonly int BaseMap = Shader.PropertyToID("_BaseMap"); + private static readonly int CutoffProp = Shader.PropertyToID("_Cutoff"); + private static readonly int ZWrite = Shader.PropertyToID("_ZWrite"); + private static readonly int SrcBlend = Shader.PropertyToID("_SrcBlend"); + private static readonly int DstBlend = Shader.PropertyToID("_DstBlend"); + private static readonly string SurfaceTypeTransparentKeyword = "_SURFACE_TYPE_TRANSPARENT"; + private static readonly string AlphaTestOnKeyword = "_ALPHATEST_ON"; + private static readonly string AlphaPremultiplyOnKeyword = "_ALPHAPREMULTIPLY_ON"; + private static readonly string AlphaModulateOnKeyword = "_ALPHAMODULATE_ON"; + + protected UrpBaseShaderContext(Material material) + { + Material = material; + } + + public Material Material { get; } + + /// + /// これが有効な場合、Validate() 関数が呼ばれるべき場合でも自動的に呼ばれなくなります。 + /// + /// 処理最適化目的で使用できます。 + /// + public bool UnsafeEditMode { get; set; } = false; + + public UrpLitSurfaceType SurfaceType + { + get => (UrpLitSurfaceType)Material.GetFloat(Surface); + set + { + Material.SetFloat(Surface, (float)value); + if (!UnsafeEditMode) Validate(); + } + } + + public UrpLitBlendMode BlendMode + { + get => (UrpLitBlendMode)Material.GetFloat(Blend); + set + { + Material.SetFloat(Blend, (float)value); + if (!UnsafeEditMode) Validate(); + } + } + + public bool IsAlphaClipEnabled + { + get => Material.GetFloat(AlphaClip) >= 0.5f; + set + { + Material.SetFloat(AlphaClip, value ? 1.0f : 0.0f); + if (!UnsafeEditMode) Validate(); + } + } + + public CullMode CullMode + { + get => (CullMode)Material.GetFloat(Cull); + set + { + Material.SetFloat(Cull, (float)value); + Material.doubleSidedGI = value != CullMode.Back; + } + } + + public Color BaseColorSrgb + { + get => Material.GetColor(BaseColorProp); + set => Material.SetColor(BaseColorProp, value); + } + + public Texture BaseTexture + { + get => Material.GetTexture(BaseMap); + set => Material.SetTexture(BaseMap, value); + } + + public Vector2 BaseTextureOffset + { + get => Material.GetTextureOffset(BaseMap); + set => Material.SetTextureOffset(BaseMap, value); + } + + public Vector2 BaseTextureScale + { + get => Material.GetTextureScale(BaseMap); + set => Material.SetTextureScale(BaseMap, value); + } + + public float Cutoff + { + get => Material.GetFloat(CutoffProp); + set => Material.SetFloat(CutoffProp, value); + } + + + public virtual void Validate() + { + // Surface Type + var surfaceType = (UrpLitSurfaceType)Material.GetFloat(Surface); + Material.SetKeyword(SurfaceTypeTransparentKeyword, surfaceType != UrpLitSurfaceType.Opaque); + + // Alpha Clip + var alphaClip = Material.GetFloat(AlphaClip) >= 0.5f; + Material.SetKeyword(AlphaTestOnKeyword, alphaClip); + + // Blend Mode + var blendMode = (UrpLitBlendMode)Material.GetFloat(Blend); + Material.SetKeyword(AlphaPremultiplyOnKeyword, blendMode == UrpLitBlendMode.Premultiply); + Material.SetKeyword(AlphaModulateOnKeyword, blendMode == UrpLitBlendMode.Additive); + + // ZWrite + var zWrite = surfaceType == UrpLitSurfaceType.Opaque; + Material.SetFloat(ZWrite, zWrite ? 1.0f : 0.0f); + Material.SetShaderPassEnabled("DepthOnly", zWrite); + + // Render Settings + Material.SetFloat(SrcBlend, (surfaceType, blendMode) switch + { + (UrpLitSurfaceType.Opaque, _) => (float)UnityEngine.Rendering.BlendMode.One, + (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Alpha) => (float)UnityEngine.Rendering.BlendMode.SrcAlpha, + (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Premultiply) => (float)UnityEngine.Rendering.BlendMode.One, + (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Additive) => (float)UnityEngine.Rendering.BlendMode.One, + (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Multiply) => (float)UnityEngine.Rendering.BlendMode.DstColor, + _ => (float)UnityEngine.Rendering.BlendMode.One, + }); + Material.SetFloat(DstBlend, (surfaceType, blendMode) switch + { + (UrpLitSurfaceType.Opaque, _) => (float)UnityEngine.Rendering.BlendMode.Zero, + (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Alpha) => (float)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha, + (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Premultiply) => (float)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha, + (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Additive) => (float)UnityEngine.Rendering.BlendMode.One, + (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Multiply) => (float)UnityEngine.Rendering.BlendMode.Zero, + _ => (float) UnityEngine.Rendering.BlendMode.Zero, + }); + Material.SetOverrideTag("RenderType", (surfaceType, alphaClip) switch + { + (UrpLitSurfaceType.Opaque, false) => "Opaque", + (UrpLitSurfaceType.Opaque, true) => "TransparentCutout", + (UrpLitSurfaceType.Transparent, _) => "Transparent", + _ => "Opaque", + }); + Material.renderQueue = (surfaceType, alphaClip) switch + { + (UrpLitSurfaceType.Opaque, false) => (int)RenderQueue.Geometry, + (UrpLitSurfaceType.Opaque, true) => (int)RenderQueue.AlphaTest, + (UrpLitSurfaceType.Transparent, _) => (int)RenderQueue.Transparent, + _ => Material.shader.renderQueue, + }; + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpBaseShaderContext.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpBaseShaderContext.cs.meta new file mode 100644 index 000000000..2d2ffbfbd --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpBaseShaderContext.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a0a218f533e64925a87626ce8129f264 +timeCreated: 1722615731 \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpLitContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpLitContext.cs index da8b430b2..920454f63 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpLitContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpLitContext.cs @@ -15,22 +15,13 @@ namespace UniGLTF /// - Environment Reflections Toggle /// - Sorting Priority /// - public class UrpLitContext + public class UrpLitContext : UrpBaseShaderContext { - private readonly Material _mat; - private static readonly int WorkflowMode = Shader.PropertyToID("_WorkflowMode"); - private static readonly int Surface = Shader.PropertyToID("_Surface"); - private static readonly int AlphaClip = Shader.PropertyToID("_AlphaClip"); - private static readonly int Blend = Shader.PropertyToID("_Blend"); - private static readonly int Cull = Shader.PropertyToID("_Cull"); - private static readonly int BaseColorProp = Shader.PropertyToID("_BaseColor"); - private static readonly int BaseMap = Shader.PropertyToID("_BaseMap"); private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor"); private static readonly int EmissionMap = Shader.PropertyToID("_EmissionMap"); private static readonly int OcclusionMap = Shader.PropertyToID("_OcclusionMap"); private static readonly int ParallaxMap = Shader.PropertyToID("_ParallaxMap"); - private static readonly int CutoffProp = Shader.PropertyToID("_Cutoff"); private static readonly int SmoothnessProp = Shader.PropertyToID("_Smoothness"); private static readonly int SmoothnessTextureChannelProp = Shader.PropertyToID("_SmoothnessTextureChannel"); private static readonly int MetallicProp = Shader.PropertyToID("_Metallic"); @@ -39,131 +30,45 @@ namespace UniGLTF private static readonly int SpecGlossMapProp = Shader.PropertyToID("_SpecGlossMap"); private static readonly int BumpScaleProp = Shader.PropertyToID("_BumpScale"); private static readonly int BumpMapProp = Shader.PropertyToID("_BumpMap"); - private static readonly int ZWrite = Shader.PropertyToID("_ZWrite"); - private static readonly int SrcBlend = Shader.PropertyToID("_SrcBlend"); - private static readonly int DstBlend = Shader.PropertyToID("_DstBlend"); private static readonly string SpecularSetupKeyword = "_SPECULAR_SETUP"; private static readonly string MetallicSpecGlossMapKeyword = "_METALLICSPECGLOSSMAP"; - private static readonly string SurfaceTypeTransparentKeyword = "_SURFACE_TYPE_TRANSPARENT"; private static readonly string SmoothnessTextureAlbedoChannelAKeyword = "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A"; private static readonly string NormalMapKeyword = "_NORMALMAP"; private static readonly string EmissionKeyword = "_EMISSION"; private static readonly string OcclusionMapKeyword = "_OCCLUSIONMAP"; private static readonly string ParallaxMapKeyword = "_PARALLAXMAP"; - private static readonly string AlphaTestOnKeyword = "_ALPHATEST_ON"; - private static readonly string AlphaPremultiplyOnKeyword = "_ALPHAPREMULTIPLY_ON"; - private static readonly string AlphaModulateOnKeyword = "_ALPHAMODULATE_ON"; private static readonly int OcclusionStrengthProp = Shader.PropertyToID("_OcclusionStrength"); private static readonly int ParallaxProp = Shader.PropertyToID("_Parallax"); - public UrpLitContext(Material material) + public UrpLitContext(Material material) : base(material) { - _mat = material; + } - public Material Material => _mat; - - /// - /// これが有効な場合、Validate() 関数が呼ばれるべき場合でも自動的に呼ばれなくなります。 - /// - /// 処理最適化目的で使用できます。 - /// - public bool UnsafeEditMode { get; set; } = false; - public UrpLitWorkflowType WorkflowType { - get => (UrpLitWorkflowType)_mat.GetFloat(WorkflowMode); + get => (UrpLitWorkflowType)Material.GetFloat(WorkflowMode); set { - _mat.SetFloat(WorkflowMode, (float)value); + Material.SetFloat(WorkflowMode, (float)value); if (!UnsafeEditMode) Validate(); } } - public UrpLitSurfaceType SurfaceType - { - get => (UrpLitSurfaceType)_mat.GetFloat(Surface); - set - { - _mat.SetFloat(Surface, (float)value); - if (!UnsafeEditMode) Validate(); - } - } - - public UrpLitBlendMode BlendMode - { - get => (UrpLitBlendMode)_mat.GetFloat(Blend); - set - { - _mat.SetFloat(Blend, (float)value); - if (!UnsafeEditMode) Validate(); - } - } - - public bool IsAlphaClipEnabled - { - get => _mat.GetFloat(AlphaClip) >= 0.5f; - set - { - _mat.SetFloat(AlphaClip, value ? 1.0f : 0.0f); - if (!UnsafeEditMode) Validate(); - } - } - - public CullMode CullMode - { - get => (CullMode)_mat.GetFloat(Cull); - set - { - _mat.SetFloat(Cull, (float)value); - _mat.doubleSidedGI = value != CullMode.Back; - } - } - - public Color BaseColorSrgb - { - get => _mat.GetColor(BaseColorProp); - set => _mat.SetColor(BaseColorProp, value); - } - - public Texture BaseTexture - { - get => _mat.GetTexture(BaseMap); - set => _mat.SetTexture(BaseMap, value); - } - - public Vector2 BaseTextureOffset - { - get => _mat.GetTextureOffset(BaseMap); - set => _mat.SetTextureOffset(BaseMap, value); - } - - public Vector2 BaseTextureScale - { - get => _mat.GetTextureScale(BaseMap); - set => _mat.SetTextureScale(BaseMap, value); - } - - public float Cutoff - { - get => _mat.GetFloat(CutoffProp); - set => _mat.SetFloat(CutoffProp, value); - } - public float Smoothness { - get => _mat.GetFloat(SmoothnessProp); - set => _mat.SetFloat(SmoothnessProp, value); + get => Material.GetFloat(SmoothnessProp); + set => Material.SetFloat(SmoothnessProp, value); } public UrpLitSmoothnessMapChannel SmoothnessTextureChannel { // NOTE: Float Prop 以外に条件があるので、Keyword から読み取った方が確実 - get => _mat.IsKeywordEnabled(SmoothnessTextureAlbedoChannelAKeyword) ? UrpLitSmoothnessMapChannel.AlbedoAlpha : UrpLitSmoothnessMapChannel.SpecularMetallicAlpha; + get => Material.IsKeywordEnabled(SmoothnessTextureAlbedoChannelAKeyword) ? UrpLitSmoothnessMapChannel.AlbedoAlpha : UrpLitSmoothnessMapChannel.SpecularMetallicAlpha; set { - _mat.SetFloat(SmoothnessTextureChannelProp, (float)value); + Material.SetFloat(SmoothnessTextureChannelProp, (float)value); if (!UnsafeEditMode) Validate(); } } @@ -171,179 +76,129 @@ namespace UniGLTF public float Metallic { // NOTE: Metallic ワークフロー専用 - get => _mat.GetFloat(MetallicProp); - set => _mat.SetFloat(MetallicProp, value); + get => Material.GetFloat(MetallicProp); + set => Material.SetFloat(MetallicProp, value); } public Texture MetallicGlossMap { // NOTE: Metallic ワークフロー専用 - get => _mat.GetTexture(MetallicGlossMapProp); - set => _mat.SetTexture(MetallicGlossMapProp, value); + get => Material.GetTexture(MetallicGlossMapProp); + set => Material.SetTexture(MetallicGlossMapProp, value); } public Color SpecColorSrgb { // NOTE: Specular ワークフロー専用 - get => _mat.GetColor(SpecColorProp); - set => _mat.SetColor(SpecColorProp, value); + get => Material.GetColor(SpecColorProp); + set => Material.SetColor(SpecColorProp, value); } public Texture SpecGlossMap { // NOTE: Specular ワークフロー専用 - get => _mat.GetTexture(SpecGlossMapProp); - set => _mat.SetTexture(SpecGlossMapProp, value); + get => Material.GetTexture(SpecGlossMapProp); + set => Material.SetTexture(SpecGlossMapProp, value); } public float BumpScale { - get => _mat.GetFloat(BumpScaleProp); - set => _mat.SetFloat(BumpScaleProp, value); + get => Material.GetFloat(BumpScaleProp); + set => Material.SetFloat(BumpScaleProp, value); } public Texture BumpMap { - get => _mat.GetTexture(BumpMapProp); + get => Material.GetTexture(BumpMapProp); set { - _mat.SetTexture(BumpMapProp, value); - _mat.SetKeyword(NormalMapKeyword, value != null); + Material.SetTexture(BumpMapProp, value); + Material.SetKeyword(NormalMapKeyword, value != null); } } public bool IsEmissionEnabled { - get => _mat.IsKeywordEnabled(EmissionKeyword); + get => Material.IsKeywordEnabled(EmissionKeyword); set { - _mat.SetKeyword(EmissionKeyword, value); + Material.SetKeyword(EmissionKeyword, value); if (value) { - _mat.globalIlluminationFlags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack; + Material.globalIlluminationFlags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack; } else { - _mat.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack; + Material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack; } } } public Color EmissionColorLinear { - get => _mat.GetColor(EmissionColor); - set => _mat.SetColor(EmissionColor, value); + get => Material.GetColor(EmissionColor); + set => Material.SetColor(EmissionColor, value); } public Texture EmissionTexture { - get => _mat.GetTexture(EmissionMap); - set => _mat.SetTexture(EmissionMap, value); + get => Material.GetTexture(EmissionMap); + set => Material.SetTexture(EmissionMap, value); } public float OcclusionStrength { - get => _mat.GetFloat(OcclusionStrengthProp); - set => _mat.SetFloat(OcclusionStrengthProp, value); + get => Material.GetFloat(OcclusionStrengthProp); + set => Material.SetFloat(OcclusionStrengthProp, value); } public Texture OcclusionTexture { - get => _mat.GetTexture(OcclusionMap); + get => Material.GetTexture(OcclusionMap); set { - _mat.SetTexture(OcclusionMap, value); - _mat.SetKeyword(OcclusionMapKeyword, value != null); + Material.SetTexture(OcclusionMap, value); + Material.SetKeyword(OcclusionMapKeyword, value != null); } } public float Parallax { - get => _mat.GetFloat(ParallaxProp); - set => _mat.SetFloat(ParallaxProp, value); + get => Material.GetFloat(ParallaxProp); + set => Material.SetFloat(ParallaxProp, value); } public Texture ParallaxTexture { - get => _mat.GetTexture(ParallaxMap); + get => Material.GetTexture(ParallaxMap); set { - _mat.SetTexture(ParallaxMap, value); - _mat.SetKeyword(ParallaxMapKeyword, value != null); + Material.SetTexture(ParallaxMap, value); + Material.SetKeyword(ParallaxMapKeyword, value != null); } } /// /// 複数のプロパティに関連して設定されるキーワードやプロパティなどを更新する /// - public void Validate() + public override void Validate() { + base.Validate(); + // Workflow - var workflowType = (UrpLitWorkflowType)_mat.GetFloat(WorkflowMode); + var workflowType = (UrpLitWorkflowType)Material.GetFloat(WorkflowMode); var isSpecularSetup = workflowType == UrpLitWorkflowType.Specular; - _mat.SetKeyword(SpecularSetupKeyword, isSpecularSetup); + Material.SetKeyword(SpecularSetupKeyword, isSpecularSetup); // GlossMap var glossMapName = isSpecularSetup ? SpecGlossMapProp : MetallicGlossMapProp; - var hasGlossMap = _mat.GetTexture(glossMapName) != null; - _mat.SetKeyword(MetallicSpecGlossMapKeyword, hasGlossMap); - - // Surface Type - var surfaceType = (UrpLitSurfaceType)_mat.GetFloat(Surface); - _mat.SetKeyword(SurfaceTypeTransparentKeyword, surfaceType != UrpLitSurfaceType.Opaque); + var hasGlossMap = Material.GetTexture(glossMapName) != null; + Material.SetKeyword(MetallicSpecGlossMapKeyword, hasGlossMap); // SmoothnessTextureChannel - var isOpaque = surfaceType == UrpLitSurfaceType.Opaque; - var smoothnessMapChannel = (UrpLitSmoothnessMapChannel)_mat.GetFloat(SmoothnessTextureChannelProp); - _mat.SetKeyword(SmoothnessTextureAlbedoChannelAKeyword, isOpaque && smoothnessMapChannel == UrpLitSmoothnessMapChannel.AlbedoAlpha); - - // Alpha Clip - var alphaClip = _mat.GetFloat(AlphaClip) >= 0.5f; - _mat.SetKeyword(AlphaTestOnKeyword, alphaClip); - - // Blend Mode - var blendMode = (UrpLitBlendMode)_mat.GetFloat(Blend); - _mat.SetKeyword(AlphaPremultiplyOnKeyword, blendMode == UrpLitBlendMode.Premultiply); - _mat.SetKeyword(AlphaModulateOnKeyword, blendMode == UrpLitBlendMode.Additive); - - // ZWrite - var zWrite = surfaceType == UrpLitSurfaceType.Opaque; - _mat.SetFloat(ZWrite, zWrite ? 1.0f : 0.0f); - _mat.SetShaderPassEnabled("DepthOnly", zWrite); - - // Render Settings - _mat.SetFloat(SrcBlend, (surfaceType, blendMode) switch - { - (UrpLitSurfaceType.Opaque, _) => (float)UnityEngine.Rendering.BlendMode.One, - (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Alpha) => (float)UnityEngine.Rendering.BlendMode.SrcAlpha, - (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Premultiply) => (float)UnityEngine.Rendering.BlendMode.One, - (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Additive) => (float)UnityEngine.Rendering.BlendMode.One, - (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Multiply) => (float)UnityEngine.Rendering.BlendMode.DstColor, - _ => (float)UnityEngine.Rendering.BlendMode.One, - }); - _mat.SetFloat(DstBlend, (surfaceType, blendMode) switch - { - (UrpLitSurfaceType.Opaque, _) => (float)UnityEngine.Rendering.BlendMode.Zero, - (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Alpha) => (float)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha, - (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Premultiply) => (float)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha, - (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Additive) => (float)UnityEngine.Rendering.BlendMode.One, - (UrpLitSurfaceType.Transparent, UrpLitBlendMode.Multiply) => (float)UnityEngine.Rendering.BlendMode.Zero, - _ => (float) UnityEngine.Rendering.BlendMode.Zero, - }); - _mat.SetOverrideTag("RenderType", (surfaceType, alphaClip) switch - { - (UrpLitSurfaceType.Opaque, false) => "Opaque", - (UrpLitSurfaceType.Opaque, true) => "TransparentCutout", - (UrpLitSurfaceType.Transparent, _) => "Transparent", - _ => "Opaque", - }); - _mat.renderQueue = (surfaceType, alphaClip) switch - { - (UrpLitSurfaceType.Opaque, false) => (int)RenderQueue.Geometry, - (UrpLitSurfaceType.Opaque, true) => (int)RenderQueue.AlphaTest, - (UrpLitSurfaceType.Transparent, _) => (int)RenderQueue.Transparent, - _ => _mat.shader.renderQueue, - }; + var isOpaque = SurfaceType == UrpLitSurfaceType.Opaque; + var smoothnessMapChannel = (UrpLitSmoothnessMapChannel)Material.GetFloat(SmoothnessTextureChannelProp); + Material.SetKeyword(SmoothnessTextureAlbedoChannelAKeyword, isOpaque && smoothnessMapChannel == UrpLitSmoothnessMapChannel.AlbedoAlpha); } } } \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpUnlitContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpUnlitContext.cs new file mode 100644 index 000000000..1d4a6c864 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpUnlitContext.cs @@ -0,0 +1,12 @@ +using UnityEngine; + +namespace UniGLTF +{ + public class UrpUnlitContext : UrpBaseShaderContext + { + public UrpUnlitContext(Material material) : base(material) + { + + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpUnlitContext.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpUnlitContext.cs.meta new file mode 100644 index 000000000..7fc4a5dde --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/ShaderUtil/Lit/UrpUnlitContext.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3fe15309261045ba937d6a8dafb6a93d +timeCreated: 1722616677 \ No newline at end of file From 7a801071bdd6a054abd177c0970f95d70e7a87cb Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Sat, 3 Aug 2024 01:47:21 +0900 Subject: [PATCH 08/11] refactoring --- .../URP/Export/Materials/UrpLitMaterialExporter.cs | 13 +++++++++---- .../Export/Materials/UrpUniUnlitMaterialExporter.cs | 7 ++++++- .../Export/Materials/UrpUnlitMaterialExporter.cs | 10 +++++++--- .../UniGLTFShaderNotMatchedInternalException.cs | 9 +++++++++ ...UniGLTFShaderNotMatchedInternalException.cs.meta | 3 +++ 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Utils/UniGLTFShaderNotMatchedInternalException.cs create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Utils/UniGLTFShaderNotMatchedInternalException.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs index 96faa86e5..2fca9ea28 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs @@ -24,8 +24,8 @@ namespace UniGLTF try { if (src == null) throw new ArgumentNullException(nameof(src)); - if (src.shader != Shader) throw new ArgumentException(nameof(src)); if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); + if (src.shader != Shader) throw new UniGLTFShaderNotMatchedInternalException(src.shader); dst = new glTFMaterial { @@ -52,6 +52,11 @@ namespace UniGLTF return true; } + catch (UniGLTFShaderNotMatchedInternalException) + { + dst = default; + return false; + } catch (Exception e) { Debug.LogException(e); @@ -60,7 +65,7 @@ namespace UniGLTF } } - public static void ExportSurfaceSettings(UrpLitContext context, glTFMaterial dst, ITextureExporter textureExporter) + public static void ExportSurfaceSettings(UrpBaseShaderContext context, glTFMaterial dst, ITextureExporter textureExporter) { dst.alphaMode = (context.SurfaceType, context.IsAlphaClipEnabled) switch { @@ -74,7 +79,7 @@ namespace UniGLTF dst.doubleSided = context.CullMode != CullMode.Back; // NOTE: cull front not supported in glTF } - public static void ExportBaseColor(UrpLitContext context, glTFMaterial dst, ITextureExporter textureExporter) + public static void ExportBaseColor(UrpBaseShaderContext context, glTFMaterial dst, ITextureExporter textureExporter) { dst.pbrMetallicRoughness.baseColorFactor = context.BaseColorSrgb.ToFloat4(ColorSpace.sRGB, ColorSpace.Linear); if (context.BaseTexture != null) @@ -185,7 +190,7 @@ namespace UniGLTF } } - private static void ExportBaseTexTransform(UrpLitContext context, glTFTextureInfo dst) + private static void ExportBaseTexTransform(UrpBaseShaderContext context, glTFTextureInfo dst) { GltfMaterialExportUtils.ExportTextureTransform( context.BaseTextureOffset, diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs index 5a34299dd..8f68209a4 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs @@ -23,8 +23,8 @@ namespace UniGLTF try { if (src == null) throw new ArgumentNullException(nameof(src)); - if (src.shader != Shader) throw new ArgumentException(nameof(src)); if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); + if (src.shader != Shader) throw new UniGLTFShaderNotMatchedInternalException(src.shader); dst = glTF_KHR_materials_unlit.CreateDefault(); dst.name = src.name; @@ -63,6 +63,11 @@ namespace UniGLTF return true; } + catch (UniGLTFShaderNotMatchedInternalException) + { + dst = default; + return false; + } catch (Exception e) { Debug.LogException(e); diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs index 93d9a4996..df8523d8c 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs @@ -22,19 +22,23 @@ namespace UniGLTF try { if (src == null) throw new ArgumentNullException(nameof(src)); - if (src.shader != Shader) throw new ArgumentException(nameof(src)); if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); + if (src.shader != Shader) throw new UniGLTFShaderNotMatchedInternalException(src.shader); dst = glTF_KHR_materials_unlit.CreateDefault(); dst.name = src.name; - var context = new UrpLitContext(src); - + 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); diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Utils/UniGLTFShaderNotMatchedInternalException.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Utils/UniGLTFShaderNotMatchedInternalException.cs new file mode 100644 index 000000000..d83951461 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Utils/UniGLTFShaderNotMatchedInternalException.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace UniGLTF +{ + internal class UniGLTFShaderNotMatchedInternalException : UniGLTFException + { + public UniGLTFShaderNotMatchedInternalException(Shader shader) : base(shader != null ? shader.name : "") { } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Utils/UniGLTFShaderNotMatchedInternalException.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Utils/UniGLTFShaderNotMatchedInternalException.cs.meta new file mode 100644 index 000000000..af5b0c5b5 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Utils/UniGLTFShaderNotMatchedInternalException.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7857ff1b8d15440f9886f293a747ebb1 +timeCreated: 1722617046 \ No newline at end of file From d17f03c45db1ecff2910dc1dc451bfefe3d24507 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Sat, 3 Aug 2024 02:06:51 +0900 Subject: [PATCH 09/11] null check --- .../MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs | 2 +- .../URP/Export/Materials/UrpUniUnlitMaterialExporter.cs | 2 +- .../MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs index 2fca9ea28..3ae4807ee 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs @@ -25,7 +25,7 @@ namespace UniGLTF { if (src == null) throw new ArgumentNullException(nameof(src)); if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); - if (src.shader != Shader) throw new UniGLTFShaderNotMatchedInternalException(src.shader); + if (src.shader != Shader || Shader == null) throw new UniGLTFShaderNotMatchedInternalException(src.shader); dst = new glTFMaterial { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs index 8f68209a4..05670b81a 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUniUnlitMaterialExporter.cs @@ -24,7 +24,7 @@ namespace UniGLTF { if (src == null) throw new ArgumentNullException(nameof(src)); if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); - if (src.shader != Shader) throw new UniGLTFShaderNotMatchedInternalException(src.shader); + if (src.shader != Shader || Shader == null) throw new UniGLTFShaderNotMatchedInternalException(src.shader); dst = glTF_KHR_materials_unlit.CreateDefault(); dst.name = src.name; diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs index df8523d8c..67659c474 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs @@ -23,7 +23,7 @@ namespace UniGLTF { if (src == null) throw new ArgumentNullException(nameof(src)); if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); - if (src.shader != Shader) throw new UniGLTFShaderNotMatchedInternalException(src.shader); + if (src.shader != Shader || Shader == null) throw new UniGLTFShaderNotMatchedInternalException(src.shader); dst = glTF_KHR_materials_unlit.CreateDefault(); dst.name = src.name; From de9713a7683455215b520cb387d7fc39fe8fe2a5 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Sat, 3 Aug 2024 02:45:54 +0900 Subject: [PATCH 10/11] refactor --- .../UniGLTF/IO/MaterialIO/Import/MaterialFactory.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialFactory.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialFactory.cs index 5f96c22e4..322d691fc 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialFactory.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialFactory.cs @@ -136,7 +136,8 @@ namespace UniGLTF if (texture != null) { material.SetTexture(kv.Key, texture); - SetTextureOffsetAndScale(material, kv.Key, kv.Value.Offset, kv.Value.Scale); + material.SetTextureOffset(kv.Key, kv.Value.Offset); + material.SetTextureScale(kv.Key, kv.Value.Scale); } } @@ -174,11 +175,5 @@ namespace UniGLTF return material; } - - public static void SetTextureOffsetAndScale(Material material, string propertyName, Vector2 offset, Vector2 scale) - { - material.SetTextureOffset(propertyName, offset); - material.SetTextureScale(propertyName, scale); - } } } From 6842cd933cd92afe625626a7d7242d7241a99b46 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Sat, 3 Aug 2024 03:01:45 +0900 Subject: [PATCH 11/11] VrmAnimation depends on IMaterialDescriptorGenerator instead of "Standard" --- .../IO/MaterialIO/Import/MaterialFactory.cs | 38 +++++++++++-------- .../Vrm10AnimationInstance.cs | 3 +- .../VRM10/Runtime/IO/VrmAnimationImporter.cs | 5 ++- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialFactory.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialFactory.cs index 322d691fc..ab4d0955b 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialFactory.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialFactory.cs @@ -10,11 +10,9 @@ namespace UniGLTF public class MaterialFactory : IResponsibilityForDestroyObjects { private readonly IReadOnlyDictionary m_externalMap; - - /// - /// デフォルトマテリアルの MaterialDescriptor は IMaterialDescriptorGenerator の実装によって異なるので外から渡す - /// + private readonly SubAssetKey m_defaultMaterialKey = new SubAssetKey(typeof(Material), "__UNIGLTF__DEFAULT__MATERIAL__"); private readonly MaterialDescriptor m_defaultMaterialParams; + private readonly List m_materials = new List(); /// /// gltfPritmitive.material が無い場合のデフォルトマテリアル @@ -23,6 +21,9 @@ namespace UniGLTF /// private Material m_defaultMaterial; + public IReadOnlyList Materials => m_materials; + + public MaterialFactory(IReadOnlyDictionary externalMaterialMap, MaterialDescriptor defaultMaterialParams) { m_externalMap = externalMaterialMap; @@ -45,18 +46,6 @@ namespace UniGLTF } } - List m_materials = new List(); - public IReadOnlyList Materials => m_materials; - void Remove(Material material) - { - var index = m_materials.FindIndex(x => x.Asset == material); - if (index >= 0) - { - m_materials.RemoveAt(index); - - } - } - public void Dispose() { foreach (var x in m_materials) @@ -67,6 +56,11 @@ namespace UniGLTF UnityObjectDestroyer.DestroyRuntimeOrEditor(x.Asset); } } + + if (m_defaultMaterial != null) + { + UnityObjectDestroyer.DestroyRuntimeOrEditor(m_defaultMaterial); + } } /// @@ -90,6 +84,12 @@ namespace UniGLTF m_materials.Remove(x); } } + + if (m_defaultMaterial != null) + { + take(m_defaultMaterialKey, m_defaultMaterial); + m_defaultMaterial = null; + } } public Material GetMaterial(int index) @@ -101,6 +101,12 @@ namespace UniGLTF public async Task GetDefaultMaterialAsync(IAwaitCaller awaitCaller) { + if (m_externalMap.ContainsKey(m_defaultMaterialKey)) + { + m_defaultMaterial = m_externalMap[m_defaultMaterialKey]; + return m_externalMap[m_defaultMaterialKey]; + } + if (m_defaultMaterial == null) { m_defaultMaterial = await LoadAsync(m_defaultMaterialParams, (_, _) => null, awaitCaller); diff --git a/Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10AnimationInstance.cs b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10AnimationInstance.cs index 39bce21b7..2835f6ab6 100644 --- a/Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10AnimationInstance.cs +++ b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10AnimationInstance.cs @@ -171,7 +171,7 @@ namespace UniVRM10 public float custom_98; public float custom_99; - public void Initialize(IEnumerable keys) + public void Initialize(IEnumerable keys, Material material) { var humanoid = gameObject.AddComponent(); if (humanoid.AssignBonesFromAnimator()) @@ -183,7 +183,6 @@ namespace UniVRM10 // create SkinnedMesh for bone visualize var animator = this.GetComponentOrThrow(); BoxMan = SkeletonMeshUtility.CreateRenderer(animator); - var material = new Material(Shader.Find("Standard")); BoxMan.sharedMaterial = material; var mesh = BoxMan.sharedMesh; mesh.name = "box-man"; diff --git a/Assets/VRM10/Runtime/IO/VrmAnimationImporter.cs b/Assets/VRM10/Runtime/IO/VrmAnimationImporter.cs index 933a3727e..4928ffe0a 100644 --- a/Assets/VRM10/Runtime/IO/VrmAnimationImporter.cs +++ b/Assets/VRM10/Runtime/IO/VrmAnimationImporter.cs @@ -244,6 +244,9 @@ namespace UniVRM10 } Data.GLTF.scenes[0].nodes = Data.GLTF.scenes[0].nodes.Take(1).ToArray(); + // 可視化メッシュ用マテリアル。base.LoadAsync を呼ぶ前に生成する。 + var defaultMaterial = await MaterialFactory.GetDefaultMaterialAsync(awaitCaller); + // Humanoid Animation が Gltf アニメーションとしてロードされる var instance = await base.LoadAsync(awaitCaller, measureTime); @@ -285,7 +288,7 @@ namespace UniVRM10 // VRMA-animation solver var animationInstance = instance.gameObject.AddComponent(); - animationInstance.Initialize(expressions.Select(x => x.Key)); + animationInstance.Initialize(expressions.Select(x => x.Key), defaultMaterial); return instance; }