| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using DCL.Models; |
| | 5 | | using Newtonsoft.Json; |
| | 6 | | using NUnit.Framework; |
| | 7 | | using System.Collections; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.TestTools; |
| | 10 | | using UnityGLTF; |
| | 11 | |
|
| | 12 | | public class GLTFShape_Tests : IntegrationTestSuite_Legacy |
| | 13 | | { |
| | 14 | | [UnityTest] |
| | 15 | | public IEnumerator ShapeUpdate() |
| | 16 | | { |
| 1 | 17 | | string entityId = "1"; |
| 1 | 18 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| | 19 | |
|
| 1 | 20 | | Assert.IsTrue( |
| | 21 | | scene.entities[entityId].gameObject.GetComponentInChildren<UnityGLTF.InstantiatedGLTFObject>() == null, |
| | 22 | | "Since the shape hasn't been updated yet, the 'GLTFScene' child object shouldn't exist"); |
| | 23 | |
|
| 1 | 24 | | TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject( |
| | 25 | | new |
| | 26 | | { |
| | 27 | | src = TestAssetsUtils.GetPath() + "/GLB/Trunk/Trunk.glb" |
| | 28 | | })); |
| | 29 | |
|
| 1 | 30 | | LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]); |
| 7 | 31 | | yield return new WaitUntil(() => gltfShape.alreadyLoaded); |
| | 32 | |
|
| 1 | 33 | | Assert.IsTrue( |
| | 34 | | scene.entities[entityId].gameObject.GetComponentInChildren<UnityGLTF.InstantiatedGLTFObject>() != null, |
| | 35 | | "'GLTFScene' child object with 'InstantiatedGLTF' component should exist if the GLTF was loaded correctly"); |
| 1 | 36 | | } |
| | 37 | |
|
| | 38 | | [Test] |
| | 39 | | public void CustomContentProvider() |
| | 40 | | { |
| 1 | 41 | | string entityId = "1"; |
| 1 | 42 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| | 43 | |
|
| 1 | 44 | | string mockupAssetId = "cdd5a4ea94388dd21babdecd26dd560f739dce2fbb8c99cc10a45bb8306b6076"; |
| 1 | 45 | | string mockupKey = "key"; |
| 1 | 46 | | string mockupValue = "Value"; |
| | 47 | |
|
| 1 | 48 | | SceneAssetPack sceneAssetPack = new SceneAssetPack(); |
| 1 | 49 | | sceneAssetPack.assets = new System.Collections.Generic.List<SceneObject>(); |
| 1 | 50 | | sceneAssetPack.id = "mockupId"; |
| | 51 | |
|
| 1 | 52 | | SceneObject sceneObject = new SceneObject(); |
| 1 | 53 | | sceneObject.id = mockupAssetId; |
| 1 | 54 | | sceneObject.contents = new System.Collections.Generic.Dictionary<string, string>(); |
| 1 | 55 | | sceneObject.contents.Add(mockupKey, mockupValue); |
| | 56 | |
|
| 1 | 57 | | sceneAssetPack.assets.Add(sceneObject); |
| | 58 | |
|
| 1 | 59 | | AssetCatalogBridge.i.AddSceneAssetPackToCatalog(sceneAssetPack); |
| | 60 | |
|
| 1 | 61 | | TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject( |
| | 62 | | new |
| | 63 | | { |
| | 64 | | assetId = mockupAssetId, |
| | 65 | | src = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb" |
| | 66 | | })); |
| | 67 | |
|
| | 68 | |
|
| 1 | 69 | | LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]); |
| | 70 | |
|
| 1 | 71 | | if (!(gltfShape is LoadWrapper_GLTF)) |
| 0 | 72 | | Assert.Fail(); |
| | 73 | |
|
| | 74 | |
|
| 1 | 75 | | LoadWrapper_GLTF gltfWrapper = (LoadWrapper_GLTF) gltfShape; |
| 1 | 76 | | ContentProvider customContentProvider = AssetCatalogBridge.i.GetContentProviderForAssetIdInSceneObjectCatalog(mo |
| 1 | 77 | | Assert.AreEqual(customContentProvider.baseUrl, gltfWrapper.customContentProvider.baseUrl); |
| 1 | 78 | | Assert.AreEqual(mockupKey, gltfWrapper.customContentProvider.contents[0].file); |
| 1 | 79 | | Assert.AreEqual(mockupValue, gltfWrapper.customContentProvider.contents[0].hash); |
| 1 | 80 | | } |
| | 81 | |
|
| | 82 | | [UnityTest] |
| | 83 | | public IEnumerator PreExistentShapeUpdate() |
| | 84 | | { |
| 1 | 85 | | string entityId = "1"; |
| 1 | 86 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| | 87 | |
|
| 1 | 88 | | var componentId = TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.Ser |
| | 89 | | new |
| | 90 | | { |
| | 91 | | src = TestAssetsUtils.GetPath() + "/GLB/Trunk/Trunk.glb" |
| | 92 | | })); |
| | 93 | |
|
| 1 | 94 | | LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]); |
| 7 | 95 | | yield return new WaitUntil(() => gltfShape.alreadyLoaded); |
| | 96 | |
|
| | 97 | | { |
| 1 | 98 | | var gltfObject = scene.entities[entityId].gameObject.GetComponentInChildren<InstantiatedGLTFObject>(); |
| | 99 | |
|
| 1 | 100 | | Assert.IsTrue(gltfObject != null, "InstantiatedGLTFObject is null in first object!"); |
| 1 | 101 | | Assert.IsTrue(gltfObject.transform.Find("TreeStump_01") != null, "Can't find \"TreeStump_01!\""); |
| | 102 | | } |
| | 103 | |
|
| 1 | 104 | | TestHelpers.UpdateShape(scene, componentId, JsonConvert.SerializeObject( |
| | 105 | | new |
| | 106 | | { |
| | 107 | | src = TestAssetsUtils.GetPath() + "/GLB/PalmTree_01.glb" |
| | 108 | | })); |
| | 109 | |
|
| 1 | 110 | | gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]); |
| 7 | 111 | | yield return new WaitUntil(() => gltfShape.alreadyLoaded); |
| | 112 | |
|
| | 113 | | { |
| 1 | 114 | | var gltfObject = scene.entities[entityId].gameObject.GetComponentInChildren<InstantiatedGLTFObject>(); |
| | 115 | |
|
| 1 | 116 | | Assert.IsTrue(gltfObject != null, "InstantiatedGLTFObject is null in second object!"); |
| 1 | 117 | | Assert.IsTrue(gltfObject.transform.Find("PalmTree_01") != null, |
| | 118 | | "Can't find \"PalmTree_01\"!"); |
| | 119 | | } |
| 1 | 120 | | } |
| | 121 | |
|
| | 122 | | [UnityTest] |
| | 123 | | public IEnumerator PreExistentShapeImmediateUpdate() |
| | 124 | | { |
| 1 | 125 | | string entityId = "1"; |
| 1 | 126 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| | 127 | |
|
| 1 | 128 | | var componentId = TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.Ser |
| | 129 | | new |
| | 130 | | { |
| | 131 | | src = TestAssetsUtils.GetPath() + "/GLB/Trunk/Trunk.glb" |
| | 132 | | })); |
| | 133 | |
|
| 1 | 134 | | LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]); |
| 7 | 135 | | yield return new WaitUntil(() => gltfShape.alreadyLoaded); |
| | 136 | |
|
| 1 | 137 | | TestHelpers.UpdateShape(scene, componentId, JsonConvert.SerializeObject( |
| | 138 | | new |
| | 139 | | { |
| | 140 | | src = TestAssetsUtils.GetPath() + "/GLB/PalmTree_01.glb" |
| | 141 | | })); |
| | 142 | |
|
| 1 | 143 | | gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]); |
| 7 | 144 | | yield return new WaitUntil(() => gltfShape.alreadyLoaded); |
| | 145 | |
|
| 1 | 146 | | Assert.AreEqual(1, |
| | 147 | | scene.entities[entityId].gameObject.GetComponentsInChildren<InstantiatedGLTFObject>().Length, |
| | 148 | | "Only 1 'InstantiatedGLTFObject' should remain once the GLTF shape has been updated"); |
| 1 | 149 | | } |
| | 150 | |
|
| | 151 | | [UnityTest] |
| | 152 | | public IEnumerator AttachedGetsReplacedOnNewAttachment() |
| | 153 | | { |
| 1 | 154 | | var entity = TestHelpers.CreateSceneEntity(scene); |
| | 155 | |
|
| | 156 | | // set first GLTF |
| 1 | 157 | | string gltfId1 = TestHelpers.CreateAndSetShape(scene, entity.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, |
| | 158 | | JsonConvert.SerializeObject(new |
| | 159 | | { |
| | 160 | | src = TestAssetsUtils.GetPath() + "/GLB/PalmTree_01.glb" |
| | 161 | | })); |
| 1 | 162 | | var gltf1 = scene.GetSharedComponent(gltfId1); |
| | 163 | |
|
| 1 | 164 | | LoadWrapper gltfLoader = GLTFShape.GetLoaderForEntity(entity); |
| 7 | 165 | | yield return new WaitUntil(() => gltfLoader.alreadyLoaded); |
| | 166 | |
|
| 1 | 167 | | Assert.AreEqual(gltf1, entity.GetSharedComponent(typeof(BaseShape))); |
| | 168 | |
|
| | 169 | | // set second GLTF |
| 1 | 170 | | string gltfId2 = TestHelpers.CreateAndSetShape(scene, entity.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, |
| | 171 | | JsonConvert.SerializeObject(new |
| | 172 | | { |
| | 173 | | src = TestAssetsUtils.GetPath() + "/GLB/Trunk/Trunk.glb" |
| | 174 | | })); |
| | 175 | |
|
| 1 | 176 | | gltfLoader = GLTFShape.GetLoaderForEntity(entity); |
| 7 | 177 | | yield return new WaitUntil(() => gltfLoader.alreadyLoaded); |
| | 178 | |
|
| 1 | 179 | | Assert.AreEqual(scene.GetSharedComponent(gltfId2), entity.GetSharedComponent(typeof(BaseShape))); |
| 1 | 180 | | Assert.IsFalse(gltf1.GetAttachedEntities().Contains(entity)); |
| 1 | 181 | | } |
| | 182 | |
|
| | 183 | | // NOTE: Since every deployed scene carries compiled core code of the sdk at the moment of deploying, most of them h |
| | 184 | | // different than the new default value, that's why we are forcing the colliders to be ON on EVERY GLTF until that g |
| | 185 | | [UnityTest] |
| | 186 | | [Explicit] |
| | 187 | | [Category("Explicit")] |
| | 188 | | public IEnumerator CollisionProperty() |
| | 189 | | { |
| 0 | 190 | | string entityId = "entityId"; |
| 0 | 191 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| 0 | 192 | | var entity = scene.entities[entityId]; |
| 0 | 193 | | yield return null; |
| | 194 | |
|
| | 195 | | // Create shape component |
| 0 | 196 | | var shapeModel = new LoadableShape<LoadWrapper_GLTF, LoadableShape.Model>.Model(); |
| 0 | 197 | | shapeModel.src = TestAssetsUtils.GetPath() + "/GLB/PalmTree_01.glb"; |
| | 198 | |
|
| 0 | 199 | | var shapeComponent = TestHelpers.SharedComponentCreate<LoadableShape<LoadWrapper_GLTF, LoadableShape.Model>, Loa |
| 0 | 200 | | yield return shapeComponent.routine; |
| | 201 | |
|
| 0 | 202 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 203 | |
|
| 0 | 204 | | var shapeLoader = GLTFShape.GetLoaderForEntity(entity); |
| 0 | 205 | | yield return new WaitUntil(() => shapeLoader.alreadyLoaded); |
| | 206 | |
|
| 0 | 207 | | yield return TestHelpers.TestShapeCollision(shapeComponent, shapeModel, entity); |
| 0 | 208 | | } |
| | 209 | |
|
| | 210 | | [UnityTest] |
| | 211 | | [Explicit] |
| | 212 | | [Category("Explicit")] |
| | 213 | | public IEnumerator VisibleProperty() |
| | 214 | | { |
| 0 | 215 | | string entityId = "entityId"; |
| 0 | 216 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| 0 | 217 | | var entity = scene.entities[entityId]; |
| 0 | 218 | | yield return null; |
| | 219 | |
|
| | 220 | | // Create shape component |
| 0 | 221 | | var shapeModel = new LoadableShape<LoadWrapper_GLTF, LoadableShape.Model>.Model(); |
| 0 | 222 | | shapeModel.src = TestAssetsUtils.GetPath() + "/GLB/PalmTree_01.glb"; |
| | 223 | |
|
| 0 | 224 | | var shapeComponent = TestHelpers.SharedComponentCreate<LoadableShape<LoadWrapper_GLTF, LoadableShape.Model>, Loa |
| 0 | 225 | | yield return shapeComponent.routine; |
| | 226 | |
|
| 0 | 227 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 228 | |
|
| 0 | 229 | | var shapeLoader = GLTFShape.GetLoaderForEntity(entity); |
| 0 | 230 | | yield return new WaitUntil(() => shapeLoader.alreadyLoaded); |
| | 231 | |
|
| 0 | 232 | | yield return TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity); |
| 0 | 233 | | } |
| | 234 | |
|
| | 235 | | [Test] |
| | 236 | | public void OnReadyBeforeLoading() |
| | 237 | | { |
| 1 | 238 | | GLTFShape gltfShape = TestHelpers.CreateEntityWithGLTFShape(scene, Vector3.zero, TestAssetsUtils.GetPath() + "/G |
| | 239 | |
|
| 1 | 240 | | bool isOnReady = false; |
| 1 | 241 | | gltfShape.CallWhenReady((x) => { isOnReady = true; }); |
| | 242 | |
|
| 1 | 243 | | Assert.IsFalse(isOnReady); |
| 1 | 244 | | } |
| | 245 | |
|
| | 246 | | [UnityTest] |
| | 247 | | public IEnumerator OnReadyWaitLoading() |
| | 248 | | { |
| 1 | 249 | | GLTFShape gltfShape = TestHelpers.CreateEntityWithGLTFShape(scene, Vector3.zero, TestAssetsUtils.GetPath() + "/G |
| | 250 | |
|
| 1 | 251 | | bool isOnReady = false; |
| 3 | 252 | | gltfShape.CallWhenReady((x) => { isOnReady = true; }); |
| 1 | 253 | | yield return TestHelpers.WaitForGLTFLoad(entity); |
| | 254 | |
|
| 1 | 255 | | Assert.IsTrue(isOnReady); |
| 1 | 256 | | } |
| | 257 | |
|
| | 258 | | [Test] |
| | 259 | | [Explicit] |
| | 260 | | [Category("Explicit")] |
| | 261 | | public void OnReadyWithoutAttachInstantlyCalled() |
| | 262 | | { |
| 0 | 263 | | GLTFShape gltfShape = TestHelpers.SharedComponentCreate<GLTFShape, GLTFShape.Model>(scene, CLASS_ID.GLTF_SHAPE, |
| | 264 | | { |
| | 265 | | src = TestAssetsUtils.GetPath() + "/GLB/Trevor/Trevor.glb" |
| | 266 | | }); |
| | 267 | |
|
| 0 | 268 | | bool isOnReady = false; |
| 0 | 269 | | gltfShape.CallWhenReady((x) => { isOnReady = true; }); |
| | 270 | |
|
| 0 | 271 | | Assert.IsTrue(isOnReady); |
| 0 | 272 | | } |
| | 273 | |
|
| | 274 | | [UnityTest] |
| | 275 | | public IEnumerator OnReadyAfterLoadingInstantlyCalled() |
| | 276 | | { |
| 1 | 277 | | GLTFShape gltfShape = TestHelpers.CreateEntityWithGLTFShape(scene, Vector3.zero, TestAssetsUtils.GetPath() + "/G |
| 1 | 278 | | yield return TestHelpers.WaitForGLTFLoad(entity); |
| | 279 | |
|
| 1 | 280 | | bool isOnReady = false; |
| 3 | 281 | | gltfShape.CallWhenReady((x) => { isOnReady = true; }); |
| 1 | 282 | | Assert.IsTrue(isOnReady); |
| 1 | 283 | | } |
| | 284 | |
|
| | 285 | | [UnityTest] |
| | 286 | | public IEnumerator OnDestroyWhileLoading() |
| | 287 | | { |
| 1 | 288 | | GLTFShape gltfShape = TestHelpers.CreateEntityWithGLTFShape(scene, Vector3.zero, TestAssetsUtils.GetPath() + "/G |
| 1 | 289 | | GLTFShape gltfShape2 = TestHelpers.CreateEntityWithGLTFShape(scene, Vector3.zero, TestAssetsUtils.GetPath() + "/ |
| 1 | 290 | | GLTFShape gltfShape3 = TestHelpers.CreateEntityWithGLTFShape(scene, Vector3.zero, TestAssetsUtils.GetPath() + "/ |
| | 291 | |
|
| 1 | 292 | | TestHelpers.SetEntityParent(scene, entity2, entity); |
| 1 | 293 | | TestHelpers.SetEntityParent(scene, entity3, entity); |
| | 294 | |
|
| 1 | 295 | | yield return null; |
| 1 | 296 | | yield return null; |
| 1 | 297 | | yield return null; |
| | 298 | |
|
| 1 | 299 | | Object.Destroy(entity.gameObject); |
| | 300 | |
|
| 1 | 301 | | yield return null; |
| 1 | 302 | | } |
| | 303 | | } |