Skip to content

Commit

Permalink
Merge pull request #72 from Live2D/develop
Browse files Browse the repository at this point in the history
Update to Cubism 4 SDK for Unity R7
  • Loading branch information
itoh-at-live2d-com authored May 25, 2023
2 parents c7ac7b6 + af345b2 commit f35c939
Show file tree
Hide file tree
Showing 43 changed files with 47,007 additions and 92,677 deletions.
22 changes: 22 additions & 0 deletions Assets/Live2D/Cubism/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ 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/).


## [4-r.7] - 2023-05-25

### Added

* The number of render textures used can now be increased arbitrarily.
* The maximum number of masks when using multiple render textures has been increased to "number of render textures * 32".
* You can also continue to use the pre-R6_2 method.
* Importing a model now generates a MaskTexture asset containing the model's name.
* It is generated only if the model prefab has not been generated.
* Add the function of checking consistency on importing a MOC3. (`CubismMoc.CreateFrom`)
* This feature is enabled by default.Please see the following manual for more information.
* https://docs.live2d.com/cubism-sdk-manual/moc3-consistency/
* Add component for changing Multiply Color / Screen Color from parent part.
* Components are automatically added to each part object of the model when the model is imported.

### Fixed

* Fix to improve physics and rendering performance. by [@ppcuni](https://github.com/ppcuni)
* Fix an issue with `ResetSwapInfoFlags` function where flags were not initialized correctly. by [@ppcuni](https://github.com/ppcuni)


## [4-r.6.2] - 2023-03-16

### Fixed
Expand Down Expand Up @@ -282,6 +303,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.


[4-r.7]: https://github.com/Live2D/CubismUnityComponents/compare/4-r.6.2...4-r.7
[4-r.6.2]: https://github.com/Live2D/CubismUnityComponents/compare/4-r.6.1...4-r.6.2
[4-r.6.1]: https://github.com/Live2D/CubismUnityComponents/compare/4-r.6...4-r.6.1
[4-r.6]: https://github.com/Live2D/CubismUnityComponents/compare/4-r.5...4-r.6
Expand Down
9 changes: 8 additions & 1 deletion Assets/Live2D/Cubism/Core/CubismMoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ public static bool HasMocConsistency(byte[] moc3)
/// Creates a <see cref="CubismMoc"/> asset from raw bytes.
/// </summary>
/// <param name="moc3">Source.</param>
/// <param name="shouldCheckMocConsistency">Use the verification function?</param>
/// <returns>Instance.</returns>
public static CubismMoc CreateFrom(byte[] moc3)
public static CubismMoc CreateFrom(byte[] moc3, bool shouldCheckMocConsistency = true)
{
if (shouldCheckMocConsistency && !HasMocConsistency(moc3))
{
Debug.LogError("This Moc3 is Invalid. This model generation process is aborted and prefab is not created.");
return null;
}

var moc = CreateInstance<CubismMoc>();


Expand Down
10 changes: 10 additions & 0 deletions Assets/Live2D/Cubism/Editor/Importers/CubismModel3JsonImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Live2D.Cubism.Framework.Motion;
using Live2D.Cubism.Framework.MotionFade;
using Live2D.Cubism.Framework.Pose;
using Live2D.Cubism.Rendering.Masking;
using System;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -204,6 +205,15 @@ public override void Import()
CubismImporter.SendModelTextureImportEvent(this, model, texture);
}

var modelMaskTexture = ScriptableObject.CreateInstance<CubismMaskTexture>();
modelMaskTexture.name = model.name + "MaskTexture";

var filePath = string.Format("{0}/{1}.asset", Path.GetDirectoryName(AssetPath), modelMaskTexture.name);

if (!File.Exists(filePath))
{
AssetDatabase.CreateAsset(modelMaskTexture, filePath);
}

// Create prefab and trigger saving of changes.
#if UNITY_2018_3_OR_NEWER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ internal sealed class CubismMaskTextureInspector : UnityEditor.Editor
{
#region Editor

private bool _foldoutStatus = true;

/// <summary>
/// Draws inspector.
/// </summary>
Expand All @@ -39,10 +41,41 @@ public override void OnInspectorGUI()
// Show settings.
EditorGUI.BeginChangeCheck();

var message = "Current using system: ";
message += texture.RenderTextureCount < 1 ? "Subdivisions (Legacy)" : "Multiple RenderTexture";
EditorGUILayout.HelpBox(message, MessageType.Info);
EditorGUILayout.Space();

EditorGUILayout.LabelField("Subdivisions (Legacy)", EditorStyles.boldLabel);

EditorGUI.indentLevel++;
texture.Size = EditorGUILayout.IntField("Size (In Pixels)", texture.Size);
texture.Subdivisions = EditorGUILayout.IntSlider("Subdivisions", texture.Subdivisions, 1, 5);
EditorGUILayout.ObjectField("Render Texture (Read-only)", (RenderTexture) texture, typeof(RenderTexture), false);
EditorGUI.indentLevel--;

EditorGUILayout.Space();
EditorGUILayout.LabelField("Multiple RenderTexture", EditorStyles.boldLabel);

EditorGUI.indentLevel++;
texture.RenderTextureCount = EditorGUILayout.IntSlider("RenderTextureCount", texture.RenderTextureCount, 0, 5);
EditorGUILayout.Space();

_foldoutStatus = EditorGUILayout.Foldout(_foldoutStatus, "Render Textures (Read-only)");
if (_foldoutStatus)
{
EditorGUILayout.BeginVertical(GUI.skin.box);

// Make it practically ReadOnly.
GUI.enabled = false;
for (int renderTextureIndex = 0; renderTextureIndex < texture.RenderTextures.Length; renderTextureIndex++)
{
EditorGUILayout.ObjectField($"element {renderTextureIndex} (Read-only)", texture.RenderTextures[renderTextureIndex], typeof(RenderTexture), false);
}
GUI.enabled = true;
EditorGUILayout.EndVertical();
}
EditorGUI.indentLevel--;


// Save any changes.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* 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 https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/


using UnityEditor;
using Live2D.Cubism.Rendering;


namespace Live2D.Cubism.Editor.Inspectors
{
[CustomEditor(typeof(CubismPartColorsEditor)), CanEditMultipleObjects]
internal sealed class PortfolioPartBlendColorEditorInspector : UnityEditor.Editor
{
private SerializedProperty childDrawableRenderers;

#region Editor

/// <summary>
/// Draws inspector.
/// </summary>
public override void OnInspectorGUI()
{
var blendColorEditor = target as CubismPartColorsEditor;

// Fail silently.
if (blendColorEditor == null)
{
return;
}

// Obtains a property from a component.
if (childDrawableRenderers == null)
{
childDrawableRenderers = serializedObject.FindProperty("_childDrawableRenderers");
}

if (childDrawableRenderers != null)
{
// Show renderers.
EditorGUILayout.PropertyField(childDrawableRenderers);
}

EditorGUI.BeginChangeCheck();

// Display OverwriteColorForPartMultiplyColors.
using (var scope = new EditorGUI.ChangeCheckScope())
{
var overwriteColorForPartMultiplyColors = EditorGUILayout.Toggle("OverwriteColorForPartMultiplyColors", blendColorEditor.OverwriteColorForPartMultiplyColors);

if (scope.changed)
{
foreach (CubismPartColorsEditor partBlendColorEditor in targets)
{
partBlendColorEditor.OverwriteColorForPartMultiplyColors = overwriteColorForPartMultiplyColors;
}
}
}

// Display OverwriteColorForPartScreenColors.
using (var scope = new EditorGUI.ChangeCheckScope())
{
var overwriteColorForPartScreenColors = EditorGUILayout.Toggle("OverwriteColorForPartScreenColors", blendColorEditor.OverwriteColorForPartScreenColors);

if (scope.changed)
{
foreach (CubismPartColorsEditor partBlendColorEditor in targets)
{
partBlendColorEditor.OverwriteColorForPartScreenColors = overwriteColorForPartScreenColors;
}
}
}

// Display multiply color.
using (var scope = new EditorGUI.ChangeCheckScope())
{
var multiplyColor = EditorGUILayout.ColorField("MultiplyColor", blendColorEditor.MultiplyColor);

if (scope.changed)
{
foreach (CubismPartColorsEditor partBlendColorEditor in targets)
{
partBlendColorEditor.MultiplyColor = multiplyColor;
}
}
}

// Display screen color.
using (var scope = new EditorGUI.ChangeCheckScope())
{
var screenColor = EditorGUILayout.ColorField("ScreenColor", blendColorEditor.ScreenColor);

if (scope.changed)
{
foreach (CubismPartColorsEditor partBlendColorEditor in targets)
{
partBlendColorEditor.ScreenColor = screenColor;
}
}
}


// Save any changes.
if (EditorGUI.EndChangeCheck())
{
foreach (CubismPartColorsEditor partBlendColorEditor in targets)
{
EditorUtility.SetDirty(partBlendColorEditor);

foreach (var renderer in partBlendColorEditor.ChildDrawableRenderers)
{
EditorUtility.SetDirty(renderer);
// HACK Get mesh renderer directly.
EditorUtility.SetDirty(renderer.MeshRenderer);
}
}
}
}

#endregion
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion Assets/Live2D/Cubism/Framework/Json/CubismModel3Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,21 @@ public CubismModel ToModel(MaterialPicker pickMaterial, TexturePicker pickTextur
}


if (model.Parts != null)
{
var parts = model.Parts;

// Create and initialize partColorsEditors.
for (int i = 0; i < parts.Length; i++)
{
var partColorsEditor = parts[i].gameObject.AddComponent<CubismPartColorsEditor>();
partColorsEditor.TryInitialize(rendererController, parts[i], model.Drawables);
}
}


// Initialize drawables.
if(HitAreas != null)
if (HitAreas != null)
{
for (var i = 0; i < HitAreas.Length; i++)
{
Expand Down
6 changes: 6 additions & 0 deletions Assets/Live2D/Cubism/Framework/Physics/CubismPhysicsInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ public void InitializeGetter()
[NonSerialized]
public CubismParameter Source;

/// <summary>
/// <see cref="Source"/> index.
/// </summary>
[NonSerialized]
public int SourceIndex;

/// <summary>
/// Function of getting normalized parameter value.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions Assets/Live2D/Cubism/Framework/Physics/CubismPhysicsOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ public void InitializeGetter()
[NonSerialized]
public CubismParameter Destination;

/// <summary>
/// <see cref="Destination"/> index.
/// </summary>
[NonSerialized]
public int DestinationIndex;

/// <summary>
/// Function of getting output value.
/// </summary>
Expand Down
Loading

0 comments on commit f35c939

Please sign in to comment.