bool EntityHasPointerEvent(IDCLEntity entity)
 {
     return(entity.components.ContainsKey(Models.CLASS_ID_COMPONENT.UUID_CALLBACK) ||
            entity.components.ContainsKey(Models.CLASS_ID_COMPONENT.UUID_ON_UP) ||
            entity.components.ContainsKey(Models.CLASS_ID_COMPONENT.UUID_ON_DOWN) ||
            entity.components.ContainsKey(Models.CLASS_ID_COMPONENT.UUID_ON_CLICK));
 }
    public IEnumerator WorkCorrectlyWhenAttachedBeforeShape()
    {
        IDCLEntity entity = TestHelpers.CreateSceneEntity(scene);

        DCLTexture dclTexture = TestHelpers.CreateDCLTexture(
            scene,
            TestAssetsUtils.GetPath() + "/Images/atlas.png",
            DCLTexture.BabylonWrapMode.CLAMP,
            FilterMode.Bilinear);

        yield return(dclTexture.routine);

        BasicMaterial mat = TestHelpers.SharedComponentCreate <BasicMaterial, BasicMaterial.Model>
                                (scene, CLASS_ID.BASIC_MATERIAL,
                                new BasicMaterial.Model
        {
            texture   = dclTexture.id,
            alphaTest = 0.5f
        });

        yield return(mat.routine);

        TestHelpers.SharedComponentAttach(mat, entity);

        SphereShape shape = TestHelpers.SharedComponentCreate <SphereShape, SphereShape.Model>(scene,
                                                                                               CLASS_ID.SPHERE_SHAPE,
                                                                                               new SphereShape.Model {
        });

        TestHelpers.SharedComponentAttach(shape, entity);

        Assert.IsTrue(entity.meshRootGameObject != null);
        Assert.IsTrue(entity.meshRootGameObject.GetComponent <MeshRenderer>() != null);
        Assert.AreEqual(entity.meshRootGameObject.GetComponent <MeshRenderer>().sharedMaterial, mat.material);
    }
Beispiel #3
0
 protected virtual void OnEntityAdded(IDCLEntity e)
 {
     e.OnMeshesInfoUpdated += OnEntityMeshInfoUpdated;
     e.OnMeshesInfoCleaned += OnEntityMeshInfoCleaned;
     model.entities++;
     isDirty = true;
 }
    public IEnumerator UnloadWhenEntityDestroyedBeforeFinishing()
    {
        GameObject meshRootGameObject = new GameObject();

        string url = TestAssetsUtils.GetPath() + "/GLB/Trunk/Trunk.glb";

        IDCLEntity entity = Substitute.For <IDCLEntity>();

        entity.meshRootGameObject.Returns(meshRootGameObject);

        LoadWrapper_GLTF wrapper = Substitute.ForPartsOf <LoadWrapper_GLTF>();

        wrapper.entity = entity;
        wrapper.customContentProvider = new ContentProvider();

        bool loaded   = false;
        bool failed   = false;
        bool unloaded = false;

        wrapper.WhenForAnyArgs(x => x.Unload()).Do((info) => unloaded = true);

        wrapper.Load(url, loadWrapper => loaded = true, loadWrapper => failed = true);

        entity.OnCleanupEvent?.Invoke(entity);

        yield return(new WaitUntil(() => loaded || failed || unloaded));

        Object.Destroy(meshRootGameObject);

        Assert.IsTrue(unloaded, "Unload should be called if entity is cleaned up while loading mesh");
    }
    public IEnumerator AlbedoTexture_AlbedoAlpha(float alpha)
    {
        yield return(InitVisualTestsScene($"PBRMaterialVisualTests_AlbedoTexture_AlbedoAlpha_{alpha.ToString(CultureInfo.InvariantCulture)}"));

        VisualTestHelpers.SetSSAOActive(true);

        Vector3 camTarget = new Vector3(5, 1, 5);

        VisualTestHelpers.RepositionVisualTestsCamera(VisualTestController.i.camera, new Vector3(4.6f, 1.8f, 0.6f), camTarget);

        DCLTexture texture = TestHelpers.CreateDCLTexture(scene, TestAssetsUtils.GetPath() + "/Images/avatar.png");

        yield return(texture.routine);

        PlaneShape plane       = TestHelpers.CreateEntityWithPlaneShape(scene, new Vector3(5, 1, 5), true);
        IDCLEntity planeEntity = plane.attachedEntities.FirstOrDefault();

        TestHelpers.SetEntityTransform(scene, planeEntity, new Vector3(5, 1, 5), Quaternion.Euler(0, 0, 180), Vector3.one * 3);
        PBRMaterial planeMaterial = TestHelpers.AttachPBRMaterialToEntity(scene, planeEntity, new PBRMaterial.Model
        {
            transparencyMode = 2,
            albedoTexture    = texture.id,
            albedoColor      = new Color(1, 1, 1, alpha)
        });

        yield return(plane.routine);

        yield return(planeMaterial.routine);

        yield return(null);

        yield return(VisualTestHelpers.TakeSnapshot());
    }
