Merge pull request #11 from croakfang/master
Fix the outline problem, add VMD output support
This commit is contained in:
@@ -62,3 +62,4 @@ sysinfo.txt
|
||||
crashlytics-build.properties
|
||||
|
||||
/Assets/Plugins/RootMotion/PuppetMaster/_Integration
|
||||
/VMDRecords
|
||||
|
||||
@@ -7,7 +7,7 @@ public class GlobalValue : EditorWindow
|
||||
{
|
||||
float _Global_MaxDensity = 1.0f;
|
||||
float _Global_MaxHeight = 10.0f;
|
||||
float _GlobalOutlineOffest = 0.0f;
|
||||
float _GlobalOutlineOffset = 0.0f;
|
||||
float _GlobalOutlineWidth = 1.0f;
|
||||
float _GlobalCameraFov = 0.0f;
|
||||
float _CylinderBlend = 0.0f;
|
||||
@@ -72,7 +72,7 @@ public class GlobalValue : EditorWindow
|
||||
//Float
|
||||
_Global_MaxDensity = EditorGUILayout.Slider("最低能见度", _Global_MaxDensity, 0, 1);
|
||||
_Global_MaxHeight = EditorGUILayout.Slider("最高可见高度", _Global_MaxHeight, 0, 10);
|
||||
_GlobalOutlineOffest = EditorGUILayout.Slider("_GlobalOutlineOffest", _GlobalOutlineOffest, 0, 100);
|
||||
_GlobalOutlineOffset = EditorGUILayout.Slider("_GlobalOutlineOffset", _GlobalOutlineOffset, -100, 100);
|
||||
_GlobalOutlineWidth = EditorGUILayout.Slider("全局轮廓线宽度", _GlobalOutlineWidth, 0, 100);
|
||||
_GlobalCameraFov = EditorGUILayout.Slider("_GlobalCameraFov", _GlobalCameraFov, 0, 100);
|
||||
_CylinderBlend = EditorGUILayout.Slider("_CylinderBlend", _CylinderBlend, 0, 100);
|
||||
@@ -131,7 +131,7 @@ public class GlobalValue : EditorWindow
|
||||
//Float
|
||||
Shader.SetGlobalFloat("_Global_MaxDensity", _Global_MaxDensity);
|
||||
Shader.SetGlobalFloat("_Global_MaxHeight", _Global_MaxHeight);
|
||||
Shader.SetGlobalFloat("_GlobalOutlineOffest", _GlobalOutlineOffest);
|
||||
Shader.SetGlobalFloat("_GlobalOutlineOffset", _GlobalOutlineOffset);
|
||||
Shader.SetGlobalFloat("_GlobalOutlineWidth", _GlobalOutlineWidth);
|
||||
Shader.SetGlobalFloat("_GlobalCameraFov", _GlobalCameraFov);
|
||||
Shader.SetGlobalFloat("_CylinderBlend", _CylinderBlend);
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 668efe4a54d94f244a2f44a5a3947550
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0738b70a6f9235d4fa3ee1907af514cc
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -691,7 +691,7 @@ RectTransform:
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 260, y: 260}
|
||||
m_SizeDelta: {x: 265, y: 265}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &5440685832306619784
|
||||
CanvasRenderer:
|
||||
|
||||
+996
-20
File diff suppressed because it is too large
Load Diff
@@ -8,6 +8,7 @@ using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
public class CameraOrbit : MonoBehaviour
|
||||
{
|
||||
public static CameraOrbit instance;
|
||||
public int CameraMode = 0;
|
||||
public int AAMode = 0;
|
||||
|
||||
@@ -52,6 +53,7 @@ public class CameraOrbit : MonoBehaviour
|
||||
eventSystem = EventSystem.current;
|
||||
|
||||
lookRotation = transform.localRotation;
|
||||
instance = this;
|
||||
}
|
||||
|
||||
void Update()
|
||||
@@ -83,7 +85,7 @@ public class CameraOrbit : MonoBehaviour
|
||||
if (AAMode != AAModeDropdown.value)
|
||||
{
|
||||
var postprocessLayerMain = Camera.main.GetComponent<PostProcessLayer>();
|
||||
var postprocessLayerPreview = UmaViewerBuilder.Instance.PreviewCamera.GetComponent<PostProcessLayer>();
|
||||
var postprocessLayerPreview = UmaViewerBuilder.Instance.AnimationCamera.GetComponent<PostProcessLayer>();
|
||||
postprocessLayerMain.antialiasingMode = postprocessLayerPreview.antialiasingMode = (PostProcessLayer.Antialiasing)AAModeDropdown.value;
|
||||
Debug.Log($"Switched AntiAliasing to {(PostProcessLayer.Antialiasing)AAModeDropdown.value}");
|
||||
AAMode = AAModeDropdown.value;
|
||||
|
||||
@@ -82,11 +82,13 @@ public class DynamicBone : MonoBehaviour
|
||||
[Tooltip("The force apply to bones.")]
|
||||
#endif
|
||||
public Vector3 m_Force = Vector3.zero;
|
||||
|
||||
|
||||
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
[Tooltip("Bones exclude from physics simulation.")]
|
||||
[Tooltip("The limit angle to bones.")]
|
||||
#endif
|
||||
public Vector3 m_LimitAngel_Min = Vector3.zero;
|
||||
public Vector3 m_LimitAngel_Max = Vector3.zero;
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
[Tooltip("Bones exclude from physics simulation.")]
|
||||
#endif
|
||||
public List<Transform> m_Exclusions = null;
|
||||
|
||||
@@ -131,6 +133,9 @@ public class DynamicBone : MonoBehaviour
|
||||
public float m_BoneLength = 0;
|
||||
public bool m_isCollide = false;
|
||||
|
||||
|
||||
public Vector3 m_LimitAngel_Min = Vector3.zero;
|
||||
public Vector3 m_LimitAngel_Max = Vector3.zero;
|
||||
public Vector3 m_Position = Vector3.zero;
|
||||
public Vector3 m_PrevPosition = Vector3.zero;
|
||||
public Vector3 m_EndOffset = Vector3.zero;
|
||||
@@ -417,6 +422,8 @@ public class DynamicBone : MonoBehaviour
|
||||
p.m_Inert = m_Inert;
|
||||
p.m_Friction = m_Friction;
|
||||
p.m_Radius = m_Radius;
|
||||
p.m_LimitAngel_Min = m_LimitAngel_Min;
|
||||
p.m_LimitAngel_Max = m_LimitAngel_Max;
|
||||
|
||||
if (m_BoneTotalLength > 0)
|
||||
{
|
||||
@@ -529,7 +536,8 @@ public class DynamicBone : MonoBehaviour
|
||||
|
||||
// keep shape
|
||||
float stiffness = Mathf.Lerp(1.0f, p.m_Stiffness, m_Weight);
|
||||
if (stiffness > 0 || p.m_Elasticity > 0)
|
||||
float elasticity = p.m_Elasticity;
|
||||
if (stiffness > 0 || elasticity > 0)
|
||||
{
|
||||
Matrix4x4 m0 = p0.m_Transform.localToWorldMatrix;
|
||||
m0.SetColumn(3, p0.m_Position);
|
||||
@@ -540,7 +548,7 @@ public class DynamicBone : MonoBehaviour
|
||||
restPos = m0.MultiplyPoint3x4(p.m_EndOffset);
|
||||
|
||||
Vector3 d = restPos - p.m_Position;
|
||||
p.m_Position += d * (p.m_Elasticity * timeVar);
|
||||
p.m_Position += d * (elasticity * timeVar);
|
||||
|
||||
if (stiffness > 0)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ public class Screenshot : MonoBehaviour
|
||||
|
||||
public static void TakeScreenshot()
|
||||
{
|
||||
var camera = UmaViewerBuilder.Instance.PreviewCamera.enabled ? UmaViewerBuilder.Instance.PreviewCamera : Camera.main;
|
||||
var camera = UmaViewerBuilder.Instance.AnimationCamera.enabled ? UmaViewerBuilder.Instance.AnimationCamera : Camera.main;
|
||||
int width = int.Parse(UmaViewerUI.Instance.SSWidth.text);
|
||||
int height = int.Parse(UmaViewerUI.Instance.SSHeight.text);
|
||||
width = width == -1 ? Screen.width : width;
|
||||
@@ -46,7 +46,7 @@ public class Screenshot : MonoBehaviour
|
||||
|
||||
private IEnumerator RecordGif(int width, int height, bool transparent, int quality)
|
||||
{
|
||||
var camera = UmaViewerBuilder.Instance.PreviewCamera.enabled ? UmaViewerBuilder.Instance.PreviewCamera : Camera.main;
|
||||
var camera = UmaViewerBuilder.Instance.AnimationCamera.enabled ? UmaViewerBuilder.Instance.AnimationCamera : Camera.main;
|
||||
var ppLayer = camera.GetComponent<PostProcessLayer>();
|
||||
bool oldPpState = ppLayer.enabled;
|
||||
ppLayer.enabled = false;
|
||||
|
||||
@@ -28,6 +28,10 @@ public class UmaContainer : MonoBehaviour
|
||||
public float EyeHeight;
|
||||
public bool EnableEyeTracking = true;
|
||||
|
||||
[Header("Cheek")]
|
||||
public Texture CheekTex;
|
||||
public Material CheekMaterial;
|
||||
|
||||
[Header("Generic")]
|
||||
public bool IsGeneric = false;
|
||||
public string VarCostumeIdShort, VarCostumeIdLong, VarSkin, VarHeight, VarSocks, VarBust;
|
||||
@@ -41,6 +45,9 @@ public class UmaContainer : MonoBehaviour
|
||||
public bool EnablePhysics = true;
|
||||
public List<CySpringDataContainer> cySpringDataContainers;
|
||||
|
||||
[Header("Shader")]
|
||||
public Material FaceMaterial;
|
||||
|
||||
public void MergeModel()
|
||||
{
|
||||
if (!Body) return;
|
||||
@@ -97,6 +104,7 @@ public class UmaContainer : MonoBehaviour
|
||||
OverrideController = Instantiate(UmaViewerBuilder.Instance.OverrideController);
|
||||
UmaAnimator.runtimeAnimatorController = OverrideController;
|
||||
|
||||
FaceMaterial = transform.Find("M_Face").GetComponent<SkinnedMeshRenderer>().material;
|
||||
}
|
||||
|
||||
public void SetHeight(int scale)
|
||||
@@ -172,5 +180,23 @@ public class UmaContainer : MonoBehaviour
|
||||
{
|
||||
FaceDrivenKeyTarget.ProcessLocator();
|
||||
}
|
||||
|
||||
if (!IsMini && FaceMaterial)
|
||||
{
|
||||
if (isAnimatorControl)
|
||||
{
|
||||
FaceMaterial.SetVector("_FaceForward", Vector3.zero);
|
||||
FaceMaterial.SetVector("_FaceUp", Vector3.zero);
|
||||
FaceMaterial.SetVector("_FaceCenterPos", Vector3.zero);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//Used to calculate facial shadows
|
||||
FaceMaterial.SetVector("_FaceForward", HeadBone.transform.forward);
|
||||
FaceMaterial.SetVector("_FaceUp", HeadBone.transform.up);
|
||||
FaceMaterial.SetVector("_FaceCenterPos", HeadBone.transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
public AnimatorOverrideController OverrideController;
|
||||
public AnimatorOverrideController FaceOverrideController;
|
||||
public AnimatorOverrideController CameraOverrideController;
|
||||
public Animator PreviewCameraAnimator;
|
||||
public Camera PreviewCamera;
|
||||
public Animator AnimationCameraAnimator;
|
||||
public Camera AnimationCamera;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -167,7 +167,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
//Load Physics
|
||||
foreach (var asset1 in UmaViewerMain.Instance.AbChara.Where(a => a.Name.StartsWith(UmaDatabaseController.BodyPath + $"bdy{id}_{costumeId}/clothes")))
|
||||
{
|
||||
if (asset1.Name.Contains("cloth04"))
|
||||
if (asset1.Name.Contains("cloth00"))
|
||||
RecursiveLoadAsset(asset1);
|
||||
}
|
||||
}
|
||||
@@ -824,6 +824,9 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
GameObject head = Instantiate(go, CurrentUMAContainer.transform);
|
||||
CurrentUMAContainer.Head = head;
|
||||
|
||||
//Some setting for Head
|
||||
CurrentUMAContainer.EnableEyeTracking = UI.EnableEyeTracking;
|
||||
|
||||
foreach (Renderer r in head.GetComponentsInChildren<Renderer>())
|
||||
{
|
||||
foreach (Material m in r.sharedMaterials)
|
||||
@@ -863,11 +866,23 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
{
|
||||
m.shader = alphaShader;
|
||||
}
|
||||
//Blush Setting
|
||||
if (r.name.Contains("Cheek")){
|
||||
CurrentUMAContainer.CheekMaterial = m;
|
||||
CurrentUMAContainer.CheekTex = CurrentUMAContainer.Head.GetComponent<AssetHolder>()._assetTable.list.Find(a => { return a.Key == "cheek1"; }).Value as Texture;
|
||||
if (UI.IsCheekBlushing)
|
||||
{
|
||||
m.SetTexture("_MainTex", CurrentUMAContainer.CheekTex);
|
||||
}
|
||||
else
|
||||
{
|
||||
m.SetTexture("_MainTex", null);
|
||||
}
|
||||
}
|
||||
switch (m.shader.name)
|
||||
{
|
||||
case "Gallop/3D/Chara/MultiplyCheek":
|
||||
m.shader = cheekShader;
|
||||
m.CopyPropertiesFromMaterial(TransMaterialCharas);
|
||||
m.shader = cheekShader;;
|
||||
break;
|
||||
case "Gallop/3D/Chara/ToonFace/TSER":
|
||||
m.shader = faceShader;
|
||||
@@ -939,6 +954,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
}
|
||||
else if (clip.name.EndsWith("_E"))
|
||||
{
|
||||
CurrentUMAContainer.UmaAnimator.Rebind();
|
||||
CurrentUMAContainer.OverrideController["clip_e"] = clip;
|
||||
}
|
||||
else if (clip.name.EndsWith("_loop"))
|
||||
@@ -1037,7 +1053,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
SetPreviewCamera(null);
|
||||
}
|
||||
CurrentUMAContainer.UmaAnimator.Play("motion_2", 0, 0);
|
||||
CurrentUMAContainer.TrackTarget = PreviewCamera.gameObject;
|
||||
CurrentUMAContainer.TrackTarget = AnimationCamera.gameObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1060,14 +1076,14 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
{
|
||||
if (controller)
|
||||
{
|
||||
PreviewCameraAnimator.runtimeAnimatorController = controller;
|
||||
PreviewCamera.enabled = true;
|
||||
PreviewCameraAnimator.Play("motion_1", 0, 0);
|
||||
AnimationCameraAnimator.runtimeAnimatorController = controller;
|
||||
AnimationCamera.enabled = true;
|
||||
AnimationCameraAnimator.Play("motion_1", 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
PreviewCameraAnimator.runtimeAnimatorController = null;
|
||||
PreviewCamera.enabled = false;
|
||||
AnimationCameraAnimator.runtimeAnimatorController = null;
|
||||
AnimationCamera.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1166,9 +1182,9 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (PreviewCamera && PreviewCamera.enabled == true)
|
||||
if (AnimationCamera && AnimationCamera.enabled == true)
|
||||
{
|
||||
PreviewCamera.fieldOfView = PreviewCamera.gameObject.transform.parent.transform.localScale.x;
|
||||
AnimationCamera.fieldOfView = AnimationCamera.gameObject.transform.parent.transform.localScale.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ public class UmaViewerDownload : MonoBehaviour
|
||||
public static IEnumerator DownloadText(string url, System.Action<string> callback)
|
||||
{
|
||||
UnityWebRequest www = UnityWebRequest.Get(url);
|
||||
www.timeout = 3;
|
||||
yield return www.SendWebRequest();
|
||||
|
||||
|
||||
if (www.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Debug.Log(www.error);
|
||||
|
||||
@@ -7,9 +7,9 @@ public class UmaViewerGlobalShader : MonoBehaviour
|
||||
//仅用于设置游戏开局shader全局变量的初始值,若想即时调整请使用Editor内部工具
|
||||
public float _Global_MaxDensity = 1.0f;
|
||||
public float _Global_MaxHeight = 10.0f;
|
||||
public float _GlobalOutlineOffest = 0.0f;
|
||||
public float _GlobalOutlineOffset = 1f;
|
||||
public float _GlobalOutlineWidth = 1.0f;
|
||||
public float _GlobalCameraFov = 0.0f;
|
||||
public float _GlobalCameraFov = 0.1f;
|
||||
public float _CylinderBlend = 0.0f;
|
||||
public Color _GlobalToonColor = new Color(1, 1, 1, 0);
|
||||
public Color _Global_FogColor;
|
||||
@@ -69,7 +69,7 @@ public class UmaViewerGlobalShader : MonoBehaviour
|
||||
//Float
|
||||
Shader.SetGlobalFloat("_Global_MaxDensity", _Global_MaxDensity);
|
||||
Shader.SetGlobalFloat("_Global_MaxHeight", _Global_MaxHeight);
|
||||
Shader.SetGlobalFloat("_GlobalOutlineOffest", _GlobalOutlineOffest);
|
||||
Shader.SetGlobalFloat("_GlobalOutlineOffset", _GlobalOutlineOffset);
|
||||
Shader.SetGlobalFloat("_GlobalOutlineWidth", _GlobalOutlineWidth);
|
||||
Shader.SetGlobalFloat("_GlobalCameraFov", _GlobalCameraFov);
|
||||
Shader.SetGlobalFloat("_CylinderBlend", _CylinderBlend);
|
||||
@@ -123,4 +123,19 @@ public class UmaViewerGlobalShader : MonoBehaviour
|
||||
setGlobal();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
//Used to calculate the correct outline
|
||||
if (UmaViewerBuilder.Instance.CurrentUMAContainer)
|
||||
{
|
||||
var container = UmaViewerBuilder.Instance.CurrentUMAContainer;
|
||||
var aniCamera = UmaViewerBuilder.Instance.AnimationCamera;
|
||||
var camera = aniCamera.enabled ? aniCamera: Camera.main;
|
||||
var distance = Vector3.Distance(camera.transform.position, container.transform.position);
|
||||
var outlineWidth = (container.IsMini ? 20f : 40.0f) * (distance * Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad));
|
||||
Shader.SetGlobalFloat("_GlobalCameraFov", outlineWidth);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
|
||||
public Slider GifSlider;
|
||||
public Button GifButton;
|
||||
public Button VMDButton;
|
||||
public List<GameObject> TogglablePanels = new List<GameObject>();
|
||||
public List<GameObject> TogglableFacials = new List<GameObject>();
|
||||
|
||||
@@ -82,6 +83,8 @@ public class UmaViewerUI : MonoBehaviour
|
||||
|
||||
public bool isCriware = false;
|
||||
public bool isHeadFix = false;
|
||||
public bool EnableEyeTracking = true;
|
||||
public bool IsCheekBlushing = false;
|
||||
|
||||
public FaceDrivenKeyTarget currentFaceDrivenKeyTarget;
|
||||
|
||||
@@ -220,7 +223,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
container.Name = morph.name + " (" + morph.tag + ")";
|
||||
container.Slider.value = morph.weight;
|
||||
container.Slider.maxValue = 1;
|
||||
container.Slider.minValue = 0;
|
||||
container.Slider.minValue = morph.tag.Contains("Range") ? -1 : 0;
|
||||
container.Slider.onValueChanged.AddListener((a) => { target.ChangeMorphWeight(morph, a); });
|
||||
}
|
||||
}
|
||||
@@ -229,7 +232,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
{
|
||||
currentFaceDrivenKeyTarget = target;
|
||||
|
||||
foreach (UmaUIContainer ui in FacialList.GetComponentsInChildren<UmaUIContainer>())
|
||||
foreach (UmaUIContainer ui in FacialList.GetComponentsInChildren<UmaUIContainer>(true))
|
||||
{
|
||||
Destroy(ui.gameObject);
|
||||
}
|
||||
@@ -579,7 +582,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
AnimationSlider.SetValueWithoutNotify(0);
|
||||
// Reset settings by Panel
|
||||
Builder.CurrentUMAContainer.UmaAnimator.speed = AnimationSpeedSlider.value;
|
||||
Builder.PreviewCameraAnimator.speed = AnimationSpeedSlider.value;
|
||||
Builder.AnimationCameraAnimator.speed = AnimationSpeedSlider.value;
|
||||
if (Builder.CurrentUMAContainer.UmaFaceAnimator)
|
||||
Builder.CurrentUMAContainer.UmaFaceAnimator.speed = AnimationSpeedSlider.value;
|
||||
}
|
||||
@@ -640,12 +643,32 @@ public class UmaViewerUI : MonoBehaviour
|
||||
|
||||
public void SetEyeTrackingEnable(bool isOn)
|
||||
{
|
||||
EnableEyeTracking = isOn;
|
||||
if (Builder.CurrentUMAContainer)
|
||||
{
|
||||
Builder.CurrentUMAContainer.EnableEyeTracking = isOn;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBlushing(bool isOn)
|
||||
{
|
||||
IsCheekBlushing = isOn;
|
||||
if (Builder.CurrentUMAContainer)
|
||||
{
|
||||
if (Builder.CurrentUMAContainer.CheekMaterial)
|
||||
{
|
||||
if (isOn)
|
||||
{
|
||||
Builder.CurrentUMAContainer.CheekMaterial.SetTexture("_MainTex", Builder.CurrentUMAContainer.CheekTex);
|
||||
}
|
||||
else
|
||||
{
|
||||
Builder.CurrentUMAContainer.CheekMaterial.SetTexture("_MainTex", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AudioPause()
|
||||
{
|
||||
if (Builder.CurrentAudioSources.Count>0)
|
||||
@@ -691,7 +714,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
{
|
||||
var animator = Builder.CurrentUMAContainer.UmaAnimator;
|
||||
var animator_face = Builder.CurrentUMAContainer.UmaFaceAnimator;
|
||||
var animator_cam = Builder.PreviewCameraAnimator;
|
||||
var animator_cam = Builder.AnimationCameraAnimator;
|
||||
var AnimeState = animator.GetCurrentAnimatorStateInfo(0);
|
||||
var state = animator.speed > 0f;
|
||||
if (state)
|
||||
@@ -731,7 +754,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
if (!Builder.CurrentUMAContainer) return;
|
||||
var animator = Builder.CurrentUMAContainer.UmaAnimator;
|
||||
var animator_face = Builder.CurrentUMAContainer.UmaFaceAnimator;
|
||||
var animator_cam = Builder.PreviewCameraAnimator;
|
||||
var animator_cam = Builder.AnimationCameraAnimator;
|
||||
if (animator != null)
|
||||
{
|
||||
var AnimeClip = Builder.CurrentUMAContainer.OverrideController["clip_2"];
|
||||
@@ -758,7 +781,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
AnimationSpeedText.text = string.Format("Animation Speed: {0:F2}", val);
|
||||
if (!Builder.CurrentUMAContainer || !Builder.CurrentUMAContainer.UmaAnimator) return;
|
||||
Builder.CurrentUMAContainer.UmaAnimator.speed = val;
|
||||
Builder.PreviewCameraAnimator.speed = val;
|
||||
Builder.AnimationCameraAnimator.speed = val;
|
||||
if (Builder.CurrentUMAContainer.UmaFaceAnimator)
|
||||
{
|
||||
Builder.CurrentUMAContainer.UmaFaceAnimator.speed = val;
|
||||
@@ -803,4 +826,51 @@ public class UmaViewerUI : MonoBehaviour
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public void RecordVMD()
|
||||
{
|
||||
var buttonText = VMDButton.GetComponentInChildren<TextMeshProUGUI>();
|
||||
if (!UmaViewerBuilder.Instance.CurrentUMAContainer|| UmaViewerBuilder.Instance.CurrentUMAContainer.IsMini)
|
||||
{
|
||||
buttonText.text = string.Format("<color=#FF0000>{0}</color>", "Need Normal UMA");
|
||||
return;
|
||||
}
|
||||
|
||||
var container = UmaViewerBuilder.Instance.CurrentUMAContainer;
|
||||
var camera = UmaViewerBuilder.Instance.AnimationCamera;
|
||||
|
||||
var rootbone = container.transform.Find("Position");
|
||||
if(rootbone.gameObject.TryGetComponent(out UnityHumanoidVMDRecorder recorder))
|
||||
{
|
||||
if (recorder.IsRecording)
|
||||
{
|
||||
if (camera.enabled)
|
||||
{
|
||||
var cameraRecorder = camera.GetComponent<UnityCameraVMDRecorder>();
|
||||
cameraRecorder.StopRecording();
|
||||
cameraRecorder.SaveVMD();
|
||||
}
|
||||
recorder.StopRecording();
|
||||
buttonText.text = "Saving";
|
||||
recorder.SaveVMD(container.name);
|
||||
buttonText.text = "Record VMD";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var newRecorder = rootbone.gameObject.AddComponent<UnityHumanoidVMDRecorder>();
|
||||
newRecorder.Initialize();
|
||||
if (!newRecorder.IsRecording)
|
||||
{
|
||||
if (camera.enabled)
|
||||
{
|
||||
var cameraRecorder = camera.gameObject.AddComponent<UnityCameraVMDRecorder>();
|
||||
cameraRecorder.Initialize();
|
||||
cameraRecorder.StartRecording();
|
||||
}
|
||||
newRecorder.StartRecording();
|
||||
buttonText.text = "Recording...";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af9fce8e2f501f243a8fe818cde62e34
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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.
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ab3614d2453f394ab310b22ebae7aed
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,337 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public class UnityCameraVMDRecorder : MonoBehaviour
|
||||
{
|
||||
const float WorldScaleFix = 12.5f;
|
||||
const float FPSs = 0.03333f;
|
||||
|
||||
public bool RecordMainCamera = false;
|
||||
/// <summary>
|
||||
/// カメラの座標・回転を絶対座標系で計算する
|
||||
/// </summary>
|
||||
public bool UseAbsoluteCoordinateSystem = true;
|
||||
public bool IgnoreInitialPosition;
|
||||
public bool IgnoreInitialRotation;
|
||||
public Vector3 Offset = Vector3.zero;
|
||||
public int KeyReductionLevel = 2;
|
||||
public List<Vector3> LocalPositions { get; private set; } = new List<Vector3>();
|
||||
public List<Vector3> LocalRotations { get; private set; } = new List<Vector3>();
|
||||
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<Vector3> positionsSaved = new List<Vector3>();
|
||||
List<Vector3> rotationsSaved = new List<Vector3>();
|
||||
|
||||
Vector3 LastRotation;
|
||||
bool firstKey;
|
||||
Vector3 finalRotation;
|
||||
|
||||
// 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<Camera>();
|
||||
|
||||
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);
|
||||
|
||||
if (!firstKey)
|
||||
{
|
||||
finalRotation = vmdRotation;
|
||||
firstKey = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
finalRotation += DeltaVector(vmdRotation, LastRotation);
|
||||
Debug.Log(DeltaVector(vmdRotation, LastRotation)+" "+ vmdRotation + " "+ LastRotation);
|
||||
}
|
||||
|
||||
LocalPositions.Add(vmdPosition);
|
||||
LocalRotations.Add(finalRotation);
|
||||
|
||||
LastRotation = vmdRotation;
|
||||
}
|
||||
|
||||
Vector3 DeltaVector(Vector3 val ,Vector3 lastVal)
|
||||
{
|
||||
return new Vector3(DeltaDegree(val.x, lastVal.x), DeltaDegree(val.y, lastVal.y), DeltaDegree(val.z, lastVal.z));
|
||||
}
|
||||
|
||||
float DeltaDegree(float val,float lastVal)
|
||||
{
|
||||
var deltaVal = val - lastVal;
|
||||
if (Mathf.Abs(deltaVal) < 180)
|
||||
{
|
||||
return deltaVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (deltaVal >= 0)
|
||||
{
|
||||
return deltaVal - 360;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 360 + deltaVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetFPS(int fps)
|
||||
{
|
||||
Time.fixedDeltaTime = 1 / (float)fps;
|
||||
}
|
||||
|
||||
public void SetCameraTransform(Camera camera)
|
||||
{
|
||||
targetCameraTransform = camera.transform;
|
||||
this.targetCamera = camera;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// レコーディングを開始または再開
|
||||
/// </summary>
|
||||
public void StartRecording()
|
||||
{
|
||||
SetInitialPositionAndRotation();
|
||||
IsRecording = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// レコーディングを一時停止
|
||||
/// </summary>
|
||||
public void PauseRecording() { IsRecording = false; }
|
||||
|
||||
/// <summary>
|
||||
/// レコーディングを終了
|
||||
/// </summary>
|
||||
public void StopRecording()
|
||||
{
|
||||
IsRecording = false;
|
||||
frameNumberSaved = FrameNumber;
|
||||
positionsSaved = LocalPositions;
|
||||
rotationsSaved = LocalRotations;
|
||||
|
||||
FrameNumber = 0;
|
||||
LocalPositions = new List<Vector3>();
|
||||
LocalRotations = new List<Vector3>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// VMDを作成する
|
||||
/// 呼び出す際は先にStopRecordingを呼び出すこと
|
||||
/// </summary>
|
||||
/// <param name="filePath">保存先の絶対ファイルパス</param>
|
||||
public 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ファイル作成開始");
|
||||
|
||||
//ファイルの書き込み
|
||||
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ファイル作成終了");
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// VMDを作成する
|
||||
/// 呼び出す際は先にStopRecordingを呼び出すこと
|
||||
/// </summary>
|
||||
/// <param name="filePath">保存先の絶対ファイルパス</param>
|
||||
/// <param name="keyReductionLevel">キーの書き込み頻度を減らして容量を減らす</param>
|
||||
public void SaveVMD(string filePath, int keyReductionLevel)
|
||||
{
|
||||
KeyReductionLevel = keyReductionLevel;
|
||||
SaveVMD();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ec695d7ca4100640a3cccf269007798
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,926 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Gallop;
|
||||
|
||||
//初期ポーズ(T,Aポーズ)の時点でアタッチ、有効化されている必要がある
|
||||
public class UnityHumanoidVMDRecorder : MonoBehaviour
|
||||
{
|
||||
public bool UseParentOfAll = true;
|
||||
public bool UseCenterAsParentOfAll = true;
|
||||
/// <summary>
|
||||
/// 全ての親の座標・回転を絶対座標系で計算する
|
||||
/// UseParentOfAllがTrueでないと意味がない
|
||||
/// </summary>
|
||||
public bool UseAbsoluteCoordinateSystem = false;
|
||||
public bool IgnoreInitialPosition = false;
|
||||
public bool IgnoreInitialRotation = false;
|
||||
/// <summary>
|
||||
/// 一部のモデルではMMD上ではセンターが足元にある
|
||||
/// Start前に設定されている必要がある
|
||||
/// </summary>
|
||||
public bool UseBottomCenter = false;
|
||||
/// <summary>
|
||||
/// Unity上のモーフ名に1.まばたきなど番号が振られている場合、番号を除去する
|
||||
/// </summary>
|
||||
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<string, Transform> transformDictionary = new Dictionary<string, Transform>();
|
||||
public Dictionary<BoneNames, Transform> BoneDictionary { get; private set; }
|
||||
Vector3 parentInitialPosition = Vector3.zero;
|
||||
Quaternion parentInitialRotation = Quaternion.identity;
|
||||
Dictionary<BoneNames, List<Vector3>> positionDictionary = new Dictionary<BoneNames, List<Vector3>>();
|
||||
Dictionary<BoneNames, List<Vector3>> positionDictionarySaved = new Dictionary<BoneNames, List<Vector3>>();
|
||||
Dictionary<BoneNames, List<Quaternion>> rotationDictionary = new Dictionary<BoneNames, List<Quaternion>>();
|
||||
Dictionary<BoneNames, List<Quaternion>> rotationDictionarySaved = new Dictionary<BoneNames, List<Quaternion>>();
|
||||
//ボーン移動量の補正係数
|
||||
//この値は大体の値、正確ではない
|
||||
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<Transform> objs = GetComponentsInChildren<Transform>().ToList();
|
||||
BoneDictionary = new Dictionary<BoneNames, Transform>()
|
||||
{
|
||||
//下半身などというものは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<BoneNames, Transform> pair in BoneDictionary)
|
||||
{
|
||||
transformDictionary.Add(pair.Key.ToString(), pair.Value);
|
||||
}
|
||||
|
||||
var animator = GetComponentInParent<UmaContainer>().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<Vector3>());
|
||||
rotationDictionary.Add(boneName, new List<Quaternion>());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// レコーディングを開始または再開
|
||||
/// </summary>
|
||||
public void StartRecording()
|
||||
{
|
||||
SetInitialPositionAndRotation();
|
||||
IsRecording = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// レコーディングを一時停止
|
||||
/// </summary>
|
||||
public void PauseRecording() { IsRecording = false; }
|
||||
|
||||
/// <summary>
|
||||
/// レコーディングを終了
|
||||
/// </summary>
|
||||
public void StopRecording()
|
||||
{
|
||||
IsRecording = false;
|
||||
frameNumberSaved = FrameNumber;
|
||||
morphRecorderSaved = morphRecorder;
|
||||
FrameNumber = 0;
|
||||
positionDictionarySaved = positionDictionary;
|
||||
positionDictionary = new Dictionary<BoneNames, List<Vector3>>();
|
||||
rotationDictionarySaved = rotationDictionary;
|
||||
rotationDictionary = new Dictionary<BoneNames, List<Quaternion>>();
|
||||
foreach (BoneNames boneName in BoneDictionary.Keys)
|
||||
{
|
||||
if (BoneDictionary[boneName] == null) { continue; }
|
||||
|
||||
positionDictionary.Add(boneName, new List<Vector3>());
|
||||
rotationDictionary.Add(boneName, new List<Quaternion>());
|
||||
}
|
||||
morphRecorder = new MorphRecorder(transform);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// VMDを作成する
|
||||
/// 呼び出す際は先にStopRecordingを呼び出すこと
|
||||
/// </summary>
|
||||
/// <param name="modelName">VMDファイルに記載される専用モデル名</param>
|
||||
/// <param name="filePath">保存先の絶対ファイルパス</param>
|
||||
public void SaveVMD(string modelName, string filePath)
|
||||
{
|
||||
if (IsRecording)
|
||||
{
|
||||
Debug.Log(transform.name + "VMD保存前にレコーディングをストップしてください。");
|
||||
return;
|
||||
}
|
||||
|
||||
if (KeyReductionLevel <= 0) { KeyReductionLevel = 1; }
|
||||
|
||||
Debug.Log(transform.name + "VMDファイル作成開始");
|
||||
//ファイルの書き込み
|
||||
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<BoneNames, int> 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<string, int> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// VMDを作成する
|
||||
/// 呼び出す際は先にStopRecordingを呼び出すこと
|
||||
/// </summary>
|
||||
/// <param name="modelName">VMDファイルに記載される専用モデル名</param>
|
||||
/// <param name="filePath">保存先の絶対ファイルパス</param>
|
||||
/// <param name="keyReductionLevel">キーの書き込み頻度を減らして容量を減らす</param>
|
||||
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<BoneNames, (Transform ghost, bool enabled)> GhostDictionary { get; private set; } = new Dictionary<BoneNames, (Transform ghost, bool enabled)>();
|
||||
public Dictionary<BoneNames, Vector3> GhostOriginalLocalPositionDictionary { get; private set; } = new Dictionary<BoneNames, Vector3>();
|
||||
public Dictionary<BoneNames, Quaternion> GhostOriginalRotationDictionary { get; private set; } = new Dictionary<BoneNames, Quaternion>();
|
||||
public Dictionary<BoneNames, Quaternion> OriginalRotationDictionary { get; private set; } = new Dictionary<BoneNames, Quaternion>();
|
||||
|
||||
public bool UseBottomCenter { get; private set; } = false;
|
||||
|
||||
const string GhostSalt = "Ghost";
|
||||
private Dictionary<BoneNames, Transform> boneDictionary = new Dictionary<BoneNames, Transform>();
|
||||
float centerOffsetLength = 0;
|
||||
|
||||
public BoneGhost(Dictionary<BoneNames, Transform> boneDictionary, bool useBottomCenter)
|
||||
{
|
||||
this.boneDictionary = boneDictionary;
|
||||
UseBottomCenter = useBottomCenter;
|
||||
|
||||
Dictionary<BoneNames, (BoneNames optionParent1, BoneNames optionParent2, BoneNames necessaryParent)> boneParentDictionary
|
||||
= new Dictionary<BoneNames, (BoneNames optionParent1, BoneNames optionParent2, BoneNames necessaryParent)>()
|
||||
{
|
||||
{ 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<FacialMorph> FacialMorphList;
|
||||
//キーはunity上のモーフ名
|
||||
public Dictionary<string, MorphDriver> MorphDrivers { get; private set; } = new Dictionary<string, MorphDriver>();
|
||||
|
||||
public MorphRecorder(Transform model)
|
||||
{
|
||||
var facialTarget = model.GetComponentInParent<UmaContainer>().FaceDrivenKeyTarget;
|
||||
FacialMorphList = new List<FacialMorph>();
|
||||
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<FacialMorph> morphList = new List<FacialMorph>();
|
||||
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<string, MorphDriver> morphDriversTemp = new Dictionary<string, MorphDriver>();
|
||||
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<FacialMorph> Morphs;
|
||||
|
||||
public int MorphIndex { get; private set; }
|
||||
|
||||
public List<(float value, bool enabled)> ValueList = new List<(float value, bool enabled)>();
|
||||
|
||||
public MorphDriver(List<FacialMorph> facialMorph, int morphIndex)
|
||||
{
|
||||
Morphs = facialMorph;
|
||||
MorphIndex = morphIndex;
|
||||
}
|
||||
|
||||
public void RecordMorph()
|
||||
{
|
||||
float val = 0;
|
||||
foreach (var morph in Morphs)
|
||||
{
|
||||
val += morph.weight;
|
||||
}
|
||||
ValueList.Add((Mathf.Clamp(val, -1, 1), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0b34d9392c54234fae556b70776e9ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 578ee69407cced54c835f2f1bcbe77bd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -36,6 +36,9 @@ namespace Gallop
|
||||
DynamicBones.Clear();
|
||||
List<Transform> gameObjects = new List<Transform>();
|
||||
gameObjects.AddRange(transform.parent.transform.parent.GetComponentsInChildren<Transform>());
|
||||
|
||||
List<DynamicBoneColliderBase> colliders = new List<DynamicBoneColliderBase>();
|
||||
|
||||
foreach (CySpringCollisionData collider in collisionParam)
|
||||
{
|
||||
if (collider._isInner) continue;
|
||||
@@ -61,6 +64,7 @@ namespace Gallop
|
||||
dynamic.m_Height = (collider._offset - collider._offset2).magnitude + collider._radius;
|
||||
dynamic.m_Radius = collider._radius;
|
||||
dynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
|
||||
colliders.Add(dynamic);
|
||||
break;
|
||||
case CySpringCollisionData.CollisionType.Sphere:
|
||||
var Spheredynamic = child.AddComponent<DynamicBoneCollider>();
|
||||
@@ -69,12 +73,14 @@ namespace Gallop
|
||||
Spheredynamic.m_Radius = collider._radius;
|
||||
Spheredynamic.m_Height = collider._distance;
|
||||
Spheredynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
|
||||
colliders.Add(Spheredynamic);
|
||||
break;
|
||||
case CySpringCollisionData.CollisionType.Plane:
|
||||
var planedynamic = child.AddComponent<DynamicBonePlaneCollider>();
|
||||
planedynamic.ColliderName = collider._collisionName;
|
||||
child.transform.localPosition = collider._offset;
|
||||
planedynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
|
||||
colliders.Add(planedynamic);
|
||||
break;
|
||||
case CySpringCollisionData.CollisionType.None:
|
||||
break;
|
||||
@@ -82,18 +88,19 @@ namespace Gallop
|
||||
}
|
||||
}
|
||||
|
||||
gameObjects.Clear();
|
||||
gameObjects.AddRange(transform.parent.transform.parent.GetComponentsInChildren<Transform>());
|
||||
|
||||
foreach(CySpringParamDataElement spring in springParam)
|
||||
{
|
||||
var bone = gameObjects.Find(a => { return a.name == spring._boneName; });
|
||||
if (bone)
|
||||
{
|
||||
bool isTail = gameObject.name.Contains("tail");//The tail needs less traction
|
||||
var dynamic = gameObject.AddComponent<DynamicBone>();
|
||||
var dynamic = bone.gameObject.AddComponent<DynamicBone>();
|
||||
dynamic.m_Root = bone;
|
||||
dynamic.m_UpdateMode = DynamicBone.UpdateMode.Normal;
|
||||
dynamic.m_Gravity = new Vector3(0, Mathf.Clamp01(-30 / spring._gravity), 0);
|
||||
dynamic.m_LimitAngel_Min = spring._limitAngleMin;
|
||||
dynamic.m_LimitAngel_Max = spring._limitAngleMax;
|
||||
if (isTail)
|
||||
{
|
||||
dynamic.m_Damping = 0.1f;
|
||||
@@ -108,13 +115,14 @@ namespace Gallop
|
||||
|
||||
}
|
||||
dynamic.m_Radius = spring._collisionRadius;
|
||||
|
||||
dynamic.m_Friction = 0.5f;
|
||||
dynamic.m_Inert = spring.MoveSpringApplyRate / 3;
|
||||
dynamic.SetupParticles();
|
||||
DynamicBones.Add(dynamic);
|
||||
|
||||
foreach (string collisionName in spring._collisionNameList)
|
||||
{
|
||||
var tmp = gameObjects.Find(a => { return a.name == collisionName; });
|
||||
var tmp = colliders.Find(a => { return a.gameObject.name == collisionName; });
|
||||
if (tmp)
|
||||
{
|
||||
dynamic.Particles[0].m_Colliders.Add(tmp.GetComponent<DynamicBoneColliderBase>());
|
||||
@@ -122,25 +130,30 @@ namespace Gallop
|
||||
}
|
||||
foreach (CySpringParamDataChildElement Childcollision in spring._childElements)
|
||||
{
|
||||
|
||||
var tempParticle = dynamic.Particles.Find(a => { return a.m_Transform.gameObject.name == Childcollision._boneName; });
|
||||
if (tempParticle != null)
|
||||
{
|
||||
if (isTail)
|
||||
{
|
||||
tempParticle.m_Damping = 0.1f;
|
||||
tempParticle.m_Stiffness = Mathf.Clamp01(10 / spring._stiffnessForce);
|
||||
tempParticle.m_Elasticity = Mathf.Clamp01(10 / spring._dragForce);
|
||||
tempParticle.m_Stiffness = Mathf.Clamp01(10 / Childcollision._stiffnessForce);
|
||||
tempParticle.m_Elasticity = Mathf.Clamp01(10 / Childcollision._dragForce);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempParticle.m_Damping = 0.2f;
|
||||
tempParticle.m_Stiffness = Mathf.Clamp01(45 / spring._stiffnessForce);
|
||||
tempParticle.m_Elasticity = Mathf.Clamp01(45 / spring._dragForce);
|
||||
tempParticle.m_Stiffness = Mathf.Clamp01(45 / Childcollision._stiffnessForce);
|
||||
tempParticle.m_Elasticity = Mathf.Clamp01(45 / Childcollision._dragForce);
|
||||
}
|
||||
tempParticle.m_Friction = 0.5f;
|
||||
tempParticle.m_Inert = Childcollision.MoveSpringApplyRate / 3;
|
||||
tempParticle.m_Radius = Childcollision._collisionRadius;
|
||||
tempParticle.m_LimitAngel_Min = Childcollision._limitAngleMin;
|
||||
tempParticle.m_LimitAngel_Max = Childcollision._limitAngleMax;
|
||||
foreach (string collisionName in Childcollision._collisionNameList)
|
||||
{
|
||||
var tmp = gameObjects.Find(a => { return a.name == collisionName; });
|
||||
var tmp = colliders.Find(a => { return a.gameObject.name == collisionName; });
|
||||
if (tmp)
|
||||
{
|
||||
tempParticle.m_Colliders.Add(tmp.GetComponent<DynamicBoneColliderBase>());
|
||||
@@ -148,7 +161,6 @@ namespace Gallop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ PlayerSettings:
|
||||
16:10: 1
|
||||
16:9: 1
|
||||
Others: 1
|
||||
bundleVersion: 2.1.2
|
||||
bundleVersion: 2.1.3
|
||||
preloadedAssets: []
|
||||
metroInputSource: 0
|
||||
wsaTransparentSwapchain: 0
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &1
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 61
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a287be6c49135cd4f9b2b8666c39d999, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
assetDefaultFramerate: 60
|
||||
@@ -18,6 +18,9 @@ EditorUserSettings:
|
||||
value: 22424703114646680e0b0227036c7c111b120a2b182d3524633c133af6f9
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-4:
|
||||
value: 224247031146466d202a3e27132c4d1413052b2b21382a35621a1c3ef2ec310be1e238eca92f31352d1b
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-5:
|
||||
value: 22424703114646680e0b0227036c691504041125227a68252320092a
|
||||
flags: 0
|
||||
vcSharedLogLevel:
|
||||
|
||||
Reference in New Issue
Block a user