Esempio n. 1
0
        public static PB_Transform GetPBTransformFromModelJson(string json)
        {
            DCLTransform.Model transfModel = JsonUtility.FromJson <DCLTransform.Model>(json);
            PB_Transform       pbTranf     = GetPBTransform(transfModel.position, transfModel.rotation, transfModel.scale);

            return(pbTranf);
        }
Esempio n. 2
0
        public static IEnumerator ChildShapeIsEvaluated(ParcelScene scene)
        {
            string entityId = "1";

            TestHelpers.InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(8, 1, 8));
            yield return(null);

            Assert.IsFalse(MeshIsInvalid(scene.entities[entityId].meshesInfo));

            // Attach child
            string childEntityId = "2";

            TestHelpers.InstantiateEntityWithShape(scene, childEntityId, DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(8, 1, 8));
            yield return(null);

            Assert.IsFalse(MeshIsInvalid(scene.entities[childEntityId].meshesInfo));

            TestHelpers.SetEntityParent(scene, childEntityId, entityId);

            // Move parent object to surpass the scene boundaries
            var transformModel = new DCLTransform.Model {
                position = new Vector3(18, 1, 18)
            };

            TestHelpers.SetEntityTransform(scene, scene.entities[entityId], transformModel);

            yield return(null);

            yield return(null);

            Assert.IsTrue(MeshIsInvalid(scene.entities[childEntityId].meshesInfo));
        }
Esempio n. 3
0
        private void OnTransformUpdated(DCLTransform.Model transformModel)
        {
            //NOTE: there is no parenting entities in editor mode so we can set properties in world space
            gameObject.transform.position = transformModel.position;
            gameObject.transform.rotation = transformModel.rotation;

            if (isScalingAnimation || !isShapeComponentSet)
            {
                scaleTarget = transformModel.scale;
            }
            else if (isShapeComponentSet)
            {
                scaleTarget = transformModel.scale;
                gameObject.transform.localScale = transformModel.scale;
            }

            if (!isTransformComponentSet)
            {
                isTransformComponentSet = true;
                OnEntityAddedWithTransform?.Invoke(this);
            }

            if (isShapeComponentSet)
            {
                OnEntityTransformUpdated?.Invoke(this);
            }
        }
        public void OnTransformChanged(object model)
        {
            DCLTransform.Model transformModel = (DCLTransform.Model)model;

            MoveTo(
                transformModel.position - Vector3.up * DCLCharacterController.i.characterController.height / 2, // To fix the "always flying" avatars bug, We report the chara's centered position but the body hast its pivot at its feet
                transformModel.rotation);
        }
Esempio n. 5
0
        private void OnEntityTransformChanged(DCLTransform.Model updatedModel)
        {
            lastAvatarPosition = updatedModel.position;

            avatarUserInfo.userId        = model.id;
            avatarUserInfo.userName      = model.name;
            avatarUserInfo.worldPosition = updatedModel.position;
            MinimapMetadataController.i?.UpdateMinimapUserInformation(avatarUserInfo);
        }
Esempio n. 6
0
        private void OnEntityTransformChanged(DCLTransform.Model updatedModel)
        {
            lastAvatarPosition = updatedModel.position;

            avatarUserInfo.userId        = model.id;
            avatarUserInfo.userName      = model.name;
            avatarUserInfo.worldPosition = updatedModel.position;
            UpdateAvatarIconInMinimap(avatarUserInfo);
        }
Esempio n. 7
0
        public static void DecodeTransform(string payload, ref DCLTransform.Model model)
        {
#if UNITY_EDITOR
            DumpMessage(payload, TRANSFORM_FILENAME, ref transformDumpStr, ref transformCount);
#endif
            byte[] bytes = System.Convert.FromBase64String(payload);

            DCL.Interface.PB_Transform pbTransform = DCL.Interface.PB_Transform.Parser.ParseFrom(bytes);
            model.position = new Vector3(pbTransform.Position.X, pbTransform.Position.Y, pbTransform.Position.Z);
            model.scale    = new Vector3(pbTransform.Scale.X, pbTransform.Scale.Y, pbTransform.Scale.Z);
            model.rotation = new Quaternion((float)pbTransform.Rotation.X, (float)pbTransform.Rotation.Y, (float)pbTransform.Rotation.Z, (float)pbTransform.Rotation.W);
        }
