Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Assets/Live2D/Cubism/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).


## [5-r.4] 2025-05-29

### Added

* Add an empty `AnimatorController` at the same hierarchy level as each model's Prefab.
* Add an API to `CubismMotionJson` for verifying the consistency of `motion3.json`. by [@pillowtrucker](https://github.com/Live2D/CubismNativeFramework/pull/57)
* Add parameter repeat processing that connects the right and left ends of the parameter to create a loop, allowing the motion to repeat.
* Add the variable `_isOverriddenParameterRepeat` to the `CubismModel` class for managing parameter repeat flags at the model level.
* Add variables `_isOverriddenUserParameterRepeat` to the `CubismModel` class and `_isParameterRepeated` to the `CubismParameter` class for managing parameter repeat flags for each parameter.

### Changed

* Change the version of the development project to `2022.3.59f1`.
* Change CubismMath class not to inherit from MonoBehaviour.
* Change `CubismMoc._bytes` not to be displayed in Inspector.

### Fixed

* Fix `CubismPhysicsController` to be in the correct disabled state.
* When performing a Reimport Fixed a problem that `.cdi3.json` updates were not reflected in `CubismDisplayInfoParameterName`,`CubismDisplayInfoPartName`.
* Fix a problem in which the slider of CubismParametersInspector and CubismPartsInspector in the Inspector window did not move when operated.
* Fix a bug that CubismParametersInspector and CubismPartsInspector do not display the names of parameters and parts if .cdi3.json is not set on the model.
* Fix `CubismParameterInspector` and `CubismPartInspector` can be operated in play mode.
* Fix a bug that prevented MotionFade fade-out from working properly.
* Fix unnecessary processing in `CubismFadeController`.
* Fix so that end events are sent for all clips played by `CubismMotionController`.
* Fix an error that occurred when playing a expression that uses parameters that do not exist in the model.


## [5-r.3] - 2024-11-28

### Added
Expand All @@ -16,6 +45,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed

* Change an expression "overwrite" to "override" for multiply color, screen color, and culling to adapt the actual behavior.
* Change `OnGeneratedCSProjectFiles` function to be disabled in Unity 2017.3 and later by [@moz-moz](https://github.com/moz-moz)
* Change to a single function The initialization process in CubismModel class. by [@KT](https://creatorsforum.live2d.com/t/topic/2356/)
* Change to optimize update process for Multiply Color and Screen Color.
Expand Down Expand Up @@ -433,6 +463,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* Fix issue where Priority value was not reset after playing motion with CubismMotionController.


[5-r.4]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.3...5-r.4
[5-r.3]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.2...5-r.3
[5-r.2]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.1...5-r.2
[5-r.1]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.1-beta.4...5-r.1
Expand Down
3 changes: 2 additions & 1 deletion Assets/Live2D/Cubism/Core/ArrayExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


using Live2D.Cubism.Core.Unmanaged;
using Live2D.Cubism.Framework;
using System;
using UnityEngine;

Expand Down Expand Up @@ -97,7 +98,7 @@ internal static void ReadFrom(this CubismParameter[] self, CubismUnmanagedModel
// Pull.
for (var i = 0; i < self.Length; ++i)
{
self[i].Value = values[self[i].UnmanagedIndex];
self[i].OverrideValue(values[self[i].UnmanagedIndex]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Live2D/Cubism/Core/CubismMoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static uint LatestVersion
/// <summary>
/// <see cref="Bytes"/> backing field.
/// </summary>
[SerializeField]
[SerializeField, HideInInspector]
private byte[] _bytes;

/// <summary>
Expand Down
36 changes: 35 additions & 1 deletion Assets/Live2D/Cubism/Core/CubismModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,31 @@ public CubismCanvasInformation CanvasInformation
/// </summary>
CubismParameterStore _parameterStore;

/// <summary>
/// Whether parameter repetition is performed for the entire model.
/// </summary>
[SerializeField]
private bool _isOverriddenParameterRepeat = true;


/// <summary>
/// Checks whether parameter repetition is performed for the entire model.
/// </summary>
/// <returns>True if parameter repetition is performed for the entire model; otherwise returns false.</returns>
public bool GetOverrideFlagForModelParameterRepeat()
{
return _isOverriddenParameterRepeat;
}

/// <summary>
/// Sets whether parameter repetition is performed for the entire model.
/// </summary>
/// <param name="isRepeat">Use true to perform parameter repetition for the entire model, or false to not perform it.</param>
public void SetOverrideFlagForModelParameterRepeat(bool isRepeat)
{
_isOverriddenParameterRepeat = isRepeat;
}

/// <summary>
/// True if instance is revived.
/// </summary>
Expand Down Expand Up @@ -330,6 +355,8 @@ private void Reset(CubismMoc moc)
CanvasInformation = new CubismCanvasInformation(TaskableModel.UnmanagedModel);

RefreshParameterStore();

SetOverrideFlagForModelParameterRepeat(_isOverriddenParameterRepeat);
}

/// <summary>
Expand Down Expand Up @@ -484,9 +511,16 @@ private void Update()
TaskableModel.TryReadParameters(Parameters);

// restore last frame parameters value and parts opacity.
if(_parameterStore != null)
if (_parameterStore != null)
{
#if UNITY_EDITOR
if (Application.isPlaying)
{
_parameterStore.RestoreParameters();
}
#else
_parameterStore.RestoreParameters();
#endif
}

// Trigger event.
Expand Down
158 changes: 158 additions & 0 deletions Assets/Live2D/Cubism/Core/CubismParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

using Live2D.Cubism.Core.Unmanaged;
using Live2D.Cubism.Framework;
using Live2D.Cubism.Framework.Utils;
using System;
using UnityEngine;


Expand Down Expand Up @@ -142,6 +144,162 @@ public float DefaultValue
[SerializeField, HideInInspector]
public float Value;

/// <summary>
/// CubismModel cache.
/// </summary>
private CubismModel _model;

/// <summary>
/// Whether to be overridden
/// </summary>
[SerializeField]
private bool _isOverriddenUserParameterRepeat = false;

/// <summary>
/// Override flag for settings
/// </summary>
[SerializeField]
private bool _isParameterRepeated = false;

/// <summary>
/// Checks whether parameter repetition is performed for the entire model.
/// </summary>
/// <returns>True if parameter repetition is performed for the entire model; otherwise returns false.</returns>
public bool GetOverrideFlagForModelParameterRepeat()
{
if (_model == null)
{
_model = transform.FindCubismModel(true);

if (_model == null)
{
return false;
}
}

return _model.GetOverrideFlagForModelParameterRepeat();
}

/// <summary>
/// Returns the flag indicating whether to override the parameter repeat.
/// </summary>
/// <returns>True if the parameter repeat is overridden, false otherwise.</returns>
public bool GetOverrideFlagForParameterRepeat()
{
return _isOverriddenUserParameterRepeat;
}

/// <summary>
/// Sets the flag indicating whether to override the parameter repeat.
/// </summary>
/// <param name="value">True if it is to be overridden; otherwise, false.</param>
public void SetOverrideFlagForParameterRepeat(bool value)
{
_isOverriddenUserParameterRepeat = value;
}

/// <summary>
/// Returns the repeat flag.
/// </summary>
/// <returns>True if repeating, false otherwise.</returns>
public bool GetRepeatFlagForParameterRepeat()
{
return _isParameterRepeated;
}

/// <summary>
/// Sets the repeat flag.
/// </summary>
/// <param name="value">True to enable repeating, false otherwise.</param>
public void SetRepeatFlagForParameterRepeat(bool value)
{
_isParameterRepeated = value;
}

/// <summary>
/// Gets whether the parameter has the repeat setting.
/// </summary>
/// <returns>True if it is set, otherwise returns false.</returns>
public bool IsRepeat()
{
bool isRepeat;

// パラメータリピート処理を行うか判定
if (GetOverrideFlagForModelParameterRepeat() || _isOverriddenUserParameterRepeat)
{
// SDK側で設定されたリピート情報を使用する
isRepeat = _isParameterRepeated;
}
else
{
// Editorで設定されたリピート情報を使用する
isRepeat = GetParameterRepeats();
}

return isRepeat;
}

/// <summary>
/// Returns the calculated result ensuring the value falls within the parameter's range.
/// </summary>
/// <param name="value">Parameter value</param>
/// <returns>A value that falls within the parameter’s range. If the parameter does not exist, returns it as is.</returns>
public float GetParameterRepeatValue(float value)
{
var maxValue = MaximumValue;
var minValue = MinimumValue;
var valueSize = maxValue - minValue;

if (maxValue < value)
{
var overValue = CubismMath.ModF(value - maxValue, valueSize);
if (!float.IsNaN(overValue))
{
value = minValue + overValue;
}
else
{
value = maxValue;
}
}
if (value < minValue)
{
var overValue = CubismMath.ModF(minValue - value, valueSize);
if (!float.IsNaN(overValue))
{
value = maxValue - overValue;
}
else
{
value = minValue;
}
}

return value;
}

/// <summary>
/// Returns the result of clamping the value to ensure it falls within the parameter's range.
/// </summary>
/// <param name="value">Parameter value</param>
/// <returns>The clamped value. If the parameter does not exist, returns it as is.</returns>
public float GetParameterClampValue(float value)
{
var maxValue = MaximumValue;
var minValue = MinimumValue;

return CubismMath.ClampF(value, minValue, maxValue);
}

/// <summary>
/// Returns the repeat of the parameter.
/// </summary>
/// <returns>The raw data parameter repeat from the Cubism Core.</returns>
public bool GetParameterRepeats()
{
return Convert.ToBoolean(UnmanagedParameters.Repeats[UnmanagedIndex]);
}


/// <summary>
/// Revives the instance.
Expand Down
5 changes: 5 additions & 0 deletions Assets/Live2D/Cubism/Core/Unmanaged/CubismCoreDll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ public static class CubismCoreDll
[DllImport(DllName, EntryPoint = "csmGetParameterValues")]
public static extern unsafe float* GetParameterValues(IntPtr model);
/// <summary>
/// Gets Parameter Repeat informations.
/// </summary>
[DllImport(DllName, EntryPoint = "csmGetParameterRepeats")]
public static extern unsafe int* GetParameterRepeats(IntPtr model);
/// <summary>
/// Gets number of key values of each parameter.
/// </summary>
[DllImport(DllName, EntryPoint = "csmGetParameterKeyCounts")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public sealed class CubismUnmanagedParameters
/// </summary>>
public CubismUnmanagedFloatArrayView Values { get; private set; }

/// <summary>
/// Parameter Repeat informations.
/// </summary>>
public CubismUnmanagedIntArrayView Repeats { get; private set; }

/// <summary>
/// Number of key values of each parameter.
/// </summary>>
Expand Down Expand Up @@ -104,6 +109,9 @@ internal unsafe CubismUnmanagedParameters(IntPtr modelPtr)
length = CubismCoreDll.GetParameterCount(modelPtr);
Values = new CubismUnmanagedFloatArrayView(CubismCoreDll.GetParameterValues(modelPtr), length);

length = CubismCoreDll.GetParameterCount(modelPtr);
Repeats = new CubismUnmanagedIntArrayView(CubismCoreDll.GetParameterRepeats(modelPtr), length);

length = CubismCoreDll.GetParameterCount(modelPtr);
KeyCounts = new CubismUnmanagedIntArrayView(CubismCoreDll.GetParameterKeyCounts(modelPtr), length);

Expand Down
19 changes: 16 additions & 3 deletions Assets/Live2D/Cubism/Editor/Importers/CubismModel3JsonImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,22 @@ private static void CopyUserData<T>(T[] source, T[] destination, bool copyCompon

// Copy component.
var destinationComponent = destinationT.GetOrAddComponent(sourceComponent.GetType());


EditorUtility.CopySerialized(sourceComponent, destinationComponent);
if (destinationComponent is CubismDisplayInfoParameterName cdiParameterName && !string.IsNullOrEmpty(cdiParameterName.Name))
{
var name = cdiParameterName.Name;
EditorUtility.CopySerialized(sourceComponent, destinationComponent);
cdiParameterName.Name = name;
}
else if (destinationComponent is CubismDisplayInfoPartName cdiPartName && !string.IsNullOrEmpty(cdiPartName.Name))
{
var name = cdiPartName.Name;
EditorUtility.CopySerialized(sourceComponent, destinationComponent);
cdiPartName.Name = name;
}
else
{
EditorUtility.CopySerialized(sourceComponent, destinationComponent);
}
}
}
}
Expand Down
Loading