Skip to content

Commit

Permalink
Renamed WorldSpaceScale back to WorldSpaceSize
Browse files Browse the repository at this point in the history
The name should help differentiating between the actual size of the
rendered object and its scale. The doc comment was extended to reflect
the differentiation."
  • Loading branch information
tinxx committed Sep 27, 2024
1 parent 5972762 commit 1e596b3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
12 changes: 6 additions & 6 deletions Assets/SEE/Controls/Actions/MoveAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public override bool Update()
&& Raycasting.RaycastLowestNode(out RaycastHit? targetObjectHit, out Node _, nodeRef))
{
// Calculate position on object and close to the cursor
Vector3 objectSize = contextMenuObjectToMove.WorldSpaceScale();
Vector3 objectSize = contextMenuObjectToMove.WorldSpaceSize();
Vector3 objectPosition = contextMenuObjectToMove.transform.position;
Vector3 anchorPosition = targetObjectHit.Value.point;
anchorPosition.x = Mathf.Clamp(anchorPosition.x, objectPosition.x - 0.5f * objectSize.x, objectPosition.x + 0.5f * objectSize.x);
Expand Down Expand Up @@ -315,10 +315,10 @@ public bool UnGrab()
/// <returns><c>true</c> if <see cref="grabbedObject"/> can be placed</returns>
public readonly bool CanBePlaced()
{
Vector3 scale = GrabbedGameObject.WorldSpaceScale();
Vector3 parentScale = NewParent.WorldSpaceScale();
if (scale.x > parentScale.x
|| scale.z > parentScale.z)
Vector3 size = GrabbedGameObject.WorldSpaceSize();
Vector3 parentSize = NewParent.WorldSpaceSize();
if (size.x > parentSize.x
|| size.z > parentSize.z)
{
return false;
}
Expand Down Expand Up @@ -441,7 +441,7 @@ internal void MoveToTarget(GameObject targetGameObject, Vector3 targetPosition)
{
return;
}
currentPositionOfGrabbedObject = GameNodeMover.GetCoordinatesOn(GrabbedGameObject.WorldSpaceScale(), targetPosition, targetGameObject);
currentPositionOfGrabbedObject = GameNodeMover.GetCoordinatesOn(GrabbedGameObject.WorldSpaceSize(), targetPosition, targetGameObject);
MoveTo(GrabbedGameObject, currentPositionOfGrabbedObject, 0);
}

Expand Down
10 changes: 5 additions & 5 deletions Assets/SEE/Controls/Actions/ResizeNodeAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ private void InitHandles()
Vector3.right + Vector3.forward, Vector3.right + Vector3.back,
Vector3.left + Vector3.forward, Vector3.left + Vector3.back };
Vector3 position = transform.position;
Vector3 scale = gameObject.WorldSpaceScale();
Vector3 size = gameObject.WorldSpaceSize();
foreach (Vector3 direction in directions)
{
handles[CreateHandle(direction, position, scale)] = direction;
handles[CreateHandle(direction, position, size)] = direction;
}
}