Esempio n. 8
0
        public void TransformationsAreKeptRelativeAfterParenting()
        {
            DecentralandEntity entity = TestHelpers.CreateSceneEntity(scene);

            Vector3    targetPosition = new Vector3(3f, 7f, 1f);
            Quaternion targetRotation = new Quaternion(4f, 9f, 1f, 7f);
            Vector3    targetScale    = new Vector3(5f, 0.7f, 2f);

            // 1. Create component with non-default configs
            DCLTransform.Model componentModel = new DCLTransform.Model
            {
                position = targetPosition,
                rotation = targetRotation,
                scale    = targetScale
            };

            TestHelpers.SetEntityTransform(scene, entity, componentModel);

            // 2. Check configured values
            Assert.IsTrue(targetPosition == entity.gameObject.transform.localPosition);
            Assert.IsTrue(targetRotation == entity.gameObject.transform.localRotation);
            Assert.IsTrue(targetScale == entity.gameObject.transform.localScale);

            // 3. Create new parent entity
            DecentralandEntity entity2 = TestHelpers.CreateSceneEntity(scene);

            componentModel = new DCLTransform.Model
            {
                position = new Vector3(15f, 56f, 0f),
                rotation = new Quaternion(1f, 3f, 5f, 15f),
                scale    = new Vector3(2f, 3f, 5f)
            };

            TestHelpers.SetEntityTransform(scene, entity2, componentModel);

            // 4. set new parent
            TestHelpers.SetEntityParent(scene, entity.entityId, entity2.entityId);

            // 5. check transform values remains the same
            Assert.IsTrue(targetPosition == entity.gameObject.transform.localPosition);
            Assert.IsTrue(targetRotation == entity.gameObject.transform.localRotation);
            Assert.IsTrue(targetScale == entity.gameObject.transform.localScale);
        }
    // This method will be used when we apply a "loose aim" for the 3rd person camera
    void CalculateMeshCenteredPos(DCLTransform.Model transformModel = null)
    {
        if (!canvas.enabled)
        {
            return;
        }

        if (entity.meshesInfo.renderers == null || entity.meshesInfo.renderers.Length == 0)
        {
            meshCenteredPos = transform.parent.position;
        }
        else
        {
            Vector3 sum = Vector3.zero;
            for (int i = 0; i < entity.meshesInfo.renderers.Length; i++)
            {
                sum += entity.meshesInfo.renderers[i].bounds.center;
            }

            meshCenteredPos = sum / entity.meshesInfo.renderers.Length;
        }
    }
Esempio n. 10
0
        public static IEnumerator HeightIsEvaluated(ParcelScene scene)
        {
            var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(8, 5, 8));
            var entity   = boxShape.attachedEntities.First();

            yield return(null);

            Assert.IsFalse(MeshIsInvalid(entity.meshesInfo));

            // Move object to surpass the scene height boundaries
            var transformModel = new DCLTransform.Model {
                position = new Vector3(8, 30, 8)
            };

            TestHelpers.SetEntityTransform(scene, entity, transformModel);

            yield return(null);

            yield return(null);

            Assert.IsTrue(MeshIsInvalid(entity.meshesInfo));
        }
Esempio n. 11
0
        public IEnumerator InterpolatePosition()
        {
            AvatarAssetsTestHelpers.CreateTestCatalogLocal();
            AvatarShape avatar = AvatarShapeTestHelpers.CreateAvatarShape(scene, "Abortitus", "TestAvatar.json");

            // We must wait for the AvatarShape to finish or the OnTransformChanged event is not used
            yield return(new DCL.WaitUntil(() => avatar.everythingIsLoaded, 20));

            Assert.AreEqual(0f, avatar.entity.gameObject.transform.position.x);
            Assert.AreEqual(0f, avatar.entity.gameObject.transform.position.z);

            // Update position to the other end of the parcel
            var transformModel = new DCLTransform.Model {
                position = new Vector3(15, 2, 15)
            };

            TestHelpers.SetEntityTransform(scene, avatar.entity, transformModel);

            yield return(null);

            Assert.AreNotEqual(15f, avatar.entity.gameObject.transform.position.x);
            Assert.AreNotEqual(15f, avatar.entity.gameObject.transform.position.z);
        }
