Esempio n. 1
0
 protected void AddOrReplaceMetrics(DecentralandEntity entity)
 {
     if (entitiesMetrics.ContainsKey(entity))
     {
         SubstractMetrics(entity);
     }
     AddMetrics(entity);
 }
Esempio n. 2
0
 protected virtual void OnEntityRemoved(DecentralandEntity e)
 {
     SubstractMetrics(e);
     e.OnMeshesInfoUpdated -= OnEntityMeshInfoUpdated;
     e.OnMeshesInfoCleaned -= OnEntityMeshInfoCleaned;
     model.entities--;
     isDirty = true;
 }
Esempio n. 3
0
 private void ProcessEntityShape(DecentralandEntity entity)
 {
     if (entity.meshRootGameObject && entity.meshesInfo.renderers.Length > 0)
     {
         CreateColliders(entity.meshesInfo);
         SetCollidersActive(true);
     }
 }
Esempio n. 4
0
 public static void SharedComponentAttach(BaseDisposable component, DecentralandEntity entity)
 {
     entity.scene.SharedComponentAttach(
         entity.entityId,
         component.id,
         component.componentName
         );
 }
 public Dictionary <Renderer, Material> GetOriginalMaterials(DecentralandEntity entity)
 {
     if (invalidMeshesInfo.ContainsKey(entity.gameObject))
     {
         return(invalidMeshesInfo[entity.gameObject].originalMaterials);
     }
     return(null);
 }
Esempio n. 6
0
        void EvaluateMeshBounds(DecentralandEntity entity)
        {
            bool isInsideBoundaries = IsEntityInsideSceneBoundaries(entity);

            UpdateEntityMeshesValidState(entity.meshesInfo, isInsideBoundaries);
            UpdateEntityCollidersValidState(entity.meshesInfo, isInsideBoundaries);
            UpdateComponents(entity, isInsideBoundaries);
        }
Esempio n. 7
0
 public static GLTFShape CreateEntityWithGLTFShape(ParcelScene scene, Vector3 position, string url,
                                                   out DecentralandEntity entity)
 {
     return(CreateEntityWithGLTFShape(scene, position, new GLTFShape.Model()
     {
         src = url
     }, out entity));
 }
Esempio n. 8
0
 private void OnEntityRemoved(DecentralandEntity entity)
 {
     rootEntity.OnRemoved                  -= OnEntityRemoved;
     rootEntity.OnShapeUpdated             -= OnShapeUpdated;
     rootEntity.OnTransformChange          -= OnTransformUpdated;
     DCLBuilderBridge.OnPreviewModeChanged -= OnPreviewModeChanged;
     DestroyColliders();
 }
Esempio n. 9
0
        public static GLTFShape CreateEntityWithGLTFShape(ParcelScene scene, Vector3 position, GLTFShape.Model model,
                                                          out DecentralandEntity entity)
        {
            entity = CreateSceneEntity(scene);
            GLTFShape gltfShape = AttachGLTFShape(entity, scene, position, model);

            return(gltfShape);
        }
Esempio n. 10
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;
            DecentralandEntity 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 sceneObjectToApply = (string)value;

            SceneObject floorObject = JsonConvert.DeserializeObject <SceneObject>(sceneObjectToApply);
            builderInWorldEntityHandler.DeleteFloorEntities();
            builderInWorldController.CreateFloor(floorObject);
            break;
        }
    }
Esempio n. 11
0
    public static string ConvertEntityToJSON(DecentralandEntity entity)
    {
        EntityData builderInWorldEntityData = new EntityData();

        builderInWorldEntityData.entityId = entity.entityId;


        foreach (KeyValuePair <CLASS_ID_COMPONENT, BaseComponent> 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, BaseDisposable> keyValuePair in entity.GetSharedComponents())
        {
            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));
    }
Esempio n. 12
0
        protected void UpdateComponents(DecentralandEntity entity, bool isInsideBoundaries)
        {
            IOutOfSceneBoundariesHandler[] components = entity.gameObject.GetComponentsInChildren <IOutOfSceneBoundariesHandler>();

            for (int i = 0; i < components.Length; i++)
            {
                components[i].UpdateOutOfBoundariesState(isInsideBoundaries);
            }
        }
Esempio n. 13
0
    void OnShapeUpdate(DecentralandEntity decentralandEntity)
    {
        if (IsSelected)
        {
            SaveOriginalMaterialAndSetEditMaterials();
        }

        ShapeInit();
    }
Esempio n. 14
0
        public static void SharedComponentAttach(BaseDisposable component, DecentralandEntity entity)
        {
            ParcelScene scene = entity.scene as ParcelScene;

            scene.SharedComponentAttach(
                entity.entityId,
                component.id
                );
        }
