コード例 #1
0
        private void AddBox(PlaneNode planeNode)
        {
            var subPlaneNode = planeNode.GetChild("subplane");

            var boxNode = planeNode.CreateChild("Box");

            boxNode.SetScale(0.1f);

            var x = planeNode.ExtentX * (float)(random.NextDouble() - 0.5f);
            var z = planeNode.ExtentZ * (float)(random.NextDouble() - 0.5f);

            boxNode.Position = new Vector3(x, 0.1f, z) + subPlaneNode.Position;

            var box = boxNode.CreateComponent <Box>();

            box.Color = Color.Blue;

            var rotationSpeed = new Vector3(10.0f, 20.0f, 30.0f);
            var rotator       = new Rotator()
            {
                RotationSpeed = rotationSpeed
            };

            boxNode.AddComponent(rotator);
        }
コード例 #2
0
        private void OnARFrameUpdated(Frame arFrame)
        {
            var all = arCore.Session.GetAllTrackables(
                Java.Lang.Class.FromType(
                    typeof(Com.Google.AR.Core.Plane)));

            foreach (Com.Google.AR.Core.Plane plane in all)
            {
                var node = FindNodeByPlaneId(plane.GetHashCode().ToString());

                if (node == null)
                {
                    node = new PlaneNode
                    {
                        PlaneId = plane.GetHashCode().ToString(),
                        Name    = $"plane{plane.GetHashCode()}"
                    };

                    CreateSubPlane(node);
                    scene.AddChild(node);
                }

                SetPositionAndRotation(plane, node);
                UpdateSubPlane(node, Vector3.Zero);
            }
        }
コード例 #3
0
        protected void UpdateSubPlane(PlaneNode planeNode, Vector3 position)
        {
            var subPlaneNode = planeNode.GetChild("subplane");

            subPlaneNode.Scale    = new Vector3(planeNode.ExtentX, 0.05f, planeNode.ExtentZ);
            subPlaneNode.Position = position;
        }
コード例 #4
0
        protected void CreateSubPlane(PlaneNode planeNode)
        {
            var node = planeNode.CreateChild("subplane");

            node.Position = new Vector3(0, 0.05f, 0);

            var box = node.CreateComponent <Box>();

            box.Color = Color.FromHex("#22ff0000");
        }
コード例 #5
0
        private void SetPositionAndRotation(ARPlaneAnchor anchor, PlaneNode node)
        {
            arkitComponent.ApplyOpenTkTransform(node, anchor.Transform, true);

            node.ExtentX = anchor.Extent.X;
            node.ExtentZ = anchor.Extent.Z;

            var position = new Vector3(anchor.Center.X, anchor.Center.Y, -anchor.Center.Z);

            UpdateSubPlane(node, position);
        }
コード例 #6
0
        private void SetPositionAndRotation(Com.Google.AR.Core.Plane plane, PlaneNode node)
        {
            node.ExtentX  = plane.ExtentX;
            node.ExtentZ  = plane.ExtentZ;
            node.Rotation = new Quaternion(plane.CenterPose.Qx(),
                                           plane.CenterPose.Qy(),
                                           plane.CenterPose.Qz(),
                                           -plane.CenterPose.Qw());

            node.Position = new Vector3(plane.CenterPose.Tx(),
                                        plane.CenterPose.Ty(),
                                        -plane.CenterPose.Tz());
        }
コード例 #7
0
        private void UpdateOrAddPlaneNode(ARPlaneAnchor anchor)
        {
            var node = FindNodeByPlaneId(anchor.Identifier.ToString());

            if (node == null)
            {
                node = new PlaneNode()
                {
                    PlaneId = anchor.Identifier.ToString(),
                    Name    = $"plane{anchor.GetHashCode()}"
                };

                CreateSubPlane(node);
                scene.AddChild(node);
            }

            SetPositionAndRotation(anchor, node);
        }