@@ -421,6 +421,8 @@ struct attrib_t {
421421struct callback_t {
422422 // W is optional and set to 1 if there is no `w` item in `v` line
423423 void (*vertex_cb)(void *user_data, real_t x, real_t y, real_t z, real_t w);
424+ void (*vertex_color_cb)(void *user_data, real_t x, real_t y, real_t z,
425+ real_t r, real_t g, real_t b, bool has_color);
424426 void (*normal_cb)(void *user_data, real_t x, real_t y, real_t z);
425427
426428 // y and z are optional and set to 0 if there is no `y` and/or `z` item(s) in
@@ -3153,11 +3155,15 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
31533155 // vertex
31543156 if (token[0 ] == ' v' && IS_SPACE ((token[1 ]))) {
31553157 token += 2 ;
3156- // TODO(syoyo): Support parsing vertex color extension.
3157- real_t x, y, z, w; // w is optional. default = 1.0
3158- parseV (&x, &y, &z, &w, &token);
3158+ real_t x, y, z;
3159+ real_t r, g, b;
3160+
3161+ bool found_color = parseVertexWithColor (&x, &y, &z, &r, &g, &b, &token);
31593162 if (callback.vertex_cb ) {
3160- callback.vertex_cb (user_data, x, y, z, w);
3163+ callback.vertex_cb (user_data, x, y, z, r); // r=w is optional
3164+ }
3165+ if (callback.vertex_color_cb ) {
3166+ callback.vertex_color_cb (user_data, x, y, z, r, g, b, found_color);
31613167 }
31623168 continue ;
31633169 }
0 commit comments