From 0d8d6c538dfd07e3b25e0d451c9e81da1cadc105 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 21 Aug 2023 18:47:27 +0900 Subject: [PATCH] UniVRM-0.114.0 --- .../UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs | 4 +- Assets/UniGLTF/package.json | 4 +- Assets/VRM/Runtime/Format/VRMVersion.cs | 4 +- Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs | 2 + Assets/VRM/package.json | 6 +- Assets/VRM10/Samples~/SimpleVrma.meta | 8 + .../VRM10/Samples~/SimpleVrma/SimpleVrma.cs | 64 ++++ .../SimpleVrma.cs.meta} | 2 +- .../Samples~/SimpleVrma/SimpleVrma.unity | 349 ++++++++++++++++++ .../Samples~/SimpleVrma/SimpleVrma.unity.meta | 7 + .../Samples~/VRM10Viewer/Motions/BvhMotion.cs | 11 +- .../VRM10Viewer/Motions/VrmAnimation.cs | 191 ---------- .../VRM10Viewer/Motions/VrmAnimation.cs.meta | 11 - .../VRM10Viewer/VRM10Retarget.cs.meta | 11 - .../Samples~/VRM10Viewer/VRM10ViewerUI.cs | 57 ++- Assets/VRM10/package.json | 6 +- Assets/VRMShaders/package.json | 2 +- 17 files changed, 477 insertions(+), 262 deletions(-) create mode 100644 Assets/VRM10/Samples~/SimpleVrma.meta create mode 100644 Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.cs rename Assets/VRM10/Samples~/{VRM10Viewer/Motions/IMotion.cs.meta => SimpleVrma/SimpleVrma.cs.meta} (83%) create mode 100644 Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.unity create mode 100644 Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.unity.meta delete mode 100644 Assets/VRM10/Samples~/VRM10Viewer/Motions/VrmAnimation.cs delete mode 100644 Assets/VRM10/Samples~/VRM10Viewer/Motions/VrmAnimation.cs.meta delete mode 100644 Assets/VRM10/Samples~/VRM10Viewer/VRM10Retarget.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs b/Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs index 3e158725e..ad008ff6a 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 = 49; + public const int MINOR = 50; public const int PATCH = 0; - public const string VERSION = "2.49.0"; + public const string VERSION = "2.50.0"; } } diff --git a/Assets/UniGLTF/package.json b/Assets/UniGLTF/package.json index f24d9de5f..ab8426f40 100644 --- a/Assets/UniGLTF/package.json +++ b/Assets/UniGLTF/package.json @@ -1,6 +1,6 @@ { "name": "com.vrmc.gltf", - "version": "0.113.0", + "version": "0.114.0", "displayName": "UniGLTF", "description": "GLTF importer and exporter", "unity": "2019.4", @@ -11,7 +11,7 @@ "name": "VRM Consortium" }, "dependencies": { - "com.vrmc.vrmshaders": "0.113.0", + "com.vrmc.vrmshaders": "0.114.0", "com.unity.modules.animation": "1.0.0" }, "samples": [ diff --git a/Assets/VRM/Runtime/Format/VRMVersion.cs b/Assets/VRM/Runtime/Format/VRMVersion.cs index a69a315b1..0de282312 100644 --- a/Assets/VRM/Runtime/Format/VRMVersion.cs +++ b/Assets/VRM/Runtime/Format/VRMVersion.cs @@ -4,8 +4,8 @@ namespace VRM public static partial class VRMVersion { public const int MAJOR = 0; - public const int MINOR = 113; + public const int MINOR = 114; public const int PATCH = 0; - public const string VERSION = "0.113.0"; + public const string VERSION = "0.114.0"; } } diff --git a/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs b/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs index 6d9be86f7..27294ec96 100644 --- a/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs +++ b/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs @@ -387,6 +387,7 @@ namespace VRM.SimpleViewer static IMaterialDescriptorGenerator GetGltfMaterialGenerator(bool useUrp) { + //Could be refactored to no longer need this check using RenderPipelineMaterialDescriptorGeneratorUtility if (useUrp) { return new UrpGltfMaterialDescriptorGenerator(); @@ -399,6 +400,7 @@ namespace VRM.SimpleViewer static IMaterialDescriptorGenerator GetVrmMaterialGenerator(bool useUrp, VRM.glTF_VRM_extensions vrm) { + //Could be refactored to no longer need this check using VrmRenderPipelineMaterialDescriptorGeneratorDescriptorUtility if (useUrp) { return new VRM.UrpVrmMaterialDescriptorGenerator(vrm); diff --git a/Assets/VRM/package.json b/Assets/VRM/package.json index 6b0af7bfa..34475632c 100644 --- a/Assets/VRM/package.json +++ b/Assets/VRM/package.json @@ -1,6 +1,6 @@ { "name": "com.vrmc.univrm", - "version": "0.113.0", + "version": "0.114.0", "displayName": "VRM", "description": "VRM importer", "unity": "2019.4", @@ -14,8 +14,8 @@ "name": "VRM Consortium" }, "dependencies": { - "com.vrmc.vrmshaders": "0.113.0", - "com.vrmc.gltf": "0.113.0", + "com.vrmc.vrmshaders": "0.114.0", + "com.vrmc.gltf": "0.114.0", "com.unity.ugui": "1.0.0" }, "samples": [ diff --git a/Assets/VRM10/Samples~/SimpleVrma.meta b/Assets/VRM10/Samples~/SimpleVrma.meta new file mode 100644 index 000000000..ba2573e96 --- /dev/null +++ b/Assets/VRM10/Samples~/SimpleVrma.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 59ba601fea149ed498a9ca37af1d3c55 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.cs b/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.cs new file mode 100644 index 000000000..40f12753a --- /dev/null +++ b/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.cs @@ -0,0 +1,64 @@ +using UniGLTF; +using UnityEditor; +using UnityEngine; +using UniVRM10; +using UniVRM10.VRM10Viewer; +using VRMShaders; + +public class SimpleVrma : MonoBehaviour +{ + public Vrm10Instance Vrm; + + public Vrm10AnimationInstance Vrma; + + bool m_boxman = true; + + void OnGUI() + { + if (GUILayout.Button("open vrm")) + { + var path = EditorUtility.OpenFilePanel("open vrm", "", "vrm"); + Debug.Log(path); + LoadVrm(path); + } + + if (GUILayout.Button("open vrma")) + { + var path = EditorUtility.OpenFilePanel("open vrma", "", "vrma"); + Debug.Log(path); + LoadVrma(path); + } + + m_boxman = GUILayout.Toggle(m_boxman, "BoxMan"); + if (Vrma != null) + { + Vrma.BoxMan.enabled = m_boxman; + } + } + + async void LoadVrm(string path) + { + Vrm = await Vrm10.LoadPathAsync(path, + canLoadVrm0X: true, + showMeshes: false, + awaitCaller: new ImmediateCaller()); + + var instance = Vrm.GetComponent(); + instance.ShowMeshes(); + } + + async void LoadVrma(string path) + { + // load vrma + using GltfData data = new AutoGltfFileParser(path).Parse(); + using var loader = new VrmAnimationImporter(data); + var instance = await loader.LoadAsync(new ImmediateCaller()); + + Vrma = instance.GetComponent(); + Vrm.Runtime.VrmAnimation = Vrma; + Debug.Log(Vrma); + + var animation = Vrma.GetComponent(); + animation.Play(); + } +} diff --git a/Assets/VRM10/Samples~/VRM10Viewer/Motions/IMotion.cs.meta b/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.cs.meta similarity index 83% rename from Assets/VRM10/Samples~/VRM10Viewer/Motions/IMotion.cs.meta rename to Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.cs.meta index bdc7beafd..b0cba8bd7 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/Motions/IMotion.cs.meta +++ b/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: bd8db8a4bdc3e7f40a0a7a1bcd554137 +guid: e941e78669b3e784fa684c23441459fb MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.unity b/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.unity new file mode 100644 index 000000000..cd21b85b5 --- /dev/null +++ b/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.unity @@ -0,0 +1,349 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 9 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 0 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} + m_UseRadianceAmbientProbe: 0 +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 12 + m_GIWorkflowMode: 1 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 0 + m_LightmapEditorSettings: + serializedVersion: 12 + m_Resolution: 2 + m_BakeResolution: 40 + m_AtlasSize: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAmbientOcclusion: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_MixedBakeMode: 2 + m_BakeBackend: 1 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 512 + m_PVRBounces: 2 + m_PVREnvironmentSampleCount: 256 + m_PVREnvironmentReferencePointCount: 2048 + m_PVRFilteringMode: 1 + m_PVRDenoiserTypeDirect: 1 + m_PVRDenoiserTypeIndirect: 1 + m_PVRDenoiserTypeAO: 1 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVREnvironmentMIS: 1 + m_PVRCulling: 1 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_LightProbeSampleCountMultiplier: 4 + m_LightingDataAsset: {fileID: 0} + m_LightingSettings: {fileID: 0} +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + manualTileSize: 0 + tileSize: 256 + accuratePlacement: 0 + maxJobWorkers: 0 + preserveTilesOutsideBounds: 0 + debug: + m_Flags: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &45959732 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 45959734} + - component: {fileID: 45959733} + m_Layer: 0 + m_Name: Directional Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &45959733 +Light: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 45959732} + m_Enabled: 1 + serializedVersion: 10 + m_Type: 1 + m_Shape: 0 + m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_InnerSpotAngle: 21.80208 + m_CookieSize: 10 + m_Shadows: + m_Type: 2 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_CullingMatrixOverride: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 + m_UseCullingMatrixOverride: 0 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingLayerMask: 1 + m_Lightmapping: 4 + m_LightShadowCasterMode: 0 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} + m_UseBoundingSphereOverride: 0 + m_UseViewFrustumForShadowCasterCull: 1 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &45959734 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 45959732} + m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} + m_LocalPosition: {x: 0, y: 3, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!1 &231202275 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 231202278} + - component: {fileID: 231202277} + - component: {fileID: 231202276} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &231202276 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 231202275} + m_Enabled: 1 +--- !u!20 &231202277 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 231202275} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_projectionMatrixMode: 1 + m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_FocalLength: 50 + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &231202278 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 231202275} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 1, z: -10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &2069542080 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2069542081} + - component: {fileID: 2069542082} + m_Layer: 0 + m_Name: vrma + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2069542081 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2069542080} + 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: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2069542082 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2069542080} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e941e78669b3e784fa684c23441459fb, type: 3} + m_Name: + m_EditorClassIdentifier: + Vrm: {fileID: 0} + Vrma: {fileID: 0} diff --git a/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.unity.meta b/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.unity.meta new file mode 100644 index 000000000..df659705b --- /dev/null +++ b/Assets/VRM10/Samples~/SimpleVrma/SimpleVrma.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 7ceefca1729da714e8f1163c8f391445 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Samples~/VRM10Viewer/Motions/BvhMotion.cs b/Assets/VRM10/Samples~/VRM10Viewer/Motions/BvhMotion.cs index 0a801d555..ffb925bb9 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/Motions/BvhMotion.cs +++ b/Assets/VRM10/Samples~/VRM10Viewer/Motions/BvhMotion.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using UniHumanoid; @@ -5,15 +6,19 @@ using UnityEngine; namespace UniVRM10.VRM10Viewer { - public class BvhMotion : IMotion + public class BvhMotion : IVrm10Animation { UniHumanoid.BvhImporterContext m_context; public Transform Root => m_context?.Root.transform; public SkinnedMeshRenderer m_boxMan; public SkinnedMeshRenderer BoxMan => m_boxMan; (INormalizedPoseProvider, ITPoseProvider) m_controlRig; - (INormalizedPoseProvider, ITPoseProvider) IMotion.ControlRig => m_controlRig; - public IDictionary ExpressionMap { get; } = new Dictionary(); + (INormalizedPoseProvider, ITPoseProvider) IVrm10Animation.ControlRig => m_controlRig; + IDictionary> _ExpressionMap = new Dictionary>(); + public IReadOnlyDictionary> ExpressionMap => (IReadOnlyDictionary>)_ExpressionMap; + + public LookAtInput? LookAt { get; set; } + public BvhMotion(UniHumanoid.BvhImporterContext context) { m_context = context; diff --git a/Assets/VRM10/Samples~/VRM10Viewer/Motions/VrmAnimation.cs b/Assets/VRM10/Samples~/VRM10Viewer/Motions/VrmAnimation.cs deleted file mode 100644 index 2954251b5..000000000 --- a/Assets/VRM10/Samples~/VRM10Viewer/Motions/VrmAnimation.cs +++ /dev/null @@ -1,191 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using UniGLTF; -using UniJSON; -using UnityEngine; -using VRMShaders; - -namespace UniVRM10.VRM10Viewer -{ - public class VrmAnimation : IMotion - { - private readonly VrmAnimationInstance m_instance; - - (INormalizedPoseProvider, ITPoseProvider) IMotion.ControlRig => m_instance.ControlRig; - IDictionary IMotion.ExpressionMap => m_instance.ExpressionMap; - - public VrmAnimation(VrmAnimationInstance instance, - Vector3 hips = default, Dictionary map = null) - { - m_instance = instance; - if (instance.GetComponent() is Animation animation) - { - if (animation != null) - { - animation.Play(); - } - else - { - // experimental: set pose - var animator = instance.GetComponent(); - animator.GetBoneTransform(HumanBodyBones.Hips).localPosition = hips; - foreach (var kv in map) - { - var t = animator.GetBoneTransform(kv.Key); - if (t != null) - { - t.localRotation = kv.Value; - } - } - } - } - } - - public void ShowBoxMan(bool enable) - { - if (m_instance.BoxMan != null) - { - m_instance.BoxMan.enabled = enable; - } - } - - public void Dispose() - { - if (m_instance.BoxMan != null) - { - GameObject.Destroy(m_instance.BoxMan.gameObject); - } - } - - public static async Task LoadVrmAnimationFromPathAsync(string path) - { - using GltfData data = new AutoGltfFileParser(path).Parse(); - using var loader = new VrmAnimationImporter(data); - var instance = await loader.LoadAsync(new ImmediateCaller()); - return new VrmAnimation(instance.GetComponent()); - } - - static Vector3 ToVec3(JsonNode j) - { - return new Vector3(-j[0].GetSingle(), j[1].GetSingle(), j[2].GetSingle()); - } - - static Quaternion ToQuat(JsonNode j) - { - return new Quaternion(j[0].GetSingle(), -j[1].GetSingle(), -j[2].GetSingle(), j[3].GetSingle()); - } - - static (Vector3, Dictionary) GetPose(JsonNode humanoid) - { - Vector3 root = default; - var map = new Dictionary(); - - if (humanoid.TryGet("translation", out var translation)) - { - root = ToVec3(translation); - } - if (humanoid.TryGet("rotations", out var rotations)) - { - foreach (var kv in rotations.ObjectItems()) - { - switch (kv.Key.GetString()) - { - case "hips": map.Add(HumanBodyBones.Hips, ToQuat(kv.Value)); break; - case "spine": map.Add(HumanBodyBones.Spine, ToQuat(kv.Value)); break; - case "chest": map.Add(HumanBodyBones.Chest, ToQuat(kv.Value)); break; - case "upperChest": map.Add(HumanBodyBones.UpperChest, ToQuat(kv.Value)); break; - case "neck": map.Add(HumanBodyBones.Neck, ToQuat(kv.Value)); break; - case "head": map.Add(HumanBodyBones.Head, ToQuat(kv.Value)); break; - // case "leftEye": map.Add(HumanBodyBones.leftEye, ToQuat(kv.Value)); break; - // case "rightEye": map.Add(HumanBodyBones.rightEye, ToQuat(kv.Value)); break; - case "jaw": map.Add(HumanBodyBones.Jaw, ToQuat(kv.Value)); break; - case "leftShoulder": map.Add(HumanBodyBones.LeftShoulder, ToQuat(kv.Value)); break; - case "leftUpperArm": map.Add(HumanBodyBones.LeftUpperArm, ToQuat(kv.Value)); break; - case "leftLowerArm": map.Add(HumanBodyBones.LeftLowerArm, ToQuat(kv.Value)); break; - case "leftHand": map.Add(HumanBodyBones.LeftHand, ToQuat(kv.Value)); break; - case "rightShoulder": map.Add(HumanBodyBones.RightShoulder, ToQuat(kv.Value)); break; - case "rightUpperArm": map.Add(HumanBodyBones.RightUpperArm, ToQuat(kv.Value)); break; - case "rightLowerArm": map.Add(HumanBodyBones.RightLowerArm, ToQuat(kv.Value)); break; - case "rightHand": map.Add(HumanBodyBones.RightHand, ToQuat(kv.Value)); break; - case "leftUpperLeg": map.Add(HumanBodyBones.LeftUpperLeg, ToQuat(kv.Value)); break; - case "leftLowerLeg": map.Add(HumanBodyBones.LeftLowerLeg, ToQuat(kv.Value)); break; - case "leftFoot": map.Add(HumanBodyBones.LeftFoot, ToQuat(kv.Value)); break; - case "leftToes": map.Add(HumanBodyBones.LeftToes, ToQuat(kv.Value)); break; - case "rightUpperLeg": map.Add(HumanBodyBones.RightUpperLeg, ToQuat(kv.Value)); break; - case "rightLowerLeg": map.Add(HumanBodyBones.RightLowerLeg, ToQuat(kv.Value)); break; - case "rightFoot": map.Add(HumanBodyBones.RightFoot, ToQuat(kv.Value)); break; - case "rightToes": map.Add(HumanBodyBones.RightToes, ToQuat(kv.Value)); break; - case "leftThumbMetacarpal": map.Add(HumanBodyBones.LeftThumbProximal, ToQuat(kv.Value)); break; - case "leftThumbProximal": map.Add(HumanBodyBones.LeftThumbIntermediate, ToQuat(kv.Value)); break; - case "leftThumbDistal": map.Add(HumanBodyBones.LeftThumbDistal, ToQuat(kv.Value)); break; - case "leftIndexProximal": map.Add(HumanBodyBones.LeftIndexProximal, ToQuat(kv.Value)); break; - case "leftIndexIntermediate": map.Add(HumanBodyBones.LeftIndexIntermediate, ToQuat(kv.Value)); break; - case "leftIndexDistal": map.Add(HumanBodyBones.LeftIndexDistal, ToQuat(kv.Value)); break; - case "leftMiddleProximal": map.Add(HumanBodyBones.LeftMiddleProximal, ToQuat(kv.Value)); break; - case "leftMiddleIntermediate": map.Add(HumanBodyBones.LeftMiddleIntermediate, ToQuat(kv.Value)); break; - case "leftMiddleDistal": map.Add(HumanBodyBones.LeftMiddleDistal, ToQuat(kv.Value)); break; - case "leftRingProximal": map.Add(HumanBodyBones.LeftRingProximal, ToQuat(kv.Value)); break; - case "leftRingIntermediate": map.Add(HumanBodyBones.LeftRingIntermediate, ToQuat(kv.Value)); break; - case "leftRingDistal": map.Add(HumanBodyBones.LeftRingDistal, ToQuat(kv.Value)); break; - case "leftLittleProximal": map.Add(HumanBodyBones.LeftLittleProximal, ToQuat(kv.Value)); break; - case "leftLittleIntermediate": map.Add(HumanBodyBones.LeftLittleIntermediate, ToQuat(kv.Value)); break; - case "leftLittleDistal": map.Add(HumanBodyBones.LeftLittleDistal, ToQuat(kv.Value)); break; - case "rightThumbMetacarpal": map.Add(HumanBodyBones.RightThumbProximal, ToQuat(kv.Value)); break; - case "rightThumbProximal": map.Add(HumanBodyBones.RightThumbIntermediate, ToQuat(kv.Value)); break; - case "rightThumbDistal": map.Add(HumanBodyBones.RightThumbDistal, ToQuat(kv.Value)); break; - case "rightIndexProximal": map.Add(HumanBodyBones.RightIndexProximal, ToQuat(kv.Value)); break; - case "rightIndexIntermediate": map.Add(HumanBodyBones.RightIndexIntermediate, ToQuat(kv.Value)); break; - case "rightIndexDistal": map.Add(HumanBodyBones.RightIndexDistal, ToQuat(kv.Value)); break; - case "rightMiddleProximal": map.Add(HumanBodyBones.RightMiddleProximal, ToQuat(kv.Value)); break; - case "rightMiddleIntermediate": map.Add(HumanBodyBones.RightMiddleIntermediate, ToQuat(kv.Value)); break; - case "rightMiddleDistal": map.Add(HumanBodyBones.RightMiddleDistal, ToQuat(kv.Value)); break; - case "rightRingProximal": map.Add(HumanBodyBones.RightRingProximal, ToQuat(kv.Value)); break; - case "rightRingIntermediate": map.Add(HumanBodyBones.RightRingIntermediate, ToQuat(kv.Value)); break; - case "rightRingDistal": map.Add(HumanBodyBones.RightRingDistal, ToQuat(kv.Value)); break; - case "rightLittleProximal": map.Add(HumanBodyBones.RightLittleProximal, ToQuat(kv.Value)); break; - case "rightLittleIntermediate": map.Add(HumanBodyBones.RightLittleIntermediate, ToQuat(kv.Value)); break; - case "rightLittleDistal": map.Add(HumanBodyBones.RightLittleDistal, ToQuat(kv.Value)); break; - } - } - } - - return (root, map); - } - - public static async Task LoadVrmAnimationPose(string text) - { - using GltfData data = GlbLowLevelParser.ParseGltf( - "tmp.vrma", - text, - new List(), // .gltf file has no chunks. - new FileSystemStorage("_dummy_root_"), // .gltf file has resource path at file system. - new MigrationFlags() - ); - using var loader = new VrmAnimationImporter(data); - var instance = await loader.LoadAsync(new ImmediateCaller()); - - if (data.GLTF.extensions is UniGLTF.glTFExtensionImport extensions) - { - foreach (var kv in extensions.ObjectItems()) - { - if (kv.Key.GetString() == "VRMC_vrm_animation") - { - if (kv.Value.TryGet("extensions", out var inner_extensions)) - { - if (inner_extensions.TryGet("VRMC_vrm_pose", out var pose)) - { - if (pose.TryGet("humanoid", out var humanoid)) - { - var (root, map) = GetPose(humanoid); - return new VrmAnimation(instance.GetComponent(), root, map); - } - } - } - } - } - } - - throw new System.Exception("no pose"); - } - } -} diff --git a/Assets/VRM10/Samples~/VRM10Viewer/Motions/VrmAnimation.cs.meta b/Assets/VRM10/Samples~/VRM10Viewer/Motions/VrmAnimation.cs.meta deleted file mode 100644 index 1ea946b9b..000000000 --- a/Assets/VRM10/Samples~/VRM10Viewer/Motions/VrmAnimation.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f0180f844d447bc45889d6c72a2d4ec4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10Retarget.cs.meta b/Assets/VRM10/Samples~/VRM10Viewer/VRM10Retarget.cs.meta deleted file mode 100644 index 51e773495..000000000 --- a/Assets/VRM10/Samples~/VRM10Viewer/VRM10Retarget.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 49423dc9e9a224545a90221f41d975c8 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs index 88969baa9..fc5b9fe08 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs @@ -50,8 +50,8 @@ namespace UniVRM10.VRM10Viewer GameObject Root = default; - IMotion m_src = default; - public IMotion Motion + IVrm10Animation m_src = default; + public IVrm10Animation Motion { get { return m_src; } set @@ -61,9 +61,13 @@ namespace UniVRM10.VRM10Viewer m_src.Dispose(); } m_src = value; + + TPose = new Vrm10TPose(m_src.ControlRig.Item1.GetRawHipsPosition()); } } + public IVrm10Animation TPose; + private CancellationTokenSource _cancellationTokenSource; [Serializable] @@ -209,13 +213,13 @@ namespace UniVRM10.VRM10Viewer ToggleMotion = groups.First(x => x.name == "_Motion_"); } - public bool IsBvhEnabled + public bool IsTPose { - get => ToggleMotion.ActiveToggles().FirstOrDefault() == ToggleMotionBVH; + get => ToggleMotion.ActiveToggles().FirstOrDefault() == ToggleMotionTPose; set { - ToggleMotionTPose.isOn = !value; - ToggleMotionBVH.isOn = value; + ToggleMotionTPose.isOn = value; + ToggleMotionBVH.isOn = !value; } } } @@ -331,7 +335,7 @@ namespace UniVRM10.VRM10Viewer _cancellationTokenSource?.Dispose(); } - bool? m_lastUseBvh = default; + private void Update() { if (Input.GetKeyDown(KeyCode.Tab)) @@ -357,31 +361,19 @@ namespace UniVRM10.VRM10Viewer m_loaded.EnableLipSyncValue = m_enableLipSync.isOn; m_loaded.EnableBlinkValue = m_enableAutoBlink.isOn; m_loaded.EnableAutoExpressionValue = m_enableAutoExpression.isOn; + } - var useBvh = Motion != null; - if (useBvh) + if (m_loaded != null) + { + if (m_ui.IsTPose) { - // update humanoid - if (Motion.ControlRig.Item1 != null && Motion.ControlRig.Item2 != null) - { - VRM10Retarget.Retarget(Motion.ControlRig, (m_loaded.ControlRig, m_loaded.ControlRig)); - } - // update expressions - foreach (var (k, v) in Motion.ExpressionMap) - { - // VRMA-expression use localPosition.x as expression weight - m_loaded.Runtime.Expression.SetWeight(k, -v.transform.localPosition.x); - } + m_loaded.Runtime.VrmAnimation = TPose; } - else + else if (Motion != null) { - if (!m_lastUseBvh.HasValue || m_lastUseBvh.Value) - { - Debug.Log("SetPose"); - VRM10Retarget.EnforceTPose((m_loaded.ControlRig, m_loaded.ControlRig)); - } + // Automatically retarget in Vrm10Runtime.Process + m_loaded.Runtime.VrmAnimation = Motion; } - m_lastUseBvh = useBvh; } } @@ -431,7 +423,11 @@ namespace UniVRM10.VRM10Viewer } // gltf, glb etc... - Motion = await VrmAnimation.LoadVrmAnimationFromPathAsync(path); + using GltfData data = new AutoGltfFileParser(path).Parse(); + using var loader = new VrmAnimationImporter(data); + var instance = await loader.LoadAsync(new ImmediateCaller()); + Motion = instance.GetComponent(); + instance.GetComponent().Play(); } async void OnPastePoseClicked() @@ -442,12 +438,9 @@ namespace UniVRM10.VRM10Viewer return; } - m_ui.IsBvhEnabled = false; - m_lastUseBvh = false; - try { - Motion = await VrmAnimation.LoadVrmAnimationPose(text); + Motion = await Vrm10PoseLoader.LoadVrmAnimationPose(text); } catch (UniJSON.ParserException) { diff --git a/Assets/VRM10/package.json b/Assets/VRM10/package.json index c6d2432da..cd564eb56 100644 --- a/Assets/VRM10/package.json +++ b/Assets/VRM10/package.json @@ -1,6 +1,6 @@ { "name": "com.vrmc.vrm", - "version": "0.113.0", + "version": "0.114.0", "displayName": "VRM-1.0", "description": "VRM-1.0 importer", "unity": "2019.4", @@ -14,8 +14,8 @@ "name": "VRM Consortium" }, "dependencies": { - "com.vrmc.vrmshaders": "0.113.0", - "com.vrmc.gltf": "0.113.0" + "com.vrmc.vrmshaders": "0.114.0", + "com.vrmc.gltf": "0.114.0" }, "samples": [ { diff --git a/Assets/VRMShaders/package.json b/Assets/VRMShaders/package.json index c05fa38da..bdab55247 100644 --- a/Assets/VRMShaders/package.json +++ b/Assets/VRMShaders/package.json @@ -1,6 +1,6 @@ { "name": "com.vrmc.vrmshaders", - "version": "0.113.0", + "version": "0.114.0", "displayName": "VRM Shaders", "description": "VRM Shaders", "unity": "2019.4",