QCAR 加载 激活 删除dataset
来源:互联网 发布:剑三成男捏脸数据大 编辑:程序博客网 时间:2024/06/01 09:13
Swappable Device Databases
The DataSetLoadBehaviour is a script that is by default attached to the ARCamera object. The script exposes a list of device databases (that are part of the project) to be loaded at scene startup. It also contains a dropdown list to choose a device database to be activated. You can use different settings inDataSetLoadBehaviour across different scenes. This enables you to bind device databases implicitly to Unity scenes. Be aware that this script was not created to provide a runtime API. It loads/activates the device databases only at startup, but doesn’t do anything when its properties are changed later in the application lifecycle. The Runtime Dataset API needs to be used to change device databases at runtime.
Runtime device database API
Mainly three classes are used to load/unload and activate/deactivate databases at runtime –TrackerManager, ImageTracker and DataSet.
Loading a dataset
- Check whether the file at the given storage location exists: DataSet.Exists (string path, DataSet.StorageType storageType);
Note: You can also call "Exists" without specifying a storage type. The assumption, then, is that your devce database has been bundled with the application in "StreamingAssets/QCAR."
Note: You can also call “Exists” without specifying a storage type. The assumption then is that your device database has been bundled with the application in “StreamingAssets/QCAR.”
- Request an ImageTracker instance from TrackerManager:TrackerManager.Instance.GetTracker (Tracker.Type.IMAGE_TRACKER);
- Create a new DataSet instance: ImageTracker.CreateDataSet();
- Load a dataset file from its storage location: DataSet.Load(string path, DataSet.StorageType storageType);
The same storage type rules apply as for “Exists”.
Activating a dataset
- Use the imageTracker instance to activate a dataset ImageTracker.ActivateDataSet(DataSet dataset);
Example code:
// Load and activate a data set at the given path.private bool LoadDataSet(string dataSetPath, DataSet.StorageType storageType){ // Check if the data set exists at the given path. if (!DataSet.Exists(dataSetPath, storageType)) { Debug.LogError("Data set " + dataSetPath + " does not exist."); return false; } // Request an ImageTracker instance from the TrackerManager. ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER); // Create a new empty data set. DataSet dataSet = imageTracker.CreateDataSet(); // Load the data set from the given path. if (!dataSet.Load(dataSetPath, storageType)) { Debug.LogError("Failed to load data set " + dataSetPath + "."); return false; } // (Optional) Activate the data set. imageTracker.ActivateDataSet(dataSet); return true;}
Adding content to a target
In Vuforia 2.0, DataSets now contain Trackables, whereas TrackableBehaviours represent aTrackable result at runtime. All TrackableBehaviours for the currently loaded Trackables can be queried using StateManager.GetTrackableBehaviours().
To add content to the TrackableBehaviour for a specific dataset at runtime, follow these steps:
- Request the TrackableBehaviours from the StateManager: TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
- When iterating over them, check if the TrackableBehaviour belongs to the DataSet:
if (dataSet.Contains(trackableBehaviour.Trackable)) - Attach a TrackableEventHandler to the game object of the TrackableBehaviour: GameObject.AddComponent<MyTrackableEventHandler>(); write your own implementation of the ITrackableEventHandler interface, or use the DefaultTrackableEventHandler that comes with the QCAR extension. The TrackableEventHandler provides callbacks to handle Target lost and found events.
- Add a child object for augmentation to the TrackableBehaviour. GameObject.transform.parent = DataSetTrackableBehaviour.transform;
Example code:
// Add Trackable event handler and content (cubes) to the Targets. private void AttachContentToTrackables(DataSet dataSet) { // get all current TrackableBehaviours IEnumerable<TrackableBehaviour> trackableBehaviours = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours(); // Loop over all TrackableBehaviours. foreach (TrackableBehaviour trackableBehaviour in trackableBehaviours) { // check if the Trackable of the current Behaviour is part of this dataset if (dataSet.Contains(trackableBehaviour.Trackable)) { GameObject go = trackableBehaviour.gameObject; // Add a Trackable event handler to the Trackable. // This Behaviour handles Trackable lost/found callbacks. go.AddComponent<DefaultTrackableEventHandler>(); // Create a cube object. GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); // Attach the cube to the Trackable and make sure it has a proper size. cube.transform.parent = trackableBehaviour.transform; cube.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f); cube.transform.localPosition = new Vector3(0.0f, 0.35f, 0.0f); cube.transform.localRotation = Quaternion.identity; cube.active = true; trackableBehaviour.gameObject.active = true; } } }
Destroying a dataset
- Request an ImageTracker instance as explained above.
- Make sure that the dataset to destroy is not active (otherwise destruction will fail):ImageTracker.Deactivate(DataSet dataset);
- Destroy the dataset: ImageTracker.DestroyDataSet(DataSet dataset, bool destroyTrackableGameObjects);
Example code:
// Destroy a dataset.private bool DestroyDataSet(DataSet dataSet){ // Request an ImageTracker instance from the TrackerManager. ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER); // Make sure the data set is not active. imageTracker.DeactivateDataSet(dataSet); // Destroy the data set // (choose true to also destroy the Target objects that belong to the data set). bool success = imageTracker.DestroyDataSet(dataSet, true); return success;}
- QCAR 加载 激活 删除dataset
- dataset删除数据
- DataSet加载xml
- office2016删除激活向导
- 删除DATASET中行数据技巧
- DataSet 中的删除行问题
- 删除DATASET中行数据技巧
- dataset的增加,删除,,查找
- dataset中删除重复数据
- QCAR学习(1)
- DataSet增加修改删除一个数据
- C# DataSet 删除不需要的列
- DataSet SqlCommandBuilder添加修改删除数据
- C# 在dataset内删除数据
- XML基础之 DataSet加载XML数据文件
- C# 遍历文件夹加载到DataSet里面
- 从SD卡中加载Dataset
- Vuforia 动态加载DataSet和ImageTarget
- NDK 之 JNI数据传输
- java中nio独占锁共享锁交互
- Spring中IOC和AOP的详细解释
- 树的简单实现
- System.Xml.XmlReader编码问题
- QCAR 加载 激活 删除dataset
- unity3d 将摄像头视野保存到图片
- Android自动测试之monkeyrunner工具
- Css Sprites
- 18个扩展让你的Firefox成为渗透测试工具
- 我想下载
- Secure CRT 乱码问题解决
- make input element draggable after disabling it
- 黑马程序员_7K月薪面试题之_银行业务调度系统