Beispiel #1
0
            public void OnAnchorFound(ARAnchor arAnchor, ARNode arNode)
            {
                // Spawn a visual plane if a PlaneAnchor was found
                if (arAnchor.GetType() == ARAnchor.Type.Plane)
                {
                    var planeAnchor = (ARPlaneAnchor)arAnchor;

                    // Create the visual geometry representing this plane
                    var dimensions = planeAnchor.Extent;
                    var plane      = new ViroCore.Surface(1, 1)
                    {
                        Width = dimensions.X, Height = dimensions.Z
                    };

                    // Set a default material for this plane.
                    var material = new Material {
                        DiffuseColor = Color.ParseColor("#BF000000")
                    };
                    plane.Materials = new List <Material>()
                    {
                        material
                    };

                    // Attach it to the node
                    var planeNode = new Node {
                        Geometry = plane
                    };
                    planeNode.SetRotation(new Vector(-Math.ToRadians(90.0), 0, 0));
                    planeNode.SetPosition(planeAnchor.Center);

                    // Attach this planeNode to the anchor's arNode
                    arNode.AddChildNode(planeNode);
                    surfaces.Add(arAnchor.AnchorId, planeNode);

                    // Attach click listeners to be notified upon a plane onClick.
                    planeNode.Click += (s, e) =>
                    {
                        foreach (var listener in mPlaneClickListeners)
                        {
                            listener.OnClick(e.P0, e.P1, e.P2);
                        }
                    };
                    HideIsTrackingLayoutUi();
                }
            }
Beispiel #2
0
        private void Init3DModelProduct()
        {
            // Create our group node containing the light, shadow plane, and 3D models
            mProductModelGroup = new Node();

            // Create a light to be shined on the model.
            Spotlight spotLight = new Spotlight();

            spotLight.InfluenceBitMask         = 1;
            spotLight.Position                 = new Vector(0, 5, 0);
            spotLight.CastsShadow              = true;
            spotLight.AttenuationEndDistance   = 7;
            spotLight.AttenuationStartDistance = 4;
            spotLight.Direction                = new Vector(0, -1, 0);
            spotLight.Intensity                = 6000;
            spotLight.ShadowOpacity            = 0.35f;
            mProductModelGroup.AddLight(spotLight);

            // Create a mock shadow plane in AR
            Node     shadowNode    = new Node();
            var      shadowSurface = new Surface(20, 20);
            Material material      = new Material();

            material.SetShadowMode(Material.ShadowMode.Transparent);
            material.SetLightingModel(Material.LightingModel.Lambert);
            shadowSurface.Materials = new List <Material>()
            {
                material
            };
            shadowNode.Geometry = shadowSurface;
            shadowNode.LightReceivingBitMask = 1;
            shadowNode.SetPosition(new Vector(0, -0.01, 0));
            shadowNode.SetRotation(new Vector(-1.5708, 0, 0));
            // We want the shadow node to ignore all events because it contains a surface of size 20x20
            // meters and causes this to capture events which will bubble up to the mProductModelGroup node.
            shadowNode.IgnoreEventHandling = true;
            mProductModelGroup.AddChildNode(shadowNode);

            // Load the model from the given mSelected Product
            Object3D productModel = new Object3D();

            productModel.LoadModel(mViroView.ViroContext, Uri.Parse(mSelectedProduct != null?mSelectedProduct.ThreeDModelUri:""), Object3D.Type.Fbx,
                                   new AsyncObject3DListener2(this));

            // Make this 3D Product object draggable.
            mProductModelGroup.SetDragType(Node.DragType.FixedToWorld);
            mProductModelGroup.Drag += (s, e) => { };
            // Set gesture listeners such that the user can rotate this model.
            productModel.GestureRotate += (s, e) =>
            {
                if (e.P3 == RotateState.RotateEnd)
                {
                    mLastProductRotation = mSavedRotateToRotation;
                }
                else
                {
                    Vector rotateTo = new Vector(mLastProductRotation.X, mLastProductRotation.Y + e.P2,
                                                 mLastProductRotation.Z);
                    mProductModelGroup.SetRotation(rotateTo);
                    mSavedRotateToRotation = rotateTo;
                }
            };

            mProductModelGroup.Opacity = 0;
            mProductModelGroup.AddChildNode(productModel);
        }