求助大佬,Megaha:Re 异世界实干记,解包

script the convertion fade to motion, I don’t know if it works

const path = require('path');
//const dirPath = './'

function processFadeFiles(dirPath) {
    const files = fs.readdirSync(dirPath);
	console.log(files)
    for (const file of files) {
        const filePath = path.join(dirPath, file);
        const stat = fs.statSync(filePath);
        if (stat.isDirectory()) {
            processFadeFiles(filePath);
        } else if (file.endsWith('.fade.json')) {
            const fileName = path.basename(file, '.fade.json');
            const data = fs.readFileSync(filePath, 'utf8');
            const obj = JSON.parse(data);
            const motion3Json = {
                'Version': 3,
                "Meta": {
                    "Duration": 0.000,
                    "Fps": 60.0,
                    "Loop": true,
                    "AreBeziersRestricted": true,
                    "CurveCount": 0,
                    "TotalSegmentCount": 0,
                    "TotalPointCount": 0,
                    "UserDataCount": 1,
                    "TotalUserDataSize": 0
                },
                "Curves": [],
                "UserData": [
                    {
                        "Time": 0.0,
                        "Value": ""
                    }
                ]
            };
            // motion3Json.Meta.TotalSegmentCount = obj.ParameterIds * 10
            // motion3Json.Meta.TotalSegmentCount = obj.ParameterIds * 15
            let TotalSegmentCount = 0
            let maxTime = 0.0
            for (let i = 0; i < obj.ParameterCurves.length; i++) {
                let Segments = []
                for (let j = 0; j < obj.ParameterCurves[i].m_Curve.length; j++) {
                    TotalSegmentCount++;
                    Segments.push(obj.ParameterCurves[i].m_Curve[j].time ?? 0)
                    Segments.push(obj.ParameterCurves[i].m_Curve[j].value ?? 0)
                    Segments.push(obj.ParameterCurves[i].m_Curve[j].weightedMode ?? 0)
                    maxTime = maxTime > obj.ParameterCurves[i].m_Curve[j].time ? maxTime : obj.ParameterCurves[i].m_Curve[j].time
                }
                Segments.pop()
                motion3Json.Curves.push({
                    "Target": "Parameter",
                    "Id": obj.ParameterIds[i],
                    "Segments": Segments
                })
            }
            motion3Json.Meta.CurveCount = obj.ParameterIds.length
            motion3Json.Meta.Duration = maxTime
            motion3Json.Meta.TotalSegmentCount = TotalSegmentCount
            motion3Json.Meta.TotalPointCount = obj.ParameterIds.length + TotalSegmentCount
            fs.writeFileSync(path.join(dirPath, `${fileName}.motion3.json`), JSON.stringify(motion3Json, '\t'));
            console.log(path.join(dirPath, `${fileName}.motion3.json`) + "已生成");
        } else if (file.endsWith('CubismPhysicsController.json')) {
            const data = fs.readFileSync(filePath, 'utf8');
            const obj = JSON.parse(data);
            let physicsJson = {
                "Version": 3,
                "Meta": {
                    "PhysicsSettingCount": 0,
                    "TotalInputCount": 0,
                    "TotalOutputCount": 0,
                    "VertexCount": 0,
                    "Fps": 0,
                    "EffectiveForces": {
                    },
                    "PhysicsDictionary": [
                    ]
                },
                "PhysicsSettings": []
            }
            physicsJson.Meta.EffectiveForces.Gravity = obj?._rig?.Gravity
            physicsJson.Meta.EffectiveForces.Wind = obj?._rig?.Wind
            physicsJson.Meta.Fps = obj._rig.Fps ?? 60
            for (let i = 0; i < obj._rig?.SubRigs?.length ?? 0; i++) {
                let physicsSetting = {
                    "Id": "PhysicsSetting",
                    "Input": [
                    ],
                    "Output": [
                    ],
                    "Vertices": [
                    ],
                    "Normalization": {
                    }
                }
                let rig = obj._rig.SubRigs[i]
                physicsSetting.Id = physicsSetting.Id + (i + 1)
                physicsJson.Meta.PhysicsDictionary.push({
                    "Id": physicsSetting.Id,
                    "Name": i + 1 + ""
                })
                for (let j = 0; j < rig?.Input.length ?? 0; j++) {
                    physicsSetting.Input.push({
                        "Source": {
                            "Target": "Parameter",
                            "Id": rig.Input[j].SourceId
                        },
                        "Weight": rig.Input[j].Weight,
                        "Type": rig.Input[j].AngleScale || rig.Input[j].AngleScale === 0 ? "Angle" : "X",
                        "Reflect": false
                    })
                }
                for (let j = 0; j < rig?.Output.length ?? 0; j++) {
                    physicsSetting.Output.push({
                        "Destination": {
                            "Target": "Parameter",
                            "Id": rig.Output[j].DestinationId
                        },
                        "VertexIndex": 1,
                        "Scale": rig.Output[j].AngleScale ?? 1,
                        "Weight": rig.Output[j].Weight,
                        "Type": rig.Output[j].AngleScale || rig.Output[j].AngleScale === 0 ? "Angle" : "X",
                        "Reflect": false
                    })
                }
                for(let j = 0; j < rig?.Particles?.length; j++) {
                    physicsSetting.Vertices.push(                        {
                        "Position": rig?.Particles[j].InitialPosition,
                        "Mobility": rig?.Particles[j].Mobility,
                        "Delay": rig?.Particles[j].Delay,
                        "Acceleration": rig?.Particles[j].Acceleration,
                        "Radius": rig?.Particles[j].Radius
                    })
                }
                physicsSetting.Normalization = rig.Normalization
                physicsJson.PhysicsSettings.push(physicsSetting)
            }
            fs.writeFileSync(path.join(dirPath, `l2d.physics3.json`), JSON.stringify(physicsJson, '\t'));
            console.log(path.join(dirPath, `l2d.physics3.json`) + "已生成");
        }
    }
}



processFadeFiles('./');

use cmd → node fadetojson.js

import os
import json

def process_fade_files(dir_path):
for root, dirs, files in os.walk(dir_path):
for file in files:
if file.endswith(‘.fade.json’):
file_path = os.path.join(root, file)

            # 读取原始文件
            with open(file_path, 'r', encoding='utf-8') as f:
                try:
                    fade_data = json.load(f)
                except Exception as e:
                    print(f"解析错误 {file_path}: {str(e)}")
                    continue

            # 准备 motion3 数据结构
            motion3 = {
                "Version": 3,
                "Meta": {
                    "Duration": 0.0,
                    "Fps": 60.0,
                    "Loop": True,
                    "AreBeziersRestricted": True,
                    "CurveCount": 0,
                    "TotalSegmentCount": 0,
                    "TotalPointCount": 0,
                    "UserDataCount": 1,
                    "TotalUserDataSize": 0
                },
                "Curves": [],
                "UserData": [{"Time": 0.0, "Value": ""}]
            }

            total_segments = 0
            max_time = 0.0

            # 处理动画曲线
            for idx, curve in enumerate(fade_data.get('ParameterCurves', [])):
                segments = []
                curve_points = curve.get('m_Curve', [])
                
                for point in curve_points:
                    time = point.get('time', 0.0)
                    value = point.get('value', 0.0)
                    mode = point.get('weightedMode', 0)
                    
                    segments.extend([time, value, mode])
                    max_time = max(max_time, time)
                    total_segments += 1
                
                if segments:
                    segments.pop()

                motion3['Curves'].append({
                    "Target": "Parameter",
                    "Id": fade_data['ParameterIds'][idx],
                    "Segments": segments
                })

            # 更新元数据
            motion3['Meta'].update({
                "CurveCount": len(motion3['Curves']),
                "Duration": max_time,
                "TotalSegmentCount": total_segments,
                "TotalPointCount": len(fade_data.get('ParameterIds', [])) + total_segments
            })

            # 生成输出文件名
            base_name = os.path.splitext(file)[0].replace('.fade', '')
            output_path = os.path.join(root, f"{base_name}.motion3.json")

            # 写入新文件
            with open(output_path, 'w', encoding='utf-8') as f:
                json.dump(motion3, f, indent='\t', ensure_ascii=False)

            print(f"已生成: {output_path}")

if name == ‘main’:
# 自动处理脚本所在目录
script_dir = os.path.dirname(os.path.abspath(file))
process_fade_files(script_dir)
input(“\n处理完成,按回车键退出…”)

试一试

1 个赞

抱歉,我尝试多次,无法有效提取,总是报错,麻烦分享一下still-anm-00007700未提取的文件夹和这个js文件,谢谢



finaly
scripts.zip (2.6 KB)

1 个赞

:+1:t2:

util, 编译了一手可以了。通过网盘分享的文件:net8.0-windows-缝合怪-httpsgithub.comYSFCStudioPluginVerreleasestagv1.38.03-PluginVer.zip
https://pan.baidu.com/s/1tLY39qhNXv3SLycDsf_jZw 提取码: 0721
和上面那个一样的。

I saw in another post that they update the plugin to unpack live2d, I tested it on the files you sent me and it worked generating moc3, motion and poseI saw in another post that they update the plugin to unpack live2d, I tested it on the files you sent me and it worked generating moc3, motion and pose automtic.

post origin 提取游戏中的live2d遇到问题,求助大佬们 - #39,来自 luojun1

1 个赞