Skip to content

Commit 21ae7d1

Browse files
Merge pull request #87 from Live2D/develop
Update to Cubism 5 SDK for Unity R5 beta1
2 parents ca8babb + 83c8ad2 commit 21ae7d1

File tree

2,164 files changed

+554185
-109310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,164 files changed

+554185
-109310
lines changed

Assets/Live2D/Cubism/CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77

8+
## [5-r.5-beta.1] - 2025-08-26
9+
10+
### Added
11+
12+
* Add support for Blend mode and Offscreen drawing.
13+
* If the model uses blend mode or offscreen drawing, it will be rendered using a new drawing method that differs from `Cubism 5.2` and earlier.
14+
* Add high-precision mask method.
15+
* This is only available with the new rendering method in `Cubism 5.3` and later, and masks in the new rendering method from `Cubism 5.3` onward will automatically use this method.
16+
17+
### Changed
18+
19+
* Change the version of the development project to `6000.0.55f1`.
20+
* Change `_isOverriddenDrawableScreenColors` and `_isOverriddenDrawableMultiplyColors` to `_isOverriddenDrawObjectScreenColors` and `_isOverriddenDrawObjectMultiplyColors`.
21+
* The property names that use these backing fields have also been updated accordingly.
22+
* Serialization of `_isOverriddenDrawableScreenColors` and `_isOverriddenDrawableMultiplyColors` is maintained by the `FormerlySerializedAs` attribute.
23+
24+
### Removed
25+
26+
* Remove `CubismCoreDll.GetDrawableRenderOrders` and `CubismUnmanagedDrawables.RenderOrders`.
27+
* If you need to use these functions, please use `CubismModel.AllDrawObjectsRenderOrder` instead.
28+
* See `CHANGELOG.md` in Core.
29+
* Remove Chrome OS from the tested environment.
30+
31+
832
## [5-r.4.1] - 2025-07-17
933

1034
### Changed
@@ -474,6 +498,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
474498
* Fix issue where Priority value was not reset after playing motion with CubismMotionController.
475499

476500

501+
[5-r.5-beta.1]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.4.1...5-r.5-beta.1
477502
[5-r.4.1]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.4...5-r.4.1
478503
[5-r.4]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.3...5-r.4
479504
[5-r.3]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.2...5-r.3

Assets/Live2D/Cubism/Core/ArrayExtensionMethods.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,25 @@ internal static unsafe void ReadFrom(this CubismDynamicDrawableData[] self, Cubi
278278
}
279279

280280
#endregion
281+
282+
#region Offscreens
283+
284+
/// <summary>
285+
/// Revives (and sorts) <see cref="CubismOffscreen"/>s.
286+
/// </summary>
287+
/// <param name="self">Container.</param>
288+
/// <param name="model">TaskableModel to unmanaged model.</param>
289+
internal static void Revive(this CubismOffscreen[] self, CubismUnmanagedModel model)
290+
{
291+
Array.Sort(self, (a, b) => a.UnmanagedIndex - b.UnmanagedIndex);
292+
293+
294+
for (var i = 0; i < self.Length; ++i)
295+
{
296+
self[i].Revive(model);
297+
}
298+
}
299+
300+
#endregion
281301
}
282302
}

Assets/Live2D/Cubism/Core/CubismDrawable.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
using Live2D.Cubism.Core.Unmanaged;
1010
using Live2D.Cubism.Framework;
11+
using Live2D.Cubism.Rendering.Util;
1112
using UnityEngine;
1213

1314

@@ -152,7 +153,7 @@ public Color ScreenColor
152153
_screenColor.b = UnmanagedDrawables.ScreenColors[index + 2];
153154
_screenColor.a = UnmanagedDrawables.ScreenColors[index + 3];
154155

155-
return _screenColor; ;
156+
return _screenColor;
156157
}
157158
}
158159

@@ -376,6 +377,34 @@ public bool MultiplyBlend
376377
}
377378
}
378379

