@@ -24,10 +24,20 @@ struct Bounds
24
24
{
25
25
return min.f [0 ] <= max.f [0 ] && min.f [1 ] <= max.f [1 ] && min.f [2 ] <= max.f [2 ] && min.f [3 ] <= max.f [3 ];
26
26
}
27
+
28
+ void merge (const Bounds& other)
29
+ {
30
+ for (int k = 0 ; k < 4 ; ++k)
31
+ {
32
+ min.f [k] = std::min (min.f [k], other.min .f [k]);
33
+ max.f [k] = std::max (max.f [k], other.max .f [k]);
34
+ }
35
+ }
27
36
};
28
37
29
- static void updateAttributeBounds (const Mesh& mesh, cgltf_attribute_type type, Bounds& b )
38
+ static Bounds computeBounds (const Mesh& mesh, cgltf_attribute_type type)
30
39
{
40
+ Bounds b;
31
41
Attr pad = {};
32
42
33
43
for (size_t j = 0 ; j < mesh.streams .size (); ++j)
@@ -73,6 +83,8 @@ static void updateAttributeBounds(const Mesh& mesh, cgltf_attribute_type type, B
73
83
b.min .f [k] -= pad.f [k];
74
84
b.max .f [k] += pad.f [k];
75
85
}
86
+
87
+ return b;
76
88
}
77
89
78
90
QuantizationPosition prepareQuantizationPosition (const std::vector<Mesh>& meshes, const Settings& settings)
@@ -82,12 +94,14 @@ QuantizationPosition prepareQuantizationPosition(const std::vector<Mesh>& meshes
82
94
result.bits = settings.pos_bits ;
83
95
result.normalized = settings.pos_normalized ;
84
96
85
- Bounds b ;
97
+ std::vector< Bounds> bounds (meshes. size ()) ;
86
98
87
99
for (size_t i = 0 ; i < meshes.size (); ++i)
88
- {
89
- updateAttributeBounds (meshes[i], cgltf_attribute_type_position, b);
90
- }
100
+ bounds[i] = computeBounds (meshes[i], cgltf_attribute_type_position);
101
+
102
+ Bounds b;
103
+ for (size_t i = 0 ; i < meshes.size (); ++i)
104
+ b.merge (bounds[i]);
91
105
92
106
if (b.isValid ())
93
107
{
@@ -154,7 +168,9 @@ void prepareQuantizationTexture(cgltf_data* data, std::vector<QuantizationTextur
154
168
continue ;
155
169
156
170
indices[i] = follow (parents, indices[i]);
157
- updateAttributeBounds (mesh, cgltf_attribute_type_texcoord, bounds[indices[i]]);
171
+
172
+ Bounds mb = computeBounds (mesh, cgltf_attribute_type_texcoord);
173
+ bounds[indices[i]].merge (mb);
158
174
}
159
175
160
176
// update all material data using canonical bounds
0 commit comments