// Load the underlying ARToolKit marker structure(s) and set the UID. public void Load() { //ARController.Log(LogTag + "ARMarker.Load()"); if (UID != NO_ID) { //ARController.Log(LogTag + "Marker already loaded."); return; } if (!PluginFunctions.inited) { return; } // Work out the configuration string to pass to ARToolKit. string dir = Application.streamingAssetsPath; string cfg = ""; switch (MarkerType) { case MarkerType.Square: // Multiply width by 1000 to convert from metres to ARToolKit's millimetres. cfg = "single_buffer;" + PatternWidth * 1000.0f + ";buffer=" + PatternContents; break; case MarkerType.SquareBarcode: // Multiply width by 1000 to convert from metres to ARToolKit's millimetres. cfg = "single_barcode;" + BarcodeID + ";" + PatternWidth * 1000.0f; break; case MarkerType.Multimarker: #if !UNITY_METRO if (dir.Contains("://")) { // On Android, we need to unpack the StreamingAssets from the .jar file in which // they're archived into the native file system. dir = Application.temporaryCachePath; if (!unpackStreamingAssetToCacheDir(MultiConfigFile)) { dir = ""; } else { //string[] unpackFiles = getPatternFiles; //foreach (string patternFile in patternFiles) { //if (!unpackStreamingAssetToCacheDir(patternFile)) { // dir = ""; // break; //} } } #endif if (!string.IsNullOrEmpty(dir) && !string.IsNullOrEmpty(MultiConfigFile)) { cfg = "multi;" + System.IO.Path.Combine(dir, MultiConfigFile); } break; case MarkerType.NFT: #if !UNITY_METRO if (dir.Contains("://")) { // On Android, we need to unpack the StreamingAssets from the .jar file in which // they're archived into the native file system. dir = Application.temporaryCachePath; foreach (string ext in NFTDataExts) { string basename = NFTDataName + "." + ext; if (!unpackStreamingAssetToCacheDir(basename)) { dir = ""; break; } } } #endif if (!string.IsNullOrEmpty(dir) && !string.IsNullOrEmpty(NFTDataName)) { cfg = "nft;" + System.IO.Path.Combine(dir, NFTDataName); } break; default: // Unknown marker type? break; } // If a valid config. could be assembled, get ARToolKit to process it, and assign the resulting ARMarker UID. if (!string.IsNullOrEmpty(cfg)) { UID = PluginFunctions.arwAddMarker(cfg); if (UID == NO_ID) { ARController.Log(LogTag + "Error loading marker."); } else { // Marker loaded. Do any additional configuration. //ARController.Log("Added marker with cfg='" + cfg + "'"); if (MarkerType == MarkerType.Square || MarkerType == MarkerType.SquareBarcode) { UseContPoseEstimation = currentUseContPoseEstimation; } Filtered = currentFiltered; FilterSampleRate = currentFilterSampleRate; FilterCutoffFreq = currentFilterCutoffFreq; if (MarkerType == MarkerType.NFT) { NFTScale = currentNFTScale; } // Retrieve any required information from the configured ARToolKit ARMarker. if (MarkerType == MarkerType.NFT) { int imageSizeX, imageSizeY; PluginFunctions.arwGetMarkerPatternConfig(UID, 0, null, out NFTWidth, out NFTHeight, out imageSizeX, out imageSizeY); NFTWidth *= 0.001f; NFTHeight *= 0.001f; //ARController.Log("Got NFTWidth=" + NFTWidth + ", NFTHeight=" + NFTHeight + "."); } else { // Create array of patterns. A single marker will have array length 1. int numPatterns = PluginFunctions.arwGetMarkerPatternCount(UID); //ARController.Log("Marker with UID=" + UID + " has " + numPatterns + " patterns."); if (numPatterns > 0) { patterns = new ARPattern[numPatterns]; for (int i = 0; i < numPatterns; i++) { patterns[i] = new ARPattern(UID, i); } } } } } }
// Load the underlying ARToolKit marker structure(s) and set the UID. public void Load() { lock (loadLock) { if (UID != NO_ID) { return; } if (!PluginFunctions.inited) { // If arwInitialiseAR() has not yet been called, we can't load the native trackable yet. // ARController.InitialiseAR() will call this again when arwInitialiseAR() has been called. return; } // Work out the configuration string to pass to ARToolKit. string assetDirectory = Application.streamingAssetsPath; string configuration = string.Empty; string path = string.Empty; switch (Type) { case TrackableType.TwoD: if (string.IsNullOrEmpty(TwoDImageName)) { ARController.Log(string.Format(LOAD_FAILURE, "2D image trackable due to no TwoDImageName")); return; } path = Path.Combine(TWOD_FORMAT, TwoDImageName); if (!ARUtilityFunctions.GetFileFromStreamingAssets(path, out assetDirectory)) { ARController.Log(string.Format(LOAD_FAILURE, TwoDImageName)); return; } if (!string.IsNullOrEmpty(assetDirectory)) { configuration = string.Format(TWOD_CONFIG, assetDirectory, TwoDImageHeight * ARTOOLKIT_TO_UNITY); } break; case TrackableType.Square: // Multiply width by 1000 to convert from metres to ARToolKit's millimetres. configuration = string.Format(SINGLE_BUFFER_CONFIG, PatternWidth * ARTOOLKIT_TO_UNITY, PatternContents); break; case TrackableType.SquareBarcode: // Multiply width by 1000 to convert from metres to ARToolKit's millimetres. configuration = string.Format(SINGLE_BARCODE_CONFIG, BarcodeID, PatternWidth * ARTOOLKIT_TO_UNITY); break; case TrackableType.Multimarker: if (string.IsNullOrEmpty(MultiConfigFile)) { ARController.Log(string.Format(LOAD_FAILURE, "multimarker due to no MultiConfigFile")); return; } path = Path.Combine(MULTI_FORMAT, MultiConfigFile + MULTI_EXT); ARUtilityFunctions.GetFileFromStreamingAssets(path, out assetDirectory); if (!string.IsNullOrEmpty(assetDirectory)) { configuration = string.Format(MULTI_CONFIG, assetDirectory); } break; default: // Unknown marker type? ARController.Log(string.Format(LOAD_FAILURE, "due to unknown marker")); return; } // If a valid config. could be assembled, get ARToolKit to process it, and assign the resulting ARMarker UID. if (string.IsNullOrEmpty(configuration)) { ARController.Log(LOG_TAG + "trackable configuration is null or empty."); return; } uid = PluginFunctions.arwAddMarker(configuration); if (UID == NO_ID) { ARController.Log(LOG_TAG + "Error loading trackable."); return; } // Trackable loaded. Do any additional configuration. if (Type == TrackableType.Square || Type == TrackableType.SquareBarcode) { UseContPoseEstimation = currentUseContPoseEstimation; } Filtered = currentFiltered; FilterSampleRate = currentFilterSampleRate; FilterCutoffFreq = currentFilterCutoffFreq; // Retrieve any required information from the configured ARTrackable. if (Type == TrackableType.TwoD) { int dummyImageSizeX, dummyImageSizeY; float dummyTwoDImageHeight; PluginFunctions.arwGetTrackableAppearanceConfig(UID, 0, null, out TwoDImageWidth, out dummyTwoDImageHeight, out dummyImageSizeX, out dummyImageSizeY); TwoDImageWidth *= UNITY_TO_ARTOOLKIT; } else { // Create array of patterns. A single marker will have array length 1. int numPatterns = PluginFunctions.arwGetTrackableAppearanceCount(UID); if (numPatterns > 0) { patterns = new ARPattern[numPatterns]; for (int i = 0; i < numPatterns; ++i) { patterns[i] = new ARPattern(UID, i); } } } } }