Esempio n. 12
0
        public static IEnumerator PShapeIsResetWhenReenteringBounds(ParcelScene scene)
        {
            var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(18, 1, 18));

            yield return(null);

            var entity = boxShape.attachedEntities.First();

            yield return(null);

            Assert.IsTrue(MeshIsInvalid(entity.meshesInfo));

            // Move object to re-enter the scene boundaries
            var transformModel = new DCLTransform.Model {
                position = new Vector3(8, 1, 8)
            };

            TestHelpers.SetEntityTransform(scene, entity, transformModel);

            yield return(null);

            Assert.IsFalse(MeshIsInvalid(entity.meshesInfo));
        }
Esempio n. 13
0
 public static void SetEntityTransform(ParcelScene scene, DecentralandEntity entity, DCLTransform.Model model)
 {
     SetEntityTransform(scene, entity, model.position, model.rotation, model.scale);
 }
Esempio n. 14
0
        public void TransformUpdate()
        {
            DecentralandEntity entity = TestHelpers.CreateSceneEntity(scene);

            Assert.IsTrue(entity != null);

            {
                Vector3    originalTransformPosition = entity.gameObject.transform.position;
                Quaternion originalTransformRotation = entity.gameObject.transform.rotation;
                Vector3    originalTransformScale    = entity.gameObject.transform.localScale;

                Vector3    position           = new Vector3(5, 1, 5);
                Quaternion rotationQuaternion = Quaternion.Euler(10, 50, -90);
                Vector3    scale = new Vector3(0.7f, 0.7f, 0.7f);

                var transformModel = new DCLTransform.Model {
                    position = position, rotation = rotationQuaternion, scale = scale
                };

                TestHelpers.SetEntityTransform(scene, entity, transformModel);

                Assert.AreNotEqual(originalTransformPosition, entity.gameObject.transform.position);
                Assert.AreEqual(position, entity.gameObject.transform.position);

                Assert.AreNotEqual(originalTransformRotation, entity.gameObject.transform.rotation);
                Assert.AreEqual(rotationQuaternion.ToString(), entity.gameObject.transform.rotation.ToString());

                Assert.AreNotEqual(originalTransformScale, entity.gameObject.transform.localScale);
                Assert.AreEqual(scale, entity.gameObject.transform.localScale);
            }

            {
                Vector3    originalTransformPosition = entity.gameObject.transform.position;
                Quaternion originalTransformRotation = entity.gameObject.transform.rotation;
                Vector3    originalTransformScale    = entity.gameObject.transform.localScale;

                Vector3    position           = new Vector3(51, 13, 52);
                Quaternion rotationQuaternion = Quaternion.Euler(101, 51, -91);
                Vector3    scale = new Vector3(1.7f, 3.7f, -0.7f);

                var transformModel = new DCLTransform.Model {
                    position = position, rotation = rotationQuaternion, scale = scale
                };

                TestHelpers.SetEntityTransform(scene, entity, transformModel);

                Assert.AreNotEqual(originalTransformPosition, entity.gameObject.transform.position);
                Assert.AreEqual(position, entity.gameObject.transform.position);

                Assert.AreNotEqual(originalTransformRotation, entity.gameObject.transform.rotation);
                Assert.AreEqual(rotationQuaternion.ToString(), entity.gameObject.transform.rotation.ToString());

                Assert.AreNotEqual(originalTransformScale, entity.gameObject.transform.localScale);
                Assert.AreEqual(scale, entity.gameObject.transform.localScale);
            }

            {
                Vector3    originalTransformPosition = entity.gameObject.transform.position;
                Quaternion originalTransformRotation = entity.gameObject.transform.rotation;
                Vector3    originalTransformScale    = entity.gameObject.transform.localScale;

                Vector3    position           = new Vector3(0, 0, 0);
                Quaternion rotationQuaternion = Quaternion.Euler(0, 0, 0);
                Vector3    scale = new Vector3(1, 1, 1);

                var transformModel = new DCLTransform.Model {
                    position = position, rotation = rotationQuaternion, scale = scale
                };

                TestHelpers.SetEntityTransform(scene, entity, transformModel);

                Assert.AreNotEqual(originalTransformPosition, entity.gameObject.transform.position);
                Assert.AreEqual(position, entity.gameObject.transform.position);

                Assert.AreNotEqual(originalTransformRotation, entity.gameObject.transform.rotation);
                Assert.AreEqual(rotationQuaternion.ToString(), entity.gameObject.transform.rotation.ToString());

                Assert.AreNotEqual(originalTransformScale, entity.gameObject.transform.localScale);
                Assert.AreEqual(scale, entity.gameObject.transform.localScale);
            }
        }
