// invoked by Save-button
    public IEnumerator SaveButtonClicked()
    {
        // save scene
        string sFilePath = FileUtils.GetPersitentDataPath("SavedSceneSurfaces.json");
        bool   bSaved    = SaveArScene(sFilePath);

        // save image
        if (bSaved)
        {
            string sJpegPath = FileUtils.GetPersitentDataPath("SavedSceneImage.jpg");
            SaveScreenShot(sJpegPath);
        }

        yield return(null);

        // show result
        if (bSaved && sceneInfoText)
        {
            MultiARManager marManager = MultiARManager.Instance;
            sceneInfoText.text = "Saved " + (marManager ? marManager.GetTrackedSurfacesCount() : 0) +
                                 " surfaces (head:" + (int)startHeading + ") to file: " + sFilePath;

            // wait for some time
            yield return(new WaitForSeconds(10f));

            // clear the info
            sceneInfoText.text = "Slide to save the scene into local file.";
        }

        routineRunning = false;
    }
示例#2
0
    void Start()
    {
        // get reference to ar-manager
        MultiARManager arManager = MultiARManager.Instance;

        if (arManager)
        {
            // destroys all anchors and anchored objects
            arManager.DestroyAllAnchors();

            // refresh scene references (graphic raycasters, etc.)
            arManager.RefreshSceneReferences();

            // destroy second main camera, if any
            Camera       arCamObject    = arManager.GetMainCamera();
            GameObject[] mainCamObjects = GameObject.FindGameObjectsWithTag("MainCamera");

            for (int i = mainCamObjects.Length - 1; i >= 0; i--)
            {
                GameObject mainCamObj = mainCamObjects[i];
                if (arCamObject != null && arCamObject.gameObject != mainCamObj)
                {
                    Destroy(mainCamObj);
                }
            }
        }
    }
示例#3
0
    void Start()
    {
        // get reference to MultiARManager
        arManager = MultiARManager.Instance;

        // enable the model toggle at start - make the model transform visible
        if (modelTransform)
        {
            modelTransform.gameObject.SetActive(true);
            modelTransform.position = new Vector3(0f, 0f, -10f);
        }
    }
示例#4
0
    void Update()
    {
        MultiARManager      arManager   = MultiARManager.Instance;
        ARPlatformInterface arInterface = arManager ? arManager.GetARInterface() : null;

        if (!levelLoaded && arManager && arManager.IsInitialized() &&
            arInterface != null && arInterface.IsInitialized())
        {
            Debug.Log("MultiARManager initialized. Loading 1st scene...");

            levelLoaded = true;
            SceneManager.LoadScene(1);
        }
    }
示例#5
0
    void OnDestroy()
    {
        if (instanceInited)
        {
            // disable image-anchors tracking
            if (arData.imageAnchorsEnabled && arInterface != null)
            {
                arInterface.DisableImageAnchorsTracking();
                arData.imageAnchorsEnabled = false;
            }

            instance       = null;
            instanceInited = false;
        }
    }
示例#6
0
    void Start()
    {
        timeToLoadLevel = Time.realtimeSinceStartup + waitSeconds;

        if (validateArManager && debugText != null)
        {
            MultiARManager arManager = MultiARManager.Instance;

            if (arManager == null || !arManager.IsInitialized())
            {
                debugText.text = "MultiARManager is not initialized!";
                levelLoaded    = true;
            }

//			if (arManager)
//			{
//				Debug.Log("MainCamera: " + arManager.GetMainCamera ());
//			}
        }
    }
    void Start()
    {
        // get reference to MultiARManager
        arManager = MultiARManager.Instance;

        if (infoText)
        {
            infoText.text = "Please select a model.";
        }

        // select the 1st toggle at start
        if (toggle1)
        {
            if (model1)
            {
                model1.position = new Vector3(0f, 0f, -10f);
            }

            toggle1.isOn = true;
        }
    }
