diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index ab7aa9b2f6..f4163ac819 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -2677,11 +2677,9 @@ public SimObjType ReceptableSimObjType() { return (SimObjType)Enum.Parse(typeof(SimObjType), receptacleObjectType); } - public static VisibilityScheme GetVisibilitySchemeFromString(string visibilityScheme) - { + public static VisibilityScheme GetVisibilitySchemeFromString(string visibilityScheme) { VisibilityScheme result = VisibilityScheme.Distance; - try - { + try { result = (VisibilityScheme)Enum.Parse(typeof(VisibilityScheme), visibilityScheme, true); } // including this pragma so the "ex variable declared but not used" warning stops yelling @@ -2789,8 +2787,7 @@ public enum ServerActionErrorCode { UnhandledException } -public enum VisibilityScheme -{ +public enum VisibilityScheme { Collider, //deprecated, scheme is now Distance based only Distance } diff --git a/unity/Assets/Scripts/BaseFPSAgentController.cs b/unity/Assets/Scripts/BaseFPSAgentController.cs index 5e1c994107..e5e64d81f0 100644 --- a/unity/Assets/Scripts/BaseFPSAgentController.cs +++ b/unity/Assets/Scripts/BaseFPSAgentController.cs @@ -4537,8 +4537,7 @@ protected SimObjPhysics[] GetAllVisibleSimObjPhysics( float maxDistance, out SimObjPhysics[] interactable, IEnumerable filterSimObjs = null - ) - { + ) { return GetAllVisibleSimObjPhysicsDistance( camera, maxDistance, @@ -4556,29 +4555,23 @@ public void GetVisibleObjectsFromCamera( float? maxDistance = null, //max distance from the camera origin to consider objects visible int? thirdPartyCameraId = null, //leave null to query main camera, otherwise pass in the index of the third party camera List filterObjectIds = null //only return objects with these ids - ) - { + ) { //if thirdPartyCameraId not specified, default to main camera Camera camera = m_Camera; - if (thirdPartyCameraId.HasValue) - { + if (thirdPartyCameraId.HasValue) { camera = agentManager.thirdPartyCameras[thirdPartyCameraId.Value]; - if (this.visibilityScheme != VisibilityScheme.Distance) - { + if (this.visibilityScheme != VisibilityScheme.Distance) { throw new System.NotImplementedException( $"Visibility scheme {this.visibilityScheme} is not implemented for third party cameras. Default visibility scheme should be 'Distance'." ); - } + } } //only check visibility for objects with these ids otherwise check them all List filterSimObjs = null; - if (filterObjectIds != null) - { - foreach (string objectId in filterObjectIds) - { - if (!physicsSceneManager.ObjectIdToSimObjPhysics.ContainsKey(objectId)) - { + if (filterObjectIds != null) { + foreach (string objectId in filterObjectIds) { + if (!physicsSceneManager.ObjectIdToSimObjPhysics.ContainsKey(objectId)) { throw new ArgumentException( $"Object with id {objectId} does not exist in scene." ); @@ -4597,12 +4590,12 @@ public void GetVisibleObjectsFromCamera( interactable: out interactable ); -// #if UNITY_EDITOR -// foreach (SimObjPhysics sop in visible) -// { -// Debug.Log("Visible: " + sop.name); -// } -// #endif + // #if UNITY_EDITOR + // foreach (SimObjPhysics sop in visible) + // { + // Debug.Log("Visible: " + sop.name); + // } + // #endif actionFinishedEmit(true, visible.Select(sop => sop.ObjectID).ToList()); } @@ -4617,23 +4610,18 @@ public void GetVisibleObjects( string visibilityScheme = null, int? thirdPartyCameraIndex = null, List objectIds = null - ) - { + ) { Camera camera; //which camera are we checking visibility from? - if (thirdPartyCameraIndex.HasValue) - { + if (thirdPartyCameraIndex.HasValue) { camera = agentManager.thirdPartyCameras[thirdPartyCameraIndex.Value]; - if (this.visibilityScheme != VisibilityScheme.Distance) - { + if (this.visibilityScheme != VisibilityScheme.Distance) { throw new System.NotImplementedException( $"Visibility scheme {this.visibilityScheme} is not implemented for third party cameras. Default visibility scheme should be 'Distance'." ); } } - //can also be used to query main camera - else - { + else { camera = m_Camera; } @@ -4725,8 +4713,7 @@ out SimObjPhysics[] interactable return visible.ToArray(); } - protected virtual LayerMask GetVisibilityRaycastLayerMask(bool withSimObjInvisible = false) - { + protected virtual LayerMask GetVisibilityRaycastLayerMask(bool withSimObjInvisible = false) { string[] layers = new string[] { "SimObjVisible", diff --git a/unity/Assets/Scripts/DebugInputField.cs b/unity/Assets/Scripts/DebugInputField.cs index b24b716259..b789b2bacb 100644 --- a/unity/Assets/Scripts/DebugInputField.cs +++ b/unity/Assets/Scripts/DebugInputField.cs @@ -2760,20 +2760,18 @@ IEnumerator executeBatch(JArray jActions) { action["objectId"] = splitcommand[1]; } - break; - } + break; + } - case "gvo": - { - Dictionary action = new Dictionary() - { - ["action"] = "GetVisibleObjects", - ["thirdPartyCameraIndex"] = 0, - }; + case "gvo": { + Dictionary action = new Dictionary() { + ["action"] = "GetVisibleObjects", + ["thirdPartyCameraIndex"] = 0, + }; - CurrentActiveController().ProcessControlCommand(action); - break; - } + CurrentActiveController().ProcessControlCommand(action); + break; + } case "putxy": { Dictionary action = new Dictionary(); diff --git a/unity/Assets/Scripts/FpinAgentController.cs b/unity/Assets/Scripts/FpinAgentController.cs index bffbda8a8a..aee1812096 100644 --- a/unity/Assets/Scripts/FpinAgentController.cs +++ b/unity/Assets/Scripts/FpinAgentController.cs @@ -11,10 +11,8 @@ using UnityEngine.Rendering.PostProcessing; using UnityEngine.UIElements; -namespace UnityStandardAssets.Characters.FirstPerson -{ - public class BoxBounds - { +namespace UnityStandardAssets.Characters.FirstPerson { + public class BoxBounds { public Vector3 worldCenter; public Vector3 agentRelativeCenter; public Vector3 size; @@ -22,8 +20,7 @@ public class BoxBounds [Serializable] [MessagePackObject(keyAsPropertyName: true)] - public class LoadInUnityProceduralAsset - { + public class LoadInUnityProceduralAsset { public string id; public string dir; public string extension = ".msgpack.gz"; @@ -33,8 +30,7 @@ public class LoadInUnityProceduralAsset #nullable enable [Serializable] [MessagePackObject(keyAsPropertyName: true)] - public class BodyAsset - { + public class BodyAsset { public string? assetId = null; public LoadInUnityProceduralAsset? dynamicAsset = null; public ProceduralAsset? asset = null; @@ -44,8 +40,7 @@ public class BodyAsset [Serializable] [MessagePackObject(keyAsPropertyName: true)] - public class BackwardsCompatibleInitializeParams - { + public class BackwardsCompatibleInitializeParams { // Make what parameters it uses explicit public float maxUpwardLookAngle = 0.0f; public float maxDownwardLookAngle = 0.0f; @@ -69,8 +64,7 @@ public class BackwardsCompatibleInitializeParams public string visibilityScheme = VisibilityScheme.Distance.ToString(); } - public class FpinAgentController : PhysicsRemoteFPSAgentController - { + public class FpinAgentController : PhysicsRemoteFPSAgentController { private static readonly Vector3 agentSpawnOffset = new Vector3(100.0f, 100.0f, 100.0f); private FpinMovableContinuous fpinMovable; public BoxCollider spawnedBoxCollider = null; @@ -79,12 +73,9 @@ public class FpinAgentController : PhysicsRemoteFPSAgentController private Transform topMeshTransform = null; private Bounds? agentBounds = null; public BoxBounds boxBounds = null; - public BoxBounds BoxBounds - { - get - { - if (spawnedBoxCollider != null) - { + public BoxBounds BoxBounds { + get { + if (spawnedBoxCollider != null) { BoxBounds currentBounds = new BoxBounds(); currentBounds.worldCenter = spawnedBoxCollider.transform.TransformPoint( @@ -100,9 +91,7 @@ public BoxBounds BoxBounds // Debug.Log($"world center: {boxBounds.worldCenter}"); // Debug.Log($"size: {boxBounds.size}"); // Debug.Log($"agentRelativeCenter: {boxBounds.agentRelativeCenter}"); - } - else - { + } else { // Debug.Log("why is it nullll"); return null; } @@ -117,8 +106,7 @@ public BoxBounds BoxBounds public FpinAgentController(BaseAgentComponent baseAgentComponent, AgentManager agentManager) : base(baseAgentComponent, agentManager) { } - public void Start() - { + public void Start() { //put stuff we need here when we need it maybe } @@ -129,8 +117,7 @@ public override RaycastHit[] CastBodyTrayectory( float moveMagnitude, int layerMask, CapsuleData cachedCapsule - ) - { + ) { Vector3 startPositionBoxCenter = startPosition + this.transform.TransformDirection(this.boxBounds.agentRelativeCenter); @@ -148,16 +135,14 @@ CapsuleData cachedCapsule //since the size returned by the box collider only reflects its size in local space DISREGARDING ANY TRANSFORM SCALES //IN ITS PARENTS OR ITSELF here we go - public Vector3 GetTrueSizeOfBoxCollider(BoxCollider collider) - { + public Vector3 GetTrueSizeOfBoxCollider(BoxCollider collider) { Vector3 trueSize = collider.size; // get the transform of the collider itself Transform currentTransform = collider.transform; // Apply the scale from the collider's transform and all parent transforms - while (currentTransform != null) - { + while (currentTransform != null) { trueSize.x *= currentTransform.localScale.x; trueSize.y *= currentTransform.localScale.y; trueSize.z *= currentTransform.localScale.z; @@ -170,29 +155,24 @@ public Vector3 GetTrueSizeOfBoxCollider(BoxCollider collider) } //override so we can access to fpin specific stuff - public override MetadataWrapper generateMetadataWrapper() - { + public override MetadataWrapper generateMetadataWrapper() { //get all the usual stuff from base agent's implementation MetadataWrapper metaWrap = base.generateMetadataWrapper(); //here's the fpin specific stuff - if (boxBounds != null) - { + if (boxBounds != null) { //get from BoxBounds as box world center will update as agent moves so we can't cache it metaWrap.agent.fpinColliderSize = BoxBounds.size; metaWrap.agent.fpinColliderWorldCenter = BoxBounds.worldCenter; metaWrap.agent.fpinColliderAgentRelativeCenter = BoxBounds.agentRelativeCenter; - } - else - { + } else { metaWrap.agent.fpinColliderSize = new Vector3(0, 0, 0); } return metaWrap; } - public List SamplePointsOnNavMesh(int sampleCount, float maxDistance) - { + public List SamplePointsOnNavMesh(int sampleCount, float maxDistance) { float minX = agentManager.SceneBounds.min.x; float minZ = agentManager.SceneBounds.min.z; float maxX = agentManager.SceneBounds.max.x; @@ -203,10 +183,8 @@ public List SamplePointsOnNavMesh(int sampleCount, float maxDistance) int n = (int)Mathf.Ceil(Mathf.Sqrt(sampleCount)); List initPoints = new List(); - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { initPoints.Add( new Vector3( Mathf.Lerp(minX, maxX, (i + 0.5f) / n), @@ -219,17 +197,14 @@ public List SamplePointsOnNavMesh(int sampleCount, float maxDistance) initPoints.Shuffle_(); List pointsOnMesh = new List(); - for (int i = 0; i < initPoints.Count; i++) - { - if (pointsOnMesh.Count >= sampleCount) - { + for (int i = 0; i < initPoints.Count; i++) { + if (pointsOnMesh.Count >= sampleCount) { break; } NavMeshHit hit; Vector3 randomPoint = initPoints[i]; - if (NavMesh.SamplePosition(randomPoint, out hit, maxDistance, NavMesh.AllAreas)) - { + if (NavMesh.SamplePosition(randomPoint, out hit, maxDistance, NavMesh.AllAreas)) { # if UNITY_EDITOR Debug.DrawLine( hit.position, @@ -247,17 +222,14 @@ public List SamplePointsOnNavMesh(int sampleCount, float maxDistance) return pointsOnMesh; } - public void RandomlyPlaceAgentOnNavMesh(int n = 200, float maxDistance = 0.1f) - { + public void RandomlyPlaceAgentOnNavMesh(int n = 200, float maxDistance = 0.1f) { List pointsOnMesh = SamplePointsOnNavMesh(n, maxDistance: maxDistance); - if (pointsOnMesh.Count == 0) - { + if (pointsOnMesh.Count == 0) { throw new InvalidOperationException("No points on the navmesh"); } Bounds b = UtilityFunctions.CreateEmptyBounds(); - foreach (Collider c in GetComponentsInChildren()) - { + foreach (Collider c in GetComponentsInChildren()) { b.Encapsulate(c.bounds); } @@ -266,10 +238,8 @@ public void RandomlyPlaceAgentOnNavMesh(int n = 200, float maxDistance = 0.1f) //Debug.Log($"yOffset is: {yOffset}"); bool success = false; - foreach (Vector3 point in pointsOnMesh) - { - try - { + foreach (Vector3 point in pointsOnMesh) { + try { //Debug.Log($"what is the point we are trying from the pointsOnMesh? {point:F8}"); teleportFull( position: point + new Vector3(0, yOffset, 0), @@ -279,9 +249,7 @@ public void RandomlyPlaceAgentOnNavMesh(int n = 200, float maxDistance = 0.1f) ); success = true; break; - } - catch (InvalidOperationException) - { + } catch (InvalidOperationException) { continue; } } @@ -296,8 +264,7 @@ public void spawnAgentBoxCollider( Bounds agentBounds, bool useVisibleColliderBase = false, bool spawnCollidersWithoutMesh = false - ) - { + ) { //create colliders based on the agent bounds var col = new GameObject("fpinCollider", typeof(BoxCollider)); col.layer = LayerMask.NameToLayer("Agent"); @@ -332,27 +299,22 @@ public void spawnAgentBoxCollider( //helper function to remove the currently generated agent box collider //make sure to follow this up with a subsequent generation so BoxBounds isn't left null - public void destroyAgentBoxCollider() - { + public void destroyAgentBoxCollider() { GameObject visibleBox = GameObject.Find("VisibleBox"); - if (spawnedBoxCollider != null) - { + if (spawnedBoxCollider != null) { UnityEngine.Object.DestroyImmediate(spawnedBoxCollider.transform.gameObject); spawnedBoxCollider = null; } - if (spawnedTriggerBoxCollider != null) - { + if (spawnedTriggerBoxCollider != null) { UnityEngine.Object.DestroyImmediate(spawnedTriggerBoxCollider.transform.gameObject); spawnedTriggerBoxCollider = null; } - if (visibleBox != null) - { + if (visibleBox != null) { UnityEngine.Object.DestroyImmediate(visibleBox); } #if UNITY_EDITOR GameObject visualizedBoxCollider = GameObject.Find("VisualizedBoxCollider"); - if (visualizedBoxCollider != null) - { + if (visualizedBoxCollider != null) { UnityEngine.Object.DestroyImmediate(visualizedBoxCollider); } #endif @@ -368,36 +330,30 @@ private Transform CopyMeshChildrenRecursive( Transform sourceTransform, Transform targetTransform, bool isTopMost = true - ) - { + ) { Transform thisTransform = null; - foreach (Transform child in sourceTransform) - { + foreach (Transform child in sourceTransform) { GameObject copiedChild = null; // Check if the child has a MeshFilter component MeshFilter meshFilter = child.GetComponent(); - if (meshFilter != null) - { + if (meshFilter != null) { copiedChild = CopyMeshToTarget(child, targetTransform); } // Process children only if necessary (i.e., they contain MeshFilters) - if (HasMeshInChildrenOrSelf(child)) - { + if (HasMeshInChildrenOrSelf(child)) { Transform parentForChildren = (copiedChild != null) ? copiedChild.transform : CreateContainerForHierarchy(child, targetTransform).transform; CopyMeshChildrenRecursive(child, parentForChildren, false); - if (isTopMost) - { + if (isTopMost) { thisTransform = parentForChildren; } } } - if (isTopMost) - { + if (isTopMost) { // Set up intermediate object for scaling the mesh in agent-space (since the top-level mesh could be rotated, potentially introducing a complex matrix of scales) GameObject agentScaleObject = new GameObject("AgentScaleObject"); agentScaleObject.transform.position = thisTransform.position; @@ -409,8 +365,7 @@ private Transform CopyMeshChildrenRecursive( return null; } - private GameObject CopyMeshToTarget(Transform child, Transform targetParent) - { + private GameObject CopyMeshToTarget(Transform child, Transform targetParent) { // Create a new GameObject and copy components GameObject copiedChild = new GameObject(child.name); copiedChild.transform.SetParent(targetParent); @@ -420,8 +375,7 @@ private GameObject CopyMeshToTarget(Transform child, Transform targetParent) copiedMeshFilter.mesh = meshFilter.mesh; MeshRenderer sourceMeshRenderer = child.GetComponent(); - if (sourceMeshRenderer != null) - { + if (sourceMeshRenderer != null) { MeshRenderer copiedMeshRenderer = copiedChild.AddComponent(); copiedMeshRenderer.sharedMaterials = sourceMeshRenderer.sharedMaterials; } @@ -433,26 +387,21 @@ private GameObject CopyMeshToTarget(Transform child, Transform targetParent) return copiedChild; } - private bool HasMeshInChildrenOrSelf(Transform transform) - { - foreach (Transform child in transform) - { - if (child.GetComponent() != null || HasMeshInChildrenOrSelf(child)) - { + private bool HasMeshInChildrenOrSelf(Transform transform) { + foreach (Transform child in transform) { + if (child.GetComponent() != null || HasMeshInChildrenOrSelf(child)) { return true; } } - if (transform.GetComponent() != null) - { + if (transform.GetComponent() != null) { return true; } return false; } - private GameObject CreateContainerForHierarchy(Transform child, Transform targetParent) - { + private GameObject CreateContainerForHierarchy(Transform child, Transform targetParent) { GameObject container = new GameObject(child.name + "_Container"); container.transform.SetParent(targetParent); container.transform.localPosition = child.localPosition; @@ -464,26 +413,22 @@ private GameObject CreateContainerForHierarchy(Transform child, Transform target private HashSet TransformedMeshRendererVertices( MeshRenderer mr, bool returnFirstVertexOnly = false - ) - { + ) { MeshFilter mf = mr.gameObject.GetComponent(); Matrix4x4 localToWorld = mr.transform.localToWorldMatrix; HashSet vertices = new HashSet(mf.sharedMesh.vertices); HashSet transformedVertices = new HashSet(); - foreach (Vector3 vertex in vertices) - { + foreach (Vector3 vertex in vertices) { transformedVertices.Add(localToWorld.MultiplyPoint3x4(vertex)); } return transformedVertices; } - public ActionFinished GetBoxBounds() - { + public ActionFinished GetBoxBounds() { return new ActionFinished() { success = true, actionReturn = this.BoxBounds }; } - public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles) - { + public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles) { // Move the point to the pivot's origin Vector3 dir = point - pivot; // Rotate it @@ -495,31 +440,23 @@ public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angl public ActionFinished BackwardsCompatibleInitialize( BackwardsCompatibleInitializeParams args - ) - { + ) { Debug.Log("RUNNING BackCompatInitialize from FpinAgentController.cs"); // limit camera from looking too far down/up //default max are 30 up and 60 down, different agent types may overwrite this - if (Mathf.Approximately(args.maxUpwardLookAngle, 0.0f)) - { + if (Mathf.Approximately(args.maxUpwardLookAngle, 0.0f)) { this.maxUpwardLookAngle = 30f; - } - else - { + } else { this.maxUpwardLookAngle = args.maxUpwardLookAngle; } - if (Mathf.Approximately(args.maxDownwardLookAngle, 0.0f)) - { + if (Mathf.Approximately(args.maxDownwardLookAngle, 0.0f)) { this.maxDownwardLookAngle = 60f; - } - else - { + } else { this.maxDownwardLookAngle = args.maxDownwardLookAngle; } - if (args.antiAliasing != null) - { + if (args.antiAliasing != null) { agentManager.updateAntiAliasing( postProcessLayer: m_Camera.gameObject.GetComponentInChildren(), antiAliasing: args.antiAliasing @@ -527,77 +464,62 @@ BackwardsCompatibleInitializeParams args } // m_Camera.GetComponent().SwitchRenderersToHide(this.VisibilityCapsule); - if (args.gridSize == 0) - { + if (args.gridSize == 0) { args.gridSize = 0.25f; } // note: this overrides the default FOV values set in InitializeBody() - if (args.fieldOfView > 0 && args.fieldOfView < 180) - { + if (args.fieldOfView > 0 && args.fieldOfView < 180) { m_Camera.fieldOfView = args.fieldOfView; - } - else if (args.fieldOfView < 0 || args.fieldOfView >= 180) - { + } else if (args.fieldOfView < 0 || args.fieldOfView >= 180) { errorMessage = "fov must be set to (0, 180) noninclusive."; Debug.Log(errorMessage); return new ActionFinished(success: false, errorMessage: errorMessage); } - if (args.cameraNearPlane > 0) - { + if (args.cameraNearPlane > 0) { m_Camera.nearClipPlane = args.cameraNearPlane; } - if (args.cameraFarPlane > 0) - { + if (args.cameraFarPlane > 0) { m_Camera.farClipPlane = args.cameraFarPlane; } - if (args.timeScale > 0) - { - if (Time.timeScale != args.timeScale) - { + if (args.timeScale > 0) { + if (Time.timeScale != args.timeScale) { Time.timeScale = args.timeScale; } - } - else - { + } else { errorMessage = "Time scale must be > 0"; Debug.Log(errorMessage); return new ActionFinished(success: false, errorMessage: errorMessage); } - if (args.rotateStepDegrees <= 0.0) - { + if (args.rotateStepDegrees <= 0.0) { errorMessage = "rotateStepDegrees must be a non-zero, non-negative float"; Debug.Log(errorMessage); return new ActionFinished(success: false, errorMessage: errorMessage); } // default is 90 defined in the ServerAction class, specify whatever you want the default to be - if (args.rotateStepDegrees > 0.0) - { + if (args.rotateStepDegrees > 0.0) { this.rotateStepDegrees = args.rotateStepDegrees; } - if (args.snapToGrid && !ValidRotateStepDegreesWithSnapToGrid(args.rotateStepDegrees)) - { + if (args.snapToGrid && !ValidRotateStepDegreesWithSnapToGrid(args.rotateStepDegrees)) { errorMessage = $"Invalid values 'rotateStepDegrees': ${args.rotateStepDegrees} and 'snapToGrid':${args.snapToGrid}. 'snapToGrid': 'True' is not supported when 'rotateStepDegrees' is different from grid rotation steps of 0, 90, 180, 270 or 360."; Debug.Log(errorMessage); return new ActionFinished(success: false, errorMessage: errorMessage); } - if (args.maxDownwardLookAngle < 0) - { + if (args.maxDownwardLookAngle < 0) { errorMessage = "maxDownwardLookAngle must be a non-negative float"; Debug.Log(errorMessage); return new ActionFinished(success: false, errorMessage: errorMessage); } - if (args.maxUpwardLookAngle < 0) - { + if (args.maxUpwardLookAngle < 0) { errorMessage = "maxUpwardLookAngle must be a non-negative float"; Debug.Log(errorMessage); return new ActionFinished(success: false, errorMessage: errorMessage); @@ -610,21 +532,18 @@ BackwardsCompatibleInitializeParams args || args.renderSemanticSegmentation || args.renderInstanceSegmentation || args.renderNormalsImage - ) - { + ) { this.updateImageSynthesis(true); } - if (args.visibilityDistance > 0.0f) - { + if (args.visibilityDistance > 0.0f) { this.maxVisibleDistance = args.visibilityDistance; } var navmeshAgent = this.GetComponentInChildren(); var collider = this.GetComponent(); - if (collider != null && navmeshAgent != null) - { + if (collider != null && navmeshAgent != null) { navmeshAgent.radius = collider.radius; navmeshAgent.height = collider.height; navmeshAgent.transform.localPosition = new Vector3( @@ -636,14 +555,11 @@ BackwardsCompatibleInitializeParams args // navmeshAgent.radius = - if (args.gridSize <= 0 || args.gridSize > 5) - { + if (args.gridSize <= 0 || args.gridSize > 5) { errorMessage = "grid size must be in the range (0,5]"; Debug.Log(errorMessage); return new ActionFinished(success: false, errorMessage: errorMessage); - } - else - { + } else { gridSize = args.gridSize; // Don't know what this was for @@ -666,8 +582,7 @@ BackwardsCompatibleInitializeParams args return new ActionFinished( success: true, - actionReturn: new InitializeReturn - { + actionReturn: new InitializeReturn { cameraNearPlane = m_Camera.nearClipPlane, cameraFarPlane = m_Camera.farClipPlane } @@ -682,8 +597,7 @@ public ActionFinished Initialize( Vector3? colliderScaleRatio = null, bool useAbsoluteSize = false, bool useVisibleColliderBase = false - ) - { + ) { this.visibilityScheme = VisibilityScheme.Distance; var actionFinished = this.InitializeBody( bodyAsset: bodyAsset, @@ -705,16 +619,14 @@ public ActionFinished InitializeBody( Vector3? colliderScaleRatio = null, bool useAbsoluteSize = false, bool useVisibleColliderBase = false - ) - { + ) { // if using no source body mesh, we default to using absolute size via the colliderScaleRatio // since a non absolute size doesn't make sense if we have no default mesh size to base the scale // ratio on Vector3 meshScaleRatio = colliderScaleRatio.GetValueOrDefault(Vector3.one); bool noMesh = false; - if (bodyAsset == null) - { + if (bodyAsset == null) { useAbsoluteSize = true; noMesh = true; } @@ -729,21 +641,18 @@ public ActionFinished InitializeBody( //remove any old copied meshes or generated colliders from previous fpin agent now destroyAgentBoxCollider(); - if (fpinVisibilityCapsule != null) - { + if (fpinVisibilityCapsule != null) { UnityEngine.Object.DestroyImmediate(fpinVisibilityCapsule); } var spawnAssetActionFinished = new ActionFinished(); Bounds meshBoundsWorld = new Bounds(this.transform.position, Vector3.zero); - if (bodyAsset != null) - { + if (bodyAsset != null) { //spawn in a default mesh in an out-of-the-way location (currently 200,200,200) to base the new bounds on spawnAssetActionFinished = spawnBodyAsset(bodyAsset, out GameObject spawnedMesh); // Return early if spawn failed - if (!spawnAssetActionFinished.success) - { + if (!spawnAssetActionFinished.success) { return spawnAssetActionFinished; } @@ -759,18 +668,13 @@ public ActionFinished InitializeBody( // so we'll take the bounds-center of the first meshRenderer MeshRenderer[] meshRenderers = topMeshTransform.gameObject.GetComponentsInChildren(); - foreach (MeshRenderer mr in meshRenderers) - { + foreach (MeshRenderer mr in meshRenderers) { // No need to run TransformedMeshRendererVertices if the meshRenderer's GameObject isn't rotated - if (mr.transform.eulerAngles.magnitude < 1e-4f) - { + if (mr.transform.eulerAngles.magnitude < 1e-4f) { meshBoundsWorld.Encapsulate(mr.bounds); - } - else - { + } else { HashSet vertices = TransformedMeshRendererVertices(mr); - foreach (Vector3 vertex in vertices) - { + foreach (Vector3 vertex in vertices) { meshBoundsWorld.Encapsulate(vertex); } } @@ -781,17 +685,14 @@ public ActionFinished InitializeBody( topMeshTransform.position = meshBoundsWorld.center; topMeshTransform.GetChild(0).position = currentTopMeshTransformChildPos; - if (useAbsoluteSize) - { + if (useAbsoluteSize) { topMeshTransform.localScale = new Vector3( meshScaleRatio.x / meshBoundsWorld.size.x, meshScaleRatio.y / meshBoundsWorld.size.y, meshScaleRatio.z / meshBoundsWorld.size.z ); meshBoundsWorld.size = meshScaleRatio; - } - else - { + } else { topMeshTransform.localScale = meshScaleRatio; meshBoundsWorld.size = new Vector3( meshScaleRatio.x * meshBoundsWorld.size.x, @@ -810,18 +711,14 @@ public ActionFinished InitializeBody( this.transform.position + Vector3.up * meshBoundsWorld.extents.y; // remove the spawned mesh cause we are done with it - foreach (var sop in spawnedMesh.GetComponentsInChildren()) - { + foreach (var sop in spawnedMesh.GetComponentsInChildren()) { agentManager.physicsSceneManager.RemoveFromObjectsInScene(sop); } - if (spawnedMesh.activeInHierarchy) - { + if (spawnedMesh.activeInHierarchy) { UnityEngine.Object.DestroyImmediate(spawnedMesh); } - } - else - { + } else { meshBoundsWorld = new Bounds( this.transform.position + (Vector3.up * meshScaleRatio.y / 2), meshScaleRatio @@ -836,8 +733,7 @@ public ActionFinished InitializeBody( // set reference to the meshes so the base agent and fpin agent are happy VisibilityCapsule = fpinVisibilityCapsule = viscap; - if (topMeshTransform != null) - { + if (topMeshTransform != null) { topMeshTransform.SetParent(viscap.transform); } @@ -853,8 +749,7 @@ public ActionFinished InitializeBody( ); // spawn the visible collider base if we need to - if (useVisibleColliderBase) - { + if (useVisibleColliderBase) { GameObject visibleBase = GameObject.CreatePrimitive(PrimitiveType.Cube); visibleBase.name = "visibleBase"; visibleBase.GetComponent().enabled = false; @@ -966,8 +861,7 @@ public ActionFinished InitializeBody( originalRotation, checkBoxLayerMask ) - ) - { + ) { this.transform.position = originalPosition; this.transform.rotation = originalRotation; string error = @@ -989,10 +883,8 @@ public ActionFinished InitializeBody( fpinMovable = new FpinMovableContinuous(this.GetComponentInParent()); // we had a body asset used, so actionFinished returns info related to that - if (bodyAsset != null) - { - return new ActionFinished(spawnAssetActionFinished) - { + if (bodyAsset != null) { + return new ActionFinished(spawnAssetActionFinished) { // TODO: change to a proper class once metadata return is defined actionReturn = new Dictionary() { @@ -1006,11 +898,8 @@ spawnAssetActionFinished.actionReturn as ObjectSphereBounds { "cameraFarPlane", m_Camera.farClipPlane } } }; - } - else - { - return new ActionFinished() - { + } else { + return new ActionFinished() { // TODO: change to a proper class once metadata return is defined actionReturn = new Dictionary() { @@ -1022,18 +911,14 @@ spawnAssetActionFinished.actionReturn as ObjectSphereBounds } } - private ActionFinished spawnBodyAsset(BodyAsset bodyAsset, out GameObject spawnedMesh) - { - if (bodyAsset == null) - { + private ActionFinished spawnBodyAsset(BodyAsset bodyAsset, out GameObject spawnedMesh) { + if (bodyAsset == null) { throw new ArgumentNullException("bodyAsset is null"); - } - else if ( - bodyAsset.assetId == null - && bodyAsset.dynamicAsset == null - && bodyAsset.asset == null - ) - { + } else if ( + bodyAsset.assetId == null + && bodyAsset.dynamicAsset == null + && bodyAsset.asset == null + ) { throw new ArgumentNullException( "`bodyAsset.assetId`, `bodyAsset.dynamicAsset` or `bodyAsset.asset` must be provided all are null." ); @@ -1047,8 +932,7 @@ private ActionFinished spawnBodyAsset(BodyAsset bodyAsset, out GameObject spawne if ( (bodyAsset.dynamicAsset != null || bodyAsset.asset != null) && bodyAsset.assetId == null - ) - { + ) { var id = bodyAsset.dynamicAsset != null ? bodyAsset.dynamicAsset.id @@ -1056,24 +940,20 @@ private ActionFinished spawnBodyAsset(BodyAsset bodyAsset, out GameObject spawne var assetMap = ProceduralTools.getAssetMap(); // Check if asset is in AssetDatabase already - if (assetMap.ContainsKey(id)) - { + if (assetMap.ContainsKey(id)) { Debug.Log("------- Already contains key"); bodyAsset.assetId = id; } } - if (bodyAsset.assetId != null) - { + if (bodyAsset.assetId != null) { actionFinished = SpawnAsset( bodyAsset.assetId, "agentMesh", new Vector3(200f, 200f, 200f) ); spawnedMesh = GameObject.Find("agentMesh"); - } - else if (bodyAsset.dynamicAsset != null) - { + } else if (bodyAsset.dynamicAsset != null) { actionFinished = this.CreateRuntimeAsset( id: bodyAsset.dynamicAsset.id, dir: bodyAsset.dynamicAsset.dir, @@ -1082,9 +962,7 @@ private ActionFinished spawnBodyAsset(BodyAsset bodyAsset, out GameObject spawne serializable: true ); spawnedMesh = GameObject.Find("mesh"); - } - else if (bodyAsset.asset != null) - { + } else if (bodyAsset.asset != null) { bodyAsset.asset.serializable = true; actionFinished = this.CreateRuntimeAsset(asset: bodyAsset.asset); } @@ -1092,8 +970,7 @@ private ActionFinished spawnBodyAsset(BodyAsset bodyAsset, out GameObject spawne if ( bodyAsset.assetId == null && (bodyAsset.dynamicAsset != null || bodyAsset.asset != null) - ) - { + ) { var id = bodyAsset.dynamicAsset != null ? bodyAsset.dynamicAsset.id @@ -1101,8 +978,7 @@ private ActionFinished spawnBodyAsset(BodyAsset bodyAsset, out GameObject spawne Debug.Log( $"-- checks {bodyAsset.assetId == null} {bodyAsset.dynamicAsset != null} {bodyAsset.asset != null} " ); - if (!actionFinished.success || actionFinished.actionReturn == null) - { + if (!actionFinished.success || actionFinished.actionReturn == null) { return new ActionFinished( success: false, errorMessage: $"Could not create asset `{bodyAsset.dynamicAsset}` error: {actionFinished.errorMessage}" @@ -1115,8 +991,7 @@ private ActionFinished spawnBodyAsset(BodyAsset bodyAsset, out GameObject spawne return actionFinished; } - protected override LayerMask GetVisibilityRaycastLayerMask(bool withSimObjInvisible = false) - { + protected override LayerMask GetVisibilityRaycastLayerMask(bool withSimObjInvisible = false) { // No agent because camera can be in the path of colliders string[] layers = new string[] { @@ -1126,8 +1001,7 @@ protected override LayerMask GetVisibilityRaycastLayerMask(bool withSimObjInvisi "Procedural3", "Procedural0" //, "Agent" }; - if (withSimObjInvisible) - { + if (withSimObjInvisible) { layers = layers.Append("SimObjInvisible").ToArray(); } return LayerMask.GetMask(layers); @@ -1140,8 +1014,7 @@ public override void TeleportFull( float? horizon = null, bool? standing = null, bool forceAction = false - ) - { + ) { teleportFull( position: position, rotation: rotation, @@ -1155,8 +1028,7 @@ protected override void teleportFull( Vector3? rotation, float? horizon, bool forceAction - ) - { + ) { //Debug.Log($"what even is the position passed in at the start? {position:F8}"); if ( rotation.HasValue @@ -1164,8 +1036,7 @@ bool forceAction !Mathf.Approximately(rotation.Value.x, 0f) || !Mathf.Approximately(rotation.Value.z, 0f) ) - ) - { + ) { throw new ArgumentOutOfRangeException( "No agents currently can change in pitch or roll. So, you must set rotation(x=0, y=yaw, z=0)." + $" You gave {rotation.Value.ToString("F6")}." @@ -1177,8 +1048,7 @@ bool forceAction !forceAction && horizon.HasValue && (horizon.Value > maxDownwardLookAngle || horizon.Value < -maxUpwardLookAngle) - ) - { + ) { throw new ArgumentOutOfRangeException( $"Each horizon must be in [{-maxUpwardLookAngle}:{maxDownwardLookAngle}]. You gave {horizon}." ); @@ -1188,15 +1058,13 @@ bool forceAction !forceAction && position.HasValue && !agentManager.SceneBounds.Contains(position.Value) - ) - { + ) { throw new ArgumentOutOfRangeException( $"Teleport position {position.Value.ToString("F6")} out of scene bounds! Ignore this by setting forceAction=true." ); } - if (!forceAction && position.HasValue && !isPositionOnGrid(position.Value)) - { + if (!forceAction && position.HasValue && !isPositionOnGrid(position.Value)) { throw new ArgumentOutOfRangeException( $"Teleport position {position.Value.ToString("F6")} is not on the grid of size {gridSize}." ); @@ -1225,15 +1093,13 @@ bool forceAction targetPosition: position.GetValueOrDefault(transform.position) ); - if (!forceAction) - { + if (!forceAction) { if ( isAgentCapsuleColliding( collidersToIgnore: collidersToIgnoreDuringMovement, includeErrorMessage: true ) - ) - { + ) { transform.position = oldPosition; transform.rotation = oldRotation; autoSyncTransforms(); @@ -1247,8 +1113,7 @@ bool forceAction collidersToIgnore: collidersToIgnoreDuringMovement, includeErrorMessage: true ) - ) - { + ) { transform.position = oldPosition; transform.rotation = oldRotation; autoSyncTransforms(); @@ -1260,11 +1125,9 @@ bool forceAction actionFinished(success: true); } - protected override void assertTeleportedNearGround(Vector3? targetPosition) - { + protected override void assertTeleportedNearGround(Vector3? targetPosition) { // position should not change if it's null. - if (targetPosition == null) - { + if (targetPosition == null) { return; } @@ -1279,8 +1142,7 @@ protected override void assertTeleportedNearGround(Vector3? targetPosition) autoSyncTransforms(); // perhaps like y=2 was specified, with an agent's standing height of 0.9 - if (Mathf.Abs(transform.position.y - pos.y) > 1.0f) - { + if (Mathf.Abs(transform.position.y - pos.y) > 1.0f) { throw new InvalidOperationException( "After teleporting and adjusting agent position to floor, there was too large a change." + " This may be due to the target teleport coordinates causing the agent to fall through the floor." @@ -1294,10 +1156,8 @@ public IEnumerator MoveAgent( float ahead = 0, float right = 0, float speed = 1 - ) - { - if (ahead == 0 && right == 0) - { + ) { + if (ahead == 0 && right == 0) { throw new ArgumentException("Must specify ahead or right!"); } Vector3 direction = new Vector3(x: right, y: 0, z: ahead); @@ -1325,8 +1185,7 @@ public IEnumerator MoveAhead( float? moveMagnitude = null, float speed = 1, bool returnToStart = true - ) - { + ) { return MoveAgent( ahead: moveMagnitude.GetValueOrDefault(gridSize), speed: speed, @@ -1338,8 +1197,7 @@ public IEnumerator MoveBack( float? moveMagnitude = null, float speed = 1, bool returnToStart = true - ) - { + ) { return MoveAgent( ahead: -moveMagnitude.GetValueOrDefault(gridSize), speed: speed, @@ -1351,8 +1209,7 @@ public IEnumerator MoveRight( float? moveMagnitude = null, float speed = 1, bool returnToStart = true - ) - { + ) { return MoveAgent( right: moveMagnitude.GetValueOrDefault(gridSize), speed: speed, @@ -1364,8 +1221,7 @@ public IEnumerator MoveLeft( float? moveMagnitude = null, float speed = 1, bool returnToStart = true - ) - { + ) { return MoveAgent( right: -moveMagnitude.GetValueOrDefault(gridSize), speed: speed, @@ -1377,8 +1233,7 @@ public IEnumerator RotateRight( float? degrees = null, float speed = 1.0f, bool returnToStart = true - ) - { + ) { return RotateAgent( degrees: degrees.GetValueOrDefault(rotateStepDegrees), speed: speed, @@ -1390,8 +1245,7 @@ public IEnumerator RotateLeft( float? degrees = null, float speed = 1.0f, bool returnToStart = true - ) - { + ) { return RotateAgent( degrees: -degrees.GetValueOrDefault(rotateStepDegrees), speed: speed, @@ -1403,8 +1257,7 @@ public virtual IEnumerator RotateAgent( float degrees, float speed = 1.0f, bool returnToStart = true - ) - { + ) { CollisionListener collisionListener = fpinMovable.collisionListener; collisionListener.Reset(); diff --git a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs index 99854954b5..686c1ae06d 100644 --- a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs +++ b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs @@ -218,14 +218,13 @@ public IEnumerator TestGetVisibleObjectsFromCamera() action["thirdPartyCameraId"] = 0; yield return step(action); - List visibleObjects = (List) actionReturn; - #if UNITY_EDITOR - foreach(string obj in visibleObjects) + List visibleObjects = (List)actionReturn; +#if UNITY_EDITOR + foreach (string obj in visibleObjects) { Debug.Log(obj); - } - #endif +#endif //check for expected object at first few elements //also check for total count of visible objects to be the expected amount @@ -241,14 +240,13 @@ public IEnumerator TestGetVisibleObjectsFromCamera() yield return step(action); visibleObjects.Clear(); - visibleObjects = (List) actionReturn; - #if UNITY_EDITOR - foreach(string obj in visibleObjects) + visibleObjects = (List)actionReturn; +#if UNITY_EDITOR + foreach (string obj in visibleObjects) { Debug.Log(obj); - } - #endif +#endif Assert.AreEqual(visibleObjects.Count, 1); Assert.AreEqual(visibleObjects[0], "Apple|-00.47|+01.15|+00.48");