I'm quite new to blender and I'm trying to render some meshes in .ply format shown below.

format ascii 1.0
element vertex 470282
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 940612
property list uchar int vertex_index
x y z R G B
3 v1 v2 v3

This is what I tried so far and I can get the rendered image like 1st image but without any colors. What should I add in the python script so the rendered image has colors like the 2nd image(I was able to get this by changing to vertex paint in blender GUI but couldn't get the same image during rendering)? Would it be easier if I save the mesh in .obj format?

import bpy, sys, os
from math import pi

for this_obj in bpy.data.objects:
    if this_obj.type=="MESH":
        bpy.ops.object.delete(use_global=False, confirm=False)

file_loc = 'path/to/mesh.ply'
imported_object = bpy.ops.import_mesh.ply(filepath=file_loc)

for this_obj in bpy.data.objects:
    if this_obj.type=="MESH":
        bpy.context.view_layer.objects.active = this_obj

# bpy.ops.object.mode_set(mode='VERTEX_PAINT')

# render
# rotate obj
bpy.context.object.rotation_euler[0] = pi / 2
bpy.context.object.rotation_euler[2] = -3 * pi / 4

# view - 1
cam = bpy.data.objects['Camera']
cam.location.x = -0.05
cam.location.y = -1.2
cam.location.z = 0.52
cam.rotation_euler[0] = 1.13446
cam.rotation_euler[1] = 0
cam.rotation_euler[2] = 0

bpy.context.scene.render.image_settings.color_mode = 'RGBA'
bpy.context.scene.render.filepath = 'path/to/render.png'

enter image description here

enter image description here

  • $\begingroup$ Hello ! If you need to plug an attribute node set to the name of your vertex color attribute into the output of your material $\endgroup$
    – Gorgious
    Commented Jan 12, 2023 at 7:02
  • $\begingroup$ thanks, could you elaborate a bit more? $\endgroup$
    – Qimin Chen
    Commented Jan 12, 2023 at 18:24
  • $\begingroup$ i.sstatic.net/P2M51.png $\endgroup$
    – Gorgious
    Commented Jan 13, 2023 at 12:47
  • $\begingroup$ Thank you so much, i figured it out $\endgroup$
    – Qimin Chen
    Commented Jan 13, 2023 at 19:04


You must log in to answer this question.

Browse other questions tagged .