mirror of
				https://github.com/aelurum/AssetStudio.git
				synced 2025-11-03 14:35:14 -05:00 
			
		
		
		
	Add support for Live2D Fade motions
This commit is contained in:
		@ -12,6 +12,7 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
        General,
 | 
			
		||||
        Convert,
 | 
			
		||||
        Logger,
 | 
			
		||||
        Live2D,
 | 
			
		||||
        FBX,
 | 
			
		||||
        Filter,
 | 
			
		||||
        Advanced,
 | 
			
		||||
@ -83,6 +84,9 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
        public static bool convertTexture;
 | 
			
		||||
        public static Option<ImageFormat> o_imageFormat;
 | 
			
		||||
        public static Option<AudioFormat> o_audioFormat;
 | 
			
		||||
        //live2d
 | 
			
		||||
        public static Option<CubismLive2DExtractor.Live2DMotionMode> o_l2dMotionMode;
 | 
			
		||||
        public static Option<bool> f_l2dForceBezier;
 | 
			
		||||
        //fbx
 | 
			
		||||
        public static Option<float> o_fbxScaleFactor;
 | 
			
		||||
        public static Option<int> o_fbxBoneSize;
 | 
			
		||||
@ -203,7 +207,7 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
                optionDefaultValue: "ASExport",
 | 
			
		||||
                optionName: "-o, --output <path>",
 | 
			
		||||
                optionDescription: "Specify path to the output folder\n" +
 | 
			
		||||
                    "If path isn't specifyed, 'ASExport' folder will be created in the program's work folder\n",
 | 
			
		||||
                    "If path isn't specified, 'ASExport' folder will be created in the program's work folder\n",
 | 
			
		||||
                optionHelpGroup: HelpGroups.General
 | 
			
		||||
            );
 | 
			
		||||
            o_displayHelp = new GroupedOption<bool>
 | 
			
		||||
@ -260,6 +264,30 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
            );
 | 
			
		||||
            #endregion
 | 
			
		||||
 | 
			
		||||
            #region Init Cubism Live2D Options
 | 
			
		||||
            o_l2dMotionMode = new GroupedOption<CubismLive2DExtractor.Live2DMotionMode>
 | 
			
		||||
            (
 | 
			
		||||
                optionDefaultValue: CubismLive2DExtractor.Live2DMotionMode.MonoBehaviour,
 | 
			
		||||
                optionName: "--l2d-motion-mode <value>",
 | 
			
		||||
                optionDescription: "Specify Live2D motion export mode\n" +
 | 
			
		||||
                    "<Value: monoBehaviour(default) | animationClip>\n" +
 | 
			
		||||
                    "MonoBehaviour - Try to export motions from MonoBehaviour Fade motions\n" +
 | 
			
		||||
                    "If no Fade motions are found, the AnimationClip method will be used\n" +
 | 
			
		||||
                    "AnimationClip - Try to export motions using AnimationClip assets\n" +
 | 
			
		||||
                    "Example: \"--l2d-motion-mode animationClip\"\n",
 | 
			
		||||
                optionHelpGroup: HelpGroups.Live2D
 | 
			
		||||
            );
 | 
			
		||||
            f_l2dForceBezier = new GroupedOption<bool>
 | 
			
		||||
            (
 | 
			
		||||
                optionDefaultValue: false,
 | 
			
		||||
                optionName: "--l2d-force-bezier",
 | 
			
		||||
                optionDescription: "(Flag) If specified, Linear motion segments will be calculated as Bezier segments\n" +
 | 
			
		||||
                    "(May help if the exported motions look jerky/not smooth enough)",
 | 
			
		||||
                optionHelpGroup: HelpGroups.Live2D,
 | 
			
		||||
                isFlag: true
 | 
			
		||||
            );
 | 
			
		||||
            #endregion
 | 
			
		||||
 | 
			
		||||
            #region Init FBX Options
 | 
			
		||||
            o_fbxScaleFactor = new GroupedOption<float>
 | 
			
		||||
            (
 | 
			
		||||
@ -411,6 +439,7 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
                }    
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            #region Parse "Working Mode" Option
 | 
			
		||||
            var workModeOptionIndex = resplittedArgs.FindIndex(x => x.ToLower() == "-m" || x.ToLower() == "--mode");
 | 
			
		||||
            if (workModeOptionIndex >= 0)
 | 
			
		||||
            {
 | 
			
		||||
@ -437,6 +466,7 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
                    case "info":
 | 
			
		||||
                        o_workMode.Value = WorkMode.Info;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "l2d":
 | 
			
		||||
                    case "live2d":
 | 
			
		||||
                        o_workMode.Value = WorkMode.ExportLive2D;
 | 
			
		||||
                        o_exportAssetTypes.Value = new List<ClassIDType>()
 | 
			
		||||
@ -468,6 +498,7 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
                }
 | 
			
		||||
                resplittedArgs.RemoveRange(workModeOptionIndex, 2);
 | 
			
		||||
            }
 | 
			
		||||
            #endregion
 | 
			
		||||
 | 
			
		||||
            #region Parse Flags
 | 
			
		||||
            for (int i = 0; i < resplittedArgs.Count; i++) 
 | 
			
		||||
