This class stores information about a VisAnchor.
Example #1
0
        /// <summary>
        /// Creates a new <see cref="ViewContainer"/> and adds it to the list of containers.
        /// </summary>
        /// <param name="container">The <see cref="VisContainer"/> object representing the settings for the new <see cref="ViewContainer"/>.</param>
        /// <param name="syncWithRemote">Indicates whether the container should also be created on remote clients.</param>
        public void CreateViewContainer(VisContainer container, bool syncWithRemote = true)
        {
            // add to list of containers or update list
            if (ViewContainers.ContainsKey(container.Id))
            {
                // already in list, update
                ViewContainers[container.Id].Init(container);
            }
            else
            {
                // not in list, create and add
                Transform worldAnchor = GameObject.FindGameObjectWithTag("VisRootAnchor").transform;
                var       placeholder = Instantiate(VisPlaceholderPrefab, worldAnchor);       // instantiate placeholder prefab, set the World Anchor as parent, to make sure every client sees the same
                placeholder.Init(container);
                ViewContainers.Add(container.Id, placeholder.GetComponent <ViewContainer>()); // add to list
            }

            if (syncWithRemote)
            {
                var message = new MessageCreateVisContainer(container);
                Services.NetworkManager().SendMessage(message.Pack());
            }
        }
Example #2
0
        private List <VisContainer> ParseAnchors(List <VisAnchor> anchorXml)
        {
            var results = new List <VisContainer>();

            foreach (var anchor in anchorXml)
            {
                // create struct with default data
                var visContainer = new VisContainer
                {
                    Position    = new float[] { 0, 0, 0 },
                    Scale       = new float[] { 1, 1, 1 },
                    Orientation = new float[] { 0, 0, 0, 1 },
                    Id          = anchor.Id,
                    ParentId    = anchor.ParentId,
                };
                float unitScaleFactor = 1.0f;
                switch (anchor.Units)
                {
                case "mm":
                    unitScaleFactor = 0.001f;
                    break;

                case "cm":
                    unitScaleFactor = 0.01f;
                    break;

                case "m":
                    unitScaleFactor = 1f;
                    break;
                }

                // rotation format
                RotationFormat rotationFormat = RotationFormat.QUATERNION;
                switch (anchor.RotationFormat)
                {
                case "euler_deg":
                    rotationFormat = RotationFormat.EULER_DEG;
                    break;

                case "euler_rad":
                    rotationFormat = RotationFormat.EULER_RAD;
                    break;

                case "quaternion":
                    rotationFormat = RotationFormat.QUATERNION;
                    break;

                case "direction_vector":
                    rotationFormat = RotationFormat.DIRECTION_VECTOR;
                    break;
                }

                if (IsLiteral(anchor.PositionX) && IsLiteral(anchor.PositionY) && IsLiteral(anchor.PositionZ))
                {
                    var position = ParseStaticPosition(anchor.PositionX, anchor.PositionY, anchor.PositionZ, unitScaleFactor);
                    visContainer.Position = new float[] { position.x, position.y, position.z };
                }

                if (IsLiteral(anchor.ScaleX) && IsLiteral(anchor.ScaleY) && IsLiteral(anchor.ScaleZ))
                {
                    var scale = ParseStaticScale(anchor.ScaleX, anchor.ScaleY, anchor.ScaleZ);
                    visContainer.Scale = new float[] { scale.x, scale.y, scale.z };
                }

                if (anchor.RotationW.Length == 0)
                {
                    if (IsLiteral(anchor.RotationX) && IsLiteral(anchor.RotationY) && IsLiteral(anchor.RotationZ))
                    {
                        var rotation = ParseStaticRotation(anchor.RotationX, anchor.RotationY, anchor.RotationZ, rotationFormat);
                        visContainer.Orientation = new float[] { rotation.x, rotation.y, rotation.z, rotation.w };
                    }
                }
                else
                {
                    if (IsLiteral(anchor.RotationW) && IsLiteral(anchor.RotationX) && IsLiteral(anchor.RotationY) && IsLiteral(anchor.RotationZ))
                    {
                        var rotation = ParseStaticRotation(anchor.RotationW, anchor.RotationX, anchor.RotationY, anchor.RotationZ);
                        visContainer.Orientation = new float[] { rotation.x, rotation.y, rotation.z, rotation.w };
                    }
                }

                results.Add(visContainer);
            }

            return(results);
        }