2

I'm using the assimp3.0 on windows with OpenGL. I tried to load and display a ply model by following lines:

Assimp::Importer importer;
const aiScene* scene = NULL;
scene = importer.ReadFile('filename', 0);

I built the vertex buffer with scene->mMeshes[0]->mVertices and color buffer with scene->mMeshes[0]->mColors However, when I debug the code, only scene->mMeshes[0]->mColors[0] got the colors, scene->mMeshes[0]->mColors[1] and the following elements remains to be NULL following is a short ply example I I wrote:

ply
format ascii 1.0
comment VCGLIB generated
element vertex 3
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
property uchar alpha
element face 1
property list uchar int vertex_indices
end_header
0.0 0.0 0.0 219 227 248 255
1.0 0.0 0.0 220 230 212 255
2.0 0.0 2.0 160 122 221 255
3 0 1 2

I'm currently wondering if it was caused by the wrong pFlags parameter of importer.ReadFile(pFile,pFlags).

Can anyone help me figure out which part went wrong.

Teng Long
  • 435
  • 6
  • 14
  • In the ReadFile method try sending pFlags as aiProcessPreset_TargetRealtime_Quality. However, it should not matter in this case. – codetiger Aug 19 '16 at 08:57
  • I tried it, but it still won't load the color information for vertices except the first one. – Teng Long Aug 19 '16 at 09:29

1 Answers1

2

I think I understood the problem.

You are reading colours like this

for (int i = 0; i < vertexCount; i++)
    vertexColor = scene->mMeshes[0]->mColors[i];

However, AssImp can store more than one vertex colour channel, so you are suppose to read it like this.

for (int i = 0; i < vertexCount; i++)
    vertexColor = scene->mMeshes[0]->mColors[0][i];

This will read the colours in the 0th vertex colour channel

codetiger
  • 2,650
  • 20
  • 37
  • I know that the mColors is an array of vector3d. The problem is that only mColors[0] got the correct value say..[0.9,0.8,0.9], but mColors[1] got NULL and it's the same for the following spaces.. – Teng Long Aug 20 '16 at 15:34
  • Read the values like this. mColors[0][0], mColors[0][1], mColors[0][2], mColors[0][3], mColors[0][4], ... , mColors[0][n] where n is number of vertices. There is one vertex colour channel in the ply so all colour values are aside the 2 dimensional array – codetiger Aug 22 '16 at 03:46