@@ -350,6 +350,23 @@ struct hash<std::pair<uint64_t, uint64_t> >
350350};
351351} // namespace std
352352
353+ struct PrimitiveCacheEntry
354+ {
355+ size_t offset;
356+ size_t size;
357+ QuantizationTexture qt;
358+ };
359+
360+ static bool sameQuantization (const QuantizationTexture& lhs, const QuantizationTexture& rhs, const Settings& settings)
361+ {
362+ if (!settings.quantize || settings.tex_float )
363+ return true ;
364+
365+ return lhs.offset [0 ] == rhs.offset [0 ] && lhs.offset [1 ] == rhs.offset [1 ] &&
366+ lhs.scale [0 ] == rhs.scale [0 ] && lhs.scale [1 ] == rhs.scale [1 ] &&
367+ lhs.bits == rhs.bits && lhs.normalized == rhs.normalized ;
368+ }
369+
353370static size_t process (cgltf_data* data, const char * input_path, const char * output_path, const char * report_path, std::vector<Mesh>& meshes, std::vector<Animation>& animations, const Settings& settings, std::string& json, std::string& bin, std::string& fallback, size_t & fallback_size, const char * meshopt_ext)
354371{
355372 if (settings.verbose )
@@ -582,7 +599,7 @@ static size_t process(cgltf_data* data, const char* input_path, const char* outp
582599 ext_texture_transform = ext_texture_transform || mi.uses_texture_transform ;
583600 }
584601
585- std::unordered_map<std::pair<uint64_t , uint64_t >, std::pair< size_t , size_t > > primitive_cache;
602+ std::unordered_map<std::pair<uint64_t , uint64_t >, PrimitiveCacheEntry > primitive_cache;
586603
587604 for (size_t i = 0 ; i < meshes.size (); ++i)
588605 {
@@ -614,18 +631,19 @@ static size_t process(cgltf_data* data, const char* input_path, const char* outp
614631
615632 if (prim.geometry_duplicate )
616633 {
617- std::pair< size_t , size_t >& primitive_json = primitive_cache[std::make_pair (prim.geometry_hash [0 ], prim.geometry_hash [1 ])];
634+ PrimitiveCacheEntry& entry = primitive_cache[std::make_pair (prim.geometry_hash [0 ], prim.geometry_hash [1 ])];
618635
619- if (primitive_json. second )
636+ if (entry. size && sameQuantization (entry. qt , qt, settings) )
620637 {
621638 // reuse previously written accessors
622- json_meshes.append (json_meshes, primitive_json. first , primitive_json. second );
639+ json_meshes.append (json_meshes, entry. offset , entry. size );
623640 }
624641 else
625642 {
626- primitive_json. first = json_meshes.size ();
643+ entry. offset = json_meshes.size ();
627644 writeMeshGeometry (json_meshes, views, json_accessors, accr_offset, prim, qp, qt, settings);
628- primitive_json.second = json_meshes.size () - primitive_json.first ;
645+ entry.size = json_meshes.size () - entry.offset ;
646+ entry.qt = qt;
629647 }
630648 }
631649 else
0 commit comments