Esempio n. 1
0
        void Start()
        {
            //if the clear flag isn't set to Depth then
            //we'll have problems rendering the color camera
            //to the camera with the depth overlay.
            GameLog.Log("Checking camera clear flags...");
            Camera cam = this.GetComponent <Camera>();

            if (cam != null)
            {
                if ((this.GetComponent <Camera>().clearFlags & CameraClearFlags.Depth) != CameraClearFlags.Depth)
                {
                    //make sure camera is set to depth for clear flags
                    //otherwise it will not draw the back camera view.
                    this.GetComponent <Camera>().clearFlags |= CameraClearFlags.Depth;
                    GameLog.Log("clear flag changed to depth.");
                }
            }
#if UNITY_IPHONE
            Screen.orientation = ScreenOrientation.LandscapeLeft;
#endif
        }
Esempio n. 2
0
        /// <summary>
        /// Raises the button click event.
        /// </summary>
        ///***********************  IMPORTANT  ***********************
        /// this is the method that sends the start, done and reset
        /// commands to the plug-in!
        public virtual void HandleButtonClickedEvent(object sender, ButtonEventArgs buttonArgs)
        {
            //we already know what state we're in, and what state we
            //need to go to. The local property will update the button's
            //when it's changed.
            switch (this.gameState)
            {
            case SensorState.DeviceReady:     // DeviceReady -> Scanning
                if (this.MainCamera.GetComponent <PinchToScale>() != null)
                {
                    this.MainCamera.GetComponent <PinchToScale>().enablePinchToScale = false;
                }
                //tell StructurePlugin to start scanning
                StructureARPlugin.startScanning();
                this.gameState = SensorState.Scanning;
                break;

            case SensorState.Scanning:     // Scanning -> WaitingForMesh
                if (this.trackingIsGood)
                {
                    //tell StructurePlugin to finish scanning.
                    //this finishes up the scanning session, when the
                    //mesh is finished, it's sent to the wireframe
                    //object where it's copied over.
                    //the HandleStructureEvent gets ScannedMeshReady where
                    //the construction of the mesh is completed.
                    StructureARPlugin.doneScanning();
                    this.gameState = SensorState.WaitingForMesh;
                }
                else
                {
                    if (this.MainCamera.GetComponent <PinchToScale>() != null)
                    {
                        this.MainCamera.GetComponent <PinchToScale>().enablePinchToScale = true;
                    }

                    //clear scanned mesh
                    this.ClearScannedMesh();

                    StructureARPlugin.resetScanning();    //tell StructurePlugin to reset the scanned data.
                    this.gameState = SensorState.DeviceReady;
                }
                break;

            case SensorState.WaitingForMesh:     // WaitingForMesh -> Playing
                UploadScannedMesh();
                break;

            case SensorState.Playing:     // Playing -> DeviceReady
                if (this.MainCamera.GetComponent <PinchToScale>() != null)
                {
                    this.MainCamera.GetComponent <PinchToScale>().enablePinchToScale = true;
                }

                //clear scanned mesh
                this.ClearScannedMesh();

                StructureARPlugin.resetScanning();    //tell StructurePlugin to reset the scanned data.
                this.gameState = SensorState.DeviceReady;
                break;

            default:
                GameLog.Log(this.ToString() + " -- unhandled game state for button" + buttonArgs.toState);
                break;
            }
        }
