Skip to content

Commit

Permalink
Merge pull request Unity-Technologies#262 from Unity-Technologies/fix…
Browse files Browse the repository at this point in the history
…_bbox3d_scaling

Fix bbox3d calculation
  • Loading branch information
mkamalza authored Mar 22, 2021
2 parents a097c1f + 8593a13 commit a127eaa
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ void ProcessLabel(Labeling labeledEntity)
// Need to convert all bounds into labeling mesh space...
foreach (var mesh in meshFilters)
{
if (!mesh.GetComponent<Renderer>().enabled)
continue;

var currentTransform = mesh.gameObject.transform;
// Grab the bounds of the game object from the mesh, although these bounds are axis-aligned,
// they are axis-aligned with respect to the current component's coordinate space. This, in theory
Expand All @@ -260,6 +263,8 @@ void ProcessLabel(Labeling labeledEntity)
// Apply the transformations on this object until we reach the labeled transform
while (currentTransform != labelTransform)
{
transformedBounds.center = Vector3.Scale(transformedBounds.center, currentTransform.localScale);
transformedBounds.center = currentTransform.localRotation * transformedBounds.center;
transformedBounds.center += currentTransform.localPosition;
transformedBounds.extents = Vector3.Scale(transformedBounds.extents, currentTransform.localScale);
transformedRotation *= currentTransform.localRotation;
Expand Down Expand Up @@ -287,7 +292,7 @@ void ProcessLabel(Labeling labeledEntity)

// Convert the combined bounds into world space
combinedBounds.center = labelTransform.TransformPoint(combinedBounds.center);
combinedBounds.extents = Vector3.Scale(combinedBounds.extents, labelTransform.localScale);
combinedBounds.extents = Vector3.Scale(combinedBounds.extents, labelTransform.lossyScale);

// Now convert all points into camera's space
var cameraCenter = cameraTransform.InverseTransformPoint(combinedBounds.center);
Expand Down

0 comments on commit a127eaa

Please sign in to comment.