Esempio n. 15
0
        public override void AttachTo(DecentralandEntity entity, System.Type overridenAttachedType = null)
        {
            if (attachedEntities.Contains(entity))
            {
                return;
            }

            base.AttachTo(entity);
        }
Esempio n. 16
0
        private void OnEntityDetachedMaterial(DecentralandEntity entity)
        {
            if (texturePlayer != null)
            {
                texturePlayer.Pause();
            }

            entity.OnShapeUpdated -= OnEntityShapeUpdated;
        }
        public IEnumerator MaterialTransitionWithParametrizableMeshes()
        {
            DCL.Configuration.EnvironmentSettings.DEBUG = true;

            var entity1 = TestHelpers.CreateSceneEntity(scene);

            ParcelSettings.VISUAL_LOADING_ENABLED = true;

            DecentralandEntity entity = null;
            ConeShape          shape  = TestHelpers.InstantiateEntityWithShape <ConeShape, ConeShape.Model>
                                        (
                scene,
                DCL.Models.CLASS_ID.CONE_SHAPE,
                new Vector3(2, 1, 3),
                out entity,
                new ConeShape.Model());

            yield return(null);

            float timeout = 0f;
            float maxTime = 20f;

            while (timeout < maxTime)
            {
                timeout += Time.deltaTime;

                if (timeout > maxTime)
                {
                    timeout = maxTime;
                }

                if (entity.meshRootGameObject != null)
                {
                    var c = entity.meshRootGameObject.GetComponentInChildren <MaterialTransitionController>();

                    if (c != null) // NOTE(Brian): Wait for it
                    {
                        Assert.IsTrue(!c.useHologram, "useHologram must be false");
                        Assert.IsTrue(entity.meshRootGameObject != null, "meshGameObject is null");
                        Assert.IsTrue(c.placeholder == null,
                                      "placeholder must be null because we're not using holograms with parametric shapes.");

                        yield return(new WaitForSeconds(2f));

                        Assert.IsTrue(c == null, "MaterialTransitionController should be destroyed by now!");

                        break;
                    }
                }

                yield return(null);
            }

            Assert.Less(timeout, maxTime + 0.1f, "Timeout! MaterialTransitionController never appeared?");

            yield return(null);
        }
Esempio n. 18
0
        public void AddEntityToBeChecked(DecentralandEntity entity)
        {
            if (!SceneController.i.useBoundariesChecker)
            {
                return;
            }

            OnAddEntity(entity);
        }
Esempio n. 19
0
        public void RemoveEntityToBeChecked(DecentralandEntity entity)
        {
            if (!SceneController.i.useBoundariesChecker)
            {
                return;
            }

            entitiesToCheck.Remove(entity);
        }
Esempio n. 20
0
    void OnShapeUpdate(DecentralandEntity decentralandEntity)
    {
        ShapeInit();

        if (IsSelected)
        {
            SetEditMaterial();
        }
    }
Esempio n. 21
0
        private void OnEntityIsRemoved(DecentralandEntity entity)
        {
            var builderEntity = entity.gameObject.GetComponent <DCLBuilderEntity>();

            if (builderEntity != null)
            {
                OnEntityRemoved?.Invoke(builderEntity);
            }
        }
    public void Setup(string button, string feedbackText, DecentralandEntity entity)
    {
        text.text   = feedbackText;
        this.entity = entity;

        ConfigureIcon(button);

        canvas.enabled = enabled && isHovered;
    }
Esempio n. 23
0
        private void OnAvatarShapeUpdated(DecentralandEntity entity, AvatarShape avatarShape)
        {
            if (rootEntity != entity)
            {
                return;
            }

            OnShapeUpdated(rootEntity);
        }
        protected override void OnRemoveEntity(DecentralandEntity entity)
        {
            base.OnRemoveEntity(entity);

            if (entity.gameObject != null)
            {
                RemoveInvalidMeshEffect(entity);
            }
        }
Esempio n. 25
0
        public static GLTFShape AttachGLTFShape(DecentralandEntity entity, ParcelScene scene, Vector3 position, GLTFShape.Model model)
        {
            string    componentId = GetComponentUniqueId(scene, "gltfShape", (int)CLASS_ID.GLTF_SHAPE, entity.entityId);
            GLTFShape gltfShape   = SharedComponentCreate <GLTFShape, GLTFShape.Model>(scene, CLASS_ID.GLTF_SHAPE, model);

            SetEntityTransform(scene, entity, position, Quaternion.identity, Vector3.one);
            SharedComponentAttach(gltfShape, entity);
            return(gltfShape);
        }
Esempio n. 26
0
        public void RemoveEntityToBeChecked(DecentralandEntity entity)
        {
            if (!enabled)
            {
                return;
            }

            OnRemoveEntity(entity);
        }