380+
#region Cubism 5.3
381+
382+
/// <summary>
383+
/// Gets the color blend mode of the drawable.
384+
/// </summary>
385+
public BlendTypes.ColorBlend ColorBlend
386+
{
387+
get
388+
{
389+
// Pull data.
390+
return (BlendTypes.ColorBlend)(UnmanagedDrawables.BlendModes[UnmanagedIndex] & 0xFF);
391+
}
392+
}
393+
394+
/// <summary>
395+
/// Gets the alpha blend mode of the drawable.
396+
/// </summary>
397+
public BlendTypes.AlphaBlend AlphaBlend
398+
{
399+
get
400+
{
401+
// Pull data.
402+
return (BlendTypes.AlphaBlend)((UnmanagedDrawables.BlendModes[UnmanagedIndex] >> 8) & 0xFF);
403+
}
404+
}
405+
406+
#endregion
407+
379408
/// <summary>
380409
/// Revives instance.
381410
/// </summary>

Assets/Live2D/Cubism/Core/CubismMoc.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ public uint Version
199199
{
200200
get
201201
{
202+
if (!IsRevived)
203+
{
204+
Revive();
205+
}
206+
202207
return UnmanagedMoc.MocVersion;
203208
}
204209
}

Assets/Live2D/Cubism/Core/CubismModel.cs

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
*/
77

88

9+
using Live2D.Cubism.Core.Unmanaged;
910
using Live2D.Cubism.Framework;
1011
using System;
1112
using UnityEngine;
13+
using Live2D.Cubism.Rendering.Util;
14+
15+
1216
#if UNITY_2019_3_OR_NEWER
1317
using UnityEngine.LowLevel;
1418
using UnityEngine.PlayerLoop;
@@ -115,7 +119,7 @@ public CubismMoc Moc
115119
private CubismParameter[] _parameters;
116120

117121
/// <summary>
118-
/// Drawables of model.
122+
/// Parameters of model.
119123
/// </summary>
120124
public CubismParameter[] Parameters
121125
{
@@ -204,6 +208,40 @@ public CubismCanvasInformation CanvasInformation
204208
private set { _canvasInformation = value; }
205209
}
206210

211+
/// <summary>
212+
/// <see cref="Offscreens"/> backing field.
213+
/// </summary>
214+
[NonSerialized]
215+
private CubismOffscreen[] _offscreens;
216+
217+
/// <summary>
218+
/// Offscreens of model.
219+
/// </summary>
220+
public CubismOffscreen[] Offscreens
221+
{
222+
get
223+
{
224+
if (_offscreens == null)
225+
{
226+
Revive();
227+
}
228+
229+
return _offscreens;
230+
}
231+
private set { _offscreens = value; }
232+
}
233+
234+
/// <summary>
235+
/// All draw objects render order.
236+
/// </summary>
237+
public CubismUnmanagedIntArrayView AllDrawObjectsRenderOrder
238+
{
239+
get
240+
{
241+
return TaskableModel.UnmanagedModel.AllDrawObjectRenderOrders;
242+
}
243+
}
244+
207245
/// <summary>
208246
/// Parameter store cache.
209247
/// </summary>
@@ -271,6 +309,39 @@ private bool CanRevive
271309
/// </summary>
272310
private int LastTick { get; set; }
273311

312+
/// <summary>
313+
/// Is the model's MOC version higher than Cubism 5.0?
314+
/// </summary>
315+
public bool IsOverMocVersion50
316+
{
317+
get
318+
{
319+
return CubismCoreDll.MocVersion_50 < Moc.Version;
320+
}
321+
}
322+
323+
/// <summary>
324+
/// Is this model using blend mode.
325+
/// </summary>
326+
[SerializeField, HideInInspector]
327+
private bool _isUsingBlendMode;
328+
329+
330+
/// <summary>
331+
/// Get Flag is this model using blend mode.
332+
/// </summary>
333+
/// <returns>True if Is this model using blend mode; otherwise returns false.</returns>
334+
public bool IsUsingBlendMode
335+
{
336+
get
337+
{
338+
return _isUsingBlendMode;
339+
}
340+
private set
341+
{
342+
_isUsingBlendMode = value;
343+
}
344+
}
274345

275346
/// <summary>
276347
/// Revives instance.
@@ -309,7 +380,6 @@ private void Reset(CubismMoc moc)
309380
return;
310381
}
311382

312-
313383
Parameters = GetComponentsInChildren<CubismParameter>();
314384
if (Parameters.Length < 1 && (transform.Find("Parameters") == null))
315385
{
@@ -351,6 +421,42 @@ private void Reset(CubismMoc moc)
351421
Drawables.Revive(TaskableModel.UnmanagedModel);
352422
}
353423