Beispiel #6
0
    DCLBuilderInWorldEntity SetupEntityToEdit(IDCLEntity entity, bool hasBeenCreated = false)
    {
        if (!convertedEntities.ContainsKey(GetConvertedUniqueKeyForEntity(entity)))
        {
            DCLBuilderInWorldEntity entityToEdit = Utils.GetOrCreateComponent <DCLBuilderInWorldEntity>(entity.gameObject);
            entityToEdit.Init(entity, editMaterial);
            convertedEntities.Add(entityToEdit.entityUniqueId, entityToEdit);
            entity.OnRemoved  += RemoveConvertedEntity;
            entityToEdit.IsNew = hasBeenCreated;

            string entityName  = entityToEdit.GetDescriptiveName();
            var    catalogItem = entityToEdit.GetCatalogItemAssociated();

            if ((string.IsNullOrEmpty(entityName) || entityNameList.Contains(entityName)) && catalogItem != null)
            {
                entityName = GetNewNameForEntity(catalogItem);
                SetEntityName(entityToEdit, entityName);
            }
            else if (!string.IsNullOrEmpty(entityName) && !entityNameList.Contains(entityName))
            {
                entityNameList.Add(entityName);
            }

            return(entityToEdit);
        }
        else
        {
            return(convertedEntities[GetConvertedUniqueKeyForEntity(entity)]);
        }
    }
Beispiel #7
0
 private void OnShapeUpdated(IDCLEntity entity)
 {
     if (entity != null)
     {
         InitMaterial(entity.meshRootGameObject);
     }
 }
Beispiel #8
0
 protected void OnRemoveEntity(IDCLEntity entity)
 {
     highPrioEntitiesToCheck.Remove(entity);
     entitiesToCheck.Remove(entity);
     persistentEntities.Remove(entity);
     feedbackStyle.ApplyFeedback(entity.meshesInfo, true);
 }
 public void RemoveChild(IDCLEntity entity)
 {
     if (children.ContainsKey(entity.entityId))
     {
         children.Remove(entity.entityId);
     }
 }
 public void AddChild(IDCLEntity entity)
 {
     if (!children.ContainsKey(entity.entityId))
     {
         children.Add(entity.entityId, entity);
     }
 }
    //TODO: When refactoring these tests to split them by shape, replicate this on them
    public IEnumerator UpdateWithCollisionInMultipleEntities(int entitiesCount, bool withCollision)
    {
        Environment.i.world.sceneBoundsChecker.Stop();

        // Arrange: set inverse of withCollision to trigger is dirty later
        BaseShape shapeComponent = TestHelpers.SharedComponentCreate <BoxShape, BaseShape.Model>(scene, CLASS_ID.BOX_SHAPE, new BaseShape.Model {
            withCollisions = !withCollision
        });

        yield return(shapeComponent.routine);

        List <IDCLEntity> entities = new List <IDCLEntity>();

        for (int i = 0; i < entitiesCount; i++)
        {
            IDCLEntity entity = TestHelpers.CreateSceneEntity(scene, $"entity{i}");
            TestHelpers.SharedComponentAttach(shapeComponent, entity);
            entities.Add(entity);
        }

        // Act: Update withCollision
        shapeComponent.UpdateFromModel(new BoxShape.Model {
            withCollisions = withCollision
        });
        yield return(shapeComponent.routine);

        // Assert:
        foreach (IDCLEntity entity in entities)
        {
            for (int i = 0; i < entity.meshesInfo.colliders.Count; i++)
            {
                Assert.AreEqual(withCollision, entity.meshesInfo.colliders[i].enabled);
            }
        }
    }
        public void Initialize(IDCLEntity entity)
        {
            Renderer[] rendererList = entity?.meshesInfo?.renderers;

            if (rendererList == null || rendererList.Length == 0)
            {
                return;
            }

            IShape shape = entity.meshesInfo.currentShape;

            if (lastShape == shape)
            {
                return;
            }

            this.ownerEntity = entity;
            lastShape        = shape;

            DestroyColliders();

            if (shape == null)
            {
                return;
            }

            colliders = new Collider[rendererList.Length];

            for (int i = 0; i < colliders.Length; i++)
            {
                colliders[i] = CreateColliders(rendererList[i]);
            }
        }
Beispiel #13
0
    public DCLBuilderInWorldEntity CreateEmptyEntity(ParcelScene parcelScene, Vector3 entryPoint, Vector3 editionGOPosition, bool notifyEntityList = true)
    {
        IDCLEntity newEntity = parcelScene.CreateEntity(Guid.NewGuid().ToString());

        DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entryPoint, parcelScene);

        Vector3 pointToLookAt = Camera.main.transform.position;

        pointToLookAt.y = editionGOPosition.y;
        Quaternion lookOnLook = Quaternion.LookRotation(editionGOPosition - pointToLookAt);

        DCLTransform.model.rotation = lookOnLook;
        DCLTransform.model.scale    = newEntity.gameObject.transform.lossyScale;

        parcelScene.EntityComponentCreateOrUpdateWithModel(newEntity.entityId, CLASS_ID_COMPONENT.TRANSFORM, DCLTransform.model);

        DCLBuilderInWorldEntity convertedEntity = SetupEntityToEdit(newEntity, true);

        hudController?.UpdateSceneLimitInfo();

        if (notifyEntityList)
        {
            EntityListChanged();
        }
        return(convertedEntity);
    }
        public void AddOrUpdateEntityCollider(IDCLEntity entity, Collider collider)
        {
            if (!collidersByEntity.ContainsKey(entity))
            {
                collidersByEntity.Add(entity, new List <Collider>());
            }

            List <Collider> collidersList = collidersByEntity[entity];

            if (!collidersList.Contains(collider))
            {
                collidersList.Add(collider);
            }

            ColliderInfo info = new ColliderInfo();

            info.entity   = entity;
            info.meshName = collider.transform.parent != null ? collider.transform.parent.name : "";
            info.scene    = entity.scene;
            AddOrUpdateColliderInfo(collider, info);

            // Note (Zak): avoid adding the event multiple times
            entity.OnCleanupEvent -= OnEntityCleanUpEvent;
            entity.OnCleanupEvent += OnEntityCleanUpEvent;
        }
Beispiel #15
0
        protected bool IsHighPrioEntity(IDCLEntity entity)
        {
            Vector3 scale    = entity.gameObject.transform.lossyScale;
            Vector3 position = entity.gameObject.transform.localPosition;

            return(scale.x > TRIGGER_HIGHPRIO_VALUE || scale.y > TRIGGER_HIGHPRIO_VALUE || scale.z > TRIGGER_HIGHPRIO_VALUE || position.x > TRIGGER_HIGHPRIO_VALUE || position.y > TRIGGER_HIGHPRIO_VALUE || position.z > TRIGGER_HIGHPRIO_VALUE);
        }
    public void EntityDuplicate()
    {
        IDCLEntity duplicateEntity = entityHandler.DuplicateEntity(entity).rootEntity;
        BIWEntity  convertedEntity = entityHandler.GetConvertedEntity(duplicateEntity);

        Assert.IsNotNull(convertedEntity);
    }
