Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New distance functions and improvements to bbox / magnet sphere code. #1060

Merged
merged 34 commits into from
Sep 29, 2022

Conversation

Lucaweihs
Copy link
Collaborator

@Lucaweihs Lucaweihs commented Aug 17, 2022

This PR makes the following changes:

  1. Fixes bug where, when using cloud rendering, we were incorrectly matching CUDA GPU indices to Vulkan GPU indices.
  2. Adds an additional field (touchedNotHeldObjects) to the arm metadata which corresponds to a list of object ids that are currently being touched, but are not currently being held, by the arm's magnet sphere.
  3. Adds a GetObjectMetadata action that returns the metadata for the objects corresponding to a given list of object ids.
  4. Adds a GetVisibleObjects action that returns a list of object ids of visible objects (given a max visible distance and visibility scheme).
  5. Fixes a bug where the GetAllVisibleSimObjPhysicsDistance function was ignoring the maxDistance argument.
  6. Adds a BBoxDistance action that computes the (approximate) distance between two objects using their bounding boxes. This should be far more accurate than using the distance between the centerpoints of objects (e.g. the distance between an apply siting on the side of a couch would be large when considering centerpoints but will be near 0 when computing the distance between bounding boxes).
  7. Adds CheckUnobstructedPathBetweenObjectCenters action that does what it says (sees if you can send a raycast between two objects' center points without hitting any other object). This is a nice way to check if two objects are actually side-by-side when they are nearby (e.g. imagine two objects on two sides of a wall, they can be close in L2 distance but are not actually "nearby" in a meaningful sense).
  8. Adds a CheckWhatObjectsOn action that returns the object id of the object that a given object is sitting on. Useful when the receptacle bounding box is not usable (e.g. imagine a box that's been turned on its side with an apple sitting on it, the apple is "on" the box but the receptacle trigger box will, correctly, be empty but we'd still like to know that the apple is on the box in some settings).
  9. Simplified the code in WhatIsInsideMagnetSphere.cs.

Lucaweihs and others added 18 commits April 5, 2022 15:58
…ere it reported the closest distance between a point and a non-convex mesh collider as being 0.
@lgtm-com
Copy link

lgtm-com bot commented Aug 17, 2022

This pull request introduces 2 alerts and fixes 2 when merging 28692f1 into af96708 - view on LGTM.com

new alerts:

  • 1 for Container contents are never accessed
  • 1 for Useless assignment to local variable

fixed alerts:

  • 2 for Use of default ToString()

@lgtm-com
Copy link

lgtm-com bot commented Aug 18, 2022

This pull request introduces 2 alerts and fixes 2 when merging 8e70929 into 7f79e43 - view on LGTM.com

new alerts:

  • 2 for Dereferenced variable may be null

fixed alerts:

  • 2 for Use of default ToString()

@lgtm-com
Copy link

lgtm-com bot commented Sep 15, 2022

This pull request introduces 2 alerts and fixes 2 when merging 663dd36 into 2a3a8b4 - view on LGTM.com

new alerts:

  • 2 for Dereferenced variable may be null

fixed alerts:

  • 2 for Use of default ToString()

@lgtm-com
Copy link

lgtm-com bot commented Sep 15, 2022

This pull request introduces 2 alerts and fixes 2 when merging d16b3df into 2a3a8b4 - view on LGTM.com

new alerts:

  • 2 for Dereferenced variable may be null

fixed alerts:

  • 2 for Use of default ToString()

@lgtm-com
Copy link

lgtm-com bot commented Sep 17, 2022

This pull request introduces 2 alerts and fixes 2 when merging 7f0c32f into 2a3a8b4 - view on LGTM.com

new alerts:

  • 2 for Dereferenced variable may be null

fixed alerts:

  • 2 for Use of default ToString()

public virtual ObjectMetadata[] generateObjectMetadata(SimObjPhysics[] simObjects = null) {
if (simObjects == null) {
if (this.simObjFilter != null) {
simObjects = this.simObjFilter;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little surprising, passing null and getting metadata. Could be good for this function to just work with the simObjects it's passed, but I see the filtering needs to happen somewhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateObjectMetadata now has no default and will throw an error if passed a null value.

VisibilityScheme visSchemeEnum;
if (visibilityScheme != null) {
visibilityScheme = visibilityScheme.ToLower();
if (visibilityScheme.ToLower() == "collider") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change string literal comparison to -> Enum.GetName(typeof(VisibilityScheme), VisibilityScheme.Collider, ignoreCase: true) == visibilityScheme

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Results in an error:

Assets/Scripts/BaseFPSAgentController.cs(2956,107): error CS1739: The best overload for 'GetName' does not have a parameter named 'ignoreCase'

Will do

Enum.GetName(typeof(VisibilityScheme), VisibilityScheme.Collider).ToLower() == visibilityScheme

instead.

# if UNITY_EDITOR
Vector3? lastPoint = null;
# endif
foreach (float x in xVals) {
Copy link
Collaborator

@AlvaroHG AlvaroHG Sep 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference you can do new List<float> {xVals, yVals, zVals}.CartesianProduct().Select(p => bc.center + new Vector3(p[0], p[1], p[2])) defined in our Extensions.cs. But I think we should keep it as it is because it's probably the fastest.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool 👍

Vector3 pLocal = c1.transform.InverseTransformPoint(p) - c1.center;
Vector3 size = c1.size;
if (
(-0.5f * size.x < pLocal.x && pLocal.x < 0.5f * size.x) &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does constant 0.5 mean perhaps create named constant?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just because BoxCollider.size corresponds to the lengths of the box's sides whereas the comparisons we're doing here are w.r.t. the box's center so we want half of these lengths. Will add a comment.

}
c1.enabled = false;

c0.enabled = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does enabling/disabling each do?

Copy link
Collaborator Author

@Lucaweihs Lucaweihs Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the colliders aren't enabled when running functions that do physics checks (namely ClosestPoint in this code) then we will get incorrect results (this is a hard thing to debug as, iirc, it doesn't throw an error). I'll add comment.

c is BoxCollider ||
c is SphereCollider ||
c is CapsuleCollider ||
(c is MeshCollider && ((MeshCollider) c).convex)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are this sub type checks needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ClosestPoint function only works on these types of colliders (it fails on nonconvex mesh colliders). Note that we fallback to using an object's bounding box if it has no such colliders. I'll add a comment.

@@ -168,7 +176,17 @@ public class PhysicsMaterialValues {
ContainedObjectReferences.Remove(t);
}

public void syncBoundingBoxes(bool forceCacheReset = false) {
public void syncBoundingBoxes(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name seems a misnomer if I understand correctly? It's not syncing the boxes just setting flags to do so at some point?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, it will actually regenerate the bounding boxes so long as:

  1. The object has moved/rotated or
  2. We explicitly pass the forceCacheReset argument.

In this PR I added another argument to force the creation of an object-oriented bounding box as sometimes these are not created for certain objects..

@AlvaroHG
Copy link
Collaborator

Could you add a description to the PR for future reference? like what problem you're trying to solve and how it solved it/what is covered.

Some minor comments, LGTM after that

@Lucaweihs
Copy link
Collaborator Author

@AlvaroHG Made the requested changes and added a description.

@lgtm-com
Copy link

lgtm-com bot commented Sep 28, 2022

This pull request introduces 2 alerts and fixes 2 when merging 55ccf96 into 250b12c - view on LGTM.com

new alerts:

  • 2 for Dereferenced variable may be null

fixed alerts:

  • 2 for Use of default ToString()

@Lucaweihs Lucaweihs merged commit 8aa4d9a into nanna Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants