From e060b4f4aa4f74c1e90d4c5c6efa951f8cce0ca7 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Wed, 21 Feb 2018 20:53:30 +0900 Subject: [PATCH 1/8] Remove unused variable. --- experimental/tinyobj_loader_opt.h | 1 - 1 file changed, 1 deletion(-) diff --git a/experimental/tinyobj_loader_opt.h b/experimental/tinyobj_loader_opt.h index c926245..9d17597 100644 --- a/experimental/tinyobj_loader_opt.h +++ b/experimental/tinyobj_loader_opt.h @@ -1523,7 +1523,6 @@ bool parseObj(attrib_t *attrib, std::vector *shapes, size_t t_count = t_offsets[t]; size_t f_count = f_offsets[t]; size_t face_count = face_offsets[t]; - int material_id = -1; // -1 = default unknown material. for (size_t i = 0; i < commands[t].size(); i++) { if (commands[t][i].type == COMMAND_EMPTY) { From b85714b4cf15f51e928d62e043014056e95e0629 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Fri, 23 Feb 2018 20:25:13 +0900 Subject: [PATCH 2/8] Skip parsing incomplete or invalid face definition(e.g. `f` definition only contains 1 or 2 indices). --- models/invalid-face-definition.mtl | 24 ++++++++++++++++++++++++ models/invalid-face-definition.obj | 18 ++++++++++++++++++ tests/tester.cc | 18 ++++++++++++++++++ tiny_obj_loader.h | 5 +++++ 4 files changed, 65 insertions(+) create mode 100644 models/invalid-face-definition.mtl create mode 100644 models/invalid-face-definition.obj diff --git a/models/invalid-face-definition.mtl b/models/invalid-face-definition.mtl new file mode 100644 index 0000000..d3a1c7a --- /dev/null +++ b/models/invalid-face-definition.mtl @@ -0,0 +1,24 @@ +newmtl white +Ka 0 0 0 +Kd 1 1 1 +Ks 0 0 0 + +newmtl red +Ka 0 0 0 +Kd 1 0 0 +Ks 0 0 0 + +newmtl green +Ka 0 0 0 +Kd 0 1 0 +Ks 0 0 0 + +newmtl blue +Ka 0 0 0 +Kd 0 0 1 +Ks 0 0 0 + +newmtl light +Ka 20 20 20 +Kd 1 1 1 +Ks 0 0 0 diff --git a/models/invalid-face-definition.obj b/models/invalid-face-definition.obj new file mode 100644 index 0000000..73ca678 --- /dev/null +++ b/models/invalid-face-definition.obj @@ -0,0 +1,18 @@ +mtllib invalid-face-definition.mtl + +v 0.000000 2.000000 2.000000 +v 0.000000 0.000000 2.000000 +v 2.000000 0.000000 2.000000 +v 2.000000 2.000000 2.000000 +v 0.000000 2.000000 0.000000 +v 0.000000 0.000000 0.000000 +v 2.000000 0.000000 0.000000 +v 2.000000 2.000000 0.000000 +# 8 vertices + +g front cube +usemtl white +f 1 +g back cube +# expects white material +f 8 7 diff --git a/tests/tester.cc b/tests/tester.cc index d5d83c6..e3bc006 100644 --- a/tests/tester.cc +++ b/tests/tester.cc @@ -751,6 +751,24 @@ TEST_CASE("smoothing-group", "[Issue162]") { } +TEST_CASE("invalid-face-definition", "[face]") { + tinyobj::attrib_t attrib; + std::vector shapes; + std::vector materials; + + std::string err; + bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/invalid-face-definition.obj", gMtlBasePath); + + + if (!err.empty()) { + std::cerr << "[face] " << err << std::endl; + } + + REQUIRE(true == ret); + REQUIRE(1 == shapes.size()); + REQUIRE(0 == shapes[0].mesh.indices.size()); +} + #if 0 int main( diff --git a/tiny_obj_loader.h b/tiny_obj_loader.h index ac1421e..a876842 100644 --- a/tiny_obj_loader.h +++ b/tiny_obj_loader.h @@ -1023,6 +1023,11 @@ static bool exportFaceGroupToShape(shape_t *shape, for (size_t i = 0; i < faceGroup.size(); i++) { const face_t &face = faceGroup[i]; + if (face.vertex_indices.size() < 3) { + // Face must have 3+ vertices. + continue; + } + vertex_index_t i0 = face.vertex_indices[0]; vertex_index_t i1(-1); vertex_index_t i2 = face.vertex_indices[1]; From 12837cc8b2456445f64f912100d1c6558301031b Mon Sep 17 00:00:00 2001 From: LZaw <28070263+LZaw@users.noreply.github.com> Date: Thu, 8 Mar 2018 15:47:06 +0100 Subject: [PATCH 3/8] Adapt v 1.0.x Added an attributes parameter --- examples/obj_sticher/obj_writer.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/obj_sticher/obj_writer.h b/examples/obj_sticher/obj_writer.h index bb367b6..aa3b269 100644 --- a/examples/obj_sticher/obj_writer.h +++ b/examples/obj_sticher/obj_writer.h @@ -1,9 +1,8 @@ #ifndef __OBJ_WRITER_H__ #define __OBJ_WRITER_H__ -#include "../../tiny_obj_loader.h" - -extern bool WriteObj(const std::string& filename, const std::vector& shapes, const std::vector& materials, bool coordTransform = false); +#include "tiny_obj_loader.h" +extern bool WriteObj(const std::string& filename, const tinyobj::attrib_t& attributes, const std::vector& shapes, const std::vector& materials, bool coordTransform = false); #endif // __OBJ_WRITER_H__ From 707014f843f44279845fa36794a82de68f37c96d Mon Sep 17 00:00:00 2001 From: LZaw <28070263+LZaw@users.noreply.github.com> Date: Thu, 8 Mar 2018 15:48:45 +0100 Subject: [PATCH 4/8] Update obj_writer.cc --- examples/obj_sticher/obj_writer.cc | 174 ++++++++++++++--------------- 1 file changed, 82 insertions(+), 92 deletions(-) diff --git a/examples/obj_sticher/obj_writer.cc b/examples/obj_sticher/obj_writer.cc index 694ce45..9ea8d7c 100644 --- a/examples/obj_sticher/obj_writer.cc +++ b/examples/obj_sticher/obj_writer.cc @@ -30,6 +30,8 @@ bool WriteMat(const std::string& filename, const std::vector& shapes, const std::vector& materials, bool coordTransform) { +bool WriteObj(const std::string& filename, const tinyobj::attrib_t& attributes, const std::vector& shapes, const std::vector& materials, bool coordTransform) { FILE* fp = fopen(filename.c_str(), "w"); if (!fp) { fprintf(stderr, "Failed to open file [ %s ] for write.\n", filename.c_str()); @@ -48,17 +50,53 @@ bool WriteObj(const std::string& filename, const std::vector& std::string basename = GetFileBasename(filename); std::string material_filename = basename + ".mtl"; - int v_offset = 0; - int vn_offset = 0; - int vt_offset = 0; int prev_material_id = -1; - fprintf(fp, "mtllib %s\n", material_filename.c_str()); + fprintf(fp, "mtllib %s\n\n", material_filename.c_str()); + + // facevarying vtx + for (size_t k = 0; k < attributes.vertices.size(); k+=3) { + if (coordTransform) { + fprintf(fp, "v %f %f %f\n", + attributes.vertices[k + 0], + attributes.vertices[k + 2], + -attributes.vertices[k + 1]); + } else { + fprintf(fp, "v %f %f %f\n", + attributes.vertices[k + 0], + attributes.vertices[k + 1], + attributes.vertices[k + 2]); + } + } + + fprintf(fp, "\n"); + + // facevarying normal + for (size_t k = 0; k < attributes.normals.size(); k += 3) { + if (coordTransform) { + fprintf(fp, "vn %f %f %f\n", + attributes.normals[k + 0], + attributes.normals[k + 2], + -attributes.normals[k + 1]); + } else { + fprintf(fp, "vn %f %f %f\n", + attributes.normals[k + 0], + attributes.normals[k + 1], + attributes.normals[k + 2]); + } + } + + fprintf(fp, "\n"); + + // facevarying texcoord + for (size_t k = 0; k < attributes.texcoords.size(); k += 2) { + fprintf(fp, "vt %f %f\n", + attributes.texcoords[k + 0], + attributes.texcoords[k + 1]); + } for (size_t i = 0; i < shapes.size(); i++) { - - bool has_vn = false; - bool has_vt = false; + fprintf(fp, "\n"); if (shapes[i].name.empty()) { fprintf(fp, "g Unknown\n"); @@ -66,101 +104,53 @@ bool WriteObj(const std::string& filename, const std::vector& fprintf(fp, "g %s\n", shapes[i].name.c_str()); } - //if (!shapes[i].material.name.empty()) { - // fprintf(fp, "usemtl %s\n", shapes[i].material.name.c_str()); - //} - - // facevarying vtx - for (size_t k = 0; k < shapes[i].mesh.indices.size() / 3; k++) { - for (int j = 0; j < 3; j++) { - int idx = shapes[i].mesh.indices[3*k+j]; - if (coordTransform) { - fprintf(fp, "v %f %f %f\n", - shapes[i].mesh.positions[3*idx+0], - shapes[i].mesh.positions[3*idx+2], - -shapes[i].mesh.positions[3*idx+1]); - } else { - fprintf(fp, "v %f %f %f\n", - shapes[i].mesh.positions[3*idx+0], - shapes[i].mesh.positions[3*idx+1], - shapes[i].mesh.positions[3*idx+2]); - } - } + bool has_vn = false; + bool has_vt = false; + // Assumes normals and textures are set shape-wise. + if(shapes[i].mesh.indices.size() > 0){ + has_vn = shapes[i].mesh.indices[0].normal_index != -1; + has_vt = shapes[i].mesh.indices[0].texcoord_index != -1; } - // facevarying normal - if (shapes[i].mesh.normals.size() > 0) { - for (size_t k = 0; k < shapes[i].mesh.indices.size() / 3; k++) { - for (int j = 0; j < 3; j++) { - int idx = shapes[i].mesh.indices[3*k+j]; - if (coordTransform) { - fprintf(fp, "vn %f %f %f\n", - shapes[i].mesh.normals[3*idx+0], - shapes[i].mesh.normals[3*idx+2], - -shapes[i].mesh.normals[3*idx+1]); - } else { - fprintf(fp, "vn %f %f %f\n", - shapes[i].mesh.normals[3*idx+0], - shapes[i].mesh.normals[3*idx+1], - shapes[i].mesh.normals[3*idx+2]); - } - } - } - } - if (shapes[i].mesh.normals.size() > 0) has_vn = true; - - // facevarying texcoord - if (shapes[i].mesh.texcoords.size() > 0) { - for (size_t k = 0; k < shapes[i].mesh.indices.size() / 3; k++) { - for (int j = 0; j < 3; j++) { - int idx = shapes[i].mesh.indices[3*k+j]; - fprintf(fp, "vt %f %f\n", - shapes[i].mesh.texcoords[2*idx+0], - shapes[i].mesh.texcoords[2*idx+1]); - } - } - } - if (shapes[i].mesh.texcoords.size() > 0) has_vt = true; - // face - for (size_t k = 0; k < shapes[i].mesh.indices.size() / 3; k++) { - - // Face index is 1-base. - //int v0 = shapes[i].mesh.indices[3*k+0] + 1 + v_offset; - //int v1 = shapes[i].mesh.indices[3*k+1] + 1 + v_offset; - //int v2 = shapes[i].mesh.indices[3*k+2] + 1 + v_offset; - int v0 = (3*k + 0) + 1 + v_offset; - int v1 = (3*k + 1) + 1 + v_offset; - int v2 = (3*k + 2) + 1 + v_offset; - - int vt0 = (3*k + 0) + 1 + vt_offset; - int vt1 = (3*k + 1) + 1 + vt_offset; - int vt2 = (3*k + 2) + 1 + vt_offset; - - int material_id = shapes[i].mesh.material_ids[k]; + int face_index = 0; + for (size_t k = 0; k < shapes[i].mesh.indices.size(); k += shapes[i].mesh.num_face_vertices[face_index++]) { + // Check Materials + int material_id = shapes[i].mesh.material_ids[face_index]; if (material_id != prev_material_id) { std::string material_name = materials[material_id].name; fprintf(fp, "usemtl %s\n", material_name.c_str()); prev_material_id = material_id; } - if (has_vn && has_vt) { - fprintf(fp, "f %d/%d/%d %d/%d/%d %d/%d/%d\n", - v0, vt0, v0, v1, vt1, v1, v2, vt2, v2); - } else if (has_vn && !has_vt) { - fprintf(fp, "f %d//%d %d//%d %d//%d\n", v0, v0, v1, v1, v2, v2); - } else if (!has_vn && has_vt) { - fprintf(fp, "f %d/%d %d/%d %d/%d\n", v0, v0, v1, v1, v2, v2); - } else { - fprintf(fp, "f %d %d %d\n", v0, v1, v2); + unsigned char v_per_f = shapes[i].mesh.num_face_vertices[face_index]; + // Imperformant, but if you want to have variable vertices per face, you need some kind of a dynamic loop. + fprintf(fp, "f"); + for(int l = 0; l < v_per_f; l++){ + const tinyobj::index_t& ref = shapes[i].mesh.indices[k + l]; + if(has_vn && has_vt){ + // v0/t0/vn0 + fprintf(fp, " %d/%d/%d", ref.vertex_index + 1, ref.texcoord_index + 1, ref.normal_index + 1); + continue; + } + if(has_vn && !has_vt){ + // v0//vn0 + fprintf(fp, " %d//%d", ref.vertex_index + 1, ref.normal_index + 1); + continue; + } + if(!has_vn && has_vt){ + // v0/vt0 + fprintf(fp, " %d/%d", ref.vertex_index + 1, ref.texcoord_index + 1); + continue; + } + if(!has_vn && !has_vt){ + // v0 v1 v2 + fprintf(fp, " %d", ref.vertex_index + 1); + continue; + } } - + fprintf(fp, "\n"); } - - v_offset += shapes[i].mesh.indices.size(); - //vn_offset += shapes[i].mesh.normals.size() / 3; - vt_offset += shapes[i].mesh.texcoords.size() / 2; - } fclose(fp); From d174e625a22a80bd9cdb60c77461d93b6de32437 Mon Sep 17 00:00:00 2001 From: LZaw <28070263+LZaw@users.noreply.github.com> Date: Thu, 8 Mar 2018 15:58:39 +0100 Subject: [PATCH 5/8] Update obj_writer.h --- examples/obj_sticher/obj_writer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/obj_sticher/obj_writer.h b/examples/obj_sticher/obj_writer.h index aa3b269..262c681 100644 --- a/examples/obj_sticher/obj_writer.h +++ b/examples/obj_sticher/obj_writer.h @@ -1,7 +1,7 @@ #ifndef __OBJ_WRITER_H__ #define __OBJ_WRITER_H__ -#include "tiny_obj_loader.h" +#include "../../tiny_obj_loader.h" extern bool WriteObj(const std::string& filename, const tinyobj::attrib_t& attributes, const std::vector& shapes, const std::vector& materials, bool coordTransform = false); From a4eabf54b11f8f693c7849a32ca426c085ff83d1 Mon Sep 17 00:00:00 2001 From: LZaw <28070263+LZaw@users.noreply.github.com> Date: Fri, 9 Mar 2018 13:43:52 +0100 Subject: [PATCH 6/8] Adapt 1.0.x datastructure --- examples/obj_sticher/obj_sticher.cc | 117 ++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 34 deletions(-) diff --git a/examples/obj_sticher/obj_sticher.cc b/examples/obj_sticher/obj_sticher.cc index f59fee4..ae3b093 100644 --- a/examples/obj_sticher/obj_sticher.cc +++ b/examples/obj_sticher/obj_sticher.cc @@ -1,6 +1,8 @@ // -// Stiches multiple .obj files into one .obj. +// Stiches multiple .obj files into one .obj. // + +#define TINYOBJLOADER_IMPLEMENTATION #include "../../tiny_obj_loader.h" #include "obj_writer.h" @@ -11,27 +13,59 @@ typedef std::vector Shape; typedef std::vector Material; +typedef tinyobj::attrib_t Attribute; void StichObjs( + tinyobj::attrib_t& out_attribute, std::vector& out_shape, std::vector& out_material, + const std::vector& attributes, const std::vector& shapes, const std::vector& materials) { - int numShapes = 0; - for (size_t i = 0; i < shapes.size(); i++) { - numShapes += (int)shapes[i].size(); + // The amount of attributes, shape-vectors and material-vecotrs should be the same. + if(attributes.size() != shapes.size() && attributes.size() != materials.size()){ + std::cerr << "Size of attributes, shapes and Materials don't fit!" << attributes.size() << " " << shapes.size() <<" " << materials.size() << std::endl;; + exit(1); + } + int num_shapes = 0; + // 4 values (vertices, normals, texcoords, colors) + std::vector num_attributes(4, 0); + int num_materials = 0; + for(int i = 0; i < shapes.size(); i++){ + num_shapes += shapes[i].size(); + } + for(int i = 0; i < attributes.size(); i++){ + num_attributes[0] += attributes[i].vertices.size(); + num_attributes[1] += attributes[i].normals.size(); + num_attributes[2] += attributes[i].texcoords.size(); + num_attributes[3] += attributes[i].colors.size(); + } + for(int i = 0; i < materials.size(); i++){ + num_materials += materials[i].size(); } - printf("Total # of shapes = %d\n", numShapes); - int materialIdOffset = 0; + // More performant, than push_back + out_attribute.vertices.resize(num_attributes[0]); + out_attribute.normals.resize(num_attributes[1]); + out_attribute.texcoords.resize(num_attributes[2]); + out_attribute.colors.resize(num_attributes[3]); + out_shape.resize(num_shapes); + out_material.resize(num_materials); - size_t face_offset = 0; + int material_id_offset = 0; + int shape_id_offset = 0; + int vertex_idx_offset = 0; + int normal_idx_offset = 0; + int texcoord_idx_offset = 0; + int color_idx_offset = 0; + + // shapes.size() = attributes.size() = materials.size() for (size_t i = 0; i < shapes.size(); i++) { + // Copy shapes for (size_t k = 0; k < shapes[i].size(); k++) { - std::string new_name = shapes[i][k].name; // Add suffix char buf[1024]; @@ -39,36 +73,51 @@ StichObjs( new_name += std::string(buf); printf("shape[%ld][%ld].name = %s\n", i, k, shapes[i][k].name.c_str()); - assert((shapes[i][k].mesh.indices.size() % 3) == 0); - assert((shapes[i][k].mesh.positions.size() % 3) == 0); tinyobj::shape_t new_shape = shapes[i][k]; - // Add offset. - for (size_t f = 0; f < new_shape.mesh.material_ids.size(); f++) { - new_shape.mesh.material_ids[f] += materialIdOffset; + // Add material offset. + for(size_t f = 0; f < new_shape.mesh.material_ids.size(); f++) { + new_shape.mesh.material_ids[f] += material_id_offset; + } + // Add indices offset. + for(size_t f = 0; f < new_shape.mesh.indices.size(); f++){ + tinyobj::index_t& ref = new_shape.mesh.indices[f]; + if(ref.vertex_index > -1){ + ref.vertex_index += vertex_idx_offset; + } + if(ref.normal_index > -1){ + ref.normal_index += normal_idx_offset; + } + if(ref.texcoord_index > -1){ + ref.texcoord_index += texcoord_idx_offset; + } } new_shape.name = new_name; printf("shape[%ld][%ld].new_name = %s\n", i, k, new_shape.name.c_str()); - out_shape.push_back(new_shape); + out_shape[shape_id_offset++] = new_shape; } - materialIdOffset += materials[i].size(); - } - - for (size_t i = 0; i < materials.size(); i++) { + // Copy materials for (size_t k = 0; k < materials[i].size(); k++) { - out_material.push_back(materials[i][k]); + out_material[material_id_offset++] = materials[i][k]; } - } + // Copy attributes (3 floats per vertex, 3 floats per normal, 2 floats per texture-coordinate, 3 floats per color) + // You could also include a check here, if the sizes are dividable by 3 (resp. 2), but it's safe to simply assume, they do. + std::copy(attributes[i].vertices.begin(), attributes[i].vertices.end(), out_attribute.vertices.begin() + vertex_idx_offset * 3); + vertex_idx_offset += attributes[i].vertices.size() / 3; + std::copy(attributes[i].normals.begin(), attributes[i].normals.end(), out_attribute.normals.begin() + normal_idx_offset * 3); + normal_idx_offset += attributes[i].normals.size() / 3; + std::copy(attributes[i].texcoords.begin(), attributes[i].texcoords.end(), out_attribute.texcoords.begin() + texcoord_idx_offset * 2); + texcoord_idx_offset += attributes[i].texcoords.size() / 2; + std::copy(attributes[i].colors.begin(), attributes[i].colors.end(), out_attribute.colors.begin() + color_idx_offset * 3); + color_idx_offset += attributes[i].colors.size(); + } } -int -main( - int argc, - char **argv) +int main(int argc, char **argv) { if (argc < 3) { printf("Usage: obj_sticher input0.obj input1.obj ... output.obj\n"); @@ -78,16 +127,15 @@ main( int num_objfiles = argc - 2; std::string out_filename = std::string(argv[argc-1]); // last element - std::vector shapes; - std::vector materials; - shapes.resize(num_objfiles); - materials.resize(num_objfiles); + std::vector attributes(num_objfiles); + std::vector shapes(num_objfiles); + std::vector materials(num_objfiles); for (int i = 0; i < num_objfiles; i++) { std::cout << "Loading " << argv[i+1] << " ... " << std::flush; std::string err; - bool ret = tinyobj::LoadObj(shapes[i], materials[i], err, argv[i+1]); + bool ret = tinyobj::LoadObj(&attributes[i], &shapes[i], &materials[i], &err, argv[i+1]); if (!err.empty()) { std::cerr << err << std::endl; } @@ -98,12 +146,13 @@ main( std::cout << "DONE." << std::endl; } - std::vector out_shape; - std::vector out_material; - StichObjs(out_shape, out_material, shapes, materials); + Attribute out_attribute; + Shape out_shape; + Material out_material; + StichObjs(out_attribute, out_shape, out_material, attributes, shapes, materials); - bool coordTransform = true; - bool ret = WriteObj(out_filename, out_shape, out_material, coordTransform); + bool coordTransform = false; + bool ret = WriteObj(out_filename, out_attribute, out_shape, out_material, coordTransform); assert(ret); return 0; From 94f1dc15b3b07c011ef7ae2029d1b3646942aaad Mon Sep 17 00:00:00 2001 From: LZaw <28070263+LZaw@users.noreply.github.com> Date: Fri, 9 Mar 2018 13:48:05 +0100 Subject: [PATCH 7/8] Update obj_sticher.cc --- examples/obj_sticher/obj_sticher.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/obj_sticher/obj_sticher.cc b/examples/obj_sticher/obj_sticher.cc index ae3b093..9032722 100644 --- a/examples/obj_sticher/obj_sticher.cc +++ b/examples/obj_sticher/obj_sticher.cc @@ -151,7 +151,7 @@ int main(int argc, char **argv) Material out_material; StichObjs(out_attribute, out_shape, out_material, attributes, shapes, materials); - bool coordTransform = false; + bool coordTransform = true; bool ret = WriteObj(out_filename, out_attribute, out_shape, out_material, coordTransform); assert(ret); From f95510b04b949fa0865f3e86114787073fd0824b Mon Sep 17 00:00:00 2001 From: LZaw <28070263+LZaw@users.noreply.github.com> Date: Fri, 9 Mar 2018 13:57:18 +0100 Subject: [PATCH 8/8] Removed multiplication for color_idx_offset --- examples/obj_sticher/obj_sticher.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/obj_sticher/obj_sticher.cc b/examples/obj_sticher/obj_sticher.cc index 9032722..47c06eb 100644 --- a/examples/obj_sticher/obj_sticher.cc +++ b/examples/obj_sticher/obj_sticher.cc @@ -112,7 +112,7 @@ StichObjs( normal_idx_offset += attributes[i].normals.size() / 3; std::copy(attributes[i].texcoords.begin(), attributes[i].texcoords.end(), out_attribute.texcoords.begin() + texcoord_idx_offset * 2); texcoord_idx_offset += attributes[i].texcoords.size() / 2; - std::copy(attributes[i].colors.begin(), attributes[i].colors.end(), out_attribute.colors.begin() + color_idx_offset * 3); + std::copy(attributes[i].colors.begin(), attributes[i].colors.end(), out_attribute.colors.begin() + color_idx_offset); color_idx_offset += attributes[i].colors.size(); } }