private static void UpdatePreView(ref ImageTargetBehaviour marker) { if (Application.isPlaying) { return; } var mat = GetMarkerMaterial(Application.streamingAssetsPath + "/" + marker.GetPath()); if (mat) { var render = marker.GetComponent <MeshRenderer>(); if (render == null) { render = marker.gameObject.AddComponent <MeshRenderer>(); } render.material = mat; float ratio = (float)mat.mainTexture.height / (float)mat.mainTexture.width; var meshFilter = marker.GetComponent <MeshFilter>(); if (meshFilter == null) { meshFilter = marker.gameObject.AddComponent <MeshFilter>(); } meshFilter.sharedMesh = makeQuadMesh(ratio); } EditorUtility.UnloadUnusedAssetsImmediate(); }
// Assign material and texture to Image Target. public static void UpdateMaterial(ImageTargetBehaviour it) { // Load reference material. string referenceMaterialPath = QCARUtilities.GlobalVars.REFERENCE_MATERIAL_PATH; Material referenceMaterial = (Material)AssetDatabase.LoadAssetAtPath(referenceMaterialPath, typeof(Material)); if (referenceMaterial == null) { Debug.LogError("Could not find reference material at " + referenceMaterialPath + " please reimport Unity package."); return; } // Load texture from texture folder. Textures have per convention the // same name as Image Targets + "_scaled" as postfix. string pathToTexture = QCARUtilities.GlobalVars.TARGET_TEXTURES_PATH; string textureFile = pathToTexture + it.DataSetName + "/" + it.TrackableName + "_scaled"; if (File.Exists(textureFile + ".png")) { textureFile += ".png"; } else if (File.Exists(textureFile + ".jpg")) { textureFile += ".jpg"; } Texture2D targetTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(textureFile, typeof(Texture2D)); if (targetTexture == null) { // If the texture is null we simply assign a default material. it.GetComponent <Renderer>().sharedMaterial = referenceMaterial; return; } // We create a new material that is based on the reference material but // also contains a texture. Material materialForTargetTexture = new Material(referenceMaterial); materialForTargetTexture.mainTexture = targetTexture; materialForTargetTexture.name = targetTexture.name + "Material"; materialForTargetTexture.mainTextureScale = new Vector2(1, 1); it.GetComponent <Renderer>().sharedMaterial = materialForTargetTexture; // Cleanup assets that have been created temporarily. EditorUtility.UnloadUnusedAssets(); }
public void BuildTarget() { if (udt_FrameQuality == ImageTargetBuilder.FrameQuality.FRAME_QUALITY_HIGH) { //print(targetBehaviour.GetComponent<DefaultTrackableEventHandler>().didclick); didPress = !didPress; targetBehaviour.GetComponent <DefaultTrackableEventHandler>().HideorShowOnButtonPress(didPress); // I want to build a new target udt_targetBuildingBehaviour.BuildNewTarget(targetCounter.ToString(), targetBehaviour.GetSize().x); } }
/// <summary> /// Create or destroy the virtual button with the given name. /// </summary> public void ToggleVirtualButton(string name) { if (mImageTargetWood.ImageTarget != null) { // Get the virtual button if it exists. VirtualButton vb = mImageTargetWood.ImageTarget.GetVirtualButtonByName(name); if (vb != null) { // Destroy the virtual button if it exists. mImageTargetWood.DestroyVirtualButton(name); } else { // Get the position and scale originally used for this virtual button. Vector3 position, scale; if (mVBPositionDict.TryGetValue(name, out position) && mVBScaleDict.TryGetValue(name, out scale)) { // Deactivate the dataset before creating the virtual button. ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>(); DataSet dataSet = objectTracker.GetActiveDataSets().First(); objectTracker.DeactivateDataSet(dataSet); // Create the virtual button. VirtualButtonBehaviour vbb = mImageTargetWood.CreateVirtualButton( name, new Vector2(position.x, position.z), new Vector2(scale.x, scale.z)) as VirtualButtonBehaviour; if (vbb != null) { // Register the button with the event handler on the Wood target. vbb.RegisterEventHandler(mImageTargetWood.GetComponent <VirtualButtonEventHandler>()); // Add a mesh to outline the button. CreateVBMesh(vbb); // If the Wood target isn't currently tracked hide the button. if (mImageTargetWood.CurrentStatus == TrackableBehaviour.Status.NOT_FOUND) { vbb.GetComponent <Renderer>().enabled = false; } } // Reactivate the dataset. objectTracker.ActivateDataSet(dataSet); } } } base.CloseMenu(); }
// Here we handle a cloud target recognition event public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult) { // do something with the target metadata mTargetMetadata = targetSearchResult.MetaData; Debug.Log("mTargetMetadata" + mTargetMetadata.ToString()); Debug.Log("targetSearchResult" + targetSearchResult.ToString()); // stop the target finder (i.e. stop scanning the cloud) mCloudRecoBehaviour.CloudRecoEnabled = false; // Build augmentation based on target if (ImageTargetTemplate) { // enable the new result with the same ImageTargetBehaviour: ObjectTracker tracker = TrackerManager.Instance.GetTracker <ObjectTracker>(); ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)tracker.TargetFinder.EnableTracking( targetSearchResult, ImageTargetTemplate.gameObject); string metaData = targetSearchResult.MetaData; imageTargetBehaviour.GetComponent <DefaultTrackableEventHandler>().assetFileName = metaData; } }