Expand Down Expand Up @@ -525,7 +525,7 @@ void UpdateSize()
// Correct sibling overlap
foreach (Transform sibling in siblings)
{
Vector3 siblingSize = sibling.gameObject.LocalScale();
Vector3 siblingSize = sibling.gameObject.LocalSize();
Vector3 siblingPos = sibling.localPosition;
// A small offset of 0.0001f is used as a difference between the detection and the set value.
otherBounds.Left = siblingPos.x - siblingSize.x / 2 - currentResizeStep.LocalPadding.x + 0.0001f;
Expand Down Expand Up @@ -589,7 +589,7 @@ void UpdateSize()
{
// Child position and scale on common parent
Vector3 childPos = Vector3.Scale(child.localPosition, transform.localScale) + transform.localPosition;
Vector3 childSize = Vector3.Scale(child.gameObject.LocalScale(), transform.localScale);
Vector3 childSize = Vector3.Scale(child.gameObject.LocalSize(), transform.localScale);
otherBounds.Left = childPos.x - childSize.x / 2 - currentResizeStep.LocalPadding.x + 0.0001f;
otherBounds.Right = childPos.x + childSize.x / 2 + currentResizeStep.LocalPadding.x - 0.0001f;
otherBounds.Back = childPos.z - childSize.z / 2 - currentResizeStep.LocalPadding.z + 0.0001f;
Expand Down Expand Up @@ -723,7 +723,7 @@ public ResizeStepData (Vector3 initialHitPoint, Vector3 direction, Transform tra
InitialHitPoint = initialHitPoint;
Direction = direction;
InitialLocalPosition = transform.localPosition;
InitialLocalSize = transform.gameObject.LocalScale();
InitialLocalSize = transform.gameObject.LocalSize();
Vector3 localScale = transform.localScale;
ScaleSizeFactor = new (
InitialLocalSize.x / localScale.x,
Expand Down
2 changes: 1 addition & 1 deletion Assets/SEE/Game/SceneManipulation/GameNodeMover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static Vector3 GetCoordinatesOn(Vector3 childWorldScale, Vector3 childPos

// Make sure mappingTarget stays within the roof of parent.
{
Vector3 parentWorldExtent = target.WorldSpaceScale() / 2;
Vector3 parentWorldExtent = target.WorldSpaceSize() / 2;

// Fit child into x range of parent.
if (childPosition.x + childWorldExtent.x > target.transform.position.x + parentWorldExtent.x)
Expand Down
35 changes: 25 additions & 10 deletions Assets/SEE/GameObjects/GameObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public static void SetAbsoluteScale(this GameObject gameObject, Vector3 worldSca
/// <returns>world-space y position of the roof of this <paramref name="gameObject"/></returns>
public static float GetRoof(this GameObject gameObject)
{
return gameObject.transform.position.y + gameObject.WorldSpaceScale().y / 2.0f;
return gameObject.transform.position.y + gameObject.WorldSpaceSize().y / 2.0f;
}

/// <summary>
Expand All @@ -356,7 +356,7 @@ public static float GetRoof(this GameObject gameObject)
public static Vector3 GetRoofCenter(this GameObject gameObject)
{
Vector3 result = gameObject.transform.position;
result.y += gameObject.WorldSpaceScale().y / 2.0f;
result.y += gameObject.WorldSpaceSize().y / 2.0f;
return result;
}

Expand All @@ -368,7 +368,7 @@ public static Vector3 GetRoofCenter(this GameObject gameObject)
public static Vector3 GetGroundCenter(this GameObject gameObject)
{
Vector3 result = gameObject.transform.position;
result.y -= gameObject.WorldSpaceScale().y / 2.0f;
result.y -= gameObject.WorldSpaceSize().y / 2.0f;
return result;
}

Expand Down Expand Up @@ -434,14 +434,23 @@ public static Vector3 GetTop(this GameObject gameObject, Func<Transform, bool> f
}

/// <summary>
/// Returns the scale of the given <paramref name="gameObject"/> in world space.
/// Returns the size of the given <paramref name="gameObject"/> in world space.
/// <para>
/// This is a shorthand to get the <c>bounds.size</c> of the <see cref="Renderer"/> component, if present.
/// This value reflects the actual world-space bounds of the cuboid that contains the rendered object.
/// </para><para>
/// This value should often be used instead of the <c>transform.lossyScale</c> because the scale only reflects
/// the size for objects with a standardized size like cube primitives.
/// </para><para>
/// Local-space counterpart: <see cref="LocalSize"/>
/// </para>
/// </summary>
/// <remarks>
/// If the game object has no renderer, its <c>lossyScale</c> is returned.
/// </remarks>
/// <param name="gameObject">object whose scale is requested</param>
/// <returns>scale of given <paramref name="gameObject"/></returns>
public static Vector3 WorldSpaceScale(this GameObject gameObject)
/// <returns>size of given <paramref name="gameObject"/></returns>
public static Vector3 WorldSpaceSize(this GameObject gameObject)
{
// For some objects, such as capsules, lossyScale gives wrong results.
// The more reliable option to determine the scale is using the
Expand All @@ -458,17 +467,23 @@ public static Vector3 WorldSpaceScale(this GameObject gameObject)
}

/// <summary>
/// Returns the scale of the given <paramref name="gameObject"/> in local space,
/// Returns the size of the given <paramref name="gameObject"/> in local space,
/// i.e., in relation to its parent.
/// <para>
/// This value should often be used instead of the <c>transform.localScale</c> because the scale only reflects
/// the size for objects with a standardized size like cube primitives.
/// </para><para>
/// World-space counterpart: <see cref="WorldSpaceSize"/>
/// </para>
/// </summary>
/// <remarks>
/// If the game object has no renderer, its <c>localScale</c> is returned.
/// </remarks>
/// <param name="gameObject">object whose scale is requested</param>
/// <returns>scale of given <paramref name="gameObject"/></returns>
public static Vector3 LocalScale(this GameObject gameObject)
/// <returns>size of given <paramref name="gameObject"/></returns>
public static Vector3 LocalSize(this GameObject gameObject)
{
// For some objects, such as capsules, lossyScale gives wrong results.
// For some objects, such as capsules, localScale gives wrong results.
// The more reliable option to determine the scale is using the
// object's renderer if it has one.
if (gameObject.TryGetComponent(out Renderer renderer))
Expand Down
4 changes: 2 additions & 2 deletions Assets/SEE/Utils/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void Get(ICollection<GameObject> gameObjects, out Vector2 leftLowe

foreach (GameObject go in gameObjects)
{
Vector3 extent = go.WorldSpaceScale() / 2.0f;
Vector3 extent = go.WorldSpaceSize() / 2.0f;
// Note: position denotes the center of the object
Vector3 position = go.transform.position;
{
Expand Down Expand Up @@ -80,7 +80,7 @@ public static float GetRoof(ICollection<GameObject> gameObjects)
float result = float.NegativeInfinity;
foreach (GameObject gameObject in gameObjects)
{
float yTop = gameObject.transform.position.y + gameObject.WorldSpaceScale().y / 2.0f;
float yTop = gameObject.transform.position.y + gameObject.WorldSpaceSize().y / 2.0f;
if (yTop > result)
{
result = yTop;
Expand Down

0 comments on commit 1e596b3

Please sign in to comment.