@@ -199,9 +199,13 @@ namespace RadeonRays
199
199
std::size_t num_items = 0 ;
200
200
for (auto iter = begin; iter != end; ++iter)
201
201
{
202
+ auto shape = static_cast <const ShapeImpl *>(*iter);
203
+ auto mesh = static_cast <const Mesh *>(shape->is_instance () ? static_cast <const Instance *>(shape)->GetBaseShape () : shape);
204
+
202
205
// Quads are deprecated and no longer supported
203
- assert (static_cast <const Mesh *>(*iter)->puretriangle ());
204
- num_items += static_cast <const Mesh *>(*iter)->num_faces ();
206
+ assert (mesh->puretriangle ());
207
+
208
+ num_items += mesh->num_faces ();
205
209
}
206
210
207
211
auto deleter = [](void *ptr) { Deallocate (ptr); };
@@ -234,12 +238,24 @@ namespace RadeonRays
234
238
std::size_t current_face = 0 ;
235
239
for (auto iter = begin; iter != end; ++iter)
236
240
{
237
- auto mesh = static_cast <const Mesh *>(*iter);
241
+ auto shape = static_cast <const ShapeImpl *>(*iter);
242
+ auto isinstance = shape->is_instance ();
243
+ auto mesh = static_cast <const Mesh *>(isinstance ? static_cast <const Instance *>(shape)->GetBaseShape () : shape);
244
+
245
+ matrix m, minv;
246
+ shape->GetTransform (m, minv);
238
247
239
248
for (std::size_t face_index = 0 ; face_index < mesh->num_faces (); ++face_index, ++current_face)
240
249
{
241
250
bbox bounds;
242
- mesh->GetFaceBounds (face_index, false , bounds);
251
+ mesh->GetFaceBounds (face_index, isinstance, bounds);
252
+
253
+ // Instance is using its own transform for base shape geometry
254
+ // so we need to get object space bounds and transform them manually
255
+ if (isinstance)
256
+ {
257
+ bounds = transform_bbox (bounds, m);
258
+ }
243
259
244
260
auto pmin = _mm_set_ps (bounds.pmin .w , bounds.pmin .z , bounds.pmin .y , bounds.pmin .x );
245
261
auto pmax = _mm_set_ps (bounds.pmax .w , bounds.pmax .z , bounds.pmax .y , bounds.pmax .x );
0 commit comments