示例#8
0
    void Start()
    {
        // get reference to ar-manager
        arManager = MultiARManager.Instance;

        // start location services
        if (SystemInfo.supportsLocationService && Input.location.isEnabledByUser)
        {
            locationEnabled = true;
            Input.location.Start(1f, 0.1f);
            Input.compass.enabled = true;
        }
        else
        {
            if (locationInfoText)
            {
                locationInfoText.text = "Location service not supported or enabled.";
            }
        }

        // enable gyro
        if (SystemInfo.supportsGyroscope)
        {
            gyroEnabled = true;

            gyro         = Input.gyro;
            gyro.enabled = true;

            gyroParentRot  = Quaternion.Euler(90f, 90f, 0f);
            initialGyroRot = Quaternion.Euler(0f, 0f, 180f);
        }
        else
        {
            if (gyroInfoText)
            {
                gyroInfoText.text = "Gyroscope not supported.";
            }
        }
    }
    // saves the current screen shot
    public bool SaveScreenShot(string saveFilePath)
    {
        if (saveFilePath == string.Empty)
        {
            return(false);
        }

        MultiARManager marManager    = MultiARManager.Instance;
        Texture2D      texScreenshot = MultiARInterop.MakeScreenShot(marManager != null ? marManager.GetMainCamera() : null);

        if (texScreenshot)
        {
            byte[] btScreenShot = texScreenshot.EncodeToJPG();
            GameObject.Destroy(texScreenshot);

            File.WriteAllBytes(saveFilePath, btScreenShot);

            return(true);
        }

        return(false);
    }
示例#10
0
    void OnDestroy()
    {
        if (instanceInited)
        {
            // disable image-anchors tracking
            if (arData.imageAnchorsEnabled && arInterface != null)
            {
                arInterface.DisableImageAnchorsTracking();
                arData.imageAnchorsEnabled = false;
            }

            // release background tex, if needed
            if (arData.backgroundTex != null)
            {
                arData.backgroundTex.Release();
                arData.backgroundTex = null;
            }

            instance       = null;
            instanceInited = false;
        }
    }
 void Start()
 {
     // get reference to MultiARManager
     arManager = MultiARManager.Instance;
 }
示例#12
0
    protected virtual void Start()
    {
        try
        {
            //LogFilter.currentLogLevel = LogFilter.Debug;

            // get reference to the multi-ar manager
            marManager = MultiARManager.Instance;

            // setup network manager component
            netManager = GetComponent <ClientNetworkManager>();
            if (netManager == null)
            {
                netManager = gameObject.AddComponent <ClientNetworkManager>();
            }

            if (netManager != null)
            {
                netManager.arClient = this;

                if (playerPrefab != null)
                {
                    netManager.playerPrefab = playerPrefab;
                }

                if (spawnPrefabs != null && spawnPrefabs.Count > 0)
                {
                    netManager.spawnPrefabs.AddRange(spawnPrefabs);
                }
            }

            if (serverHost != "0.0.0.0" && !string.IsNullOrEmpty(serverHost))
            {
                // connect to the server
                ConnectToServer();
            }
            else
            {
                // start network discovery
                netDiscovery = gameObject.GetComponent <ClientNetworkDiscovery>();
                if (netDiscovery == null)
                {
                    netDiscovery = gameObject.AddComponent <ClientNetworkDiscovery>();
                }

                if (netDiscovery != null)
                {
                    netDiscovery.arClient = this;
                    //netDiscovery.broadcastPort = broadcastPort;
                    //netDiscovery.broadcastKey = serverPort;
                    //netDiscovery.broadcastData = gameName;
                    netDiscovery.showGUI = false;

                    netDiscovery.Initialize();
                    netDiscovery.StartAsClient();
                }
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.Message + "\n" + ex.StackTrace);

            if (statusText)
            {
                statusText.text = ex.Message;
            }
        }
    }
