/**<summary> Process image or folder of images for debugging a session from device </summary>*/ public void ProcessImages(string path) { ARController arController = FindObjectOfType <ARController>(); if (!arController) { return; } arController.SnapshotPose(); #pragma warning disable 4014 if (path.Contains(".jpg") || path.Contains(".jpeg")) { ServerAPI.LocationFine(locationController.buildingID, FileIO.GetFile(path)); // -> ARController.OnLocationResponse } else { foreach (string file in Directory.GetFiles(path)) { if (file.Contains("jpg") || file.Contains(".jpeg")) { ServerAPI.LocationFine(locationController.buildingID, FileIO.GetFile(file)); } // -> ARController.OnLocationResponse } } #pragma warning restore 4014 }
void Update() { if (arCamera == null) { return; } if (!isSetup) { ARCameraManager manager = arCamera.GetComponent <ARCameraManager>(); if (manager.TryGetIntrinsics(out var intrinsics)) { ConstructCameraFrame(intrinsics); isSetup = true; } } var pose = ARController.ARPoseToUnity(arCameraTransform.AsPose()); //var relativePose = TfListener.RelativePoseToFixedFrame(pose); //Transform.SetParentLocal(TfListener.Instance.FixedFrame.Transform); //var relativePose = TfListener.RelativePoseToOrigin(pose); //Transform.SetParentLocal(TfListener.OriginFrame.Transform); Transform.SetLocalPose(pose); }
public bool SetupCamera(float nearClipPlane, float farClipPlane, Matrix4x4 projectionMatrix, ref bool opticalOut) { Camera c = this.gameObject.GetComponent <Camera>(); // A perspective projection matrix from the tracker c.orthographic = false; // Shouldn't really need to set these, because they are part of the custom // projection matrix, but it seems that in the editor, the preview camera view // isn't using the custom projection matrix. c.nearClipPlane = nearClipPlane; c.farClipPlane = farClipPlane; if (Optical) { float fovy; float aspect; float[] m = new float[16]; float[] p = new float[16]; opticalSetupOK = PluginFunctions.arwLoadOpticalParams(null, OpticalParamsFileContents, OpticalParamsFileContents.Length, out fovy, out aspect, m, p); if (!opticalSetupOK) { ARController.Log(LogTag + "Error loading optical parameters."); return(false); } m[12] *= 0.001f; m[13] *= 0.001f; m[14] *= 0.001f; ARController.Log(LogTag + "Optical parameters: fovy=" + fovy + ", aspect=" + aspect + ", camera position (m)={" + m[12].ToString("F3") + ", " + m[13].ToString("F3") + ", " + m[14].ToString("F3") + "}"); c.projectionMatrix = ARUtilityFunctions.MatrixFromFloatArray(p); opticalViewMatrix = ARUtilityFunctions.MatrixFromFloatArray(m); if (OpticalEyeLateralOffsetRight != 0.0f) { opticalViewMatrix = Matrix4x4.TRS(new Vector3(-OpticalEyeLateralOffsetRight, 0.0f, 0.0f), Quaternion.identity, Vector3.one) * opticalViewMatrix; } // Convert to left-hand matrix. opticalViewMatrix = ARUtilityFunctions.LHMatrixFromRHMatrix(opticalViewMatrix); opticalOut = true; } else { c.projectionMatrix = projectionMatrix; } // Don't clear anything or else we interfere with other foreground cameras c.clearFlags = CameraClearFlags.Nothing; // Renders after the clear and background cameras c.depth = 2; c.transform.position = new Vector3(0.0f, 0.0f, 0.0f); c.transform.rotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); c.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); return(true); }
private void OnReceivedMessage() { if (this.firstRun == false) { this.player.SetClientID(ARNetworkHub.Instance.GetClientID()); this.firstRun = true; } //process message here ARLocalMessage localMsg = ARMessageQueue.Instance.GetLatestMessage(); //ConsoleManager.LogMessage (TAG + " received message with type of " + localMsg.GetActionType ()); if (localMsg.GetActionType() == ARNetworkMessage.ActionType.SPAWN_OBJECT && !this.opponents.ContainsKey(localMsg.GetClientID())) { ConsoleManager.LogMessage(TAG + " Spawning opponent for " + localMsg.GetClientID()); ARController opponent = GameObject.Instantiate <ARController>(this.opponentCopy, this.opponentCopy.transform.parent); opponent.gameObject.transform.position = this.player.transform.position; opponent.gameObject.SetActive(true); opponent.SetClientID(localMsg.GetClientID()); this.opponents.Add(localMsg.GetClientID(), opponent); } else if (localMsg.GetActionType() == ARNetworkMessage.ActionType.MOVE) { this.opponents[localMsg.GetClientID()].MoveToDestination(localMsg.GetPosition()); //this.opponent.MoveToDestination(localMsg.GetPosition()); } }
public void startAugmented() { ARController aRController = FindObjectOfType <ARController>(); aRController.StartAR(); //float sds = gameObject.transform.position.x; }
// Get the trackable, if any, currently acting as the base. public ARTrackable GetBaseTrackable() { if (baseTrackable != null) { if (baseTrackable.Visible) { return(baseTrackable); } else { baseTrackable = null; } } foreach (ARTrackable m in trackablesEligibleForBaseTrackable) { if (m.Visible) { baseTrackable = m; ARController.Log("Trackable " + m.UID + " became base trackable."); break; } } return(baseTrackable); }
private void copyToStreamingAssets(String path) { String fileName = path.Substring(path.LastIndexOf('/') + 1); String destination = Application.streamingAssetsPath + "/" + ARToolKitAssetManager.IMAGES_DIRECTORY_NAME + "/" + fileName; //Check type of file to be .jpg or .jpeg if (fileName.Contains(".jpg") || fileName.Contains(".jpeg")) { ARController.Log("Copy image from: " + path + " to: " + destination); if (!File.Exists(destination)) { FileUtil.CopyFileOrDirectory(path, destination); AssetDatabase.Refresh(); ARToolKitAssetManager.Reload(); } else { Debug.logger.Log(LogType.Error, "File with name: " + fileName + " already exists at destination: " + destination); } } else { //Dropped file is not a valid format print a warning\ Debug.logger.Log(LogType.Warning, "<color=red>Item with invalid extension dropped. Only .jpg and .jpeg allowed.</color>"); } }
IEnumerator DoTransition(bool flyIn) { ARController arcontroller = Component.FindObjectOfType(typeof(ARController)) as ARController; float transitionSpeed = flyIn ? 1.0f : -1.0f; bool transitioning = true; while (transitioning) { transitionAmount += transitionSpeed * Time.deltaTime; if (transitionAmount > 1.0f) { transitionAmount = 1.0f; transitioning = false; } if (transitionAmount < 0.0f) { transitionAmount = 0.0f; transitioning = false; } if (arcontroller != null) { arcontroller.SetVideoAlpha(1.0f - transitionAmount); } yield return(null); } print("Transition complete"); }
public static void OnPostProcessBuild(BuildTarget target, string appPath) { string[] pathSplit = appPath.Split('/'); string fileName = pathSplit[pathSplit.Length - 1]; string pathDirectory = appPath.TrimEnd(fileName.ToCharArray()); ARController.Log(string.Format(FILE_NAME_STATUS, fileName)); fileName = fileName.Trim(EXE.ToCharArray()); string fromPath = Path.Combine(pathDirectory, string.Format(RELATIVE_PATH, fileName)); if (Directory.Exists(string.Format(RELATIVE_PATH, fileName))) { ARController.Log("ARTOOLKIT BUILD ERROR: Couldn't data directory!. Please move DLLs from [appname]_data/Plugins to the same directory as the exe!"); return; } // Error when copying to remote drives. if (fromPath.StartsWith("//")) { fromPath = fromPath.Remove(0, 1); } foreach (string redistFile in REDIST_FILES) { File.Move(Path.Combine(fromPath, redistFile), Path.Combine(pathDirectory, redistFile)); } }
private static ARTrackable.TrackableType DetermineTrackableType(int markerIndex) { int start = ARToolKitAssetManager.Images.Length; if (markerIndex < start) { return(ARTrackable.TrackableType.TwoD); } start += ARToolKitAssetManager.PatternMarkers.Length; if (markerIndex < start) { return(ARTrackable.TrackableType.Square); } start += ARToolKitAssetManager.Multimarkers.Length; if (markerIndex < start) { return(ARTrackable.TrackableType.Multimarker); } ARController arController = ARController.Instance; start += ARToolKitAssetManager.GetBarcodeList(arController.MatrixCodeType).Length; if (markerIndex < start) { return(ARTrackable.TrackableType.SquareBarcode); } // Default. Harmless out of range. return(ARTrackable.TrackableType.Square); }
// Start is called before the first frame update void Start() { raycastManager = FindObjectOfType <ARRaycastManager>(); arController = FindObjectOfType <ARController>(); placementBase = transform.GetChild(0).gameObject; placementBase.SetActive(false); }
// Use this for initialization void Awake() { isRunning = false; arController = gameObject.GetComponent <ARController>(); arController.VideoThresholdMode = ARController.ARToolKitThresholdMode.Manual; markers = gameObject.GetComponents <ARMarker>(); thresholds = new VisibilityForThreshold[256]; }
/// <summary> /// Called when the user denies camera permissions in response to CheckCameraPermissions() or RequestCameraPermissions(). /// </summary> /// <param name="message">(unused)</param> void OnCameraPermissionDenied(string message) { ARController.Log("=====>> Warning: Camera permissions denied."); if (ShouldDisplayCameraPermissionsRationale()) { DisplayCameraPermissionsRationale(); } }
public void Start() { // initilizations arController = FindObjectOfType <ARController> (); pathPoints = new List <Vector2> (); pathMarkers = new List <GameObject> (); state = State.FindingFloor; undoTime = 0.0f; }
public static Quaternion QuaternionFromMatrix(Matrix4x4 m) { // Trap the case where the matrix passed in has an invalid rotation submatrix. if (m.GetColumn(2) == Vector4.zero) { ARController.Log("QuaternionFromMatrix got zero matrix."); return(Quaternion.identity); } return(Quaternion.LookRotation(m.GetColumn(2), m.GetColumn(1))); }
private bool CheckCameraPermissions(string gameObject) { if (!isAndroidMarshmallow()) { return(true); } ARController.Log(LogTag + "CheckCameraPermissions called."); return(this.androidPlugin.Call <bool>("checkCameraPermissions", gameObject)); }
private void Awake() { if (null == instance) { instance = this; } else { ARController.Log("ERROR: MORE THAN ONE ARSTATICCAMERA IN SCENE!"); } }
private bool isAndroidMarshmallow() { #if !UNITY_EDITOR int version = this.androidPlugin.Call <int>("getAndroidVersion"); ARController.Log(LogTag + "Android SDK version: " + version); return(version >= AndroidMarshmallow); #else return(false); #endif }
static ARToolKitMenuEditor() { if (EditorPrefs.GetBool(FIRST_RUN, true)) { EditorPrefs.SetBool(FIRST_RUN, false); ARController.Log(string.Format(GET_TOOLS_MESSAGE, TOOLS_MENU_PATH)); #if UNITY_EDITOR_WIN ARController.Log(string.Format(WINDOWS_UNITY_MESSAGE, TOOLS_MENU_PATH)); #endif } }
public void TogglePlanes(Boolean value) { ARController controller = GameObject.FindObjectOfType <ARController>(); controller.planes.ForEach(p => p.SetActive(value)); PointcloudVisualizer pointCloud = GameObject.FindObjectOfType <PointcloudVisualizer>(); pointCloud.gameObject.SetActive(value); controller.PlanesSearch = value; }
private void Start() { arController = FindObjectOfType <ARController>(); worldController = FindObjectOfType <WorldController>(); ServerAPI.OnAreasResponse += OnAreasResponse; ServerAPI.OnGPSResponse += OnGPSResponse; ServerAPI.UpdateGPSLocation(); // -> OnGPSResponse #if UNITY_EDITOR //Buildings(); #endif }
// Use this for initialization void Start() { arOrigin = this.gameObject.GetComponentInParent <AROrigin>(); audio1 = GameObject.FindGameObjectWithTag("arAudio1").GetComponent <AudioSource>(); audio2 = GameObject.FindGameObjectWithTag("arAudio2").GetComponent <AudioSource>(); markers = FindObjectsOfType(typeof(ARMarker)) as ARMarker[]; foreach (ARMarker m in markers) { m.OnDisable(); } myARController = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <ARController>(); FXCamera.SetActive(false); }
public void FindTrackables() { RemoveAllTrackables(); if (findTrackableMode != FindMode.Manual) { ARTrackable[] ms = FindObjectsOfType <ARTrackable>(); // Does not find inactive objects. foreach (ARTrackable m in ms) { if (findTrackableMode == FindMode.AutoAll || (findTrackableMode == FindMode.AutoByTags && findTrackableTags.Contains(m.Tag))) { trackablesEligibleForBaseTrackable.Add(m); } } ARController.Log(LogTag + "Found " + trackablesEligibleForBaseTrackable.Count + " trackables eligible to become base trackable."); } }
public void FindMarkers() { RemoveAllMarkers(); if (findMarkerMode != FindMode.Manual) { ARMarker[] ms = FindObjectsOfType <ARMarker>(); // Does not find inactive objects. foreach (ARMarker m in ms) { if (findMarkerMode == FindMode.AutoAll || (findMarkerMode == FindMode.AutoByTags && findMarkerTags.Contains(m.Tag))) { markersEligibleForBaseMarker.Add(m); } } ARController.Log(LogTag + "Found " + markersEligibleForBaseMarker.Count + " markers eligible to become base marker."); } }
void Start() { Physics.gravity = new Vector3(0, -200f, 0); m_Anim = GetComponent <Animator>(); m_Rigid = GetComponent <Rigidbody>(); m_PlayerTrans = transform; destinationPos = m_PlayerTrans.position; m_Speed = Speed; m_Enemy = GameObject.FindGameObjectWithTag("Enemy").transform; m_ARController = GetComponent <ARController>(); //attack and defend buttons b_Attack = GetComponent <Button>(); b_Attack.onClick.AddListener(() => B_Attack_1()); b_Defend = GetComponent <Button>(); b_Defend.onClick.AddListener(() => B_Defend_1()); }
private bool unpackStreamingAssetToCacheDir(string basename) { if (!File.Exists(System.IO.Path.Combine(Application.temporaryCachePath, basename))) { string file = System.IO.Path.Combine(Application.streamingAssetsPath, basename); // E.g. "jar:file://" + Application.dataPath + "!/assets/" + basename; WWW unpackerWWW = new WWW(file); while (!unpackerWWW.isDone) { } // This will block in the webplayer. TODO: switch to co-routine. if (!string.IsNullOrEmpty(unpackerWWW.error)) { ARController.Log(LogTag + "Error unpacking '" + file + "'"); return(false); } File.WriteAllBytes(System.IO.Path.Combine(Application.temporaryCachePath, basename), unpackerWWW.bytes); // 64MB limit on File.WriteAllBytes. } return(true); }
public void reload() { SceneManager.LoadScene("SampleScene"); ARController arc = GameObject.Find("ARController").GetComponent <ARController>(); arc.FitToScanOverlay.SetActive(false); arc.AugmentedImageVisualizerPrefab.Object.SetActive(true); //Destroy(GameObject.Find("ARController").GetComponent<ARController>().AugmentedImageVisualizerPrefab.Object); //TicTacToe.transform.localScale = new Vector3(0.02f, 0.02f, 0.02f); //starting size of the grid //TicTacToe.transform.localRotation = Quaternion.Euler(0, 0, 0); //Instantiate(TicTacToe, new Vector3(0, 0, 0), Quaternion.identity); //Object = GameObject.Find("ARController").GetComponent<ARController>().AugmentedImageVisualizerPrefab.Object; ////Object.transform.localScale = new Vector3(0.02f, 0.02f, 0.02f); //starting size of the grid ////Object.transform.localRotation = Quaternion.Euler(0, 0, 0); //Instantiate(Object, new Vector3(0, 0, 0), Quaternion.identity); }
// We use Update() here, but be aware that unless ARController has been configured to // execute first (Unity Editor->Edit->Project Settings->Script Execution Order) then // state produced by this update may lag by one frame. void Update() { float[] matrixRawArray = new float[16]; ARController.Log(LogTag + "ARMarker.Update()"); if (UID == NO_ID || !PluginFunctions.inited) { visible = false; return; } // Query visibility if we are running in the Player. if (Application.isPlaying) { visible = PluginFunctions.arwQueryMarkerTransformation(UID, matrixRawArray); ARController.Log(LogTag + "ARMarker.Update() UID=" + UID + ", visible=" + visible); if (visible) { matrixRawArray[12] *= 0.001f; // Scale the position from ARToolKit units (mm) into Unity units (m). matrixRawArray[13] *= 0.001f; matrixRawArray[14] *= 0.001f; Matrix4x4 matrixRaw = ARUtilityFunctions.MatrixFromFloatArray(matrixRawArray); //ARController.Log("arwQueryMarkerTransformation(" + UID + ") got matrix: [" + Environment.NewLine + matrixRaw.ToString("F3").Trim() + "]"); // ARToolKit uses right-hand coordinate system where the marker lies in x-y plane with right in direction of +x, // up in direction of +y, and forward (towards viewer) in direction of +z. // Need to convert to Unity's left-hand coordinate system where marker lies in x-y plane with right in direction of +x, // up in direction of +y, and forward (towards viewer) in direction of -z. transformationMatrix = ARUtilityFunctions.LHMatrixFromRHMatrix(matrixRaw); // Output current position: Added by Kazu on Apr 2 2016 Vector3 position = ARUtilityFunctions.PositionFromMatrix(transformationMatrix); print("Position of Barcode ID #" + BarcodeID + ": (" + position.x * 1000 + ", " + position.y * 1000 + ", " + position.z * 1000 + ")"); // print ("position.x [mm]: "+ position.x * 1000); // print ("position.y [mm]: "+ position.y * 1000); // print ("position.z [mm]: "+ position.z * 1000); // If you need quaternion, you can use the followings. // Quaternion orientation = ARUtilityFunctions.QuaternionFromMatrix(transformationMatrix); } } }
public static bool GetFileFromStreamingAssets(string relative, out string desination) { desination = Path.Combine(Application.streamingAssetsPath, relative); ARController.Log("GetFileFromStreamingAssets(): destination: " + desination); #if !UNITY_METRO // On Android, we need to unpack the StreamingAssets from the .jar file in which // they're archived into the native file system. // URIs are valid whether we're using an absolute path or not. // Check specifically for URL-like scheme. if (desination.Contains("://")) { // E.g. "jar:file://" + Application.dataPath + "!/assets/" + basename; string source = desination; desination = Path.Combine(Application.temporaryCachePath, relative); // File has already been unpacked. Skip. // TODO: Add some integrity checking that it's the right file. if (File.Exists(desination)) { ARController.Log("File already exists at destination: " + desination); return(true); } WWW www = new WWW(source); // This will block in the webplayer. // TODO: switch to co-routine. while (!www.isDone) { ; } if (!string.IsNullOrEmpty(www.error)) { ARController.Log(string.Format(UNPACK_ERROR, source, desination)); desination = string.Empty; return(false); } // Note: 64MB limit on File.WriteAllBytes. // TODO: Verify limit. Directory.CreateDirectory(desination.Substring(0, desination.LastIndexOf('/'))); File.WriteAllBytes(desination, www.bytes); } #endif return(true); }
private void connectToAndroidPlugin() { ARController.Log(LogTag + "About to initialize the Android Plugin"); using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){ if (jc != null) { using (AndroidJavaObject activity = jc.GetStatic <AndroidJavaObject> ("currentActivity")) { androidPlugin = activity.Call <AndroidJavaObject> ("getARToolKitPlugin"); if (null == androidPlugin) { ARController.Log(LogTag + "ERROR: Could not connect to ARToolKit-Android plugin! Are we missing ar6jUnity.jar?"); } else { androidPlugin.Call("unityIsUp", new object[] { true }); } } } } }