I have some problem with my blender code export to fbx file. I set color by vertex_color and set mode is Vertex_paint. But when I export this object to fbx file and open in Unity it is not include color. I think the reason might be dont set color for material of object. So could you help me to convert ? This is my code. Thank you so much for your help
import math
# mesh arrays
verts = []
faces = []
# mesh variables
numX = 10
numY = 10
# wave variables
freq = 1
amp = 1
scale = 1
#fill verts array
for i in range (0, numX):
for j in range(0,numY):
x = scale * i
y = scale * j
z = scale*((amp*math.cos(i*freq))+(amp*math.sin(j*freq)))
vert = (x,y,z)
verts.append(vert)
#fill faces array
count = 0
for i in range (0, numY *(numX-1)):
if count < numY-1:
A = i
B = i+1
C = (i+numY)+1
D = (i+numY)
face = (A,B,C,D)
faces.append(face)
count = count + 1
else:
count = 0
#create mesh and object
mesh = bpy.data.meshes.new("wave")
object = bpy.data.objects.new("wave",mesh)
#set mesh location
object.location = bpy.context.scene.cursor.location
bpy.context.collection.objects.link(object)
#create mesh from python data
mesh.from_pydata(verts,[],faces)
mesh.update(calc_edges=True)
vert_list = mesh.vertices
color_map_collection = mesh.vertex_colors
if len(color_map_collection) == 0:
color_map_collection.new()
else:
color_map_collection.active
color_map = color_map_collection['Col']
i = 0
for poly in mesh.polygons:
for idx in poly.loop_indices:
loop = mesh.loops[idx]
v = loop.vertex_index
final = (0.1,0.5,0.2,1)
color_map.data[i].color = final
i += 1
bpy.context.view_layer.objects.active = object
bpy.ops.object.mode_set(mode='VERTEX_PAINT', toggle=False)