从 3D 模型的数据集中,我需要自动识别哪些模型有烘焙纹理,哪些没有。我正在使用 Blender-Python 来操作模型,但我愿意接受建议。
(型号太多,一一打开)
从 3D 模型的数据集中,我需要自动识别哪些模型有烘焙纹理,哪些没有。我正在使用 Blender-Python 来操作模型,但我愿意接受建议。
(型号太多,一一打开)
首先,我们需要一种方法来识别对象是否使用烘焙纹理。假设所有烘焙纹理都使用名称中带有“baked”的图像,那么让我们寻找图像纹理节点。
下面将查找当前混合文件中使用名称中带有“baked”的图像纹理的所有对象。
import bpy
for obj in bpy.data.objects:
# does object have a material?
if len(obj.material_slots) < 1: continue
for slot in obj.material_slots:
# skip empty slots and mats that don't use nodes
if not slot.material or not slot.material.use_nodes: continue
for n in slot.material.node_tree.nodes:
if n.type == 'TEX_IMAGE' and 'baked' in n.image.name:
print(f'{obj.name} uses baked image {n.image.name}')
由于 Blender 会在打开新的 Blend 文件时清除脚本,所以我们需要一个脚本来告诉 Blender 打开一个文件并运行之前的脚本,然后对每个文件重复。为了保持跨平台,我们也可以使用python。
from glob import glob
from subprocess import call
for blendFile in glob('*.blend'):
arglist = [
'blender',
'--factory-startup',
'-b',
blendFile,
'--python',
'check_baked.py',
]
print(f'Checking {blendFile}...')
call(arglist)