# Why have I got an extra vertex when exporting to ply format?

The following is a very simple object in Blender (that I have cut out from a much larger object in order to highlight where the issue lies). It has nine vertices and four quad faces. There is vertex colour applied, although it is not obvious here as there's not much variation over this scale.

When I export this object to .ply format and examine the file, I see this:

ply
format ascii 1.0
comment Created by Blender 2.91.0 - www.blender.org
element vertex 10
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
property uchar alpha
element face 4
property list uchar uint vertex_indices
-6.090830 9.806936 23.743603 144 133 135 255
-6.092340 9.750036 23.692902 147 130 134 255
-6.125180 9.707676 23.744701 145 134 135 255
-6.123610 9.763186 23.793701 124 113 116 255
-6.137280 9.662676 23.802002 149 136 136 255
-6.136250 9.718307 23.849602 162 143 138 255
-6.130440 9.814006 23.842001 152 137 142 255
-6.085920 9.851616 23.802301 178 163 168 255
-6.144290 9.771136 23.897602 160 138 134 255
-6.123610 9.763186 23.793701 124 113 116 0
4 0 1 2 3
4 3 2 4 5
4 0 3 6 7
4 8 6 9 5


I now suddenly have ten vertices!

• Note that vertices 3 and 9 (or rows 4 and 10 of the vertex list if you prefer) have identical values except that one has an alpha value of 255 and the other 0.

• From the location, I can tell that these two duplicates correspond to the central of the nine vertices.

• On a larger scale, this has happened to 19 of about 100,000 vertices in the full original object, so it's a rare but not unique occurrence.

• As far as I was aware, I never did anything that might edit the alpha channel.

• Vertex colours originally came from a texture bake using the "Bake to vertex color" add-on. After a bit of experimenting, I have narrowed down the problem to this add-on, or at least to the vertex colours in some way. If I export prior to creating the vertex colours, I get the correct number of vertices.

What gives, and how can I fix it? I am working on the .ply file via some external scripts, and it is a nightmare having doubled-up vertices in the list.

• I mean, you seem to know why already. If every vert in a ply has a unique color, then obviously a vert with two different colors in Blender will be split into multiple verts when exported to ply. This is similar to this. Do you want a way to set all vert color alphas to 1? – scurest Feb 25 at 15:22
• @scurest The linked question is very helpful for understanding what is going on, thank you! I didn't know that individual vertices could have multiple properties in that way. So yes, presumably if I am able to set all alpha values to be the same, that would fix the issue. Is there a simple way to do that? It doesn't quite explain where the variation in alpha values has come from, beyond that it must be a minor bug in the add-on I'm using. – user2390246 Feb 25 at 16:34

This script will set all vertex color alphas to 1 on the active object (I couldn't find a way to do it through the UI). Select your object, make sure you're in Object Mode, paste it in the text editor and hit run.

import bpy
assert bpy.context.mode == 'OBJECT'
for vc in bpy.context.active_object.data.vertex_colors:
for c in vc.data:
c.color[3] = 1


However a vert might still get split up if there are different vertex colors at the different corners that meet it, like this:

This will export with 16 verts. There's not really anything you can do about that, I think that's just how .ply works.

• Fantastic, thanks! Incidentally, I got an error after the line assert bpy.context.mode == 'OBJECT' which said Traceback (most recent call last): File "<blender_console>", line 1, in <module> AssertionError. However it still worked despite this error. – user2390246 Feb 26 at 9:32