从3D模型的数据集中,我需要自动识别哪些模型有烘焙纹理,哪些没有。我正在使用Blender-Python来操作模型,但我对建议持开放态度。
(模型太多,不能一一打开)
发布于 2020-02-15 16:33:23
首先,我们需要一种方法来识别对象是否使用烘焙纹理。假设所有烘焙纹理都使用名称中带有" 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会在新的混合文件打开时清除脚本,我们需要一个脚本来告诉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)https://stackoverflow.com/questions/60097850
复制相似问题