@ -495,6 +526,16 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
                                return;
 | 
			
		||||
                        }
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "--l2d-force-bezier":
 | 
			
		||||
                        if (o_workMode.Value != WorkMode.ExportLive2D)
 | 
			
		||||
                        {
 | 
			
		||||
                            Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{flag}] flag. This flag is not suitable for the current working mode [{o_workMode.Value}].\n");
 | 
			
		||||
                            ShowOptionDescription(o_workMode.Description);
 | 
			
		||||
                            return;
 | 
			
		||||
                        }
 | 
			
		||||
                        f_l2dForceBezier.Value = true;
 | 
			
		||||
                        resplittedArgs.RemoveAt(i);
 | 
			
		||||
                        break;
 | 
			
		||||
                }
 | 
			
		||||
            }            
 | 
			
		||||
            #endregion
 | 
			
		||||
@ -693,6 +734,28 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
                                    return;
 | 
			
		||||
                            }
 | 
			
		||||
                            break;
 | 
			
		||||
                        case "--l2d-motion-mode":
 | 
			
		||||
                            if (o_workMode.Value != WorkMode.ExportLive2D)
 | 
			
		||||
                            {
 | 
			
		||||
                                Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option}] option. This option is not suitable for the current working mode [{o_workMode.Value}].\n");
 | 
			
		||||
                                ShowOptionDescription(o_workMode.Description);
 | 
			
		||||
                                return;
 | 
			
		||||
                            }
 | 
			
		||||
                            switch (value.ToLower())
 | 
			
		||||
                            {
 | 
			
		||||
                                case "fade":
 | 
			
		||||
                                case "monobehaviour":
 | 
			
		||||
                                    o_l2dMotionMode.Value = CubismLive2DExtractor.Live2DMotionMode.MonoBehaviour;
 | 
			
		||||
                                    break;
 | 
			
		||||
                                case "animationclip":
 | 
			
		||||
                                    o_l2dMotionMode.Value = CubismLive2DExtractor.Live2DMotionMode.AnimationClip;
 | 
			
		||||
                                    break;
 | 
			
		||||
                                default:
 | 
			
		||||
                                    Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option}] option. Unsupported Live2D motion mode: [{value.Color(brightRed)}].\n");
 | 
			
		||||
                                    ShowOptionDescription(o_l2dMotionMode.Description);
 | 
			
		||||
                                    return;
 | 
			
		||||
                            }
 | 
			
		||||
                            break;
 | 
			
		||||
                        case "--fbx-scale-factor":
 | 
			
		||||
                            var isFloat = float.TryParse(value, out float floatValue);
 | 
			
		||||
                            if (isFloat && floatValue >= 0 && floatValue <= 100)
 | 
			
		||||
@ -832,12 +895,12 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
 | 
			
		||||
        private static bool TryFindOptionDescription(string option, Dictionary<string, string> dict, bool isFlag = false)
 | 
			
		||||
        {
 | 
			
		||||
            var optionDesc = dict.Where(x => x.Key.Contains(option));
 | 
			
		||||
            var optionDesc = dict.Where(x => x.Key.Contains(option)).ToArray();
 | 
			
		||||
            if (optionDesc.Any())
 | 
			
		||||
            {
 | 
			
		||||
                var arg = isFlag ? "flag" : "option";
 | 
			
		||||
                var rand = new Random();
 | 
			
		||||
                var rndOption = optionDesc.ElementAt(rand.Next(0, optionDesc.Count()));
 | 
			
		||||
                var rndOption = optionDesc.ElementAt(rand.Next(0, optionDesc.Length));
 | 
			
		||||
                Console.WriteLine($"Did you mean [{$"{rndOption.Key}".Color(CLIAnsiColors.BrightYellow)}] {arg}?");
 | 
			
		||||
                Console.WriteLine($"Here's a description of it: \n\n{rndOption.Value}");
 | 
			
		||||
 | 
			
		||||
@ -946,7 +1009,7 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
                    sb.AppendLine($"# Log Output: {o_logOutput}");
 | 
			
		||||
                    sb.AppendLine($"# Export Asset List: {o_exportAssetList}");
 | 
			
		||||
                    sb.AppendLine(ShowCurrentFilter());
 | 
			
		||||
                    sb.AppendLine($"# Assebmly Path: \"{o_assemblyPath}\"");
 | 
			
		||||
                    sb.AppendLine($"# Assembly Path: \"{o_assemblyPath}\"");
 | 
			
		||||
                    sb.AppendLine($"# Unity Version: \"{o_unityVersion}\"");
 | 
			
		||||
                    if (o_workMode.Value == WorkMode.Export)
 | 
			
		||||
                    {
 | 
			
		||||
@ -975,7 +1038,9 @@ namespace AssetStudioCLI.Options
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        sb.AppendLine($"# Assebmly Path: \"{o_assemblyPath}\"");
 | 
			
		||||
                        sb.AppendLine($"# Live2D Motion Export Method: {o_l2dMotionMode}");
 | 
			
		||||
                        sb.AppendLine($"# Force Bezier: {f_l2dForceBezier }");
 | 
			
		||||
                        sb.AppendLine($"# Assembly Path: \"{o_assemblyPath}\"");
 | 
			
		||||
                    }
 | 
			
		||||
                    sb.AppendLine($"# Unity Version: \"{o_unityVersion}\"");
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
@ -611,6 +611,8 @@ namespace AssetStudioCLI
 | 
			
		||||
        {
 | 
			
		||||
            var baseDestPath = Path.Combine(CLIOptions.o_outputFolder.Value, "Live2DOutput");
 | 
			
		||||
            var useFullContainerPath = false;
 | 
			
		||||
            var motionMode = CLIOptions.o_l2dMotionMode.Value;
 | 
			
		||||
            var forceBezier = CLIOptions.f_l2dForceBezier.Value;
 | 
			
		||||
 | 
			
		||||
            Progress.Reset();
 | 
			
		||||
            Logger.Info($"Searching for Live2D files...");
 | 
			
		||||
@ -683,7 +685,7 @@ namespace AssetStudioCLI
 | 
			
		||||
                    container = Path.HasExtension(container) ? container.Replace(Path.GetExtension(container), "") : container;
 | 
			
		||||
                    var destPath = Path.Combine(baseDestPath, container) + Path.DirectorySeparatorChar;
 | 
			
		||||
 | 
			
		||||
                    ExtractLive2D(assets, destPath, modelName, assemblyLoader);
 | 
			
		||||
                    ExtractLive2D(assets, destPath, modelName, assemblyLoader, motionMode, forceBezier);
 | 
			
		||||
                    modelCounter++;
 | 
			
		||||
                }
 | 
			
		||||
                catch (Exception ex)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user