Esempio n. 3
0
        public IEnumerator LoadObject(GameObject gameObject)
        {
            //clear the old mesh and replace it with a new one
            this.objectMesh = new Mesh();

            // The LoadObject method is called from the manager
            // and we ask the plugin to update a gameObject's mesh
            StructureARPlugin.getMeshObj(ref this.objectMesh);

            if (this.objectMesh == null)
            {
                yield return(null);
            }
            else
            {
                GameLog.Log("getting mesh object from plugin...");

                // check if there is allready a MeshFilter present, if not add one
                MeshFilter meshFilter = (MeshFilter)gameObject.GetComponent <MeshFilter>() as MeshFilter;

                //if we were not able to get the meshFilter component of this game object then
                //we shuld add one here
                if (meshFilter == null)
                {
                    //adding the mesh filter here
                    meshFilter = gameObject.AddComponent <MeshFilter>() as MeshFilter;
                }

                //make sure that the mesh on the object's mesh filter is this one.
                meshFilter.mesh = this.objectMesh;

                //check if there is allready a MeshRenderer present, if not add one
                MeshRenderer meshRenderer = (MeshRenderer)gameObject.GetComponent <MeshRenderer>() as MeshRenderer;
                if (meshRenderer == null)
                {
                    meshRenderer = gameObject.AddComponent <MeshRenderer>() as MeshRenderer;
                    Material mat = this.AssignMaterial(@"Materials/TransparentInvisible");
                    if (mat != null)
                    {
                        meshRenderer.material = mat;
                    }
                }

                //more of the same with the collider.
                MeshCollider meshCollider = (MeshCollider)gameObject.GetComponent <MeshCollider>() as MeshCollider;
                if (meshCollider == null)
                {
                    meshCollider            = gameObject.AddComponent <MeshCollider>() as MeshCollider;
                    meshCollider.sharedMesh = meshFilter.mesh;
                }
                else
                {
                    meshCollider.sharedMesh = this.objectMesh;
                }

                this.objectMesh.RecalculateBounds();
                this.objectMesh.RecalculateNormals();

                yield return(new WaitForFixedUpdate());
            }
        }
Esempio n. 4
0
        public virtual void Start()
        {
            Manager._structureManager = this;
            if (this.MainCamera != null)
            {
                Manager._MainCamera = this.MainCamera;
            }

            //check if we need to make a GameLog.
            if (this.ShowDebugLog && this.GetComponent <GameLog>() == null)
            {
                this.gameObject.AddComponent <GameLog>();
                GameLog.ShowGameLog = this.ShowDebugLog;
            }

            //tell the game to run at 30 fps rather than at max.
            //otherwise the game might be running faster
            //than the camera.
            Application.targetFrameRate = 30;

            //check Main Camera for StructurePOV
            if (!FreezePOV)
            {
                POV sPOV = this.MainCamera.GetComponent <POV>();
                if (sPOV == null)
                {
                    //assign one if it doesn't already have one.
                    this.structurePOV = this.MainCamera.gameObject.AddComponent <POV>();
                }
                else
                {
                    //get a reference to the component if it does have one.
                    this.structurePOV = sPOV;
                }
            }

            //initialize this game manager to recieve events
            //from the plug-in. Anything else you want to have listen to
            //the plugin can be done through here.
            StructureARPlugin.StructureEvent += this.HandleStructureEvent;

            StructureARPlugin.setCallbacks();

            //object loader to build the mesh in the game world.
            this.structureObjectLoader = new ObjectLoader();

            GameLog.Log(this.ToString() + this.structureObjectLoader);


            //provide the scanned mesh a place to live in the game world.
            this.scanObject     = new GameObject("ScanObject");
            Manager._ScanObject = this.scanObject;
            Wireframe wf = this.scanObject.AddComponent <Wireframe>();

            wf.lineColor = this.ScanMeshWireColor;

            GameLog.Log(this.ToString() + this.scanObject);

            //Make color camera back plane
            this.MainCamera.clearFlags = CameraClearFlags.Depth;
            this.cameraView            = new CameraViewScript(this.MainCamera, 1f);
            this.cameraView.CameraObject.transform.parent = this.MainCamera.transform;

            //should also set the camera FOV to 45
            this.MainCamera.fieldOfView = 45.0f;

            //setup the POV camera in game to match the projection
            //of the rear camera of the device
            StructureARPlugin.initStructureAR(this.MainCamera.projectionMatrix);

            //do minor setup here, hide things, change UI etc.
            if (this.gameState == SensorState.CameraAccessRequired)
            {
                return;
            }

            // We need to update our status based on whether or not
            // the sensor is connected since we don't want to scan
            // without the sensor attached.
            if (StructureARPlugin.isStructureConnected())
            {
                this.gameState = SensorState.DeviceReady;
            }
            else
            {
                this.gameState = SensorState.DeviceNotReady;
            }

            //tracking is always false in DeviceReady and DeviceNotReady states
            this.trackingIsGood = false;
        }