2023-07-18 14:18:53 +08:00
|
|
|
|
使用方法,使用Blender打开NinjaRipper截取的文件并保存成blend文件后,执行该脚本。注意:运行完之后,需要手动导出fbx。
|
|
|
|
|
```python
|
|
|
|
|
import bpy
|
|
|
|
|
|
|
|
|
|
def convert_image_tga(sourceImagePath):
|
|
|
|
|
image = bpy.data.images.load(sourceImagePath)
|
|
|
|
|
image.file_format = "TARGA"
|
|
|
|
|
image.save_render(sourceImagePath.replace(".dds",".tga"))
|
|
|
|
|
|
|
|
|
|
# Unpack
|
|
|
|
|
blendPath=bpy.data.filepath
|
|
|
|
|
fbxPath=blendPath.replace(".blend",".fbx")
|
|
|
|
|
print(fbxPath)
|
|
|
|
|
|
|
|
|
|
bpy.ops.file.unpack_all()
|
|
|
|
|
bpy.ops.wm.save_as_mainfile()
|
|
|
|
|
|
|
|
|
|
for i in bpy.data.images:
|
|
|
|
|
if i.filepath == '':
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
currentFilePath=bpy.path.abspath(i.filepath)
|
|
|
|
|
print(currentFilePath)
|
|
|
|
|
convert_image_tga(currentFilePath)
|
|
|
|
|
i.filepath = i.filepath.replace('.dds', '.tga')
|
|
|
|
|
|
|
|
|
|
# Save Blender Project
|
|
|
|
|
bpy.ops.wm.save_as_mainfile()
|
|
|
|
|
# Export FBX
|
|
|
|
|
# bpy.ops.export_scene.fbx(fbxPath)
|
2023-11-02 16:49:34 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 贴图格式转换
|
|
|
|
|
```python
|
|
|
|
|
|
|
|
|
|
#dds 转 jpg ------
|
|
|
|
|
import bpy
|
|
|
|
|
|
|
|
|
|
for i in bpy.data.images:
|
|
|
|
|
i.filepath = i.filepath.replace('.dds', '.jpg')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#dds 转 png ------
|
|
|
|
|
import bpy
|
|
|
|
|
|
|
|
|
|
for i in bpy.data.images:
|
|
|
|
|
i.filepath = i.filepath.replace('.dds', '.png')
|
|
|
|
|
|
|
|
|
|
#dds 自动转 tga 并关联 fbx
|
|
|
|
|
import bpy
|
|
|
|
|
|
|
|
|
|
def convert_image_tga(sourceImagePath):
|
|
|
|
|
image = bpy.data.images.load(sourceImagePath)
|
|
|
|
|
image.file_format = "TARGA"
|
|
|
|
|
image.save_render(sourceImagePath.replace(".dds",".tga"))
|
|
|
|
|
|
|
|
|
|
# Pack
|
|
|
|
|
bpy.ops.file.pack_all()
|
|
|
|
|
# Unpack
|
|
|
|
|
blendPath=bpy.data.filepath
|
|
|
|
|
fbxPath=blendPath.replace(".blend",".fbx")
|
|
|
|
|
print(fbxPath)
|
|
|
|
|
bpy.ops.file.unpack_all()
|
|
|
|
|
bpy.ops.wm.save_as_mainfile()
|
|
|
|
|
|
|
|
|
|
for i in bpy.data.images:
|
|
|
|
|
if i.filepath == '':
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
currentFilePath=bpy.path.abspath(i.filepath)
|
|
|
|
|
print(currentFilePath)
|
|
|
|
|
convert_image_tga(currentFilePath)
|
|
|
|
|
i.filepath = i.filepath.replace('.dds', '.tga')
|
|
|
|
|
|
|
|
|
|
# Save Blender Project
|
|
|
|
|
bpy.ops.wm.save_as_mainfile()
|
|
|
|
|
# Export FBX
|
|
|
|
|
|
|
|
|
|
# bpy.ops.export_scene.fbx(fbxPath)
|
|
|
|
|
|
2023-07-18 14:18:53 +08:00
|
|
|
|
```
|