424+
if (0 < CubismCoreDll.GetOffscreenCount(TaskableModel.UnmanagedModel.Ptr))
425+
{
426+
IsUsingBlendMode = true;
427+
Offscreens = GetComponentsInChildren<CubismOffscreen>();
428+
if (Offscreens.Length < 1 && (transform.Find("Offscreens") == null))
429+
{
430+
// Create and initialize proxies.
431+
var offscreens = CubismOffscreen.CreateOffscreens(TaskableModel.UnmanagedModel);
432+
offscreens.transform.SetParent(transform);
433+
Offscreens = offscreens.GetComponentsInChildren<CubismOffscreen>();
434+
}
435+
else
436+
{
437+
Offscreens.Revive(TaskableModel.UnmanagedModel);
438+
}
439+
}
440+
441+
if (IsOverMocVersion50 && !IsUsingBlendMode)
442+
{
443+
var drawableCount = Drawables.Length;
444+
for (var i = 0; i < drawableCount; ++i)
445+
{
446+
var colorBlendType = Drawables[i].ColorBlend;
447+
var alphaBlendType = Drawables[i].AlphaBlend;
448+
if (colorBlendType == BlendTypes.ColorBlend.Normal &&
449+
alphaBlendType == BlendTypes.AlphaBlend.Over ||
450+
colorBlendType == BlendTypes.ColorBlend.Add ||
451+
colorBlendType == BlendTypes.ColorBlend.Multiply)
452+
{
453+
continue;
454+
}
455+
456+
IsUsingBlendMode = true;
457+
break;
458+
}
459+
}
354460

355461
CanvasInformation = new CubismCanvasInformation(TaskableModel.UnmanagedModel);
356462

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using Live2D.Cubism.Core;
2+
3+
/**
4+
* Copyright(c) Live2D Inc. All rights reserved.
5+
*
6+
* Use of this source code is governed by the Live2D Open Software license
7+
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
8+
*/
9+
10+
11+
public class CubismModelTypes
12+
{
13+
/// <summary>
14+
/// Type of draw object in a model.
15+
/// </summary>
16+
public enum DrawObjectType
17+
{
18+
Drawable,
19+
Offscreen,
20+
Unknown = -1
21+
}
22+
23+
/// <summary>
24+
/// Type of child object in a part.
25+
/// </summary>
26+
public enum PartChildObjectType
27+
{
28+
Drawable,
29+
Parts,
30+
Unknown = -1
31+
}
32+
33+
/// <summary>
34+
/// Information about a single part in a <see cref="CubismModel"/>.
35+
/// </summary>
36+
public struct PartInfo
37+
{
38+
public int PartUnmanagedIndex;
39+
public PartChildObjectInfo[] ChildObjects;
40+
public PartDrawObjectInfo DrawObjects;
41+
42+
/// <summary>
43+
/// Number of child objects in this part.
44+
/// </summary>
45+
public int ChildCount
46+
{
47+
get
48+
{
49+
if (ChildObjects == null)
50+
{
51+
return 0;
52+
}
53+
54+
return ChildObjects.Length;
55+
}
56+
}
57+
58+
/// <summary>
59+
/// Number of draw object in this part.
60+
/// </summary>
61+
public int DrawObjectCount
62+
{
63+
get
64+
{
65+
if (DrawObjects.Drawables == null)
66+
{
67+
return 0;
68+
}
69+
70+
return DrawObjects.Drawables.Length;
71+
}
72+
}
73+
}
74+
75+
/// <summary>
76+
/// Information about a child object in a part.
77+
/// </summary>
78+
public struct PartChildObjectInfo
79+
{
80+
public PartChildObjectType ChildObjectType;
81+
public int ChildObjectIndex;
82+
}
83+
84+
/// <summary>
85+
/// Information about draw objects in a part.
86+
/// </summary>
87+
public struct PartDrawObjectInfo
88+
{
89+
public CubismDrawable[] Drawables;
90+
public CubismOffscreen[] Offscreens;
91+
}
92+
}

Assets/Live2D/Cubism/Core/CubismModelTypes.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)