MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / OnTransformChanged

Method OnTransformChanged

Source/Engine/Foliage/Foliage.cpp:1549–1587  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1547}
1548
1549void Foliage::OnTransformChanged()
1550{
1551 // Base
1552 Actor::OnTransformChanged();
1553
1554 PROFILE_CPU();
1555
1556 // Update instances matrices and cached world bounds
1557 Vector3 corners[8];
1558 Matrix world;
1559 GetLocalToWorldMatrix(world);
1560 for (auto i = Instances.Begin(); i.IsNotEnd(); ++i)
1561 {
1562 auto& instance = *i;
1563 auto type = &FoliageTypes[instance.Type];
1564
1565 // Update bounds
1566 instance.Bounds = BoundingSphere::Empty;
1567 if (!type->IsReady())
1568 continue;
1569 auto& meshes = type->Model->LODs[0].Meshes;
1570 const Transform transform = _transform.LocalToWorld(instance.Transform);
1571 for (int32 j = 0; j < meshes.Count(); j++)
1572 {
1573 meshes[j].GetBox().GetCorners(corners);
1574
1575 for (int32 k = 0; k < 8; k++)
1576 {
1577 Vector3::Transform(corners[k], transform, corners[k]);
1578 }
1579 BoundingSphere meshBounds;
1580 BoundingSphere::FromPoints(corners, 8, meshBounds);
1581
1582 BoundingSphere::Merge(instance.Bounds, meshBounds, instance.Bounds);
1583 }
1584 }
1585
1586 RebuildClusters();
1587}

Callers

nothing calls this directly

Calls 9

TransformClass · 0.50
MergeFunction · 0.50
BeginMethod · 0.45
IsNotEndMethod · 0.45
IsReadyMethod · 0.45
LocalToWorldMethod · 0.45
CountMethod · 0.45
GetCornersMethod · 0.45
GetBoxMethod · 0.45

Tested by

no test coverage detected