From 869b4bb79aa0b1e8ebc5713702b7fabba1daa267 Mon Sep 17 00:00:00 2001 From: CroakFang <1605296300@qq.com> Date: Sat, 12 Nov 2022 18:13:54 +0800 Subject: [PATCH] Add VMD Recorder --- .gitignore | 1 + Assets/Scenes/Version2.unity | 934 +++++++++++++++++- Assets/Scripts/UmaContainer.cs | 2 +- Assets/Scripts/UmaViewerUI.cs | 48 + Assets/Scripts/VMDRecorder.meta | 8 + Assets/Scripts/VMDRecorder/LICENSE | 21 + Assets/Scripts/VMDRecorder/LICENSE.meta | 7 + .../VMDRecorder/UnityCameraVMDRecorder.cs | 298 ++++++ .../UnityCameraVMDRecorder.cs.meta | 11 + .../VMDRecorder/UnityHumanoidVMDRecorder.cs | 932 +++++++++++++++++ .../UnityHumanoidVMDRecorder.cs.meta | 11 + .../UnityVMDQuaternionExtentions.cs | 16 + .../UnityVMDQuaternionExtentions.cs.meta | 11 + UserSettings/EditorUserSettings.asset | 3 + 14 files changed, 2293 insertions(+), 10 deletions(-) create mode 100644 Assets/Scripts/VMDRecorder.meta create mode 100644 Assets/Scripts/VMDRecorder/LICENSE create mode 100644 Assets/Scripts/VMDRecorder/LICENSE.meta create mode 100644 Assets/Scripts/VMDRecorder/UnityCameraVMDRecorder.cs create mode 100644 Assets/Scripts/VMDRecorder/UnityCameraVMDRecorder.cs.meta create mode 100644 Assets/Scripts/VMDRecorder/UnityHumanoidVMDRecorder.cs create mode 100644 Assets/Scripts/VMDRecorder/UnityHumanoidVMDRecorder.cs.meta create mode 100644 Assets/Scripts/VMDRecorder/UnityVMDQuaternionExtentions.cs create mode 100644 Assets/Scripts/VMDRecorder/UnityVMDQuaternionExtentions.cs.meta diff --git a/.gitignore b/.gitignore index 4153e41..7cb2e66 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,4 @@ sysinfo.txt crashlytics-build.properties /Assets/Plugins/RootMotion/PuppetMaster/_Integration +/VMDRecords diff --git a/Assets/Scenes/Version2.unity b/Assets/Scenes/Version2.unity index 3736cdb..2e4deb6 100644 --- a/Assets/Scenes/Version2.unity +++ b/Assets/Scenes/Version2.unity @@ -1502,7 +1502,7 @@ RectTransform: m_Children: - {fileID: 844924682} m_Father: {fileID: 1704906816} - m_RootOrder: 17 + m_RootOrder: 19 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} @@ -4466,7 +4466,7 @@ RectTransform: - {fileID: 2094428666} - {fileID: 18660879} m_Father: {fileID: 1704906816} - m_RootOrder: 19 + m_RootOrder: 21 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} @@ -7349,6 +7349,81 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 437051804} m_CullTransparentMesh: 1 +--- !u!1 &445905560 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 445905561} + - component: {fileID: 445905563} + - component: {fileID: 445905562} + m_Layer: 5 + m_Name: Background + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &445905561 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 445905560} + 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_Children: [] + m_Father: {fileID: 1981443671} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: -0.00012207031, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &445905562 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 445905560} + 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: 10907, 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 &445905563 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 445905560} + m_CullTransparentMesh: 1 --- !u!1 &451396663 GameObject: m_ObjectHideFlags: 0 @@ -9490,6 +9565,140 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 504748474} m_CullTransparentMesh: 1 +--- !u!1 &511512329 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 511512330} + - component: {fileID: 511512332} + - component: {fileID: 511512331} + m_Layer: 5 + m_Name: Text (TMP) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &511512330 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 511512329} + 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_Children: [] + m_Father: {fileID: 668484491} + 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: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &511512331 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 511512329} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, 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_text: Record VMD + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4281479730 + m_fontColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 20 + m_fontSizeBase: 20 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 0 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 512 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &511512332 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 511512329} + m_CullTransparentMesh: 1 --- !u!1 &512008711 GameObject: m_ObjectHideFlags: 0 @@ -11800,6 +12009,140 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 665091893} m_CullTransparentMesh: 1 +--- !u!1 &668484487 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 668484491} + - component: {fileID: 668484490} + - component: {fileID: 668484489} + - component: {fileID: 668484488} + m_Layer: 5 + m_Name: RecordGif + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &668484488 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 668484487} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, 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: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 668484489} + m_OnClick: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1564959567} + m_TargetAssemblyTypeName: UmaViewerUI, umamusume + m_MethodName: RecordVMD + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 +--- !u!114 &668484489 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 668484487} + 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 &668484490 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 668484487} + m_CullTransparentMesh: 1 +--- !u!224 &668484491 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 668484487} + 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_Children: + - {fileID: 1981443671} + - {fileID: 511512330} + m_Father: {fileID: 1348880053} + 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.00012207031, y: 0} + m_SizeDelta: {x: 244, y: 45} + m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &673546061 GameObject: m_ObjectHideFlags: 0 @@ -16182,7 +16525,7 @@ RectTransform: m_Children: - {fileID: 1323454211} m_Father: {fileID: 1704906816} - m_RootOrder: 20 + m_RootOrder: 22 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -20681,7 +21024,7 @@ RectTransform: m_Children: - {fileID: 1296918362} m_Father: {fileID: 1704906816} - m_RootOrder: 16 + m_RootOrder: 18 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -22014,7 +22357,7 @@ MonoBehaviour: m_HandleRect: {fileID: 1882365342} m_Direction: 2 m_Value: 1 - m_Size: 0.88527817 + m_Size: 0.8211369 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -22089,7 +22432,7 @@ RectTransform: m_Children: - {fileID: 494042607} m_Father: {fileID: 1704906816} - m_RootOrder: 14 + m_RootOrder: 16 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -24721,6 +25064,109 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1342289414} m_CullTransparentMesh: 1 +--- !u!1 &1348880052 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1348880053} + - component: {fileID: 1348880057} + - component: {fileID: 1348880056} + - component: {fileID: 1348880055} + - component: {fileID: 1348880054} + m_Layer: 5 + m_Name: VMDRecorder + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1348880053 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1348880052} + 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_Children: + - {fileID: 668484491} + m_Father: {fileID: 1704906816} + m_RootOrder: 15 + 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: 0, y: 50} + m_Pivot: {x: 1, y: 0.5} +--- !u!114 &1348880054 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1348880052} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fa66f75ff0e8a134b8014ca7a6e65689, type: 3} + m_Name: + m_EditorClassIdentifier: + stop: 0 +--- !u!114 &1348880055 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1348880052} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5b4f73cfe8953614eadf26f26c5801c8, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &1348880056 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1348880052} + 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: 0, g: 0, b: 0, a: 0.19607843} + 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: 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 &1348880057 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1348880052} + m_CullTransparentMesh: 1 --- !u!1 &1349413336 GameObject: m_ObjectHideFlags: 0 @@ -24944,7 +25390,7 @@ RectTransform: - {fileID: 1590756440} - {fileID: 1862189160} m_Father: {fileID: 1704906816} - m_RootOrder: 21 + m_RootOrder: 23 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} @@ -26111,7 +26557,7 @@ RectTransform: m_Children: - {fileID: 787741672} m_Father: {fileID: 1704906816} - m_RootOrder: 18 + m_RootOrder: 20 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -27832,6 +28278,7 @@ MonoBehaviour: GifQualityLabel: {fileID: 542685198} GifSlider: {fileID: 776477047} GifButton: {fileID: 964213177} + VMDButton: {fileID: 668484488} TogglablePanels: - {fileID: 1974252710} - {fileID: 87578738} @@ -30762,6 +31209,8 @@ RectTransform: - {fileID: 753756319} - {fileID: 1340983837} - {fileID: 2134049658} + - {fileID: 1901726786} + - {fileID: 1348880053} - {fileID: 1198130885} - {fileID: 2126459761} - {fileID: 1111810905} @@ -31491,6 +31940,140 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1731597398} m_CullTransparentMesh: 1 +--- !u!1 &1731608459 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1731608460} + - component: {fileID: 1731608462} + - component: {fileID: 1731608461} + m_Layer: 5 + m_Name: Text (TMP) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1731608460 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1731608459} + 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_Children: [] + m_Father: {fileID: 1901726786} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1731608461 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1731608459} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, 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_text: VMDRecorder + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 25 + m_fontSizeBase: 25 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 1 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 512 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &1731608462 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1731608459} + m_CullTransparentMesh: 1 --- !u!1 &1749344627 GameObject: m_ObjectHideFlags: 0 @@ -31742,6 +32325,81 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: -20, y: 0} m_Pivot: {x: 0.5, y: 0.5} +--- !u!1 &1759784980 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1759784981} + - component: {fileID: 1759784983} + - component: {fileID: 1759784982} + m_Layer: 5 + m_Name: Fill + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1759784981 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1759784980} + 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_Children: [] + m_Father: {fileID: 1923658737} + m_RootOrder: 0 + 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: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1759784982 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1759784980} + 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 &1759784983 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1759784980} + m_CullTransparentMesh: 1 --- !u!1 &1763779818 GameObject: m_ObjectHideFlags: 0 @@ -33484,6 +34142,139 @@ RectTransform: type: 3} m_PrefabInstance: {fileID: 695731892} m_PrefabAsset: {fileID: 0} +--- !u!1 &1901726785 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1901726786} + - component: {fileID: 1901726789} + - component: {fileID: 1901726788} + - component: {fileID: 1901726787} + m_Layer: 5 + m_Name: --VMDRecorder-- + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1901726786 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901726785} + 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_Children: + - {fileID: 1731608460} + m_Father: {fileID: 1704906816} + m_RootOrder: 14 + 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: 0, y: 40} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1901726787 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901726785} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, 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: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 1901726788} + m_OnClick: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1564959567} + m_TargetAssemblyTypeName: UmaViewerUI, umamusume + m_MethodName: ToggleUIPanel + m_Mode: 2 + m_Arguments: + m_ObjectArgument: {fileID: 1348880052} + m_ObjectArgumentAssemblyTypeName: UnityEngine.GameObject, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 +--- !u!114 &1901726788 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901726785} + 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: 0.392} + 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: 10907, 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 &1901726789 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901726785} + m_CullTransparentMesh: 1 --- !u!1 &1907940556 GameObject: m_ObjectHideFlags: 0 @@ -34072,6 +34863,42 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1923521928} m_CullTransparentMesh: 1 +--- !u!1 &1923658736 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1923658737} + m_Layer: 5 + m_Name: Fill Area + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1923658737 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1923658736} + 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_Children: + - {fileID: 1759784981} + m_Father: {fileID: 1981443671} + 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: -0.00012207031, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &1923765414 GameObject: m_ObjectHideFlags: 0 @@ -35145,6 +35972,95 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1981379719} m_CullTransparentMesh: 1 +--- !u!1 &1981443670 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1981443671} + - component: {fileID: 1981443672} + m_Layer: 5 + m_Name: Slider + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1981443671 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1981443670} + 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_Children: + - {fileID: 445905561} + - {fileID: 1923658737} + m_Father: {fileID: 668484491} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: -0.000061035156, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1981443672 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1981443670} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 67db9e8f0e2ae9c40bc1e2b64352a6b4, 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: Selected + m_DisabledTrigger: Disabled + m_Interactable: 0 + m_TargetGraphic: {fileID: 0} + m_FillRect: {fileID: 1759784981} + m_HandleRect: {fileID: 0} + m_Direction: 0 + m_MinValue: 0 + m_MaxValue: 1 + m_WholeNumbers: 0 + m_Value: 1 + m_OnValueChanged: + m_PersistentCalls: + m_Calls: [] --- !u!1 &1984124020 GameObject: m_ObjectHideFlags: 0 @@ -38124,7 +39040,7 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1704906816} - m_RootOrder: 15 + m_RootOrder: 17 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} diff --git a/Assets/Scripts/UmaContainer.cs b/Assets/Scripts/UmaContainer.cs index 3527df1..231be80 100644 --- a/Assets/Scripts/UmaContainer.cs +++ b/Assets/Scripts/UmaContainer.cs @@ -32,7 +32,6 @@ public class UmaContainer : MonoBehaviour public Texture CheekTex; public Material CheekMaterial; - [Header("Generic")] public bool IsGeneric = false; public string VarCostumeIdShort, VarCostumeIdLong, VarSkin, VarHeight, VarSocks, VarBust; @@ -48,6 +47,7 @@ public class UmaContainer : MonoBehaviour [Header("Shader")] public Material FaceMaterial; + public void MergeModel() { if (!Body) return; diff --git a/Assets/Scripts/UmaViewerUI.cs b/Assets/Scripts/UmaViewerUI.cs index 9f3ab15..f59b3cc 100644 --- a/Assets/Scripts/UmaViewerUI.cs +++ b/Assets/Scripts/UmaViewerUI.cs @@ -69,6 +69,7 @@ public class UmaViewerUI : MonoBehaviour public Slider GifSlider; public Button GifButton; + public Button VMDButton; public List TogglablePanels = new List(); public List TogglableFacials = new List(); @@ -825,4 +826,51 @@ public class UmaViewerUI : MonoBehaviour } return ""; } + + public void RecordVMD() + { + var buttonText = VMDButton.GetComponentInChildren(); + if (!UmaViewerBuilder.Instance.CurrentUMAContainer|| UmaViewerBuilder.Instance.CurrentUMAContainer.IsMini) + { + buttonText.text = string.Format("{0}", "Need Normal UMA"); + return; + } + + var container = UmaViewerBuilder.Instance.CurrentUMAContainer; + var camera = UmaViewerBuilder.Instance.PreviewCamera; + + var rootbone = container.transform.Find("Position"); + if(rootbone.gameObject.TryGetComponent(out UnityHumanoidVMDRecorder recorder)) + { + if (recorder.IsRecording) + { + if (camera.enabled) + { + var cameraRecorder = camera.GetComponent(); + cameraRecorder.StopRecording(); + cameraRecorder.SaveVMD(); + } + recorder.StopRecording(); + buttonText.text = "Saving"; + recorder.SaveVMD(container.name); + buttonText.text = "Record VMD"; + } + } + else + { + var newRecorder = rootbone.gameObject.AddComponent(); + newRecorder.Initialize(); + if (!newRecorder.IsRecording) + { + if (camera.enabled) + { + var cameraRecorder = camera.gameObject.AddComponent(); + cameraRecorder.Initialize(); + cameraRecorder.StartRecording(); + } + newRecorder.StartRecording(); + buttonText.text = "Recording..."; + } + } + } } diff --git a/Assets/Scripts/VMDRecorder.meta b/Assets/Scripts/VMDRecorder.meta new file mode 100644 index 0000000..cc654aa --- /dev/null +++ b/Assets/Scripts/VMDRecorder.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: af9fce8e2f501f243a8fe818cde62e34 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/VMDRecorder/LICENSE b/Assets/Scripts/VMDRecorder/LICENSE new file mode 100644 index 0000000..1ec518e --- /dev/null +++ b/Assets/Scripts/VMDRecorder/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 hobosore + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Assets/Scripts/VMDRecorder/LICENSE.meta b/Assets/Scripts/VMDRecorder/LICENSE.meta new file mode 100644 index 0000000..9218dfc --- /dev/null +++ b/Assets/Scripts/VMDRecorder/LICENSE.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8ab3614d2453f394ab310b22ebae7aed +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/VMDRecorder/UnityCameraVMDRecorder.cs b/Assets/Scripts/VMDRecorder/UnityCameraVMDRecorder.cs new file mode 100644 index 0000000..acd5e44 --- /dev/null +++ b/Assets/Scripts/VMDRecorder/UnityCameraVMDRecorder.cs @@ -0,0 +1,298 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using UnityEngine; + +public class UnityCameraVMDRecorder : MonoBehaviour +{ + const float WorldScaleFix = 12.5f; + const float FPSs = 0.03333f; + + public bool RecordMainCamera = false; + /// + /// カメラの座標・回転を絶対座標系で計算する + /// + public bool UseAbsoluteCoordinateSystem = true; + public bool IgnoreInitialPosition; + public bool IgnoreInitialRotation; + public Vector3 Offset = Vector3.zero; + public int KeyReductionLevel = 2; + public List LocalPositions { get; private set; } = new List(); + public List LocalRotations { get; private set; } = new List(); + public bool IsRecording { get; private set; } = false; + public int FrameNumber { get; private set; } = 0; + + Transform targetCameraTransform = null; + Camera targetCamera; + Vector3 initialPosition = Vector3.zero; + Quaternion initialRotation = Quaternion.identity; + int frameNumberSaved = 0; + List positionsSaved = new List(); + List rotationsSaved = new List(); + + // Start is called before the first frame update + public void Initialize() + { + Time.fixedDeltaTime = FPSs; + + SetCameraTransform(); + + if (targetCameraTransform != null) + { + SetInitialPositionAndRotation(); + } + } + + // Update is called once per frame + void FixedUpdate() + { + if (IsRecording) + { + SaveFrame(); + FrameNumber++; + } + } + + void SetInitialPositionAndRotation() + { + if (UseAbsoluteCoordinateSystem) + { + initialPosition = targetCameraTransform.position; + initialRotation = targetCameraTransform.rotation; + } + else + { + initialPosition = targetCameraTransform.localPosition; + initialRotation = targetCameraTransform.localRotation; + } + } + + void SetCameraTransform() + { + if (RecordMainCamera) + { + if (Camera.main != null) + { + targetCameraTransform = Camera.main.transform; + targetCamera = Camera.main; + } + else + { + enabled = false; + } + } + else + { + targetCamera = GetComponent(); + + if (targetCamera != null) + { + targetCameraTransform = transform; + } + else + { + enabled = false; + } + } + } + + void SaveFrame() + { + Vector3 position = Vector3.zero; + if (targetCameraTransform != null) + { + position = UseAbsoluteCoordinateSystem ? targetCameraTransform.position : targetCameraTransform.localPosition; + } + if (IgnoreInitialPosition) { position -= initialPosition; } + Quaternion rotation = Quaternion.identity; + if (targetCameraTransform != null) + { + rotation = UseAbsoluteCoordinateSystem ? targetCameraTransform.rotation : targetCameraTransform.localRotation; + } + if (IgnoreInitialRotation) { rotation = rotation.MinusRotation(initialRotation); } + + //座標系の変換 + Vector3 vmdPosition = new Vector3(-position.x, position.y, -position.z); + Quaternion fixedRotation = new Quaternion(-rotation.x, rotation.y, -rotation.z, rotation.w); + Vector3 vmdRotation = new Vector3(fixedRotation.eulerAngles.x, 180 - fixedRotation.eulerAngles.y, fixedRotation.eulerAngles.z); + + LocalPositions.Add(vmdPosition); + LocalRotations.Add(vmdRotation); + } + + public static void SetFPS(int fps) + { + Time.fixedDeltaTime = 1 / (float)fps; + } + + public void SetCameraTransform(Camera camera) + { + targetCameraTransform = camera.transform; + this.targetCamera = camera; + } + + /// + /// レコーディングを開始または再開 + /// + public void StartRecording() + { + SetInitialPositionAndRotation(); + IsRecording = true; + } + + /// + /// レコーディングを一時停止 + /// + public void PauseRecording() { IsRecording = false; } + + /// + /// レコーディングを終了 + /// + public void StopRecording() + { + IsRecording = false; + frameNumberSaved = FrameNumber; + positionsSaved = LocalPositions; + rotationsSaved = LocalRotations; + + FrameNumber = 0; + LocalPositions = new List(); + LocalRotations = new List(); + } + + /// + /// VMDを作成する + /// 呼び出す際は先にStopRecordingを呼び出すこと + /// + /// 保存先の絶対ファイルパス + public async void SaveVMD() + { + string fileName = Application.dataPath + "/../VMDRecords/" + string.Format("Camera_{0}.vmd", DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")); + if (IsRecording) + { + Debug.Log(targetCameraTransform.name + "VMD保存前にレコーディングをストップしてください。"); + return; + } + + if (KeyReductionLevel <= 0) { KeyReductionLevel = 1; } + + const string modelName = "カメラ・照明"; + + float fieldOfView = targetCamera.fieldOfView; + bool isOrthographic = targetCamera.orthographic; + + Debug.Log(targetCameraTransform.name + "VMDファイル作成開始"); + await Task.Run(() => + { + //ファイルの書き込み + using (FileStream fileStream = new FileStream(fileName, FileMode.Create)) + using (BinaryWriter binaryWriter = new BinaryWriter(fileStream)) + { + try + { + const string ShiftJIS = "shift_jis"; + const int intByteLength = 4; + + //ファイルタイプの書き込み + const int fileTypeLength = 30; + const string RightFileType = "Vocaloid Motion Data 0002"; + byte[] fileTypeBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes(RightFileType); + binaryWriter.Write(fileTypeBytes, 0, fileTypeBytes.Length); + binaryWriter.Write(new byte[fileTypeLength - fileTypeBytes.Length], 0, fileTypeLength - fileTypeBytes.Length); + + //モーション名の書き込み、Shift_JISで保存 + const int motionNameLength = 20; + byte[] motionNameBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes(modelName); + binaryWriter.Write(motionNameBytes, 0, Mathf.Min(motionNameBytes.Length, 20)); + if (motionNameLength - motionNameBytes.Length > 0) + { + binaryWriter.Write(new byte[motionNameLength - motionNameBytes.Length], 0, motionNameLength - motionNameBytes.Length); + } + + //全ボーンフレーム数の書き込み + byte[] allKeyFrameNumberByte = BitConverter.GetBytes(0); + binaryWriter.Write(allKeyFrameNumberByte, 0, intByteLength); + + //全モーフフレーム数の書き込み + byte[] faceFrameCount = BitConverter.GetBytes(0); + binaryWriter.Write(faceFrameCount, 0, intByteLength); + + //カメラの書き込み + byte[] cameraFrameCount = BitConverter.GetBytes((uint)(frameNumberSaved / KeyReductionLevel)); + binaryWriter.Write(cameraFrameCount, 0, intByteLength); + for (int i = 0; i < frameNumberSaved; i++) + { + if ((i % KeyReductionLevel) != 0) { continue; } + + byte[] frameNumberByte = BitConverter.GetBytes((ulong)i); + binaryWriter.Write(frameNumberByte, 0, intByteLength); + + byte[] cameraDistanceByte = BitConverter.GetBytes(0); + binaryWriter.Write(cameraDistanceByte, 0, intByteLength); + + Vector3 position = positionsSaved[i] * WorldScaleFix; + byte[] positionX = BitConverter.GetBytes(position.x); + binaryWriter.Write(positionX, 0, intByteLength); + byte[] positionY = BitConverter.GetBytes(position.y); + binaryWriter.Write(positionY, 0, intByteLength); + byte[] positionZ = BitConverter.GetBytes(position.z); + binaryWriter.Write(positionZ, 0, intByteLength); + + Vector3 rotation = rotationsSaved[i] * Mathf.Deg2Rad; + byte[] rotationX = BitConverter.GetBytes(rotation.x); + binaryWriter.Write(rotationX, 0, intByteLength); + byte[] rotationY = BitConverter.GetBytes(rotation.y); + binaryWriter.Write(rotationY, 0, intByteLength); + byte[] rotationZ = BitConverter.GetBytes(rotation.z); + binaryWriter.Write(rotationZ, 0, intByteLength); + + byte[] interpolateBytes = new byte[24]; + binaryWriter.Write(interpolateBytes, 0, 24); + + byte[] viewAngleByte = BitConverter.GetBytes((ulong)fieldOfView); + binaryWriter.Write(viewAngleByte, 0, intByteLength); + + byte perspectiveByte = Convert.ToByte(isOrthographic); + byte[] perspectiveBytes = new byte[] { perspectiveByte }; + binaryWriter.Write(new byte[] { perspectiveByte }, 0, perspectiveBytes.Length); + } + + //照明の書き込み + byte[] lightFrameCount = BitConverter.GetBytes(0); + binaryWriter.Write(lightFrameCount, 0, intByteLength); + + //セルフシャドウの書き込み + byte[] selfShadowCount = BitConverter.GetBytes(0); + binaryWriter.Write(selfShadowCount, 0, intByteLength); + + //IKの書き込み + byte[] ikCount = BitConverter.GetBytes(0); + binaryWriter.Write(ikCount, 0, intByteLength); + } + catch (Exception ex) + { + Debug.Log("VMD書き込みエラー" + ex.Message); + } + finally + { + binaryWriter.Close(); + } + } + }); + Debug.Log(targetCameraTransform.name + "VMDファイル作成終了"); + } + + /// + /// VMDを作成する + /// 呼び出す際は先にStopRecordingを呼び出すこと + /// + /// 保存先の絶対ファイルパス + /// キーの書き込み頻度を減らして容量を減らす + public void SaveVMD(string filePath, int keyReductionLevel) + { + KeyReductionLevel = keyReductionLevel; + SaveVMD(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/VMDRecorder/UnityCameraVMDRecorder.cs.meta b/Assets/Scripts/VMDRecorder/UnityCameraVMDRecorder.cs.meta new file mode 100644 index 0000000..b4b8c87 --- /dev/null +++ b/Assets/Scripts/VMDRecorder/UnityCameraVMDRecorder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9ec695d7ca4100640a3cccf269007798 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/VMDRecorder/UnityHumanoidVMDRecorder.cs b/Assets/Scripts/VMDRecorder/UnityHumanoidVMDRecorder.cs new file mode 100644 index 0000000..63b8428 --- /dev/null +++ b/Assets/Scripts/VMDRecorder/UnityHumanoidVMDRecorder.cs @@ -0,0 +1,932 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System.IO; +using System; +using System.Linq; +using System.Threading.Tasks; +using Gallop; + +//初期ポーズ(T,Aポーズ)の時点でアタッチ、有効化されている必要がある +public class UnityHumanoidVMDRecorder : MonoBehaviour +{ + public bool UseParentOfAll = true; + public bool UseCenterAsParentOfAll = true; + /// + /// 全ての親の座標・回転を絶対座標系で計算する + /// UseParentOfAllがTrueでないと意味がない + /// + public bool UseAbsoluteCoordinateSystem = false; + public bool IgnoreInitialPosition = false; + public bool IgnoreInitialRotation = false; + /// + /// 一部のモデルではMMD上ではセンターが足元にある + /// Start前に設定されている必要がある + /// + public bool UseBottomCenter = false; + /// + /// Unity上のモーフ名に1.まばたきなど番号が振られている場合、番号を除去する + /// + public bool TrimMorphNumber = false; + public int KeyReductionLevel = 2; + public bool IsRecording { get; private set; } = false; + public int FrameNumber { get; private set; } = 0; + int frameNumberSaved = 0; + const float FPSs = 0.03333f; + const string CenterNameString = "センター"; + const string GrooveNameString = "グルーブ"; + public enum BoneNames + { + 全ての親, センター, 左足IK, 右足IK, 上半身, 上半身2, 首, 頭, + 左肩, 左腕, 左ひじ, 左手首, 右肩, 右腕, 右ひじ, 右手首, + 左親指1, 左親指2, 左人指1, 左人指2, 左人指3, 左中指1, 左中指2, 左中指3, + 左薬指1, 左薬指2, 左薬指3, 左小指1, 左小指2, 左小指3, 右親指1, 右親指2, + 右人指1, 右人指2, 右人指3, 右中指1, 右中指2, 右中指3, 右薬指1, 右薬指2, + 右薬指3, 右小指1, 右小指2, 右小指3, 左足, 右足, 左ひざ, 右ひざ, + 左足首, 右足首, None + //左つま先, 右つま先は情報付けると足首の回転、位置との矛盾が生じかねない + } + //コンストラクタにて初期化 + //全てのボーンを名前で引く辞書 + Dictionary transformDictionary = new Dictionary(); + public Dictionary BoneDictionary { get; private set; } + Vector3 parentInitialPosition = Vector3.zero; + Quaternion parentInitialRotation = Quaternion.identity; + Dictionary> positionDictionary = new Dictionary>(); + Dictionary> positionDictionarySaved = new Dictionary>(); + Dictionary> rotationDictionary = new Dictionary>(); + Dictionary> rotationDictionarySaved = new Dictionary>(); + //ボーン移動量の補正係数 + //この値は大体の値、正確ではない + const float DefaultBoneAmplifier = 12.5f; + + public Vector3 ParentOfAllOffset = new Vector3(0, 0, 0); + public Vector3 LeftFootIKOffset = Vector3.zero; + public Vector3 RightFootIKOffset = Vector3.zero; + + BoneGhost boneGhost; + public MorphRecorder morphRecorder; + public MorphRecorder morphRecorderSaved; + + float aposeDegress = 38.5f; + public void Initialize() + { + Time.fixedDeltaTime = FPSs; + List objs = GetComponentsInChildren().ToList(); + BoneDictionary = new Dictionary() + { + //下半身などというものはUnityにはない + { BoneNames.全ての親, transform}, + { BoneNames.センター, objs.Find(a=>a.name.Equals("Hip"))}, + { BoneNames.上半身, objs.Find(a=>a.name.Equals("Spine"))}, + { BoneNames.上半身2, objs.Find(a=>a.name.Equals("Chest"))}, + { BoneNames.頭, objs.Find(a=>a.name.Equals("Head"))}, + { BoneNames.首, objs.Find(a=>a.name.Equals("Neck"))}, + { BoneNames.左肩, objs.Find(a=>a.name.Equals("Shoulder_L"))}, + { BoneNames.右肩, objs.Find(a=>a.name.Equals("Shoulder_R"))}, + { BoneNames.左腕, objs.Find(a=>a.name.Equals("Arm_L"))}, + { BoneNames.右腕, objs.Find(a=>a.name.Equals("Arm_R"))}, + { BoneNames.左ひじ, objs.Find(a=>a.name.Equals("Elbow_L"))}, + { BoneNames.右ひじ, objs.Find(a=>a.name.Equals("Elbow_R"))}, + { BoneNames.左手首, objs.Find(a=>a.name.Equals("Wrist_L"))}, + { BoneNames.右手首, objs.Find(a=>a.name.Equals("Wrist_R"))}, + { BoneNames.左親指1, objs.Find(a=>a.name.Equals("Thumb_02_L"))}, + { BoneNames.右親指1, objs.Find(a=>a.name.Equals("Thumb_02_R"))}, + { BoneNames.左親指2, objs.Find(a=>a.name.Equals("Thumb_03_L"))}, + { BoneNames.右親指2, objs.Find(a=>a.name.Equals("Thumb_03_R"))}, + { BoneNames.左人指1, objs.Find(a=>a.name.Equals("Index_01_L"))}, + { BoneNames.右人指1, objs.Find(a=>a.name.Equals("Index_01_R"))}, + { BoneNames.左人指2, objs.Find(a=>a.name.Equals("Index_02_L"))}, + { BoneNames.右人指2, objs.Find(a=>a.name.Equals("Index_02_R"))}, + { BoneNames.左人指3, objs.Find(a=>a.name.Equals("Index_03_L"))}, + { BoneNames.右人指3, objs.Find(a=>a.name.Equals("Index_03_R"))}, + { BoneNames.左中指1, objs.Find(a=>a.name.Equals("Middle_01_L"))}, + { BoneNames.右中指1, objs.Find(a=>a.name.Equals("Middle_01_R"))}, + { BoneNames.左中指2, objs.Find(a=>a.name.Equals("Middle_02_L"))}, + { BoneNames.右中指2, objs.Find(a=>a.name.Equals("Middle_02_R"))}, + { BoneNames.左中指3, objs.Find(a=>a.name.Equals("Middle_03_L"))}, + { BoneNames.右中指3, objs.Find(a=>a.name.Equals("Middle_03_R"))}, + { BoneNames.左薬指1, objs.Find(a=>a.name.Equals("Ring_01_L"))}, + { BoneNames.右薬指1, objs.Find(a=>a.name.Equals("Ring_01_R"))}, + { BoneNames.左薬指2, objs.Find(a=>a.name.Equals("Ring_02_L"))}, + { BoneNames.右薬指2, objs.Find(a=>a.name.Equals("Ring_02_R"))}, + { BoneNames.左薬指3, objs.Find(a=>a.name.Equals("Ring_03_L"))}, + { BoneNames.右薬指3, objs.Find(a=>a.name.Equals("Ring_03_R"))}, + { BoneNames.左小指1, objs.Find(a=>a.name.Equals("Pinky_01_L"))}, + { BoneNames.右小指1, objs.Find(a=>a.name.Equals("Pinky_01_R"))}, + { BoneNames.左小指2, objs.Find(a=>a.name.Equals("Pinky_02_L"))}, + { BoneNames.右小指2, objs.Find(a=>a.name.Equals("Pinky_02_R"))}, + { BoneNames.左小指3, objs.Find(a=>a.name.Equals("Pinky_03_L"))}, + { BoneNames.右小指3, objs.Find(a=>a.name.Equals("Pinky_03_R"))}, + { BoneNames.左足IK, objs.Find(a=>a.name.Equals("Ankle_L"))}, + { BoneNames.右足IK, objs.Find(a=>a.name.Equals("Ankle_R"))}, + { BoneNames.左足, objs.Find(a=>a.name.Equals("Thigh_L"))}, + { BoneNames.右足, objs.Find(a=>a.name.Equals("Thigh_R"))}, + { BoneNames.左ひざ, objs.Find(a=>a.name.Equals("Knee_L"))}, + { BoneNames.右ひざ, objs.Find(a=>a.name.Equals("Knee_R"))}, + { BoneNames.左足首, objs.Find(a=>a.name.Equals("Ankle_L"))}, + { BoneNames.右足首, objs.Find(a=>a.name.Equals("Ankle_R"))}, + //左つま先, 右つま先は情報付けると足首の回転、位置との矛盾が生じかねない + //{ BoneNames.左つま先, (animator.GetBoneTransform(HumanBodyBones.LeftToes))}, + //{ BoneNames.右つま先, (animator.GetBoneTransform(HumanBodyBones.RightToes))} + }; + + foreach (KeyValuePair pair in BoneDictionary) + { + transformDictionary.Add(pair.Key.ToString(), pair.Value); + } + + var animator = GetComponentInParent().UmaAnimator; + var state = animator.GetCurrentAnimatorStateInfo(0); + animator.Rebind(); + + BoneDictionary[BoneNames.左腕].Rotate(0, 0, -aposeDegress); + BoneDictionary[BoneNames.右腕].Rotate(0, 0, aposeDegress); + + SetInitialPositionAndRotation(); + + foreach (BoneNames boneName in BoneDictionary.Keys) + { + if (BoneDictionary[boneName] == null) { continue; } + + positionDictionary.Add(boneName, new List()); + rotationDictionary.Add(boneName, new List()); + } + + if (BoneDictionary[BoneNames.左足IK] != null) + { + LeftFootIKOffset = Quaternion.Inverse(transform.rotation) * (BoneDictionary[BoneNames.左足IK].position - transform.position); + } + + if (BoneDictionary[BoneNames.右足IK] != null) + { + RightFootIKOffset = Quaternion.Inverse(transform.rotation) * (BoneDictionary[BoneNames.右足IK].position - transform.position); + } + + boneGhost = new BoneGhost(BoneDictionary, UseBottomCenter); + morphRecorder = new MorphRecorder(transform); + + animator.Play(state.shortNameHash, 0, state.normalizedTime); + } + + + + private void FixedUpdate() + { + if (IsRecording) + { + SaveFrame(); + FrameNumber++; + } + } + + void SaveFrame() + { + if (boneGhost != null) { boneGhost.GhostAll(); } + if (morphRecorder != null) { morphRecorder.RecrodAllMorph(); } + + foreach (BoneNames boneName in BoneDictionary.Keys) + { + if (BoneDictionary[boneName] == null) + { + continue; + } + + if (boneName == BoneNames.右足IK || boneName == BoneNames.左足IK) + { + Vector3 targetVector = Vector3.zero; + if (UseCenterAsParentOfAll) + { + if ((!UseAbsoluteCoordinateSystem && transform.parent != null) && IgnoreInitialPosition ) + { + targetVector + = Quaternion.Inverse(transform.parent.rotation) + * (BoneDictionary[boneName].position - transform.parent.position) + - parentInitialPosition; + } + else if ((!UseAbsoluteCoordinateSystem && transform.parent != null) && !IgnoreInitialPosition) + { + targetVector + = Quaternion.Inverse(transform.parent.rotation) + * (BoneDictionary[boneName].position - transform.parent.position); + } + else if ((UseAbsoluteCoordinateSystem || transform.parent == null) && IgnoreInitialPosition) + { + targetVector = BoneDictionary[boneName].position - parentInitialPosition; + } + else if ((UseAbsoluteCoordinateSystem || transform.parent == null) && transform.parent && !IgnoreInitialPosition) + { + targetVector = BoneDictionary[boneName].position; + } + } + else + { + targetVector = BoneDictionary[boneName].position - transform.position; + targetVector = Quaternion.Inverse(transform.rotation) * targetVector; + } + targetVector -= (boneName == BoneNames.左足IK ? LeftFootIKOffset : RightFootIKOffset); + Vector3 ikPosition = new Vector3(-targetVector.x, targetVector.y, -targetVector.z); + positionDictionary[boneName].Add(ikPosition * DefaultBoneAmplifier); + //回転は全部足首に持たせる + Quaternion ikRotation = Quaternion.identity; + rotationDictionary[boneName].Add(ikRotation); + continue; + } + + if (boneGhost != null && boneGhost.GhostDictionary.Keys.Contains(boneName)) + { + if (boneGhost.GhostDictionary[boneName].ghost == null || !boneGhost.GhostDictionary[boneName].enabled) + { + rotationDictionary[boneName].Add(Quaternion.identity); + positionDictionary[boneName].Add(Vector3.zero); + continue; + } + + Vector3 boneVector = boneGhost.GhostDictionary[boneName].ghost.localPosition; + Quaternion boneQuatenion = boneGhost.GhostDictionary[boneName].ghost.localRotation; + rotationDictionary[boneName].Add(new Quaternion(-boneQuatenion.x, boneQuatenion.y, -boneQuatenion.z, boneQuatenion.w)); + + boneVector -= boneGhost.GhostOriginalLocalPositionDictionary[boneName]; + + positionDictionary[boneName].Add(new Vector3(-boneVector.x, boneVector.y, -boneVector.z) * DefaultBoneAmplifier); + continue; + } + + Quaternion fixedQuatenion = Quaternion.identity; + Quaternion vmdRotation = Quaternion.identity; + + if (boneName == BoneNames.全ての親 && UseAbsoluteCoordinateSystem) + { + fixedQuatenion = BoneDictionary[boneName].rotation; + } + else + { + fixedQuatenion = BoneDictionary[boneName].localRotation; + } + + if (boneName == BoneNames.全ての親 && IgnoreInitialRotation) + { + fixedQuatenion = BoneDictionary[boneName].localRotation.MinusRotation(parentInitialRotation); + } + + vmdRotation = new Quaternion(-fixedQuatenion.x, fixedQuatenion.y, -fixedQuatenion.z, fixedQuatenion.w); + + rotationDictionary[boneName].Add(vmdRotation); + + Vector3 fixedPosition = Vector3.zero; + Vector3 vmdPosition = Vector3.zero; + + if (boneName == BoneNames.全ての親 && UseAbsoluteCoordinateSystem) + { + fixedPosition = BoneDictionary[boneName].position; + } + else + { + fixedPosition = BoneDictionary[boneName].localPosition; + } + + if (boneName == BoneNames.全ての親 && IgnoreInitialPosition) + { + fixedPosition -= parentInitialPosition; + } + + vmdPosition = new Vector3(-fixedPosition.x, fixedPosition.y, -fixedPosition.z); + + if (boneName == BoneNames.全ての親) + { + positionDictionary[boneName].Add(vmdPosition * DefaultBoneAmplifier + ParentOfAllOffset); + } + else + { + positionDictionary[boneName].Add(vmdPosition * DefaultBoneAmplifier); + } + } + } + + void SetInitialPositionAndRotation() + { + if (UseAbsoluteCoordinateSystem) + { + parentInitialPosition = transform.position; + parentInitialRotation = transform.rotation; + } + else + { + parentInitialPosition = transform.localPosition; + parentInitialRotation = transform.localRotation; + } + } + + public static void SetFPS(int fps) + { + Time.fixedDeltaTime = 1 / (float)fps; + } + + /// + /// レコーディングを開始または再開 + /// + public void StartRecording() + { + SetInitialPositionAndRotation(); + IsRecording = true; + } + + /// + /// レコーディングを一時停止 + /// + public void PauseRecording() { IsRecording = false; } + + /// + /// レコーディングを終了 + /// + public void StopRecording() + { + IsRecording = false; + frameNumberSaved = FrameNumber; + morphRecorderSaved = morphRecorder; + FrameNumber = 0; + positionDictionarySaved = positionDictionary; + positionDictionary = new Dictionary>(); + rotationDictionarySaved = rotationDictionary; + rotationDictionary = new Dictionary>(); + foreach (BoneNames boneName in BoneDictionary.Keys) + { + if (BoneDictionary[boneName] == null) { continue; } + + positionDictionary.Add(boneName, new List()); + rotationDictionary.Add(boneName, new List()); + } + morphRecorder = new MorphRecorder(transform); + } + + /// + /// VMDを作成する + /// 呼び出す際は先にStopRecordingを呼び出すこと + /// + /// VMDファイルに記載される専用モデル名 + /// 保存先の絶対ファイルパス + public async void SaveVMD(string modelName, string filePath) + { + if (IsRecording) + { + Debug.Log(transform.name + "VMD保存前にレコーディングをストップしてください。"); + return; + } + + if (KeyReductionLevel <= 0) { KeyReductionLevel = 1; } + + Debug.Log(transform.name + "VMDファイル作成開始"); + await Task.Run(() => + { + //ファイルの書き込み + using (FileStream fileStream = new FileStream(filePath, FileMode.Create)) + using (BinaryWriter binaryWriter = new BinaryWriter(fileStream)) + { + try + { + const string ShiftJIS = "shift_jis"; + const int intByteLength = 4; + + //ファイルタイプの書き込み + const int fileTypeLength = 30; + const string RightFileType = "Vocaloid Motion Data 0002"; + byte[] fileTypeBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes(RightFileType); + binaryWriter.Write(fileTypeBytes, 0, fileTypeBytes.Length); + binaryWriter.Write(new byte[fileTypeLength - fileTypeBytes.Length], 0, fileTypeLength - fileTypeBytes.Length); + + //モデル名の書き込み、Shift_JISで保存 + const int modelNameLength = 20; + byte[] modelNameBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes(modelName); + //モデル名が長すぎたとき + modelNameBytes = modelNameBytes.Take(Mathf.Min(modelNameLength, modelNameBytes.Length)).ToArray(); + binaryWriter.Write(modelNameBytes, 0, modelNameBytes.Length); + binaryWriter.Write(new byte[modelNameLength - modelNameBytes.Length], 0, modelNameLength - modelNameBytes.Length); + + //全ボーンフレーム数の書き込み + void LoopWithBoneCondition(Action action) + { + for (int i = 0; i < frameNumberSaved; i++) + { + if ((i % KeyReductionLevel) != 0) { continue; } + + foreach (BoneNames boneName in Enum.GetValues(typeof(BoneNames))) + { + if (!BoneDictionary.Keys.Contains(boneName)) { continue; } + if (BoneDictionary[boneName] == null) { continue; } + if (!UseParentOfAll && boneName == BoneNames.全ての親) { continue; } + + action(boneName, i); + } + } + } + uint allKeyFrameNumber = 0; + LoopWithBoneCondition((a, b) => { allKeyFrameNumber++; }); + byte[] allKeyFrameNumberByte = BitConverter.GetBytes(allKeyFrameNumber); + binaryWriter.Write(allKeyFrameNumberByte, 0, intByteLength); + + //人ボーンの書き込み + LoopWithBoneCondition((boneName, i) => + { + const int boneNameLength = 15; + string boneNameString = boneName.ToString(); + if (boneName == BoneNames.全ての親 && UseCenterAsParentOfAll) + { + boneNameString = CenterNameString; + } + if (boneName == BoneNames.センター && UseCenterAsParentOfAll) + { + boneNameString = GrooveNameString; + } + + byte[] boneNameBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes(boneNameString); + binaryWriter.Write(boneNameBytes, 0, boneNameBytes.Length); + binaryWriter.Write(new byte[boneNameLength - boneNameBytes.Length], 0, boneNameLength - boneNameBytes.Length); + + byte[] frameNumberByte = BitConverter.GetBytes((ulong)i); + binaryWriter.Write(frameNumberByte, 0, intByteLength); + + Vector3 position = positionDictionarySaved[boneName][i]; + byte[] positionX = BitConverter.GetBytes(position.x); + binaryWriter.Write(positionX, 0, intByteLength); + byte[] positionY = BitConverter.GetBytes(position.y); + binaryWriter.Write(positionY, 0, intByteLength); + byte[] positionZ = BitConverter.GetBytes(position.z); + binaryWriter.Write(positionZ, 0, intByteLength); + Quaternion rotation = rotationDictionarySaved[boneName][i]; + byte[] rotationX = BitConverter.GetBytes(rotation.x); + binaryWriter.Write(rotationX, 0, intByteLength); + byte[] rotationY = BitConverter.GetBytes(rotation.y); + binaryWriter.Write(rotationY, 0, intByteLength); + byte[] rotationZ = BitConverter.GetBytes(rotation.z); + binaryWriter.Write(rotationZ, 0, intByteLength); + byte[] rotationW = BitConverter.GetBytes(rotation.w); + binaryWriter.Write(rotationW, 0, intByteLength); + + byte[] interpolateBytes = new byte[64]; + binaryWriter.Write(interpolateBytes, 0, 64); + }); + + //全モーフフレーム数の書き込み + morphRecorderSaved.DisableIntron(); + if (TrimMorphNumber) { morphRecorderSaved.TrimMorphNumber(); } + void LoopWithMorphCondition(Action action) + { + for (int i = 0; i < frameNumberSaved; i++) + { + foreach (string morphName in morphRecorderSaved.MorphDrivers.Keys) + { + if (morphRecorderSaved.MorphDrivers[morphName].ValueList.Count == 0) { continue; } + if (i > morphRecorderSaved.MorphDrivers[morphName].ValueList.Count) { continue; } + //変化のない部分は省く + if (!morphRecorderSaved.MorphDrivers[morphName].ValueList[i].enabled) { continue; } + const int boneNameLength = 15; + string morphNameString = morphName.ToString(); + byte[] morphNameBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes(morphNameString); + //名前が長過ぎた場合書き込まない + if (boneNameLength - morphNameBytes.Length < 0) { continue; } + + action(morphName, i); + } + } + } + uint allMorphNumber = 0; + LoopWithMorphCondition((a, b) => { allMorphNumber++; }); + byte[] faceFrameCount = BitConverter.GetBytes(allMorphNumber); + binaryWriter.Write(faceFrameCount, 0, intByteLength); + + //モーフの書き込み + LoopWithMorphCondition((morphName, i) => + { + const int boneNameLength = 15; + string morphNameString = morphName.ToString(); + byte[] morphNameBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes(morphNameString); + + binaryWriter.Write(morphNameBytes, 0, morphNameBytes.Length); + binaryWriter.Write(new byte[boneNameLength - morphNameBytes.Length], 0, boneNameLength - morphNameBytes.Length); + + byte[] frameNumberByte = BitConverter.GetBytes((ulong)i); + binaryWriter.Write(frameNumberByte, 0, intByteLength); + + byte[] valueByte = BitConverter.GetBytes(morphRecorderSaved.MorphDrivers[morphName].ValueList[i].value); + binaryWriter.Write(valueByte, 0, intByteLength); + }); + + //カメラの書き込み + byte[] cameraFrameCount = BitConverter.GetBytes(0); + binaryWriter.Write(cameraFrameCount, 0, intByteLength); + + //照明の書き込み + byte[] lightFrameCount = BitConverter.GetBytes(0); + binaryWriter.Write(lightFrameCount, 0, intByteLength); + + //セルフシャドウの書き込み + byte[] selfShadowCount = BitConverter.GetBytes(0); + binaryWriter.Write(selfShadowCount, 0, intByteLength); + + //IKの書き込み + //0フレームにキーフレーム一つだけ置く + byte[] ikCount = BitConverter.GetBytes(1); + byte[] ikFrameNumber = BitConverter.GetBytes(0); + byte modelDisplay = Convert.ToByte(1); + //右足IKと左足IKと右足つま先IKと左足つま先IKの4つ + byte[] ikNumber = BitConverter.GetBytes(4); + const int IKNameLength = 20; + byte[] leftIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("左足IK"); + byte[] rightIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("右足IK"); + byte[] leftToeIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("左つま先IK"); + byte[] rightToeIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("右つま先IK"); + byte ikOn = Convert.ToByte(1); + byte ikOff = Convert.ToByte(0); + binaryWriter.Write(ikCount, 0, intByteLength); + binaryWriter.Write(ikFrameNumber, 0, intByteLength); + binaryWriter.Write(modelDisplay); + binaryWriter.Write(ikNumber, 0, intByteLength); + binaryWriter.Write(leftIKName, 0, leftIKName.Length); + binaryWriter.Write(new byte[IKNameLength - leftIKName.Length], 0, IKNameLength - leftIKName.Length); + binaryWriter.Write(ikOff); + binaryWriter.Write(leftToeIKName, 0, leftToeIKName.Length); + binaryWriter.Write(new byte[IKNameLength - leftToeIKName.Length], 0, IKNameLength - leftToeIKName.Length); + binaryWriter.Write(ikOff); + binaryWriter.Write(rightIKName, 0, rightIKName.Length); + binaryWriter.Write(new byte[IKNameLength - rightIKName.Length], 0, IKNameLength - rightIKName.Length); + binaryWriter.Write(ikOff); + binaryWriter.Write(rightToeIKName, 0, rightToeIKName.Length); + binaryWriter.Write(new byte[IKNameLength - rightToeIKName.Length], 0, IKNameLength - rightToeIKName.Length); + binaryWriter.Write(ikOff); + } + catch (Exception ex) + { + Debug.Log("VMD書き込みエラー" + ex.Message); + } + finally + { + binaryWriter.Close(); + } + } + }); + + Destroy(this); + } + + /// + /// VMDを作成する + /// 呼び出す際は先にStopRecordingを呼び出すこと + /// + /// VMDファイルに記載される専用モデル名 + /// 保存先の絶対ファイルパス + /// キーの書き込み頻度を減らして容量を減らす + public void SaveVMD(string modelName, int keyReductionLevel = 3) + { + string fileName = Application.dataPath + "/../VMDRecords/" + string.Format("UMA_{0}.vmd", DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")); + Directory.CreateDirectory(Application.dataPath + "/../VMDRecords"); + KeyReductionLevel = keyReductionLevel; + SaveVMD(modelName, fileName); + } + + //裏で正規化されたモデル + //(初期ポーズで各ボーンのlocalRotationがQuaternion.identityのモデル)を疑似的にアニメーションさせる + class BoneGhost + { + public Dictionary GhostDictionary { get; private set; } = new Dictionary(); + public Dictionary GhostOriginalLocalPositionDictionary { get; private set; } = new Dictionary(); + public Dictionary GhostOriginalRotationDictionary { get; private set; } = new Dictionary(); + public Dictionary OriginalRotationDictionary { get; private set; } = new Dictionary(); + + public bool UseBottomCenter { get; private set; } = false; + + const string GhostSalt = "Ghost"; + private Dictionary boneDictionary = new Dictionary(); + float centerOffsetLength = 0; + + public BoneGhost(Dictionary boneDictionary, bool useBottomCenter) + { + this.boneDictionary = boneDictionary; + UseBottomCenter = useBottomCenter; + + Dictionary boneParentDictionary + = new Dictionary() + { + { BoneNames.センター, (BoneNames.None, BoneNames.None, BoneNames.全ての親) }, + { BoneNames.左足, (BoneNames.None, BoneNames.None, BoneNames.センター) }, + { BoneNames.左ひざ, (BoneNames.None, BoneNames.None, BoneNames.左足) }, + { BoneNames.左足首, (BoneNames.None, BoneNames.None, BoneNames.左ひざ) }, + { BoneNames.右足, (BoneNames.None, BoneNames.None, BoneNames.センター) }, + { BoneNames.右ひざ, (BoneNames.None, BoneNames.None, BoneNames.右足) }, + { BoneNames.右足首, (BoneNames.None, BoneNames.None, BoneNames.右ひざ) }, + { BoneNames.上半身, (BoneNames.None, BoneNames.None, BoneNames.センター) }, + { BoneNames.上半身2, (BoneNames.None, BoneNames.None, BoneNames.上半身) }, + { BoneNames.首, (BoneNames.上半身2, BoneNames.None, BoneNames.上半身) }, + { BoneNames.頭, (BoneNames.首, BoneNames.上半身2, BoneNames.上半身) }, + { BoneNames.左肩, (BoneNames.上半身2, BoneNames.None, BoneNames.上半身) }, + { BoneNames.左腕, (BoneNames.左肩, BoneNames.上半身2, BoneNames.上半身) }, + { BoneNames.左ひじ, (BoneNames.None, BoneNames.None, BoneNames.左腕) }, + { BoneNames.左手首, (BoneNames.None, BoneNames.None, BoneNames.左ひじ) }, + { BoneNames.左親指1, (BoneNames.左手首, BoneNames.None, BoneNames.None) }, + { BoneNames.左親指2, (BoneNames.左親指1, BoneNames.None, BoneNames.None) }, + { BoneNames.左人指1, (BoneNames.左手首, BoneNames.None, BoneNames.None) }, + { BoneNames.左人指2, (BoneNames.左人指1, BoneNames.None, BoneNames.None) }, + { BoneNames.左人指3, (BoneNames.左人指2, BoneNames.None, BoneNames.None) }, + { BoneNames.左中指1, (BoneNames.左手首, BoneNames.None, BoneNames.None) }, + { BoneNames.左中指2, (BoneNames.左中指1, BoneNames.None, BoneNames.None) }, + { BoneNames.左中指3, (BoneNames.左中指2, BoneNames.None, BoneNames.None) }, + { BoneNames.左薬指1, (BoneNames.左手首, BoneNames.None, BoneNames.None) }, + { BoneNames.左薬指2, (BoneNames.左薬指1, BoneNames.None, BoneNames.None) }, + { BoneNames.左薬指3, (BoneNames.左薬指2, BoneNames.None, BoneNames.None) }, + { BoneNames.左小指1, (BoneNames.左手首, BoneNames.None, BoneNames.None) }, + { BoneNames.左小指2, (BoneNames.左小指1, BoneNames.None, BoneNames.None) }, + { BoneNames.左小指3, (BoneNames.左小指2, BoneNames.None, BoneNames.None) }, + { BoneNames.右肩, (BoneNames.上半身2, BoneNames.None, BoneNames.上半身) }, + { BoneNames.右腕, (BoneNames.右肩, BoneNames.上半身2, BoneNames.上半身) }, + { BoneNames.右ひじ, (BoneNames.None, BoneNames.None, BoneNames.右腕) }, + { BoneNames.右手首, (BoneNames.None, BoneNames.None, BoneNames.右ひじ) }, + { BoneNames.右親指1, (BoneNames.右手首, BoneNames.None, BoneNames.None) }, + { BoneNames.右親指2, (BoneNames.右親指1, BoneNames.None, BoneNames.None) }, + { BoneNames.右人指1, (BoneNames.右手首, BoneNames.None, BoneNames.None) }, + { BoneNames.右人指2, (BoneNames.右人指1, BoneNames.None, BoneNames.None) }, + { BoneNames.右人指3, (BoneNames.右人指2, BoneNames.None, BoneNames.None) }, + { BoneNames.右中指1, (BoneNames.右手首, BoneNames.None, BoneNames.None) }, + { BoneNames.右中指2, (BoneNames.右中指1, BoneNames.None, BoneNames.None) }, + { BoneNames.右中指3, (BoneNames.右中指2, BoneNames.None, BoneNames.None) }, + { BoneNames.右薬指1, (BoneNames.右手首, BoneNames.None, BoneNames.None) }, + { BoneNames.右薬指2, (BoneNames.右薬指1, BoneNames.None, BoneNames.None) }, + { BoneNames.右薬指3, (BoneNames.右薬指2, BoneNames.None, BoneNames.None) }, + { BoneNames.右小指1, (BoneNames.右手首, BoneNames.None, BoneNames.None) }, + { BoneNames.右小指2, (BoneNames.右小指1, BoneNames.None, BoneNames.None) }, + { BoneNames.右小指3, (BoneNames.右小指2, BoneNames.None, BoneNames.None) }, + }; + + //Ghostの生成 + foreach (BoneNames boneName in boneDictionary.Keys) + { + if (boneName == BoneNames.全ての親 || boneName == BoneNames.左足IK || boneName == BoneNames.右足IK) + { + continue; + } + + if (boneDictionary[boneName] == null) + { + GhostDictionary.Add(boneName, (null, false)); + continue; + } + + Transform ghost = new GameObject(boneDictionary[boneName].name + GhostSalt).transform; + if (boneName == BoneNames.センター && UseBottomCenter) + { + ghost.position = boneDictionary[BoneNames.全ての親].position; + } + else + { + ghost.position = boneDictionary[boneName].position; + } + GhostDictionary.Add(boneName, (ghost, true)); + } + + //Ghostの親子構造を設定 + foreach (BoneNames boneName in boneDictionary.Keys) + { + if (boneName == BoneNames.全ての親 || boneName == BoneNames.左足IK || boneName == BoneNames.右足IK) + { + continue; + } + + if (GhostDictionary[boneName].ghost == null || !GhostDictionary[boneName].enabled) + { + continue; + } + + if (boneName == BoneNames.センター) + { + GhostDictionary[boneName].ghost.SetParent(boneDictionary[BoneNames.全ての親]); + continue; + } + + if (boneParentDictionary[boneName].optionParent1 != BoneNames.None && boneDictionary[boneParentDictionary[boneName].optionParent1] != null) + { + GhostDictionary[boneName].ghost.SetParent(GhostDictionary[boneParentDictionary[boneName].optionParent1].ghost); + } + else if (boneParentDictionary[boneName].optionParent2 != BoneNames.None && boneDictionary[boneParentDictionary[boneName].optionParent2] != null) + { + GhostDictionary[boneName].ghost.SetParent(GhostDictionary[boneParentDictionary[boneName].optionParent2].ghost); + } + else if (boneParentDictionary[boneName].necessaryParent != BoneNames.None && boneDictionary[boneParentDictionary[boneName].necessaryParent] != null) + { + GhostDictionary[boneName].ghost.SetParent(GhostDictionary[boneParentDictionary[boneName].necessaryParent].ghost); + } + else + { + GhostDictionary[boneName] = (GhostDictionary[boneName].ghost, false); + } + } + + //初期状態を保存 + foreach (BoneNames boneName in GhostDictionary.Keys) + { + if (GhostDictionary[boneName].ghost == null || !GhostDictionary[boneName].enabled) + { + GhostOriginalLocalPositionDictionary.Add(boneName, Vector3.zero); + GhostOriginalRotationDictionary.Add(boneName, Quaternion.identity); + OriginalRotationDictionary.Add(boneName, Quaternion.identity); + } + else + { + GhostOriginalRotationDictionary.Add(boneName, GhostDictionary[boneName].ghost.rotation); + OriginalRotationDictionary.Add(boneName, boneDictionary[boneName].rotation); + if (boneName == BoneNames.センター && UseBottomCenter) + { + GhostOriginalLocalPositionDictionary.Add(boneName, Vector3.zero); + continue; + } + GhostOriginalLocalPositionDictionary.Add(boneName, GhostDictionary[boneName].ghost.localPosition); + } + } + + centerOffsetLength = Vector3.Distance(boneDictionary[BoneNames.全ての親].position, boneDictionary[BoneNames.センター].position); + } + + public void GhostAll() + { + foreach (BoneNames boneName in GhostDictionary.Keys) + { + if (GhostDictionary[boneName].ghost == null || !GhostDictionary[boneName].enabled) { continue; } + Quaternion transQuaternion = boneDictionary[boneName].rotation * Quaternion.Inverse(OriginalRotationDictionary[boneName]); + GhostDictionary[boneName].ghost.rotation = transQuaternion * GhostOriginalRotationDictionary[boneName]; + if (boneName == BoneNames.センター && UseBottomCenter) + { + GhostDictionary[boneName].ghost.position = boneDictionary[boneName].position - centerOffsetLength * GhostDictionary[boneName].ghost.up; + continue; + } + GhostDictionary[boneName].ghost.position = boneDictionary[boneName].position; + } + } + } + + [Serializable] + public class MorphRecorder + { + public List FacialMorphList; + //キーはunity上のモーフ名 + public Dictionary MorphDrivers { get; private set; } = new Dictionary(); + + public MorphRecorder(Transform model) + { + var facialTarget = model.GetComponentInParent().FaceDrivenKeyTarget; + FacialMorphList = new List(); + FacialMorphList.AddRange(facialTarget.EyeBrowMorphs); + FacialMorphList.AddRange(facialTarget.EyeMorphs); + FacialMorphList.AddRange(facialTarget.MouthMorphs); + for (int i = 0; i < FacialMorphList.Count; i++) + { + string morphName = ConvertMorphName(FacialMorphList[i].name); + + if (MorphDrivers.Keys.Contains(morphName)) + { + if (!MorphDrivers[morphName].Morphs.Contains(FacialMorphList[i])) + { + MorphDrivers[morphName].Morphs.Add(FacialMorphList[i]); + } + } + else + { + List morphList = new List(); + morphList.Add(FacialMorphList[i]); + var driver = new MorphDriver(morphList, i); + MorphDrivers.Add(morphName, driver); + } + } + } + + public string ConvertMorphName(string name) + { + switch (name) + { + case "EyeBrow_1_R": return "にこり右"; + case "EyeBrow_1_L": return "にこり左"; + case "EyeBrow_5_R": return "真面目右"; + case "EyeBrow_5_L": return "真面目左"; + case "EyeBrow_6_R": return "困る右"; + case "EyeBrow_6_L": return "困る左"; + case "EyeBrow_7_R": return "怒り右"; + case "EyeBrow_7_L": return "怒り左"; + case "EyeBrow_11_R": return "下右"; + case "EyeBrow_11_L": return "下左"; + case "EyeBrow_21_R": return "上右"; + case "EyeBrow_21_L": return "上左"; + + case "Eye_2_R": return "ウィンク2右"; + case "Eye_2_L": return "ウィンク2"; + case "Eye_5_R": return "ウィンク右"; + case "Eye_5_L": return "ウィンク"; + case "Eye_8_R": return "ウィンク右"; + case "Eye_8_L": return "ウィンク"; + case "Eye_9_L": + case "Eye_10_L": + case "Eye_11_L": + case "Eye_18_L": return "キリッ"; + case "Eye_16_L": return "なごみ"; + case "Eye_12_L": return "びっくり"; + case "Eye_15_L": return "じと目"; + case "Eye_14_L": return "瞳小"; + + case "Mouth_9_0": return "ん"; + case "Mouth_12_0": return "にっこり"; + case "Mouth_13_0": return "口角上げ"; + case "Mouth_22_0": return "にやり"; + case "Mouth_5_0": + case "Mouth_6_0": + case "Mouth_7_0": + case "Mouth_23_0": return "あ"; + case "Mouth_25_0": + case "Mouth_8_0": return "い"; + case "Mouth_28_0": + case "Mouth_16_0": return "う"; + case "Mouth_31_0": + case "Mouth_10_0": + case "Mouth_14_0": return "お"; + case "Mouth_33_0": return "え"; + case "Mouth_41_0": return "口角下げ"; + case "Mouth_45_0": return "ぺろっ"; + case "Mouth_54_0": return "口横広げ"; + case "Mouth_55_0": return "口横狭い"; + default:return name; + } + } + + public void RecrodAllMorph() + { + foreach (MorphDriver morphDriver in MorphDrivers.Values) + { + morphDriver.RecordMorph(); + } + } + + public void TrimMorphNumber() + { + string dot = "."; + Dictionary morphDriversTemp = new Dictionary(); + foreach (string morphName in MorphDrivers.Keys) + { + //正規表現使うより、dot探して整数か見る + if (morphName.Contains(dot) && int.TryParse(morphName.Substring(0, morphName.IndexOf(dot)), out int dummy)) + { + morphDriversTemp.Add(morphName.Substring(morphName.IndexOf(dot) + 1), MorphDrivers[morphName]); + continue; + } + morphDriversTemp.Add(morphName, MorphDrivers[morphName]); + } + MorphDrivers = morphDriversTemp; + } + + public void DisableIntron() + { + foreach (string morphName in MorphDrivers.Keys) + { + for (int i = 0; i < MorphDrivers[morphName].ValueList.Count; i++) + { + //情報がなければ次へ + if (MorphDrivers[morphName].ValueList.Count == 0) { continue; } + //今、前、後が同じなら不必要なので無効化 + if (i > 0 + && i < MorphDrivers[morphName].ValueList.Count - 1 + && floatCompare(MorphDrivers[morphName].ValueList[i].value, MorphDrivers[morphName].ValueList[i - 1].value) + && floatCompare(MorphDrivers[morphName].ValueList[i].value, MorphDrivers[morphName].ValueList[i + 1].value)) + { + MorphDrivers[morphName].ValueList[i] = (MorphDrivers[morphName].ValueList[i].value, false); + } + } + } + } + + bool floatCompare(float f1, float f2) + { + int a = (int)(f1 * 100); + int b = (int)(f2 * 100); + return a == b; + } + + [Serializable] + public class MorphDriver + { + public List Morphs; + + public int MorphIndex { get; private set; } + + public List<(float value, bool enabled)> ValueList = new List<(float value, bool enabled)>(); + + public MorphDriver(List facialMorph, int morphIndex) + { + Morphs = facialMorph; + MorphIndex = morphIndex; + } + + public void RecordMorph() + { + float val = 0; + foreach(var morph in Morphs) + { + val += morph.weight; + } + ValueList.Add((Mathf.Clamp01(val), true)); + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/VMDRecorder/UnityHumanoidVMDRecorder.cs.meta b/Assets/Scripts/VMDRecorder/UnityHumanoidVMDRecorder.cs.meta new file mode 100644 index 0000000..d2e5882 --- /dev/null +++ b/Assets/Scripts/VMDRecorder/UnityHumanoidVMDRecorder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d0b34d9392c54234fae556b70776e9ea +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/VMDRecorder/UnityVMDQuaternionExtentions.cs b/Assets/Scripts/VMDRecorder/UnityVMDQuaternionExtentions.cs new file mode 100644 index 0000000..347d763 --- /dev/null +++ b/Assets/Scripts/VMDRecorder/UnityVMDQuaternionExtentions.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class UnityVMDQuaternionExtentions +{ + public static Quaternion PlusRotation(this Quaternion q1, Quaternion q2) + { + return Quaternion.Euler(q1.eulerAngles + q2.eulerAngles); + } + + public static Quaternion MinusRotation(this Quaternion q1, Quaternion q2) + { + return Quaternion.Euler(q1.eulerAngles - q2.eulerAngles); + } +} diff --git a/Assets/Scripts/VMDRecorder/UnityVMDQuaternionExtentions.cs.meta b/Assets/Scripts/VMDRecorder/UnityVMDQuaternionExtentions.cs.meta new file mode 100644 index 0000000..acdcad2 --- /dev/null +++ b/Assets/Scripts/VMDRecorder/UnityVMDQuaternionExtentions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 578ee69407cced54c835f2f1bcbe77bd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index a58cdeb..7ae7f85 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -18,6 +18,9 @@ EditorUserSettings: value: 22424703114646680e0b0227036c7c111b120a2b182d3524633c133af6f9 flags: 0 RecentlyUsedScenePath-4: + value: 224247031146466d202a3e27132c4d1413052b2b21382a35621a1c3ef2ec310be1e238eca92f31352d1b + flags: 0 + RecentlyUsedScenePath-5: value: 22424703114646680e0b0227036c691504041125227a68252320092a flags: 0 vcSharedLogLevel: