fix:3的模型动态修改模型文件
This commit is contained in:
@@ -114,10 +114,19 @@ class BinaryManager {
|
||||
// 迁移所有3D模型文件
|
||||
for (final modelFile in model3dFiles) {
|
||||
try {
|
||||
// if (modelFile == 'model.gltf') {
|
||||
// // 对于GLTF文件,我们需要修改内容
|
||||
// await _extractAndModifyGltfAsset(
|
||||
// 'assets/cup/$modelFile',
|
||||
// p.join(models3dDir.path, modelFile),
|
||||
// );
|
||||
// } else {
|
||||
// 对于其他文件,直接复制
|
||||
await _extractAsset(
|
||||
'assets/cup/$modelFile',
|
||||
p.join(models3dDir.path, modelFile),
|
||||
);
|
||||
// }
|
||||
} catch (e) {
|
||||
print('迁移3D模型文件失败 $modelFile: $e');
|
||||
// 继续迁移其他模型文件
|
||||
@@ -127,6 +136,30 @@ class BinaryManager {
|
||||
print('3D模型文件迁移完成');
|
||||
}
|
||||
|
||||
static Future<void> _extractAndModifyGltfAsset(
|
||||
String assetPath, String targetPath) async {
|
||||
try {
|
||||
// 读取资源文件内容
|
||||
final byteData = await rootBundle.load(assetPath);
|
||||
final buffer = byteData.buffer;
|
||||
final gltfContent = utf8.decode(
|
||||
buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
||||
|
||||
// 修改纹理路径(去掉"./"前缀)
|
||||
final modifiedGltfContent =
|
||||
gltfContent.replaceAll('"./texture.jpg"', '"texture.jpg"');
|
||||
|
||||
// 写入修改后的内容到目标文件
|
||||
final file = File(targetPath);
|
||||
await file.writeAsBytes(utf8.encode(modifiedGltfContent));
|
||||
|
||||
print('已修改并迁移: $assetPath -> $targetPath');
|
||||
} catch (e) {
|
||||
print('提取并修改GLTF资源失败: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> _migrateShellScript() async {
|
||||
print('开始迁移脚本文件...');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user