Esempio n. 15
0
        public BaseComponent EntityComponentCreateOrUpdateFromUnity(string entityId, CLASS_ID_COMPONENT classId, object data)
        {
            DecentralandEntity entity = GetEntityForUpdate(entityId);

            if (entity == null)
            {
                Debug.LogError($"scene '{sceneData.id}': Can't create entity component if the entity {entityId} doesn't exist!");
                return(null);
            }

            if (classId == CLASS_ID_COMPONENT.TRANSFORM)
            {
                if (!(data is DCLTransform.Model))
                {
                    Debug.LogError("Data is not a DCLTransform.Model type!");
                    return(null);
                }

                DCLTransform.Model modelRecovered = (DCLTransform.Model)data;

                if (!entity.components.ContainsKey(classId))
                {
                    entity.components.Add(classId, null);
                }


                if (entity.OnTransformChange != null)
                {
                    entity.OnTransformChange.Invoke(modelRecovered);
                }
                else
                {
                    entity.gameObject.transform.localPosition = modelRecovered.position;
                    entity.gameObject.transform.localRotation = modelRecovered.rotation;
                    entity.gameObject.transform.localScale    = modelRecovered.scale;

                    Environment.i.world.sceneBoundsChecker?.AddEntityToBeChecked(entity);
                }

                Environment.i.platform.physicsSyncController.MarkDirty();
                Environment.i.platform.cullingController.MarkDirty();
                return(null);
            }

            BaseComponent            newComponent = null;
            IRuntimeComponentFactory factory      = ownerController.componentFactory;

            Assert.IsNotNull(factory, "Factory is null?");

            if (classId == CLASS_ID_COMPONENT.UUID_CALLBACK)
            {
                string type = "";
                if (!(data is OnPointerEvent.Model))
                {
                    Debug.LogError("Data is not a DCLTransform.Model type!");
                    return(null);
                }

                OnPointerEvent.Model model = (OnPointerEvent.Model)data;

                type = model.type;

                if (!entity.uuidComponents.ContainsKey(type))
                {
                    //NOTE(Brian): We have to contain it in a gameObject or it will be pooled with the components attached.
                    var go = new GameObject("UUID Component");
                    go.transform.SetParent(entity.gameObject.transform, false);

                    switch (type)
                    {
                    case OnClick.NAME:
                        newComponent = go.GetOrCreateComponent <OnClick>();
                        break;

                    case OnPointerDown.NAME:
                        newComponent = go.GetOrCreateComponent <OnPointerDown>();
                        break;

                    case OnPointerUp.NAME:
                        newComponent = go.GetOrCreateComponent <OnPointerUp>();
                        break;
                    }

                    if (newComponent != null)
                    {
                        UUIDComponent uuidComponent = newComponent as UUIDComponent;

                        if (uuidComponent != null)
                        {
                            uuidComponent.Setup(this, entity, model);
                            entity.uuidComponents.Add(type, uuidComponent);
                        }
                        else
                        {
                            Debug.LogError("uuidComponent is not of UUIDComponent type!");
                        }
                    }
                    else
                    {
                        Debug.LogError("EntityComponentCreateOrUpdate: Invalid UUID type!");
                    }
                }
                else
                {
                    newComponent = EntityUUIDComponentUpdate(entity, type, model);
                }
            }
            else
            {
                if (!entity.components.ContainsKey(classId))
                {
                    newComponent = factory.CreateItemFromId <BaseComponent>(classId);

                    if (newComponent != null)
                    {
                        newComponent.scene  = this;
                        newComponent.entity = entity;

                        entity.components.Add(classId, newComponent);

                        newComponent.transform.SetParent(entity.gameObject.transform, false);
                        newComponent.UpdateFromJSON((string)data);
                    }
                }
                else
                {
                    newComponent = EntityComponentUpdate(entity, classId, (string)data);
                }
            }

            Environment.i.platform.physicsSyncController.MarkDirty();
            Environment.i.platform.cullingController.MarkDirty();
            return(newComponent);
        }
Esempio n. 16
0
 private void OnEntityTransformChanged(object newModel)
 {
     DCLTransform.Model newTransformModel = (DCLTransform.Model)newModel;
     lastAvatarPosition = newTransformModel.position;
 }