示例#13
0
    // checks for image anchor, to create or destroy the coffee cups
    private void CheckForImageAnchor()
    {
        MultiARManager marManager = MultiARManager.Instance;

        // Check that motion tracking is tracking.
        StringBuilder sbMessage = new StringBuilder();

        if (!marManager || marManager.GetCameraTrackingState() != MultiARInterop.CameraTrackingState.NormalTracking)
        {
            sbMessage.AppendLine("Camera - Not tracking.");
            sbMessage.AppendLine("detectedImage: " + (imageAnchorName != string.Empty ? imageAnchorName : "-"));

            ShowDebugText(sbMessage.ToString());
            return;
        }

        // Get updated augmented images for this frame.
        List <string> alImageAnchors = marManager.GetTrackedImageAnchorNames();

        sbMessage.AppendLine(alImageAnchors.Count.ToString() + " anchor images found: ");

//		for (int i = 0; i < alImageAnchors.Count; i++)
//		{
//			sbMessage.Append(i).Append (" - ").Append (alImageAnchors[i]).AppendLine();
//		}

        sbMessage.AppendLine("detectedImage: " + (imageAnchorName != string.Empty ? imageAnchorName : "-"));
        sbMessage.AppendLine("imageAnchor: " + (imageAnchor != null ? imageAnchor.name : "none"));

        ShowDebugText(sbMessage.ToString());

        if (infoText)
        {
            infoText.text = "Found image anchor: " + (imageAnchorName != string.Empty ? imageAnchorName : "-");

            if (cupIndexSelected >= 0)
            {
                infoText.text = string.Format("Selected: {0}", coffeeCupTitles[cupIndexSelected]);
            }
        }

        // check for found image anchor
        string foundImageAnchor = marManager.GetFirstTrackedImageAnchorName();

        if (imageAnchorName == string.Empty)
        {
            imageAnchorName = foundImageAnchor;

            if (imageAnchorName != string.Empty)
            {
                imageAnchor = marManager.GetTrackedImageAnchorByName(imageAnchorName);
                Camera mainCamera = marManager.GetMainCamera();

                if (imageAnchor != null && mainCamera != null)
                {
                    // create coffee cups-parent (used to smooth anchor jittering)
                    cupAnchor = new GameObject("CupAnchor");                     // GameObject.CreatePrimitive(PrimitiveType.Cube);

                    cupAnchor.transform.position = imageAnchor.transform.position;
                    Vector3 vAnchorDir = imageAnchor.transform.position - mainCamera.transform.position;
                    cupAnchor.transform.rotation = Quaternion.LookRotation(vAnchorDir, Vector3.up);                     // imageAnchor.transform.rotation;

//					// create anchor-pointer object (cube)
//					GameObject anchorPoiterObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
//					anchorPoiterObj.transform.parent = imageAnchor.transform;
//
//					anchorPoiterObj.transform.localPosition = Vector3.zero;
//					anchorPoiterObj.transform.localRotation = Quaternion.identity;
//					anchorPoiterObj.transform.localScale = new Vector3(0.05f, 0.1f, 0.15f);

                    // create cup models
                    StartCoroutine(CreateAndPlaceCups());
                }
            }
        }
        else if (imageAnchorName != foundImageAnchor)
        {
            // destroy the coffee cups
            DestroyCups();
        }
    }
示例#14
0
 /// <summary>
 /// Sets the enabled or disabled state of the interface.
 /// </summary>
 /// <param name="isEnabled">If set to <c>true</c> interface is enabled.</param>
 public void SetEnabled(bool isEnabled, MultiARManager arManager)
 {
     isInterfaceEnabled = isEnabled;
     this.arManager     = arManager;
 }
    // saves AR scene parameters and the detected surfaces
    public bool SaveArScene(string dataFilePath)
    {
        MultiARManager marManager = MultiARManager.Instance;

        if (!marManager || marManager.GetTrackedSurfacesCount() == 0)
        {
            return(false);
        }

        JsonArScene data = new JsonArScene();

        data.saverVer  = 1;
        data.sceneDesc = string.Empty;
        data.timestamp = marManager.GetTrackedSurfacesTimestamp();

        if (locationEnabled && Input.location.status == LocationServiceStatus.Running)
        {
            data.scenePos = new JsonScenePos();

            data.scenePos.lat = lastLoc.latitude;
            data.scenePos.lon = lastLoc.longitude;
            data.scenePos.alt = lastLoc.altitude;

            Vector3 latLonM = GeoUtils.LatLong2Meters(lastLoc.latitude, lastLoc.longitude, lastLoc.altitude);
            data.scenePos.latm = (long)((double)latLonM.x * 1000.0);
            data.scenePos.lonm = (long)((double)latLonM.y * 1000.0);
            data.scenePos.altm = (long)latLonM.z;
        }


        if (gyroEnabled)
        {
            data.sceneRot = new JsonSceneRot();

            data.sceneRot.gyroAtt = gyroAttitude.eulerAngles;
            data.sceneRot.gyroRot = gyroRotation.eulerAngles;
        }

        data.compHeading  = compHeading;
        data.startHeading = startHeading;
        Quaternion compStartRot = Quaternion.Euler(0f, startHeading, 0f);

        data.sceneCam        = new JsonSceneCam();
        data.sceneCam.camPos = compStartRot * camPosition;

        data.sceneCam.camRot = camRotation.eulerAngles + compStartRot.eulerAngles;
        data.sceneCam.camRot = Quaternion.Euler(data.sceneCam.camRot).eulerAngles;

        // surfaces
        data.surfaceSet              = new JsonSurfaceSet();
        data.surfaceSet.timestamp    = marManager.GetTrackedSurfacesTimestamp();
        data.surfaceSet.surfaceCount = marManager.GetTrackedSurfacesCount();
        data.surfaceSet.surfaces     = new JsonSurface[data.surfaceSet.surfaceCount];

        MultiARInterop.TrackedSurface[] trackedSurfaces = marManager.GetTrackedSurfaces(true);
        for (int i = 0; i < data.surfaceSet.surfaceCount; i++)
        {
            // transformed surfaces
            data.surfaceSet.surfaces[i] = new JsonSurface();

            Vector3 surfacePos = trackedSurfaces[i].position;
            data.surfaceSet.surfaces[i].position = compStartRot * surfacePos;

//			data.surfaceSet.surfaces[i].rotation = trackedSurfaces[i].rotation.eulerAngles;
            Vector3 surfaceRot = trackedSurfaces[i].rotation.eulerAngles + compStartRot.eulerAngles;
            data.surfaceSet.surfaces[i].rotation = Quaternion.Euler(surfaceRot).eulerAngles;

            data.surfaceSet.surfaces[i].bounds   = trackedSurfaces[i].bounds;
            data.surfaceSet.surfaces[i].vertices = trackedSurfaces[i].points;
            data.surfaceSet.surfaces[i].indices  = trackedSurfaces[i].triangles;
        }

        try
        {
            // save json
            string sJsonText = JsonUtility.ToJson(data, true);
            File.WriteAllText(dataFilePath, sJsonText);

            Debug.Log("AR-Scene (head: " + (int)data.startHeading + ") saved to: " + dataFilePath);

            return(true);
        }
        catch (System.Exception ex)
        {
            string sMessage = ex.Message + "\n" + ex.StackTrace;
            Debug.LogError(sMessage);
        }

        return(false);
    }
