@@ -760,6 +760,34 @@ void encodeIndexSequence(const std::vector<unsigned int>& data, size_t vertex_co
760760 (double (result.size () * 4 ) / 1e9 ) / (end - middle));
761761}
762762
763+ template <typename V, typename T>
764+ void validateDecodeMeshlet (const unsigned char * data, size_t size, const unsigned int * vertices, size_t vertex_count, const unsigned char * triangles, size_t triangle_count)
765+ {
766+ V rv[256 ];
767+ T rt[sizeof (T) == 1 ? 256 * 3 + 3 : 256 ];
768+
769+ int rc = meshopt_decodeMeshlet (rv, vertex_count, rt, triangle_count, data, size);
770+ assert (rc == 0 );
771+
772+ for (size_t j = 0 ; j < vertex_count; ++j)
773+ assert (rv[j] == V (vertices[j]));
774+
775+ for (size_t j = 0 ; j < triangle_count; ++j)
776+ {
777+ unsigned int a = triangles[j * 3 + 0 ];
778+ unsigned int b = triangles[j * 3 + 1 ];
779+ unsigned int c = triangles[j * 3 + 2 ];
780+
781+ unsigned int tri = sizeof (T) == 1 ? rt[j * 3 ] | (rt[j * 3 + 1 ] << 8 ) | (rt[j * 3 + 2 ] << 16 ) : rt[j];
782+
783+ unsigned int abc = (a << 0 ) | (b << 8 ) | (c << 16 );
784+ unsigned int bca = (b << 0 ) | (c << 8 ) | (a << 16 );
785+ unsigned int cba = (c << 0 ) | (a << 8 ) | (b << 16 );
786+
787+ assert (tri == abc || tri == bca || tri == cba);
788+ }
789+ }
790+
763791void encodeMeshlets (const Mesh& mesh, size_t max_vertices, size_t max_triangles, bool reorder = true )
764792{
765793 size_t max_meshlets = meshopt_buildMeshletsBound (mesh.indices .size (), max_vertices, max_triangles);
@@ -810,26 +838,10 @@ void encodeMeshlets(const Mesh& mesh, size_t max_vertices, size_t max_triangles,
810838 packed.push_back ((unsigned char )((mbs >> 8 ) & 0xff ));
811839 packed.insert (packed.end (), &cbuf[0 ], &cbuf[mbs]);
812840
813- unsigned int rv[256 ];
814- unsigned int rt[256 ];
815- int rc = meshopt_decodeMeshlet (rv, meshlet.vertex_count , rt, meshlet.triangle_count , &cbuf[0 ], mbs);
816- assert (rc == 0 );
817-
818- for (size_t j = 0 ; j < meshlet.vertex_count ; ++j)
819- assert (rv[j] == meshlet_vertices[meshlet.vertex_offset + j]);
820-
821- for (size_t j = 0 ; j < meshlet.triangle_count ; ++j)
822- {
823- unsigned int a = meshlet_triangles[meshlet.triangle_offset + j * 3 + 0 ];
824- unsigned int b = meshlet_triangles[meshlet.triangle_offset + j * 3 + 1 ];
825- unsigned int c = meshlet_triangles[meshlet.triangle_offset + j * 3 + 2 ];
826-
827- unsigned int abc = (a << 0 ) | (b << 8 ) | (c << 16 );
828- unsigned int bca = (b << 0 ) | (c << 8 ) | (a << 16 );
829- unsigned int cba = (c << 0 ) | (a << 8 ) | (b << 16 );
830-
831- assert (rt[j] == abc || rt[j] == bca || rt[j] == cba);
832- }
841+ validateDecodeMeshlet<unsigned int , unsigned int >(&cbuf[0 ], mbs, &meshlet_vertices[meshlet.vertex_offset ], meshlet.vertex_count , &meshlet_triangles[meshlet.triangle_offset ], meshlet.triangle_count );
842+ validateDecodeMeshlet<unsigned int , unsigned char >(&cbuf[0 ], mbs, &meshlet_vertices[meshlet.vertex_offset ], meshlet.vertex_count , &meshlet_triangles[meshlet.triangle_offset ], meshlet.triangle_count );
843+ validateDecodeMeshlet<unsigned short , unsigned int >(&cbuf[0 ], mbs, &meshlet_vertices[meshlet.vertex_offset ], meshlet.vertex_count , &meshlet_triangles[meshlet.triangle_offset ], meshlet.triangle_count );
844+ validateDecodeMeshlet<unsigned short , unsigned char >(&cbuf[0 ], mbs, &meshlet_vertices[meshlet.vertex_offset ], meshlet.vertex_count , &meshlet_triangles[meshlet.triangle_offset ], meshlet.triangle_count );
833845
834846 mbst += mbs;
835847 }
@@ -858,7 +870,7 @@ void encodeMeshlets(const Mesh& mesh, size_t max_vertices, size_t max_triangles,
858870 for (size_t j = 0 ; j < meshlets.size (); ++j)
859871 {
860872 size_t size = p[2 ] | (p[3 ] << 8 );
861- meshopt_decodeMeshlet (rv, p[0 ], rt, p[1 ], p + 4 , size);
873+ meshopt_decodeMeshletRaw (rv, p[0 ], rt, p[1 ], p + 4 , size);
862874 p += 4 + size;
863875 }
864876 double t1 = timestamp ();
0 commit comments