Beispiel #17
0
    public void EntityDuplicate()
    {
        IDCLEntity duplicateEntity = entityHandler.DuplicateEntity(entity);
        DCLBuilderInWorldEntity convertedEntity = entityHandler.GetConvertedEntity(duplicateEntity);

        Assert.IsNotNull(convertedEntity);
    }
Beispiel #18
0
        private DCLBuilderEntity AddBuilderEntityComponent(IDCLEntity entity)
        {
            DCLBuilderEntity builderComponent = Utils.GetOrCreateComponent <DCLBuilderEntity>(entity.gameObject);

            builderComponent.SetEntity(entity);
            return(builderComponent);
        }
Beispiel #19
0
    public void LookAtEntity(IDCLEntity entity)
    {
        if (entity.meshRootGameObject == null ||
            entity.meshesInfo == null ||
            BuilderInWorldUtils.IsBoundInsideCamera(entity.meshesInfo.mergedBounds))
        {
            return;
        }

        Vector3 pointToLook = entity.gameObject.transform.position;

        if (entity.meshesInfo.renderers.Length > 0)
        {
            Vector3 midPointFromEntityMesh = Vector3.zero;
            foreach (Renderer render in entity.renderers)
            {
                midPointFromEntityMesh += render.bounds.center;
            }

            midPointFromEntityMesh /= entity.renderers.Length;
            pointToLook             = midPointFromEntityMesh;
        }

        freeCameraController.SmoothLookAt(pointToLook);
    }
Beispiel #20
0
        protected override void AttachShape(IDCLEntity entity)
        {
            if (string.IsNullOrEmpty(model.src))
            {
#if UNITY_EDITOR
                Debug.LogError($"NFT SHAPE with url '{model.src}' couldn't be loaded.");
#endif
                return;
            }

            entity.meshesInfo.meshRootGameObject = NFTShapeFactory.InstantiateLoaderController(model.style);
            entity.meshesInfo.currentShape       = this;

            entity.meshRootGameObject.name = componentName + " mesh";
            entity.meshRootGameObject.transform.SetParent(entity.gameObject.transform);
            entity.meshRootGameObject.transform.ResetLocalTRS();

            entity.OnShapeUpdated += UpdateBackgroundColor;

            var loadableShape = GetOrAddLoaderForEntity <LoadWrapper_NFT>(entity);

            loadableShape.entity            = entity;
            loadableShape.component         = this;
            loadableShape.initialVisibility = model.visible;

            loadableShape.withCollisions  = model.withCollisions;
            loadableShape.backgroundColor = model.color;

            loadableShape.Load(model.src, OnLoadCompleted, OnLoadFailed);
        }
    //TODO: When refactoring these tests to split them by shape, replicate this on them
    public IEnumerator UpdateVisibilityInMultipleEntities(int entitiesCount, bool visible)
    {
        Environment.i.world.sceneBoundsChecker.Stop();

        // Arrange: set inverse of visible to trigger is dirty later
        BaseShape shapeComponent = TestHelpers.SharedComponentCreate <BoxShape, BaseShape.Model>(scene, CLASS_ID.BOX_SHAPE, new BaseShape.Model {
            visible = !visible
        });

        yield return(shapeComponent.routine);

        List <IDCLEntity> entities = new List <IDCLEntity>();

        for (int i = 0; i < entitiesCount; i++)
        {
            IDCLEntity entity = TestHelpers.CreateSceneEntity(scene, $"entity{i}");
            TestHelpers.SharedComponentAttach(shapeComponent, entity);
            entities.Add(entity);
        }

        // Act: Update visible
        shapeComponent.UpdateFromModel(new BoxShape.Model {
            visible = visible, withCollisions = true, isPointerBlocker = true
        });
        yield return(shapeComponent.routine);

        // Assert:
        foreach (IDCLEntity entity in entities)
        {
            for (int i = 0; i < entity.meshesInfo.renderers.Length; i++)
            {
                Assert.AreEqual(visible, entity.meshesInfo.renderers[i].enabled);
            }
        }
    }