Esempio n. 27
0
        public static AvatarShape CreateAvatarShape(ParcelScene scene, AvatarModel model)
        {
            GLTFSceneImporter.budgetPerFrameInMilliseconds = float.MaxValue;
            DecentralandEntity entity = TestHelpers.CreateSceneEntity(scene);
            AvatarShape        shape  = TestHelpers.EntityComponentCreate <AvatarShape, AvatarModel>(scene, entity, model, CLASS_ID_COMPONENT.AVATAR_SHAPE);

            TestHelpers.SetEntityTransform(scene, entity, new Vector3(0, 0, 0), Quaternion.identity, Vector3.one);
            return(shape);
        }
Esempio n. 28
0
        public void SetEntityParent(string entityId, string parentId)
        {
            SceneController.i.OnMessageDecodeStart?.Invoke("SetEntityParent");
            SceneController.i.OnMessageDecodeEnds?.Invoke("SetEntityParent");

            if (entityId == parentId)
            {
                return;
            }

            DecentralandEntity me = GetEntityForUpdate(entityId);

            if (me != null)
            {
                if (parentId == "FirstPersonCameraEntityReference" || parentId == "PlayerEntityReference") // PlayerEntityReference is for compatibility purposes
                {
                    // In this case, the entity will attached to the first person camera
                    // On first person mode, the entity will rotate with the camera. On third person mode, the entity will rotate with the avatar
                    me.SetParent(DCLCharacterController.i.firstPersonCameraReference);
                    SceneController.i.boundariesChecker.AddPersistent(me);
                    SceneController.i.physicsSyncController.MarkDirty();
                }
                else if (parentId == "AvatarEntityReference" || parentId == "AvatarPositionEntityReference") // AvatarPositionEntityReference is for compatibility purposes
                {
                    // In this case, the entity will be attached to the avatar
                    // It will simply rotate with the avatar, regardless of where the camera is pointing
                    me.SetParent(DCLCharacterController.i.avatarReference);
                    SceneController.i.boundariesChecker.AddPersistent(me);
                    SceneController.i.physicsSyncController.MarkDirty();
                }
                else
                {
                    if (me.parent == DCLCharacterController.i.firstPersonCameraReference || me.parent == DCLCharacterController.i.avatarReference)
                    {
                        SceneController.i.boundariesChecker.RemoveEntityToBeChecked(me);
                    }

                    if (parentId == "0")
                    {
                        // The entity will be child of the scene directly
                        me.SetParent(null);
                        me.gameObject.transform.SetParent(gameObject.transform, false);
                        SceneController.i.physicsSyncController.MarkDirty();
                    }
                    else
                    {
                        DecentralandEntity myParent = GetEntityForUpdate(parentId);

                        if (myParent != null)
                        {
                            me.SetParent(myParent);
                            SceneController.i.physicsSyncController.MarkDirty();
                        }
                    }
                }
            }
        }
Esempio n. 29
0
    public void AddEntityOnKernel(DecentralandEntity entity, ParcelScene scene)
    {
        List <ComponentPayload> list = new List <ComponentPayload>();

        foreach (KeyValuePair <CLASS_ID_COMPONENT, BaseComponent> keyValuePair in entity.components)
        {
            ComponentPayload componentPayLoad = new ComponentPayload();
            componentPayLoad.componentId = Convert.ToInt32(keyValuePair.Key);

            if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM)
            {
                TransformComponent entityComponentModel = new TransformComponent();

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

                componentPayLoad.data = entityComponentModel;
            }
            else
            {
                componentPayLoad.data = keyValuePair.Value.GetModel();
            }

            list.Add(componentPayLoad);
        }

        foreach (KeyValuePair <Type, BaseDisposable> keyValuePairBaseDisposable in entity.GetSharedComponents())
        {
            ComponentPayload componentPayLoad = new ComponentPayload();

            componentPayLoad.componentId = keyValuePairBaseDisposable.Value.GetClassId();

            if (keyValuePairBaseDisposable.Value.GetClassId() == (int)CLASS_ID.NFT_SHAPE)
            {
                NFTComponent   nftComponent = new NFTComponent();
                NFTShape.Model model        = (NFTShape.Model)keyValuePairBaseDisposable.Value.GetModel();

                nftComponent.color   = new ColorRepresentation(model.color);
                nftComponent.assetId = model.assetId;
                nftComponent.src     = model.src;
                nftComponent.style   = model.style;

                componentPayLoad.data = nftComponent;
            }
            else
            {
                componentPayLoad.data = keyValuePairBaseDisposable.Value.GetModel();
            }


            list.Add(componentPayLoad);
        }

        SendNewEntityToKernel(scene.sceneData.id, entity.entityId, list.ToArray());
    }
Esempio n. 30
0
        public override void AttachTo(DecentralandEntity entity, System.Type overridenAttachedType = null)
        {
            if (attachedEntities.Contains(entity))
            {
                return;
            }

            entity.RemoveSharedComponent(typeof(PBRMaterial));
            base.AttachTo(entity);
        }