private void DrawBoundingBox(IObjectAnchorsServiceEventArgs instance)
    {
        MultiAnchorObjectPlacement placement;

        if (!_objectPlacements.TryGetValue(instance.InstanceId, out placement))
        {
            var boundingBox = _objectAnchorsService.GetModelBoundingBox(instance.ModelId);
            Debug.Assert(boundingBox.HasValue);

            placement = Instantiate(MultiAnchorPlacementPrefab).GetComponent <MultiAnchorObjectPlacement>();

            var bbox = placement.ModelSpaceContent.AddComponent <WireframeBoundingBox>();
            bbox.UpdateBounds(boundingBox.Value.Center, Vector3.Scale(boundingBox.Value.Extents, instance.ScaleChange), boundingBox.Value.Orientation, WireframeMaterial);

            var mesh = new GameObject("Model Mesh");
            mesh.AddComponent <MeshRenderer>().sharedMaterial = WireframeMaterial;
            mesh.transform.SetParent(placement.ModelSpaceContent.transform, false);
            MeshLoader.AddMesh(mesh, _objectAnchorsService, instance.ModelId);

            _objectPlacements.Add(instance.InstanceId, placement);
        }

        if (instance.SurfaceCoverage > placement.SurfaceCoverage ||
            !instance.Location.HasValue)
        {
            placement.UpdatePlacement(instance);
        }
    }
        private void AddOrUpdate(IObjectAnchorsServiceEventArgs e)
        {
            Debug.Log($"" +
                      $"add or update\n" +
                      $"Model: {e.ModelId}\n" +
                      $"Instance: {e.InstanceId}\n" +
                      $"Tracking Mode: {e.TrackingMode}\n" +
                      $"Coverage: {e.SurfaceCoverage}\n" +
                      $"Scale: {e.ScaleChange.x} {e.ScaleChange.y} {e.ScaleChange.z}\n" +
                      $"Updated: {e.LastUpdatedTime}\n");

            TrackedObject to;

            if (!_instanceToTrackedObject.TryGetValue(e.InstanceId, out to))
            {
                GameObject prefab = Instantiate(TrackedObjectPrefab);

                to = prefab.GetComponent <TrackedObject>();
                if (to == null)
                {
                    to = prefab.AddComponent <TrackedObject>();
                }
                _instanceToTrackedObject.Add(e.InstanceId, to);
            }

            if (TrackingStrategy != TrackingModeStrategy.Auto && e.TrackingMode != strategyToMode[TrackingStrategy])
            {
                _objectAnchorsService.SetObjectInstanceTrackingMode(e.InstanceId, strategyToMode[TrackingStrategy]);
            }

            to.UpdateTrackedObjectData(e);
        }
    private void DrawBoundingBox(IObjectAnchorsServiceEventArgs instance)
    {
        WireframeBoundingBox bbox;

        if (!_boundingBoxes.TryGetValue(instance.InstanceId, out bbox))
        {
            var boundingBox = _objectAnchorsService.GetModelBoundingBox(instance.ModelId);
            Debug.Assert(boundingBox.HasValue);

            bbox = new GameObject("Bounding Box").AddComponent <WireframeBoundingBox>();
            bbox.transform.SetParent(transform, true);
            bbox.gameObject.SetActive(false);
            bbox.UpdateBounds(boundingBox.Value.Center, Vector3.Scale(boundingBox.Value.Extents, instance.ScaleChange), boundingBox.Value.Orientation, WireframeMaterial);

            _boundingBoxes.Add(instance.InstanceId, bbox);
        }
        else
        {
            bbox.gameObject.SetActive(false);
        }

        var location = instance.Location;

        if (location.HasValue)
        {
            bbox.transform.SetPositionAndRotation(location.Value.Position, location.Value.Orientation);
            bbox.gameObject.SetActive(true);
        }
    }
