| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Models; |
| | 6 | | using Newtonsoft.Json; |
| | 7 | | using NUnit.Framework; |
| | 8 | | using System.Collections; |
| | 9 | | using System.Linq; |
| | 10 | | using UnityEngine; |
| | 11 | |
|
| | 12 | | namespace SceneBoundariesCheckerTests |
| | 13 | | { |
| | 14 | | public static class SBC_Asserts |
| | 15 | | { |
| | 16 | | public static IEnumerator EntitiesAreBeingCorrectlyRegistered(ParcelScene scene) |
| | 17 | | { |
| 1 | 18 | | var boxShape1 = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(20, 2, 20)); |
| 1 | 19 | | var boxShape2 = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(20, 2, 20)); |
| | 20 | |
|
| 1 | 21 | | var entity1 = boxShape1.attachedEntities.First(); |
| 1 | 22 | | var entity2 = boxShape2.attachedEntities.First(); |
| | 23 | |
|
| 1 | 24 | | TestHelpers.SetEntityParent(scene, entity1, entity2); |
| | 25 | |
|
| 1 | 26 | | Assert.AreEqual(2, scene.entities.Count, "scene entities count can't be zero!"); |
| 1 | 27 | | Assert.AreEqual(2, Environment.i.world.sceneBoundsChecker.entitiesToCheckCount, "entities to check can't be |
| | 28 | |
|
| 1 | 29 | | yield return null; |
| | 30 | |
|
| 1 | 31 | | TestHelpers.RemoveSceneEntity(scene, entity2.entityId); |
| | 32 | |
|
| 1 | 33 | | Environment.i.platform.parcelScenesCleaner.ForceCleanup(); |
| | 34 | |
|
| 1 | 35 | | Assert.AreEqual(0, scene.entities.Count, "entity count should be zero"); |
| 1 | 36 | | Assert.AreEqual(0, Environment.i.world.sceneBoundsChecker.entitiesToCheckCount, "entities to check should be |
| 1 | 37 | | } |
| | 38 | |
|
| | 39 | | public static IEnumerator PShapeIsInvalidatedWhenStartingOutOfBounds(ParcelScene scene) |
| | 40 | | { |
| 2 | 41 | | var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(20, 2, 20)); |
| 2 | 42 | | yield return null; |
| | 43 | |
|
| 2 | 44 | | AssertMeshIsInvalid(boxShape.attachedEntities.First().meshesInfo); |
| 2 | 45 | | } |
| | 46 | |
|
| | 47 | | public static IEnumerator GLTFShapeIsInvalidatedWhenStartingOutOfBounds(ParcelScene scene) |
| | 48 | | { |
| 2 | 49 | | var entity = TestHelpers.CreateSceneEntity(scene); |
| | 50 | |
|
| 2 | 51 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) }); |
| | 52 | |
|
| 2 | 53 | | TestHelpers.CreateAndSetShape(scene, entity.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeO |
| | 54 | | new |
| | 55 | | { |
| | 56 | | src = TestAssetsUtils.GetPath() + "/GLB/PalmTree_01.glb" |
| | 57 | | })); |
| 2 | 58 | | LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity); |
| 14 | 59 | | yield return new UnityEngine.WaitUntil(() => gltfShape.alreadyLoaded); |
| 2 | 60 | | yield return null; |
| | 61 | |
|
| 2 | 62 | | AssertMeshIsInvalid(entity.meshesInfo); |
| 2 | 63 | | } |
| | 64 | |
|
| | 65 | | public static IEnumerator NFTShapeIsInvalidatedWhenStartingOutOfBounds(ParcelScene scene) |
| | 66 | | { |
| 0 | 67 | | var entity = TestHelpers.CreateSceneEntity(scene); |
| | 68 | |
|
| 0 | 69 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) }); |
| | 70 | |
|
| 0 | 71 | | var componentModel = new NFTShape.Model() |
| | 72 | | { |
| | 73 | | src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536" |
| | 74 | | }; |
| 0 | 75 | | NFTShape component = TestHelpers.SharedComponentCreate<NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, |
| 0 | 76 | | yield return component.routine; |
| | 77 | |
|
| 0 | 78 | | TestHelpers.SharedComponentAttach(component, entity); |
| | 79 | |
|
| 0 | 80 | | yield return null; |
| | 81 | |
|
| 0 | 82 | | LoadWrapper shapeLoader = NFTShape.GetLoaderForEntity(entity); |
| 0 | 83 | | yield return new UnityEngine.WaitUntil(() => shapeLoader.alreadyLoaded); |
| | 84 | |
|
| 0 | 85 | | yield return null; |
| | 86 | |
|
| 0 | 87 | | AssertMeshIsInvalid(entity.meshesInfo); |
| 0 | 88 | | } |
| | 89 | |
|
| | 90 | | public static IEnumerator PShapeIsInvalidatedWhenLeavingBounds(ParcelScene scene) |
| | 91 | | { |
| 2 | 92 | | var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(8, 1, 8)); |
| 2 | 93 | | yield return null; |
| | 94 | |
|
| 2 | 95 | | var entity = boxShape.attachedEntities.First(); |
| | 96 | |
|
| 2 | 97 | | AssertMeshIsValid(entity.meshesInfo); |
| | 98 | |
|
| | 99 | | // Move object to surpass the scene boundaries |
| 2 | 100 | | var transformModel = new DCLTransform.Model { position = new Vector3(18, 1, 18) }; |
| 2 | 101 | | TestHelpers.SetEntityTransform(scene, entity, transformModel); |
| | 102 | |
|
| 2 | 103 | | yield return null; |
| 2 | 104 | | yield return null; |
| | 105 | |
|
| 2 | 106 | | AssertMeshIsInvalid(entity.meshesInfo); |
| 2 | 107 | | } |
| | 108 | |
|
| | 109 | | public static IEnumerator GLTFShapeIsInvalidatedWhenLeavingBounds(ParcelScene scene) |
| | 110 | | { |
| 2 | 111 | | var entity = TestHelpers.CreateSceneEntity(scene); |
| | 112 | |
|
| 2 | 113 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) }); |
| | 114 | |
|
| 2 | 115 | | TestHelpers.CreateAndSetShape(scene, entity.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeO |
| | 116 | | new |
| | 117 | | { |
| | 118 | | src = TestAssetsUtils.GetPath() + "/GLB/PalmTree_01.glb" |
| | 119 | | })); |
| 2 | 120 | | LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity); |
| 14 | 121 | | yield return new UnityEngine.WaitUntil(() => gltfShape.alreadyLoaded); |
| | 122 | |
|
| 2 | 123 | | AssertMeshIsValid(entity.meshesInfo); |
| | 124 | |
|
| | 125 | | // Move object to surpass the scene boundaries |
| 2 | 126 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) }); |
| | 127 | |
|
| 2 | 128 | | yield return null; |
| 2 | 129 | | yield return null; |
| | 130 | |
|
| 2 | 131 | | AssertMeshIsInvalid(entity.meshesInfo); |
| 2 | 132 | | } |
| | 133 | |
|
| | 134 | | public static IEnumerator NFTShapeIsInvalidatedWhenLeavingBounds(ParcelScene scene) |
| | 135 | | { |
| 0 | 136 | | var entity = TestHelpers.CreateSceneEntity(scene); |
| | 137 | |
|
| 0 | 138 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) }); |
| | 139 | |
|
| 0 | 140 | | var componentModel = new NFTShape.Model() |
| | 141 | | { |
| | 142 | | src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536" |
| | 143 | | }; |
| 0 | 144 | | NFTShape component = TestHelpers.SharedComponentCreate<NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, |
| 0 | 145 | | yield return component.routine; |
| | 146 | |
|
| 0 | 147 | | TestHelpers.SharedComponentAttach(component, entity); |
| | 148 | |
|
| 0 | 149 | | yield return null; |
| | 150 | |
|
| 0 | 151 | | LoadWrapper shapeLoader = NFTShape.GetLoaderForEntity(entity); |
| 0 | 152 | | yield return new UnityEngine.WaitUntil(() => shapeLoader.alreadyLoaded); |
| | 153 | |
|
| 0 | 154 | | AssertMeshIsValid(entity.meshesInfo); |
| | 155 | |
|
| | 156 | | // Move object to surpass the scene boundaries |
| 0 | 157 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) }); |
| | 158 | |
|
| 0 | 159 | | yield return null; |
| | 160 | |
|
| 0 | 161 | | AssertMeshIsInvalid(entity.meshesInfo); |
| 0 | 162 | | } |
| | 163 | |
|
| | 164 | | public static IEnumerator HeightIsEvaluated(ParcelScene scene) |
| | 165 | | { |
| 2 | 166 | | var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(8, 5, 8)); |
| 2 | 167 | | var entity = boxShape.attachedEntities.First(); |
| 2 | 168 | | yield return null; |
| | 169 | |
|
| 2 | 170 | | AssertMeshIsValid(entity.meshesInfo); |
| | 171 | |
|
| | 172 | | // Move object to surpass the scene height boundaries |
| 2 | 173 | | var transformModel = new DCLTransform.Model { position = new Vector3(8, 30, 8) }; |
| 2 | 174 | | TestHelpers.SetEntityTransform(scene, entity, transformModel); |
| | 175 | |
|
| 2 | 176 | | yield return null; |
| 2 | 177 | | yield return null; |
| | 178 | |
|
| 2 | 179 | | AssertMeshIsInvalid(entity.meshesInfo); |
| 2 | 180 | | } |
| | 181 | |
|
| | 182 | | public static IEnumerator ChildShapeIsEvaluated(ParcelScene scene) |
| | 183 | | { |
| 2 | 184 | | string entityId = "1"; |
| 2 | 185 | | TestHelpers.InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(8, 1, 8)) |
| 2 | 186 | | yield return null; |
| | 187 | |
|
| 2 | 188 | | AssertMeshIsValid(scene.entities[entityId].meshesInfo); |
| | 189 | |
|
| | 190 | | // Attach child |
| 2 | 191 | | string childEntityId = "2"; |
| 2 | 192 | | TestHelpers.InstantiateEntityWithShape(scene, childEntityId, DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(8, 1 |
| 2 | 193 | | yield return null; |
| | 194 | |
|
| 2 | 195 | | AssertMeshIsValid(scene.entities[childEntityId].meshesInfo); |
| | 196 | |
|
| 2 | 197 | | TestHelpers.SetEntityParent(scene, childEntityId, entityId); |
| | 198 | |
|
| | 199 | | // Move parent object to surpass the scene boundaries |
| 2 | 200 | | var transformModel = new DCLTransform.Model { position = new Vector3(18, 1, 18) }; |
| 2 | 201 | | TestHelpers.SetEntityTransform(scene, scene.entities[entityId], transformModel); |
| | 202 | |
|
| 2 | 203 | | yield return null; |
| 2 | 204 | | yield return null; |
| | 205 | |
|
| 2 | 206 | | AssertMeshIsInvalid(scene.entities[childEntityId].meshesInfo); |
| 2 | 207 | | } |
| | 208 | |
|
| | 209 | | public static IEnumerator ChildShapeIsEvaluatedOnShapelessParent(ParcelScene scene) |
| | 210 | | { |
| | 211 | | // create shapeless parent entity |
| 2 | 212 | | string entityId = "1"; |
| 2 | 213 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| 2 | 214 | | TestHelpers.SetEntityTransform(scene, scene.entities[entityId], new Vector3(18, 1, 18), Quaternion.identity, |
| 2 | 215 | | yield return null; |
| | 216 | |
|
| 2 | 217 | | AssertMeshIsValid(scene.entities[entityId].meshesInfo); |
| | 218 | |
|
| | 219 | | // Attach child |
| 2 | 220 | | string childEntityId = "2"; |
| 2 | 221 | | TestHelpers.InstantiateEntityWithShape(scene, childEntityId, DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(0, 0 |
| 2 | 222 | | yield return null; |
| | 223 | |
|
| 2 | 224 | | TestHelpers.SetEntityParent(scene, childEntityId, entityId); |
| 2 | 225 | | yield return null; |
| | 226 | |
|
| 2 | 227 | | AssertMeshIsInvalid(scene.entities[childEntityId].meshesInfo); |
| | 228 | |
|
| | 229 | | // Move parent object to re-enter the scene boundaries |
| 2 | 230 | | TestHelpers.SetEntityTransform(scene, scene.entities[entityId], new Vector3(8, 1, 8), Quaternion.identity, V |
| | 231 | |
|
| 2 | 232 | | yield return null; |
| 2 | 233 | | yield return null; |
| | 234 | |
|
| 2 | 235 | | AssertMeshIsValid(scene.entities[childEntityId].meshesInfo); |
| 2 | 236 | | } |
| | 237 | |
|
| | 238 | | public static IEnumerator PShapeIsResetWhenReenteringBounds(ParcelScene scene) |
| | 239 | | { |
| 2 | 240 | | var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(18, 1, 18)); |
| 2 | 241 | | yield return null; |
| | 242 | |
|
| 2 | 243 | | var entity = boxShape.attachedEntities.First(); |
| 2 | 244 | | yield return null; |
| | 245 | |
|
| 2 | 246 | | AssertMeshIsInvalid(entity.meshesInfo); |
| | 247 | |
|
| | 248 | | // Move object to re-enter the scene boundaries |
| 2 | 249 | | var transformModel = new DCLTransform.Model { position = new Vector3(8, 1, 8) }; |
| 2 | 250 | | TestHelpers.SetEntityTransform(scene, entity, transformModel); |
| | 251 | |
|
| 2 | 252 | | yield return null; |
| | 253 | |
|
| 2 | 254 | | AssertMeshIsValid(entity.meshesInfo); |
| 2 | 255 | | } |
| | 256 | |
|
| | 257 | | public static IEnumerator GLTFShapeIsResetWhenReenteringBounds(ParcelScene scene) |
| | 258 | | { |
| 1 | 259 | | var entity = TestHelpers.CreateSceneEntity(scene); |
| | 260 | |
|
| 1 | 261 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) }); |
| | 262 | |
|
| 1 | 263 | | TestHelpers.CreateAndSetShape(scene, entity.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeO |
| | 264 | | new |
| | 265 | | { |
| | 266 | | src = TestAssetsUtils.GetPath() + "/GLB/PalmTree_01.glb" |
| | 267 | | })); |
| 1 | 268 | | LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity); |
| 7 | 269 | | yield return new UnityEngine.WaitUntil(() => gltfShape.alreadyLoaded); |
| 1 | 270 | | yield return null; |
| | 271 | |
|
| 1 | 272 | | AssertMeshIsInvalid(entity.meshesInfo); |
| | 273 | |
|
| | 274 | | // Move object to surpass the scene boundaries |
| 1 | 275 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) }); |
| | 276 | |
|
| 1 | 277 | | yield return null; |
| 1 | 278 | | yield return null; |
| | 279 | |
|
| 1 | 280 | | AssertMeshIsValid(entity.meshesInfo); |
| 1 | 281 | | } |
| | 282 | |
|
| | 283 | | public static IEnumerator NFTShapeIsResetWhenReenteringBounds(ParcelScene scene) |
| | 284 | | { |
| 0 | 285 | | var entity = TestHelpers.CreateSceneEntity(scene); |
| | 286 | |
|
| 0 | 287 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) }); |
| | 288 | |
|
| 0 | 289 | | var componentModel = new NFTShape.Model() |
| | 290 | | { |
| | 291 | | src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536" |
| | 292 | | }; |
| 0 | 293 | | NFTShape component = TestHelpers.SharedComponentCreate<NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, |
| 0 | 294 | | yield return component.routine; |
| | 295 | |
|
| 0 | 296 | | TestHelpers.SharedComponentAttach(component, entity); |
| | 297 | |
|
| 0 | 298 | | yield return null; |
| | 299 | |
|
| 0 | 300 | | LoadWrapper shapeLoader = NFTShape.GetLoaderForEntity(entity); |
| 0 | 301 | | yield return new UnityEngine.WaitUntil(() => shapeLoader.alreadyLoaded); |
| | 302 | |
|
| 0 | 303 | | AssertMeshIsInvalid(entity.meshesInfo); |
| | 304 | |
|
| | 305 | | // Move object to surpass the scene boundaries |
| 0 | 306 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) }); |
| | 307 | |
|
| 0 | 308 | | yield return null; |
| | 309 | |
|
| 0 | 310 | | AssertMeshIsValid(entity.meshesInfo); |
| 0 | 311 | | } |
| | 312 | |
|
| | 313 | | public static void AssertMeshIsInvalid(MeshesInfo meshesInfo) |
| | 314 | | { |
| 18 | 315 | | Assert.IsTrue(meshesInfo.meshRootGameObject != null, "MeshRootGameObject is null. The object is valid when i |
| | 316 | |
|
| 18 | 317 | | if (Environment.i.world.sceneBoundsChecker.GetFeedbackStyle() is SceneBoundsFeedbackStyle_RedFlicker) |
| | 318 | | { |
| 40 | 319 | | for (int i = 0; i < meshesInfo.renderers.Length; i++) |
| | 320 | | { |
| 10 | 321 | | string matName = meshesInfo.renderers[i].sharedMaterial.name; |
| 10 | 322 | | Assert.IsTrue(matName.Contains("Invalid"), $"Material should be Invalid. Material is: {matName}"); |
| | 323 | | } |
| 10 | 324 | | } |
| | 325 | | else |
| | 326 | | { |
| 32 | 327 | | for (int i = 0; i < meshesInfo.renderers.Length; i++) |
| | 328 | | { |
| 8 | 329 | | Assert.IsFalse(meshesInfo.renderers[i].enabled, $"Renderer {meshesInfo.renderers[i].gameObject.name} |
| | 330 | | } |
| | 331 | |
|
| 32 | 332 | | for (int i = 0; i < meshesInfo.colliders.Count; i++) |
| | 333 | | { |
| 8 | 334 | | Assert.IsFalse(meshesInfo.colliders[i].enabled, $"Collider {meshesInfo.renderers[i].gameObject.name} |
| | 335 | | } |
| | 336 | | } |
| 8 | 337 | | } |
| | 338 | |
|
| | 339 | | public static void AssertMeshIsValid(MeshesInfo meshesInfo) |
| | 340 | | { |
| 19 | 341 | | if (meshesInfo.meshRootGameObject == null) |
| 2 | 342 | | return; // It's valid if there's no mesh |
| | 343 | |
|
| 17 | 344 | | if (Environment.i.world.sceneBoundsChecker.GetFeedbackStyle() is SceneBoundsFeedbackStyle_RedFlicker) |
| | 345 | | { |
| 40 | 346 | | for (int i = 0; i < meshesInfo.renderers.Length; i++) |
| | 347 | | { |
| 10 | 348 | | string matName = meshesInfo.renderers[i].sharedMaterial.name; |
| 10 | 349 | | Assert.IsFalse(matName.Contains("Invalid"), $"Material shouldn't be invalid. Material is: {matName}" |
| | 350 | | } |
| 10 | 351 | | } |
| | 352 | | else |
| | 353 | | { |
| 28 | 354 | | for (int i = 0; i < meshesInfo.renderers.Length; i++) |
| | 355 | | { |
| 7 | 356 | | Assert.IsTrue(meshesInfo.renderers[i].enabled, $"Renderer {meshesInfo.renderers[i].gameObject.name} |
| | 357 | | } |
| | 358 | |
|
| 28 | 359 | | for (int i = 0; i < meshesInfo.colliders.Count; i++) |
| | 360 | | { |
| 7 | 361 | | Assert.IsTrue(meshesInfo.colliders[i].enabled, $"Collider {meshesInfo.renderers[i].gameObject.name} |
| | 362 | | } |
| | 363 | | } |
| 7 | 364 | | } |
| | 365 | | } |
| | 366 | | } |