示例#16
0
    // -- // -- // -- // -- // -- // -- // -- // -- // -- // -- //


    void Awake()
    {
        // initializes the singleton instance of MultiARManager
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(this);

            instanceInited = true;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
            return;
        }

        // locate available AR interfaces in the scene
        MonoBehaviour[] monoScripts = FindObjectsOfType <MonoBehaviour>();

        ARPlatformInterface arIntAvailable = null;

        arInterface = null;

        for (int i = 0; i < monoScripts.Length; i++)
        {
            if ((monoScripts[i] is ARPlatformInterface) && monoScripts[i].enabled)
            {
                ARPlatformInterface arInt = (ARPlatformInterface)monoScripts[i];
                arInt.SetEnabled(false, null);

                if (arInt.IsPlatformAvailable())
                {
                    Debug.Log(arInt.GetARPlatform().ToString() + " is available.");

                    if (arIntAvailable == null)
                    {
                        arIntAvailable = arInt;
                    }

                    if (arInt.GetARPlatform() == preferredPlatform)
                    {
                        arInterface = arInt;
                    }
                }
            }
        }

        if (arInterface == null)
        {
            arInterface = arIntAvailable;
        }

        // report the selected platform
        if (arInterface != null)
        {
            arInterface.SetEnabled(true, this);
            Debug.Log("Selected AR-Platform: " + arInterface.GetARPlatform().ToString());
        }
        else
        {
            Debug.LogError("No suitable AR-Interface found. Please check the scene setup.");
        }

        // set initialization status
        isInitialized = (arInterface != null);

        if (arInterface != null)
        {
            // check for augmented images
            AnchorImageManager imageManager = GameObject.FindObjectOfType <AnchorImageManager>();

            if (imageManager != null && imageManager.anchorImages != null && imageManager.anchorImages.Count > 0)
            {
                // prepare images for tracking
                arInterface.InitImageAnchorsTracking(imageManager);
                arData.imageAnchorsEnabled = true;
            }
        }
    }
 void Start()
 {
     lightComponent = GetComponent <Light>();
     arManager      = MultiARManager.Instance;;
 }
示例#18
0
 void Start()
 {
     arManager = MultiARManager.Instance;
     arClient  = ArClientBaseController.Instance;
 }
示例#19
0
    IEnumerator Start()
    {
        // get reference to multi-ar-manager
        marManager = MultiARManager.Instance;

        // Start service before querying location
        locServiceStarted = false;
        Input.location.Start(1f, 0.1f);

        if (locationText)
        {
            locationText.text = "Location service is starting...";
        }

//		// First, check if user has location service enabled
//		if (!Input.location.isEnabledByUser)
//		{
//			if (locationText)
//			{
//				locationText.text = "Location not enabled by the user.";
//			}
//
//			yield break;
//		}

        // Wait until service initializes
        int maxWait = 20;

        while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
        {
            yield return(new WaitForSeconds(1));

            maxWait--;
        }

        // Service didn't initialize in 20 seconds
        if (maxWait < 1)
        {
            if (locationText)
            {
                locationText.text = "Timed out.";
            }

            yield break;
        }

        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed)
        {
            if (locationText)
            {
                locationText.text = "Location service cannot be started.";
            }

            yield break;
        }

        // service is started
        locServiceStarted = true;
        if (locationText)
        {
            locationText.text = "Location service successfully started!";
        }
    }