Blender Python如何将具有材质的网格转换为顶点颜色?

时间:2018-03-27 17:05:19

标签: python colors blender material vertex

我导入了带有网格的对象,每个网格都有超过50种不同的材质,它们只显示一种独特的颜色,所以我想摆脱这些材质并使用顶点颜色。

这意味着,具有指定特定材质的面的每个顶点将着色为材质主色。

但我有问题要转换它。我无法得到材料使用的面孔。这就是我到目前为止所做的:

import bpy
import bmesh

for obj in bpy.context.scene.objects:       #support multiple selection
    if obj.type == 'MESH':                  #color only if mesh exists

        mesh = bpy.context.object.data                  
        bm = bmesh.new()
        bm.from_mesh(mesh) 

        materials = bpy.data.materials      #get current meshs materials

        for index in range(len(materials)):         #get corresponding faces of material 

            for face in bm.faces:      
                if face.material_index == index: #select face that matches current material
                    face.select = True

                    for L in face.loops:
                        L[bm.loops.layers.color.active] = materials[index].diffuse_color

       # bpy.data.materials = [] #remove all materials from material tab

        bm.to_mesh(mesh) #Assign new mesh from bmesh
        bm.free()

提前致谢。

0 个答案:

没有答案