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

问题描述 投票:0回答:1

[从3D模型的数据集中,我需要自动确定哪些模型具有烘焙纹理,哪些没有。我正在使用Blender-Python来操纵模型,但是我愿意接受建议。

(模型太多,无法一一打开)

python textures blender 3d-modelling bpy
1个回答
0
投票

首先,我们需要一种方法来识别对象是否正在使用烘焙纹理。假设所有烘焙纹理均使用名称为“ 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)
© www.soinside.com 2019 - 2024. All rights reserved.