Skip to content
Merged

R12 #33

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
121 changes: 121 additions & 0 deletions Assets/Live2D/Cubism/Core/CubismCanvasInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
* that can be found at http://live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/


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


namespace Live2D.Cubism.Core
{
/// <summary>
/// Single <see cref="CubismModel"/> canvas information.
/// </summary>
[CubismDontMoveOnReimport]
public sealed class CubismCanvasInformation
{
/// <summary>
/// Initializes instance.
/// </summary>
/// <param name="unmanagedModel">Handle to unmanaged model.</param>
public CubismCanvasInformation(CubismUnmanagedModel unmanagedModel)
{
Reset(unmanagedModel);
}


/// <summary>
/// Unmanaged canvas information from unmanaged model.
/// </summary>
private CubismUnmanagedCanvasInformation UnmanagedCanvasInformation { get; set; }


/// <summary>
/// Width of native model canvas.
/// </summary>
public float CanvasWidth
{
get
{
// Pull data.
return UnmanagedCanvasInformation.CanvasWidth;
}
}


/// <summary>
/// Height of native model canvas.
/// </summary>
public float CanvasHeight
{
get
{
// Pull data.
return UnmanagedCanvasInformation.CanvasHeight;
}
}


/// <summary>
/// Coordinate origin of X axis.
/// </summary>
public float CanvasOriginX
{
get
{
// Pull data.
return UnmanagedCanvasInformation.CanvasOriginX;
}
}


/// <summary>
/// Coordinate origin of Y axis.
/// </summary>
public float CanvasOriginY
{
get
{
// Pull data.
return UnmanagedCanvasInformation.CanvasOriginY;
}
}


/// <summary>
/// Pixels per unit of native model.
/// </summary>
public float PixelsPerUnit
{
get
{
// Pull data.
return UnmanagedCanvasInformation.PixelsPerUnit;
}
}


/// <summary>
/// Revives the instance.
/// </summary>
/// <param name="unmanagedModel">Handle to unmanaged model.</param>
internal void Revive(CubismUnmanagedModel unmanagedModel)
{
UnmanagedCanvasInformation = unmanagedModel.CanvasInformation;
}

/// <summary>
/// Restores instance to initial state.
/// </summary>
/// <param name="unmanagedModel">Handle to unmanaged model.</param>
private void Reset(CubismUnmanagedModel unmanagedModel)
{
Revive(unmanagedModel);
}
}
}
29 changes: 28 additions & 1 deletion Assets/Live2D/Cubism/Core/CubismModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,30 @@ public CubismDrawable[] Drawables
private set { _drawables = value; }
}

/// <summary>
/// <see cref="CanvasInformation"/> backing field.
/// </summary>
[NonSerialized]
private CubismCanvasInformation _canvasInformation;

/// <summary>
/// Canvas information of model.
/// </summary>
public CubismCanvasInformation CanvasInformation
{
get
{
if (_canvasInformation == null)
{
Revive();
}


return _canvasInformation;
}
private set { _canvasInformation = value; }
}

/// <summary>
/// Parameter store cache.
/// </summary>
Expand Down Expand Up @@ -222,11 +246,12 @@ private void Revive()
Parts = GetComponentsInChildren<CubismPart>();
Drawables = GetComponentsInChildren<CubismDrawable>();


Parameters.Revive(TaskableModel.UnmanagedModel);
Parts.Revive(TaskableModel.UnmanagedModel);
Drawables.Revive(TaskableModel.UnmanagedModel);

CanvasInformation = new CubismCanvasInformation(TaskableModel.UnmanagedModel);

_parameterStore = GetComponent<CubismParameterStore>();
}

Expand Down Expand Up @@ -255,6 +280,8 @@ private void Reset(CubismMoc moc)
Parameters = parameters.GetComponentsInChildren<CubismParameter>();
Parts = parts.GetComponentsInChildren<CubismPart>();
Drawables = drawables.GetComponentsInChildren<CubismDrawable>();

CanvasInformation = new CubismCanvasInformation(TaskableModel.UnmanagedModel);
}

/// <summary>
Expand Down
19 changes: 11 additions & 8 deletions Assets/Live2D/Cubism/Framework/Json/CubismModel3Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,18 +353,21 @@ public CubismModel ToModel(MaterialPicker pickMaterial, TexturePicker pickTextur


// Initialize drawables.
for (var i = 0; i < HitAreas.Length; i++)
if(HitAreas != null)
{
for (var j = 0; j < drawables.Length; j++)
for (var i = 0; i < HitAreas.Length; i++)
{
if (drawables[j].Id == HitAreas[i].Id)
for (var j = 0; j < drawables.Length; j++)
{
// Add components for hit judgement to HitArea target Drawables.
var hitDrawable = drawables[j].gameObject.AddComponent<CubismHitDrawable>();
hitDrawable.Name = HitAreas[i].Name;
if (drawables[j].Id == HitAreas[i].Id)
{
// Add components for hit judgement to HitArea target Drawables.
var hitDrawable = drawables[j].gameObject.AddComponent<CubismHitDrawable>();
hitDrawable.Name = HitAreas[i].Name;

drawables[j].gameObject.AddComponent<CubismRaycastable>();
break;
drawables[j].gameObject.AddComponent<CubismRaycastable>();
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ private void OnEnable()
}

// Create Playable Graph.
#if UNITY_2018_1_OR_NEWER
_playableGrap = PlayableGraph.Create("Playable Graph : " + this.FindCubismModel().name);
#else
_playableGrap = PlayableGraph.Create();
#endif
_playableGrap.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

// Create Playable Output.
Expand Down
17 changes: 17 additions & 0 deletions Assets/Live2D/Cubism/Framework/Motion/CubismMotionLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,32 @@ public void StopAnimation(int index)
if(index == 0 && _motionStates.Count == 1)
{
_isFinished = true;
#if UNITY_2017_3_OR_NEWER
_motionStates[0].ClipMixer.GetInput(0).Pause();
#else
_motionStates[0].ClipMixer.GetInput(0).SetPlayState(PlayState.Paused);
#endif
return;
}

// Disconnect from previou state.
var preMixer = (index == 0) ? PlayableOutput : _motionStates[index - 1].ClipMixer;
var lastInput = (index == 0) ? 0 : _motionStates[index - 1].ClipMixer.GetInputCount() - 1;

#if UNITY_2018_2_OR_NEWER
preMixer.DisconnectInput(lastInput);
#else
preMixer.GetGraph().Disconnect(preMixer, lastInput);
#endif

// Connect next state.
if(index + 1 < _motionStates.Count)
{
#if UNITY_2018_2_OR_NEWER
_motionStates[index].ClipMixer.DisconnectInput(_motionStates[index].ClipMixer.GetInputCount() - 1);
#else
_motionStates[index].ClipMixer.GetGraph().Disconnect(_motionStates[index].ClipMixer, _motionStates[index].ClipMixer.GetInputCount() - 1);
#endif

preMixer.ConnectInput(lastInput, _motionStates[index + 1].ClipMixer, 0);
preMixer.SetInputWeight(lastInput, 1.0f);
Expand Down Expand Up @@ -246,7 +259,11 @@ public void PlayAnimation(AnimationClip clip, bool isLoop = true, float speed =
}
else
{
#if UNITY_2018_2_OR_NEWER
PlayableOutput.DisconnectInput(0);
#else
PlayableOutput.GetGraph().Disconnect(PlayableOutput, 0);
#endif
PlayableOutput.ConnectInput(0, state.ClipMixer, 0);
PlayableOutput.SetInputWeight(0, 1.0f);
}
Expand Down
4 changes: 4 additions & 0 deletions Assets/Live2D/Cubism/Framework/Motion/CubismMotionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public static CubismMotionState CreateCubismMotionState(PlayableGraph playableGr
public void ConnectClipMixer(AnimationMixerPlayable clipMixer)
{
var lastInput = ClipMixer.GetInputCount() - 1;
#if UNITY_2018_2_OR_NEWER
ClipMixer.DisconnectInput(lastInput);
#else
ClipMixer.GetGraph().Disconnect(ClipMixer, lastInput);
#endif
ClipMixer.ConnectInput(lastInput, clipMixer, 0);
ClipMixer.SetInputWeight(lastInput, 1.0f);
}
Expand Down
14 changes: 2 additions & 12 deletions Assets/Live2D/Cubism/Framework/MotionFade/CubismFadeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ private void UpdateFade(ICubismFadeState fadeState)

var time = Time.time;

var isDoneAllFadeIn = true;

// Calculate MotionFade.
for (var i = 0; i < playingMotions.Count; i++)
{
Expand Down Expand Up @@ -222,18 +220,10 @@ private void UpdateFade(ICubismFadeState fadeState)
fadeMotion.ParameterFadeInTimes[index], fadeMotion.ParameterFadeOutTimes[index],
motionWeight, DestinationParts[j].Opacity);
}


if (erapsedTime > fadeInTime)
{
continue;
}
isDoneAllFadeIn = false;
}

if (!isDoneAllFadeIn || !fadeState.GetStateTransitionFinished())
if (!fadeState.GetStateTransitionFinished())
{
// Do not process any motion that has never finished fade-in.
return;
}

Expand All @@ -250,7 +240,7 @@ private void UpdateFade(ICubismFadeState fadeState)
continue;
}

// If fade-in of all motion has been completed, delete the motion that has been played back.
// If fade-in has been completed, delete the motion that has been played back.
fadeState.StopAnimation(i);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/Live2D/Cubism/Framework/Physics/CubismPhysicsMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ public static float Normalize(CubismParameter parameter,

if (maxValue < parameter.Value)
{
return result;
parameter.Value = maxValue;
}

var minValue = Mathf.Min(parameter.MaximumValue, parameter.MinimumValue);
if (minValue > parameter.Value)
{
return result;
parameter.Value = minValue;
}

var minNormValue = Mathf.Min(normalizedMinimum, normalizedMaximum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ private static void RegisterModelImporter()
private static void OnModelImport(CubismModel3JsonImporter sender, CubismModel model)
{
var shouldImportAsOriginalWorkflow = CubismUnityEditorMenu.ShouldImportAsOriginalWorkflow;
var pose3Json = sender.Model3Json.Pose3Json;

// Fail silently...
if(!shouldImportAsOriginalWorkflow)
if(!shouldImportAsOriginalWorkflow || pose3Json == null)
{
return;
}

var assetsDirectoryPath = Application.dataPath.Replace("Assets", "");
var assetPath = sender.AssetPath.Replace(assetsDirectoryPath, "");
var fileReferences = sender.Model3Json.FileReferences;
var pose3Json = sender.Model3Json.Pose3Json;

// Create pose animation clip
var motions = new List<CubismModel3Json.SerializableMotion>();
Expand Down