public IEnumerator OBJShapeUpdate() { string entityId = "1"; TestHelpers.CreateSceneEntity(scene, entityId); Material placeholderLoadingMaterial = Resources.Load <Material>("Materials/AssetLoading"); yield return(null); Assert.IsTrue(scene.entities[entityId].meshRootGameObject == null, "Since the shape hasn't been updated yet, the child mesh shouldn't exist"); TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.OBJ_SHAPE, JsonConvert.SerializeObject( new { src = Utils.GetTestsAssetsPath() + "/OBJ/teapot.obj" })); LoadWrapper objShape = LoadableShape.GetLoaderForEntity(scene.entities[entityId]); yield return(new WaitUntil(() => objShape.alreadyLoaded)); Assert.IsTrue(scene.entities[entityId].meshRootGameObject != null, "Every entity with a shape should have the mandatory 'Mesh' object as a child"); var childRenderer = scene.entities[entityId].meshRootGameObject.GetComponentInChildren <MeshRenderer>(); Assert.IsTrue(childRenderer != null, "Since the shape has already been updated, the child renderer should exist"); Assert.AreNotSame(placeholderLoadingMaterial, childRenderer.sharedMaterial, "Since the shape has already been updated, the child renderer found shouldn't have the 'AssetLoading' placeholder material"); }
public IEnumerator VisibleProperty() { string entityId = "entityId"; TestHelpers.CreateSceneEntity(scene, entityId); var entity = scene.entities[entityId]; yield return(null); // Create shape component var shapeModel = new LoadableShape <LoadWrapper_GLTF, LoadableShape.Model> .Model(); shapeModel.src = Utils.GetTestsAssetsPath() + "/GLB/PalmTree_01.glb"; var shapeComponent = TestHelpers.SharedComponentCreate <LoadableShape <LoadWrapper_GLTF, LoadableShape.Model>, LoadableShape <LoadWrapper_GLTF, LoadableShape.Model> .Model>(scene, CLASS_ID.GLTF_SHAPE, shapeModel); yield return(shapeComponent.routine); TestHelpers.SharedComponentAttach(shapeComponent, entity); var shapeLoader = GLTFShape.GetLoaderForEntity(entity); yield return(new WaitUntil(() => shapeLoader.alreadyLoaded)); yield return(TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity)); }
IEnumerator InstantiateNFTShape(Vector3 position, int styleIndex) { var entity = TestHelpers.CreateSceneEntity(scene); TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = position }); yield return(null); var componentModel = new NFTShape.Model() { src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536", color = Color.gray, style = styleIndex }; NFTShape component = TestHelpers.SharedComponentCreate <NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, componentModel); yield return(component.routine); TestHelpers.SharedComponentAttach(component, entity); // Override texture with a local test one var nftShape = LoadableShape.GetLoaderForEntity(entity) as LoadWrapper_NFT; nftShape.loaderController.UpdateTexture(Resources.Load <Texture2D>("TestTexture")); nftShape.loaderController.transform.localScale = new Vector3(1.5f, 1.5f, 1f); }
public IEnumerator VisibleProperty() { string entityId = "entityId"; TestHelpers.CreateSceneEntity(scene, entityId); var entity = scene.entities[entityId]; yield return(null); // Create shape component var shapeModel = new LoadableShape <LoadWrapper_NFT, NFTShape.Model> .Model(); shapeModel.src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536"; var shapeComponent = TestHelpers.SharedComponentCreate <LoadableShape <LoadWrapper_NFT, NFTShape.Model>, LoadableShape <LoadWrapper_NFT, NFTShape.Model> .Model>(scene, CLASS_ID.NFT_SHAPE, shapeModel); yield return(shapeComponent.routine); TestHelpers.SharedComponentAttach(shapeComponent, entity); var shapeLoader = entity.gameObject.GetComponentInChildren <LoadWrapper_NFT>(true); yield return(new WaitUntil(() => shapeLoader.alreadyLoaded)); yield return(TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity)); }
public IEnumerator ShapeUpdate() { string entityId = "1"; TestHelpers.CreateSceneEntity(scene, entityId); var entity = scene.entities[entityId]; Assert.IsTrue(entity.meshRootGameObject == null, "entity mesh object should be null as the NFTShape hasn't been initialized yet"); var componentModel = new NFTShape.Model() { src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536" }; NFTShape component = TestHelpers.SharedComponentCreate <NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, componentModel); yield return(component.routine); TestHelpers.SharedComponentAttach(component, entity); Assert.IsTrue(entity.meshRootGameObject != null, "entity mesh object should already exist as the NFTShape already initialized"); var nftShape = LoadableShape.GetLoaderForEntity(entity) as LoadWrapper_NFT; var backgroundMaterial = nftShape.loaderController.backgroundMaterial; Assert.IsTrue(backgroundMaterial.GetColor("_BaseColor") == new Color(0.6404918f, 0.611472f, 0.8584906f), "The NFT frame background color should be the default one"); // Update color and check if it changed componentModel.color = Color.yellow; yield return(TestHelpers.SharedComponentUpdate(component, componentModel)); Assert.AreEqual(Color.yellow, backgroundMaterial.GetColor("_BaseColor"), "The NFT frame background color should be yellow"); }
public IEnumerator NotLeaveCollidersOnRecycledMeshes() { // 1. Instantiate entity and add an OnPointerDown component string entity1Id = "1"; var entity1 = TestHelpers.CreateSceneEntity(scene, entity1Id); string onPointerId = "pointerevent-1"; var onPointerEventModel = new OnPointerDown.Model() { type = OnPointerDown.NAME, uuid = onPointerId }; var onPointerDownComponent = TestHelpers.EntityComponentCreate <OnPointerDown, OnPointerDown.Model>(scene, entity1, onPointerEventModel, CLASS_ID_COMPONENT.UUID_CALLBACK); // 2. Attach a shape var shapeModel = new LoadableShape <LoadWrapper_GLTF, LoadableShape.Model> .Model(); shapeModel.src = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb"; var shapeComponentId = TestHelpers.CreateAndSetShape(scene, entity1Id, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject(shapeModel)); LoadWrapper gltfShapeLoader1 = GLTFShape.GetLoaderForEntity(scene.entities[entity1Id]); yield return(new WaitUntil(() => gltfShapeLoader1.alreadyLoaded)); yield return(null); // 3. Save the mesh GO reference Transform shapeInstanceRootTransform = entity1.meshRootGameObject.transform.GetChild(0); Debug.Log("saved mesh GO: ", shapeInstanceRootTransform); // 4. Remove shape so that it returns to its pool entity1.RemoveSharedComponent(typeof(BaseShape)); yield return(null); // 5. Check that the pooled mesh doesn't have the collider children and the onPointerEvent component // doesn't have any instantiated collider (since its entity doesn't have a mesh now) var childMeshColliders = shapeInstanceRootTransform.GetComponentsInChildren <MeshCollider>(true); foreach (MeshCollider collider in childMeshColliders) { Assert.IsTrue(collider.gameObject.layer != PhysicsLayers.onPointerEventLayer); } Assert.IsNull(onPointerDownComponent.pointerEventHandler.eventColliders.colliders); }
public void GetWaitingComponentsDebugInfo() { switch (state) { case State.WAITING_FOR_COMPONENTS: foreach (string componentId in disposableNotReady) { if (disposableComponents.ContainsKey(componentId)) { var component = disposableComponents[componentId]; Debug.Log($"Waiting for: {component.ToString()}"); foreach (var entity in component.attachedEntities) { var loader = LoadableShape.GetLoaderForEntity(entity); string loadInfo = "No loader"; if (loader != null) { loadInfo = loader.ToString(); } Debug.Log($"This shape is attached to {entity.entityId} entity. Click here for highlight it.\nLoading info: {loadInfo}", entity.gameObject); } } else { Debug.Log($"Waiting for missing component? id: {componentId}"); } } break; default: Debug.Log("This scene is not waiting for any components. Its current state is " + state); break; } }
public void EvaluateEntityPosition(DecentralandEntity entity) { if (entity == null || entity.scene == null) { return; } // Recursively evaluate entity children as well, we need to check this up front because this entity may not have meshes of its own, but the children may. if (entity.children.Count > 0) { using (var iterator = entity.children.GetEnumerator()) { while (iterator.MoveNext()) { EvaluateEntityPosition(iterator.Current.Value); } } } if (entity.meshRootGameObject == null || entity.meshesInfo.renderers == null || entity.meshesInfo.renderers.Length == 0) { return; } // If the mesh is being loaded we should skip the evaluation (it will be triggered again later when the loading finishes) if (entity.meshRootGameObject.GetComponent <MaterialTransitionController>()) // the object's MaterialTransitionController is destroyed when it finishes loading { return; } else { var loadWrapper = LoadableShape.GetLoaderForEntity(entity); if (loadWrapper != null && !loadWrapper.alreadyLoaded) { return; } } EvaluateMeshBounds(entity); }
public IEnumerator NotRecreateCollidersWhenShapeDoesntChange() { // 1. Instantiate entity and add an OnPointerDown component string entityId = "1"; var entity = TestHelpers.CreateSceneEntity(scene, entityId); string onPointerId = "pointerevent-1"; var model = new OnPointerDown.Model() { type = OnPointerDown.NAME, uuid = onPointerId }; var onPointerDownComponent = TestHelpers.EntityComponentCreate <OnPointerDown, OnPointerDown.Model>(scene, entity, model, CLASS_ID_COMPONENT.UUID_CALLBACK); // 2. Attach a shape var shapeModel = new LoadableShape <LoadWrapper_GLTF, LoadableShape.Model> .Model(); shapeModel.src = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb"; var componentId = TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeObject(shapeModel)); LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(scene.entities[entityId]); yield return(new WaitUntil(() => gltfShape.alreadyLoaded)); var pointerEventColliders = onPointerDownComponent.pointerEventHandler.eventColliders.colliders; Assert.IsTrue(pointerEventColliders != null || pointerEventColliders.Length > 0); // 3. Change a shape component property conserving the same glb shapeModel.visible = false; TestHelpers.UpdateShape(scene, componentId, JsonConvert.SerializeObject(shapeModel)); yield return(null); // 4. Check the same colliders were kept Assert.IsTrue(pointerEventColliders == onPointerDownComponent.pointerEventHandler.eventColliders.colliders); }