mirror of
https://github.com/aelurum/AssetStudio.git
synced 2026-11-15 19:28:48 -05:00
Improve detection of Live2D models. Close #122
- Added an alternative way of model detection when a MonoScript asset is not loaded. - Fixed model detection regression after the https://github.com/aelurum/AssetStudio/commit/0066d673f45cfd07bbca4343e2fdf27660698c17
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using AssetStudio;
|
||||
using AssetStudio.Addons.CubismLive2D;
|
||||
using CubismLive2DExtractor.CubismJsonConverters;
|
||||
using CubismLive2DExtractor.CubismUnityClasses;
|
||||
using System;
|
||||
@@ -13,21 +14,6 @@ namespace CubismLive2DExtractor
|
||||
{
|
||||
public static readonly JsonSerializerOptions CubismJsonOptions;
|
||||
|
||||
public enum CubismMonoBehaviourType
|
||||
{
|
||||
FadeController,
|
||||
FadeMotionList,
|
||||
FadeMotion,
|
||||
ExpressionController,
|
||||
ExpressionList,
|
||||
Expression,
|
||||
Physics,
|
||||
DisplayInfo,
|
||||
PosePart,
|
||||
Model,
|
||||
RenderTexture,
|
||||
}
|
||||
|
||||
static CubismParsers()
|
||||
{
|
||||
CubismJsonOptions = new JsonSerializerOptions
|
||||
@@ -151,7 +137,7 @@ namespace CubismLive2DExtractor
|
||||
return JsonSerializer.Serialize(physicsJson, physicsOptions);
|
||||
}
|
||||
|
||||
public static OrderedDictionary ParseMonoBehaviour(MonoBehaviour m_MonoBehaviour, CubismMonoBehaviourType cubismMonoBehaviourType, AssemblyLoader assemblyLoader)
|
||||
public static OrderedDictionary ParseMonoBehaviour(MonoBehaviour m_MonoBehaviour, CubismHelpers.CubismMonoBehaviourType cubismMonoBehaviourType, AssemblyLoader assemblyLoader)
|
||||
{
|
||||
var orderedDict = m_MonoBehaviour.ToType();
|
||||
if (orderedDict != null)
|
||||
@@ -161,37 +147,37 @@ namespace CubismLive2DExtractor
|
||||
var m_Type = m_MonoBehaviour.ConvertToTypeTree(assemblyLoader);
|
||||
switch (cubismMonoBehaviourType)
|
||||
{
|
||||
case CubismMonoBehaviourType.FadeController:
|
||||
case CubismHelpers.CubismMonoBehaviourType.FadeController:
|
||||
fieldName = "cubismfademotionlist";
|
||||
break;
|
||||
case CubismMonoBehaviourType.FadeMotionList:
|
||||
case CubismHelpers.CubismMonoBehaviourType.FadeMotionList:
|
||||
fieldName = "cubismfademotionobjects";
|
||||
break;
|
||||
case CubismMonoBehaviourType.FadeMotion:
|
||||
case CubismHelpers.CubismMonoBehaviourType.FadeMotion:
|
||||
fieldName = "parameterids";
|
||||
break;
|
||||
case CubismMonoBehaviourType.ExpressionController:
|
||||
case CubismHelpers.CubismMonoBehaviourType.ExpressionController:
|
||||
fieldName = "expressionslist";
|
||||
break;
|
||||
case CubismMonoBehaviourType.ExpressionList:
|
||||
case CubismHelpers.CubismMonoBehaviourType.ExpressionList:
|
||||
fieldName = "cubismexpressionobjects";
|
||||
break;
|
||||
case CubismMonoBehaviourType.Expression:
|
||||
case CubismHelpers.CubismMonoBehaviourType.Expression:
|
||||
fieldName = "parameters";
|
||||
break;
|
||||
case CubismMonoBehaviourType.Physics:
|
||||
case CubismHelpers.CubismMonoBehaviourType.Physics:
|
||||
fieldName = "_rig";
|
||||
break;
|
||||
case CubismMonoBehaviourType.DisplayInfo:
|
||||
case CubismHelpers.CubismMonoBehaviourType.DisplayInfo:
|
||||
fieldName = "name";
|
||||
break;
|
||||
case CubismMonoBehaviourType.PosePart:
|
||||
case CubismHelpers.CubismMonoBehaviourType.PosePart:
|
||||
fieldName = "groupindex";
|
||||
break;
|
||||
case CubismMonoBehaviourType.Model:
|
||||
case CubismHelpers.CubismMonoBehaviourType.ModelPPtr:
|
||||
fieldName = "_moc";
|
||||
break;
|
||||
case CubismMonoBehaviourType.RenderTexture:
|
||||
case CubismHelpers.CubismMonoBehaviourType.RenderTexture:
|
||||
fieldName = "_maintexture";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Threading.Tasks;
|
||||
using static AssetStudio.Addons.CubismLive2D.CubismHelpers;
|
||||
using static CubismLive2DExtractor.CubismParsers;
|
||||
using Object = AssetStudio.Object;
|
||||
|
||||
@@ -23,9 +24,8 @@ namespace CubismLive2DExtractor
|
||||
{
|
||||
public sealed class Live2DExtractor
|
||||
{
|
||||
public static Dictionary<MonoBehaviour, CubismModel> MocDict { get; set; }
|
||||
public static AssemblyLoader Assembly { get; set; }
|
||||
public CubismModel Model { get; set; }
|
||||
private CubismModel Model { get; set; }
|
||||
private Live2DOptions Options { get; }
|
||||
private List<MonoBehaviour> FadeMotions { get; set; }
|
||||
private List<AnimationClip> AnimationClips { get; set; }
|
||||
@@ -34,7 +34,6 @@ namespace CubismLive2DExtractor
|
||||
private List<MonoBehaviour> PartsCdi { get; set; }
|
||||
private List<MonoBehaviour> PoseParts { get; set; }
|
||||
private List<Texture2D> Texture2Ds { get; set; }
|
||||
public MonoBehaviour MocMono { get; set; }
|
||||
private MonoBehaviour PhysicsMono { get; set; }
|
||||
private MonoBehaviour FadeMotionLst { get; set; }
|
||||
private MonoBehaviour ExpressionLst { get; set; }
|
||||
@@ -43,7 +42,7 @@ namespace CubismLive2DExtractor
|
||||
private HashSet<string> EyeBlinkParameters { get; set; }
|
||||
private HashSet<string> LipSyncParameters { get; set; }
|
||||
|
||||
public Live2DExtractor(KeyValuePair<MonoBehaviour, List<Object>> assetGroupKvp, Live2DOptions l2dOptions)
|
||||
public Live2DExtractor(List<Object> modelAssetsList, CubismModel model, Live2DOptions l2dOptions)
|
||||
{
|
||||
Options = l2dOptions;
|
||||
Expressions = new List<MonoBehaviour>();
|
||||
@@ -71,8 +70,7 @@ namespace CubismLive2DExtractor
|
||||
|
||||
Logger.Debug("Sorting model assets..");
|
||||
|
||||
MocMono = assetGroupKvp.Key;
|
||||
if (MocDict.TryGetValue(MocMono, out var model) && model != null)
|
||||
if (model != null)
|
||||
{
|
||||
Model = model;
|
||||
PhysicsMono = Model.PhysicsController;
|
||||
@@ -116,7 +114,7 @@ namespace CubismLive2DExtractor
|
||||
AnimationClips.AddRange(Model.ClipMotionList);
|
||||
}
|
||||
}
|
||||
foreach (var asset in assetGroupKvp.Value)
|
||||
foreach (var asset in modelAssetsList)
|
||||
{
|
||||
switch (asset)
|
||||
{
|
||||
@@ -197,6 +195,50 @@ namespace CubismLive2DExtractor
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (TryGetCubismMonoBehaviourType(m_MonoBehaviour, out var type))
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CubismMonoBehaviourType.Physics:
|
||||
if (PhysicsMono == null)
|
||||
PhysicsMono = m_MonoBehaviour;
|
||||
break;
|
||||
case CubismMonoBehaviourType.Expression:
|
||||
if (ExpressionLst == null)
|
||||
Expressions.Add(m_MonoBehaviour);
|
||||
break;
|
||||
case CubismMonoBehaviourType.ExpressionList:
|
||||
if (ExpressionLst == null)
|
||||
ExpressionLst = m_MonoBehaviour;
|
||||
break;
|
||||
case CubismMonoBehaviourType.FadeMotion:
|
||||
if (searchFadeMotions)
|
||||
{
|
||||
FadeMotions.Add(m_MonoBehaviour);
|
||||
}
|
||||
break;
|
||||
case CubismMonoBehaviourType.FadeMotionList:
|
||||
if (searchFadeMotions)
|
||||
{
|
||||
FadeMotionLst = m_MonoBehaviour;
|
||||
}
|
||||
break;
|
||||
case CubismMonoBehaviourType.PosePart:
|
||||
if (searchPoseParts && m_MonoBehaviour.m_GameObject.TryGet(out _))
|
||||
{
|
||||
PoseParts.Add(m_MonoBehaviour);
|
||||
}
|
||||
break;
|
||||
case CubismMonoBehaviourType.RenderTexture:
|
||||
if (searchRenderTextures && isRenderReadable)
|
||||
{
|
||||
isRenderReadable = TryGetRenderTexture(m_MonoBehaviour, out var renderTex);
|
||||
if (isRenderReadable)
|
||||
renderTextureSet.Add(renderTex);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AnimationClip m_AnimationClip:
|
||||
if (Options.SelectedClipMotions == null)
|
||||
@@ -225,14 +267,14 @@ namespace CubismLive2DExtractor
|
||||
}
|
||||
}
|
||||
|
||||
public void ExtractCubismModel(string destPath, int parallelTaskCount = 1)
|
||||
public void ExtractCubismModel(MonoBehaviour mocMono, string destPath, int parallelTaskCount = 1)
|
||||
{
|
||||
var modelName = Model?.Name ?? destPath.Split('/', '\\').Last();
|
||||
destPath += Path.DirectorySeparatorChar;
|
||||
Directory.CreateDirectory(destPath);
|
||||
|
||||
#region moc3
|
||||
using (var cubismMoc = new CubismMoc(MocMono))
|
||||
using (var cubismMoc = new CubismMoc(mocMono))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("Model Stats:");
|
||||
|
||||
Reference in New Issue
Block a user