示例#4
0
 public void UpdateTrackingData(IObjectAnchorsServiceEventArgs other)
 {
     BaseModelData   = TrackableObjectDataLoader.Instance.TrackableObjectDataFromId(other.ModelId);
     Location        = other.Location;
     Scale           = other.ScaleChange;
     InstanceId      = other.InstanceId;
     SurfaceCoverage = other.SurfaceCoverage;
     LastUpdatedTime = other.LastUpdatedTime;
     TrackingMode    = other.TrackingMode;
 }
        private void ObjectRemoved(IObjectAnchorsServiceEventArgs e)
        {
            Debug.Log($"remove instance {e.InstanceId} of model {e.ModelId}");
            TrackedObject to;

            if (_instanceToTrackedObject.TryGetValue(e.InstanceId, out to))
            {
                Destroy(to.gameObject);
                _instanceToTrackedObject.Remove(e.InstanceId);
            }
        }
    private void ObjectAnchorsService_ObjectRemoved(object sender, IObjectAnchorsServiceEventArgs args)
    {
        // This event handler is called from a non-UI thread.

        _objectAnchorsEventQueue.Enqueue(
            new ObjectAnchorsServiceEvent
        {
            Kind = ObjectAnchorsServiceEventKind.Removed,
            Args = args
        });
    }
        private void Update()
        {
            IObjectAnchorsServiceEventArgs pendingTrackedObjectData = Interlocked.Exchange(ref _pendingTrackedObjectData, null);

            if (pendingTrackedObjectData != null)
            {
                UpdatePlacement(pendingTrackedObjectData);
                UpdateMeshes();
                UpdateDebugText();
            }

            MultiAnchorRenderer.gameObject.SetActive(_objectTracker.MultiAnchorPlacement);
            SingleAnchorRenderer.gameObject.SetActive(_objectTracker.SingleAnchorPlacement);
            if (_objectTracker.SingleAnchorPlacement)
            {
                SingleAnchorRenderer.transform.localScale = _objectTracker.ScaleSingleAnchorPlacement ? _scaleChange : Vector3.one;
            }
        }
        private void UpdatePlacement(IObjectAnchorsServiceEventArgs data)
        {
            if (_multiAnchorPlacement == null)
            {
                _multiAnchorPlacement = MultiAnchorPlacement.GetComponent <MultiAnchorObjectPlacement>();
            }

            _multiAnchorPlacement.UpdatePlacement(data);

            if (data.Location.HasValue)
            {
                SingleAnchorPlacement.transform.SetPositionAndRotation(data.Location.Value.Position, data.Location.Value.Orientation);
            }
            SingleAnchorPlacement.SetActive(data.Location.HasValue);
            _scaleChange = data.ScaleChange;

            ObjectAnchorsBoundingBox?bb = TrackedObjectState.BaseLogicalBoundingBox;

            if (bb.HasValue)
            {
                LogicalCenter.transform.localPosition = bb.Value.Center;
                LogicalCenter.transform.localRotation = bb.Value.Orientation;
            }
        }
 public void UpdateTrackedObjectData(IObjectAnchorsServiceEventArgs data)
 {
     Debug.Log($"Updating tracking data for {data.InstanceId} model {data.ModelId} mode {data.TrackingMode}");
     TrackedObjectState.UpdateTrackingData(data);
     _trackedObjectDataChanged = true;
 }
 private void ObjectAdded(IObjectAnchorsServiceEventArgs e)
 {
     AddOrUpdate(e);
 }
 private void _objectAnchorsService_ObjectAdded(object sender, IObjectAnchorsServiceEventArgs e)
 {
     UpdateQueue.Enqueue(() => { ObjectAdded(e); });
 }
示例#12
0
 public void UpdateTrackedObjectData(IObjectAnchorsServiceEventArgs data)
 {
     Debug.Log($"Updating tracking data for {data.InstanceId} model {data.ModelId} mode {data.TrackingMode}");
     TrackedObjectState.UpdateTrackingData(data);
     Interlocked.Exchange(ref _pendingTrackedObjectData, data);
 }