Beispiel #22
0
        private void OnShapeUpdated(IDCLEntity entity)
        {
            isShapeComponentSet = true;
            OnEntityShapeUpdated?.Invoke(this);

            // We don't want animation to be running on editor
            meshAnimations = GetComponentsInChildren <Animation>();
            if (hasSmartItemComponent)
            {
                DefaultAnimationStop();
            }
            else
            {
                DefaultAnimationSample(0);
            }

            if (hasGizmoComponent)
            {
                gameObject.transform.localScale = Vector3.zero;
                StartCoroutine(ScaleAnimationRoutine(0.3f));
            }
            else if (isTransformComponentSet)
            {
                gameObject.transform.localScale = scaleTarget;
                ProcessEntityShape(entity);
            }

            if (OnShapeLoaded != null)
            {
                OnShapeLoaded();
                OnShapeLoaded = null;
            }
        }
Beispiel #23
0
        void CleanUpEntityRecursively(IDCLEntity entity, bool removeImmediatelyFromEntitiesList)
        {
            // Iterate through all entity children
            using (var iterator = entity.children.GetEnumerator())
            {
                while (iterator.MoveNext())
                {
                    CleanUpEntityRecursively(iterator.Current.Value, removeImmediatelyFromEntitiesList);
                }
            }

            OnEntityRemoved?.Invoke(entity);

            if (Environment.i.world.sceneBoundsChecker.enabled)
            {
                entity.OnShapeUpdated -= Environment.i.world.sceneBoundsChecker.AddEntityToBeChecked;
                Environment.i.world.sceneBoundsChecker.RemoveEntityToBeChecked(entity);
            }

            if (removeImmediatelyFromEntitiesList)
            {
                // Every entity ends up being removed through here
                entity.Cleanup();
                entities.Remove(entity.entityId);
            }
            else
            {
                Environment.i.platform.parcelScenesCleaner.MarkForCleanup(entity);
            }
        }
Beispiel #24
0
 protected virtual void OnEntityRemoved(IDCLEntity e)
 {
     SubstractMetrics(e);
     e.OnMeshesInfoUpdated -= OnEntityMeshInfoUpdated;
     e.OnMeshesInfoCleaned -= OnEntityMeshInfoCleaned;
     model.entities--;
     isDirty = true;
 }
Beispiel #25
0
 private void ProcessEntityShape(IDCLEntity entity)
 {
     if (entity.meshRootGameObject && entity.meshesInfo.renderers.Length > 0)
     {
         CreateColliders(entity.meshesInfo);
         SetCollidersActive(true);
     }
 }
Beispiel #26
0
    public static string ConvertEntityToJSON(IDCLEntity entity)
    {
        EntityData builderInWorldEntityData = new EntityData();

        builderInWorldEntityData.entityId = entity.entityId;


        foreach (KeyValuePair <CLASS_ID_COMPONENT, IEntityComponent> keyValuePair in entity.components)
        {
            if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM)
            {
                EntityData.TransformComponent entityComponentModel = new EntityData.TransformComponent();

                entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position, entity.scene);
                entityComponentModel.rotation = entity.gameObject.transform.localRotation.eulerAngles;
                entityComponentModel.scale    = entity.gameObject.transform.localScale;

                builderInWorldEntityData.transformComponent = entityComponentModel;
            }
            else
            {
                ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent();
                entityComponentModel.componentId = (int)keyValuePair.Key;
                entityComponentModel.data        = keyValuePair.Value.GetModel();

                builderInWorldEntityData.components.Add(entityComponentModel);
            }
        }

        foreach (KeyValuePair <Type, ISharedComponent> keyValuePair in entity.sharedComponents)
        {
            if (keyValuePair.Value.GetClassId() == (int)CLASS_ID.NFT_SHAPE)
            {
                EntityData.NFTComponent nFTComponent = new EntityData.NFTComponent();
                NFTShape.Model          model        = (NFTShape.Model)keyValuePair.Value.GetModel();

                nFTComponent.id      = keyValuePair.Value.id;
                nFTComponent.color   = new ColorRepresentation(model.color);
                nFTComponent.assetId = model.assetId;
                nFTComponent.src     = model.src;
                nFTComponent.style   = model.style;

                builderInWorldEntityData.nftComponent = nFTComponent;
            }
            else
            {
                ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent();
                entityComponentModel.componentId = keyValuePair.Value.GetClassId();
                entityComponentModel.data        = keyValuePair.Value.GetModel();
                entityComponentModel.classId     = keyValuePair.Value.id;

                builderInWorldEntityData.sharedComponents.Add(entityComponentModel);
            }
        }


        return(JsonConvert.SerializeObject(builderInWorldEntityData));
    }
Beispiel #27
0
    void ApplyAction(string entityIdToApply, object value, ActionType actionType, bool isUndo)
    {
        switch (actionType)
        {
        case ActionType.MOVE:
            Vector3 convertedPosition = (Vector3)value;
            builderInWorldEntityHandler.GetEntity(entityIdToApply).rootEntity.gameObject.transform.position = convertedPosition;
            break;

        case ActionType.ROTATE:
            Vector3 convertedAngles = (Vector3)value;
            builderInWorldEntityHandler.GetEntity(entityIdToApply).rootEntity.gameObject.transform.eulerAngles = convertedAngles;
            break;

        case ActionType.SCALE:
            Vector3    convertedScale = (Vector3)value;
            IDCLEntity entityToApply  = builderInWorldEntityHandler.GetEntity(entityIdToApply).rootEntity;
            Transform  parent         = entityToApply.gameObject.transform.parent;

            entityToApply.gameObject.transform.localScale = new Vector3(convertedScale.x / parent.localScale.x, convertedScale.y / parent.localScale.y, convertedScale.z / parent.localScale.z);
            break;

        case ActionType.CREATE:
            string entityString = (string)value;
            if (isUndo)
            {
                builderInWorldEntityHandler.DeleteEntity(entityString);
            }
            else
            {
                builderInWorldEntityHandler.CreateEntityFromJSON(entityString);
            }

            break;

        case ActionType.DELETE:
            string deletedEntityString = (string)value;

            if (isUndo)
            {
                builderInWorldEntityHandler.CreateEntityFromJSON(deletedEntityString);
            }
            else
            {
                builderInWorldEntityHandler.DeleteEntity(deletedEntityString);
            }

            break;

        case ActionType.CHANGE_FLOOR:
            string catalogItemToApply = (string)value;

            CatalogItem floorObject = JsonConvert.DeserializeObject <CatalogItem>(catalogItemToApply);
            builderInWorldEntityHandler.DeleteFloorEntities();
            biwFloorHandler.CreateFloor(floorObject);
            break;
        }
    }
Beispiel #28
0
    public DCLBuilderInWorldEntity GetConvertedEntity(IDCLEntity entity)
    {
        if (convertedEntities.ContainsKey(GetConvertedUniqueKeyForEntity(entity)))
        {
            return(convertedEntities[GetConvertedUniqueKeyForEntity(entity)]);
        }

        return(null);
    }
    public void Setup(string button, string feedbackText, IDCLEntity entity)
    {
        text.text   = feedbackText;
        this.entity = entity;

        ConfigureIcon(button);

        canvas.enabled = enabled && isHovered;
    }
Beispiel #30
0
        private void OnAvatarShapeUpdated(IDCLEntity entity, AvatarShape avatarShape)
        {
            if (rootEntity != entity)
            {
                return;
            }

            OnShapeUpdated(rootEntity);
        }