繁体   English   中英

在 Blender/Python 中查找烘焙纹理 3D 模型

[英]Find baked textures 3D model in 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM