void updateDynamicObjectSettings()
    {
        // Update object settings.
        if (internal_state.readyToRender)
        {
            // Update depth cameras with dynamic depth scale.
            var depthCameras = state.cameras.Where(obj => obj.isDepth);
            foreach (var objState in depthCameras)
            {
                // Get object
                ObjectState_t internal_object_state = internal_state.getWrapperObject(objState.ID, camera_template);
                GameObject    obj = internal_object_state.gameObj;

                /*
                 * // Scale depth.
                 * if (internal_object_state.postProcessingProfile.debugViews.settings.depth.scale != state.camDepthScale)
                 * {
                 *  var debugSettings = internal_object_state.postProcessingProfile.debugViews.settings;
                 *  debugSettings.mode = BuiltinDebugViewsModel.Mode.Depth;
                 *  debugSettings.depth.scale = state.camDepthScale;
                 *  internal_object_state.postProcessingProfile.debugViews.settings = debugSettings;
                 * }
                 */
            }
        }
    }
Example #2
0
    void updateDynamicObjectSettings()
    {
        // Update object settings.
        if (internal_state.readyToRender)
        {
            // Update depth cameras with dynamic depth scale.
            state.cameras.Where(obj => obj.isDepth).ToList().ForEach(
                obj_state =>
            {
                // Get object
                ObjectState_t internal_object_state = internal_state.getWrapperObject(obj_state.ID, camera_template);
                GameObject obj = internal_object_state.gameObj;

                // Scale depth.
                if (internal_object_state.postProcessingProfile.debugViews.settings.depth.scale != state.camDepthScale)
                {
                    var debugSettings         = internal_object_state.postProcessingProfile.debugViews.settings;
                    debugSettings.mode        = BuiltinDebugViewsModel.Mode.Depth;
                    debugSettings.depth.scale = state.camDepthScale;
                    internal_object_state.postProcessingProfile.debugViews.settings = debugSettings;
                }
            }
                );
        }
    }
Example #3
0
    void setCameraPostProcessSettings()
    {
        state.cameras.ToList().ForEach(
            obj_state =>
        {
            // Get object
            ObjectState_t internal_object_state = internal_state.getWrapperObject(obj_state.ID, camera_template);
            GameObject obj = internal_object_state.gameObj;


            // Copy and save postProcessingProfile into internal_object_state.
            var postBehaviour = obj.GetComponent <PostProcessingBehaviour>();
            internal_object_state.postProcessingProfile = Instantiate(postBehaviour.profile);
            postBehaviour.profile = internal_object_state.postProcessingProfile;

            // Enable depth if needed.
            if (obj_state.isDepth)
            {
                var debugSettings = internal_object_state.postProcessingProfile.debugViews.settings;

                debugSettings.mode        = BuiltinDebugViewsModel.Mode.Depth;
                debugSettings.depth.scale = state.camDepthScale;
                // Save the settings.
                internal_object_state.postProcessingProfile.debugViews.settings = debugSettings;
            }
            else
            {
                // Set CTAA settings
                CTAA_PC AA = obj.GetComponent <CTAA_PC>();
                // Check if AA object exists.
                if (AA != null)
                {
                    AA.TemporalStability     = state.temporalStability;
                    AA.HdrResponse           = state.hdrResponse;
                    AA.Sharpness             = state.sharpness;
                    AA.AdaptiveEnhance       = state.adaptiveEnhance;
                    AA.TemporalJitterScale   = state.temporalJitterScale;
                    AA.MicroShimmerReduction = state.microShimmerReduction;
                    AA.StaticStabilityPower  = state.staticStabilityPower;
                    AA.enabled = true;
                }
                else
                {
                    // If CTAA is not installed on camera, fallback to PostProcessing FXAA.
                    AntialiasingModel.Settings AASettings = internal_object_state.postProcessingProfile.antialiasing.settings;

                    AASettings.method = AntialiasingModel.Method.Fxaa;
                    AASettings.fxaaSettings.preset = AntialiasingModel.FxaaPreset.ExtremeQuality;

                    // Save the settings.
                    internal_object_state.postProcessingProfile.antialiasing.settings = AASettings;
                }
            }
        });
        //
    }
Example #4
0
 void instantiateCameras()
 {
     // Initialize Camera objects.
     state.cameras.ToList().ForEach(
         obj_state =>
     {
         // Get object
         ObjectState_t internal_object_state = internal_state.getWrapperObject(obj_state.ID, camera_template);
         GameObject obj = internal_object_state.gameObj;
         // Ensure FOV is set for camera.
         obj.GetComponent <Camera>().fieldOfView = state.camFOV;
     }
         );
 }
 void instantiateObjects()
 {
     // Initialize additional objects
     state.objects.ToList().ForEach(
         obj_state =>
     {
         // Get object
         ObjectState_t internal_object_state = internal_state.getWrapperObject(obj_state.ID, obj_state.prefabID);
         GameObject obj = internal_object_state.gameObj;
         // @TODO Set object size
         //obj.transform.localScale = ListToVector3(obj_state.size);
     }
         );
 }
Example #6
0
 void setCameraViewports()
 {
     // Resize camera viewports.
     state.cameras.ToList().ForEach(
         obj_state =>
     {
         // Get object
         ObjectState_t internal_object_state = internal_state.getWrapperObject(obj_state.ID, camera_template);
         GameObject obj = internal_object_state.gameObj;
         // Make sure camera renders to the correct portion of the screen.
         obj.GetComponent <Camera>().pixelRect = new Rect(0, state.camHeight * (state.numCameras - obj_state.outputIndex - 1), state.camWidth, state.camHeight);
         // enable Camera.
         obj.SetActive(true);
     }
         );
 }
Example #7
0
 void instantiateWindows()
 {
     // Initialize windows
     state.windows.ToList().ForEach(
         obj_state =>
     {
         // Get objects
         ObjectState_t internal_object_state = internal_state.getWrapperObject(obj_state.ID, window_template);
         GameObject obj = internal_object_state.gameObj;
         // Set window size
         obj.transform.localScale = ListToVector3(obj_state.size);
         // set window color
         obj.GetComponentInChildren <MeshRenderer>().material.SetColor("_EmissionColor", ListHSVToColor(obj_state.color));
     }
         );
 }
 void updateCameraCollisions()
 {
     if (internal_state.readyToRender)
     {
         state.hasCameraCollision = false;
         var raycastingCameras = state.cameras.Where(obj => obj.hasCollisionCheck);
         foreach (var obj_state in raycastingCameras)
         {
             // Get object
             ObjectState_t internal_object_state = internal_state.getWrapperObject(obj_state.ID, camera_template);
             GameObject    obj = internal_object_state.gameObj;
             // Check if object has collided (requires that collider hook has been setup on object previously.)
             state.hasCameraCollision = (state.hasCameraCollision || obj.GetComponent <collisionHandler>().hasCollided);
         }
     }
 }
    // Update object and camera positions based on the positions sent by ZMQ.
    void updateObjectPositions()
    {
        if (internal_state.readyToRender)
        {
            // Update camera positions

            internal_state.uavCenterOfMass = new Vector3();

            foreach (Camera_t obj_state in state.cameras)
            {
                // Get camera game object
                GameObject obj = internal_state.getGameobject(obj_state.ID, camera_template);
                // Apply translation and rotation
                Vector3 pos = ListToVector3(obj_state.position);
                obj.transform.SetPositionAndRotation(pos, ListToQuaternion(obj_state.rotation));

                // Calculate center of mass
                internal_state.uavCenterOfMass += pos;
            }

            // Adjust camera colliders such that camera colliders are at the center of mass.
            internal_state.uavCenterOfMass /= state.numCameras;

            // Get camera to cast from
            ObjectState_t internal_object_state = internal_state.getWrapperObject(state.cameras[0].ID, camera_template);

            // Get camera collider
            SphereCollider cameraCollider = internal_object_state.gameObj.GetComponent <SphereCollider>();
            // Set collider global pos to center of mass.
            cameraCollider.center = internal_state.uavCenterOfMass - internal_object_state.gameObj.transform.position;


            // Update Window positions
            foreach (Object_t obj_state in state.objects)
            {
                // Get game object
                GameObject obj = internal_state.getGameobject(obj_state.ID, obj_state.prefabID);

                // Apply translation and rotation
                obj.transform.SetPositionAndRotation(ListToVector3(obj_state.position), ListToQuaternion(obj_state.rotation));
            }
        }
    }
    void enableCollidersAndLandmarks()
    {
        internal_state.landmarkObjects = new Dictionary <string, GameObject>();

        // Enable object colliders in scene
        foreach (Collider c in FindObjectsOfType <Collider>())
        {
            c.enabled = true;
        }

        // Disable unneeded camera colliders
        var nonRaycastingCameras = state.cameras.Where(obj => !obj.hasCollisionCheck);

        foreach (Camera_t obj_state in nonRaycastingCameras)
        {
            ObjectState_t internal_object_state = internal_state.getWrapperObject(obj_state.ID, camera_template);

            // Get camera collider
            Collider cameraCollider = internal_object_state.gameObj.GetComponent <Collider>();
            cameraCollider.enabled = false;
        }

        // Find all landmarks in scene
        foreach (GameObject obj in GameObject.FindGameObjectsWithTag("IR_Markers"))
        {
            // Tag the landmarks
            string gateName   = obj.transform.parent.parent.name;
            string landmarkID = gateName + "_" + obj.name;
            // Save for later use
            try
            {
                internal_state.landmarkObjects.Add(landmarkID, obj);
            } catch (ArgumentException)
            {
                Debug.LogWarning("Landmark ID " + landmarkID + " already exists!");
            }
        }

        //UNload unused assets
        //Resources.UnloadUnusedAssets();
    }
    void instantiateCameras()
    {
        // Disable cameras in scene
        foreach (Camera c in FindObjectsOfType <Camera>())
        {
            c.enabled = false;
        }

        // Initialize new Camera objects.
        state.cameras.ForEach(
            obj_state =>
        {
            // Get object
            ObjectState_t internal_object_state = internal_state.getWrapperObject(obj_state.ID, camera_template);
            GameObject obj = internal_object_state.gameObj;
            // Ensure FOV is set for camera.
            obj.GetComponent <Camera>().fieldOfView = state.camFOV;

            // Apply translation and rotation
            obj.transform.SetPositionAndRotation(ListToVector3(obj_state.position), ListToQuaternion(obj_state.rotation));
        }
            );
    }
    void instantiateObjects()
    {
        // Initialize additional objects
        state.objects.ForEach(
            obj_state =>
        {
            // Get object
            ObjectState_t internal_object_state = internal_state.getWrapperObject(obj_state.ID, obj_state.prefabID);
            GameObject obj = internal_object_state.gameObj;
            // @TODO Set object size
            //obj.transform.localScale = ListToVector3(obj_state.size);
        }
            );

        // Check if should load obstacle perturbation file.
        if (obstacle_perturbation_file.Length > 0)
        {
            using (var reader = new StreamReader(obstacle_perturbation_file)) {
                while (reader.Peek() >= 0)
                {
                    // Read line
                    string str;
                    str = reader.ReadLine();

                    // Parse line
                    string  objectName        = str.Split(':')[0];
                    string  translationString = str.Split(':')[1];
                    float[] translationsFloat = Array.ConvertAll(translationString.Split(','), float.Parse);

                    // Find object
                    GameObject obj = GameObject.Find(objectName);
                    if (obj != null)
                    {
                        //// Check if object is statically batched. (NOT AVAILABLE IN STANDALONE BUILD)
                        //int flags = (int)GameObjectUtility.GetStaticEditorFlags(obj);
                        //if ((flags & 4)!= 0)
                        //{
                        //    // Gameobject is not movable!!!
                        //    Debug.LogError("WARNING: " + objectName + " is statically batched and not movable! Make sure the gameobject is only lightmap static.");
                        //} else
                        //{
                        // Translate and rotate object
                        obj.transform.Translate(-translationsFloat[1], 0, translationsFloat[0], Space.World);
                        obj.transform.Rotate(0, translationsFloat[2], 0, Space.World);

                        //}
                    }
                }
            }
        }
        if (outputLandmarkLocations)
        {
            // Output current locations.
            Dictionary <string, List <GameObject> > GateMarkers = new Dictionary <string, List <GameObject> >();

            // Find all landmarks and print to file.
            foreach (GameObject obj in GameObject.FindGameObjectsWithTag("IR_Markers"))
            {
                // Tag the landmarks
                string gateName   = obj.transform.parent.parent.name;
                string landmarkID = obj.name;

                // Check if gate already exists.
                if (GateMarkers.ContainsKey(gateName))
                {
                    GateMarkers[gateName].Add(obj);
                }
                else
                {
                    List <GameObject> markerList = new List <GameObject>();
                    markerList.Add(obj);
                    GateMarkers.Add(gateName, markerList);
                }
            }

            // Print results
            //Write some text to the test.txt file
            StreamWriter writer = new StreamWriter("markerLocations.yaml", false);
            foreach (var pair in GateMarkers)
            {
                writer.WriteLine(pair.Key + ":");
                writer.Write("  location: [");



                int i = 0;
                // Sort landmark IDs
                foreach (GameObject marker in pair.Value.OrderBy(gobj => gobj.name).ToList())
                {
                    // Convert vector from EUN to NWU.
                    Vector3 NWU = new Vector3(marker.transform.position.z, -marker.transform.position.x, marker.transform.position.y);

                    // Print out locations in yaml format.

                    writer.Write("[" + NWU.x + ", " + NWU.y + ", " + NWU.z + "]");
                    if (i < 3)
                    {
                        writer.Write(", ");
                    }
                    else
                    {
                        writer.WriteLine("]");
                    }
                    i++;
                }
            }
            writer.Close();
        }
    }
    void updateLandmarkVisibility()
    {
        if (internal_state.readyToRender)
        {
            // Erase old set of landmarks
            state.landmarksInView = new List <Landmark_t>();

            // Get camera to cast from
            ObjectState_t internal_object_state = internal_state.getWrapperObject(state.cameras[0].ID, camera_template);
            Camera        castingCamera         = internal_object_state.gameObj.GetComponent <Camera>();
            Vector3       cameraPosition        = internal_object_state.gameObj.transform.position;

            // Get camera collider
            Collider cameraCollider = internal_object_state.gameObj.GetComponent <Collider>();

            // Cull landmarks based on camera frustrum
            // Gives lookup table of screen positions.
            Dictionary <string, Vector3> visibleLandmarkScreenPositions = new Dictionary <string, Vector3>();

            foreach (KeyValuePair <string, GameObject> entry in internal_state.landmarkObjects)
            {
                Vector3 screenPoint = castingCamera.WorldToViewportPoint(entry.Value.transform.position);
                bool    visible     = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
                if (visible)
                {
                    visibleLandmarkScreenPositions.Add(entry.Key, screenPoint);
                }
            }


            int numLandmarksInView = visibleLandmarkScreenPositions.Count();

            // Batch raytrace from landmarks to camera
            var results  = new NativeArray <RaycastHit>(numLandmarksInView, Allocator.TempJob);
            var commands = new NativeArray <RaycastCommand>(numLandmarksInView, Allocator.TempJob);

            int i = 0;
            var visibleLandmarkScreenPosList = visibleLandmarkScreenPositions.ToArray();
            foreach (var elm in visibleLandmarkScreenPosList)
            {
                var     landmark  = internal_state.landmarkObjects[elm.Key];
                Vector3 origin    = landmark.transform.position;
                Vector3 direction = cameraPosition - origin;

                commands[i] = new RaycastCommand(origin, direction, distance: direction.magnitude, maxHits: max_num_ray_collisions);
                i++;
            }

            // Run the raytrace commands
            JobHandle handle = RaycastCommand.ScheduleBatch(commands, results, 1, default(JobHandle));
            // Wait for the batch processing job to complete.
            // @TODO: Move to end of frame.
            handle.Complete();

            // Cull based on number of collisions
            // Remove if it collided with something
            for (int j = 0; j < numLandmarksInView; j++)
            {
                // Check collisions. NOTE: indexing is via N*max_hits with first null being end of hit list.
                RaycastHit batchedHit = results[j];
                if (batchedHit.collider == null)
                {
                    // No collisions here. Add it to the current state.
                    var        landmark = visibleLandmarkScreenPosList[j];
                    Landmark_t landmarkScreenPosObject = new Landmark_t();

                    landmarkScreenPosObject.ID       = landmark.Key;
                    landmarkScreenPosObject.position = Vector3ToList(landmark.Value);
                    state.landmarksInView.Add(landmarkScreenPosObject);
                }
                else if (batchedHit.collider == cameraCollider)
                {
                    // No collisions here. Add it to the current state.
                    var        landmark = visibleLandmarkScreenPosList[j];
                    Landmark_t landmarkScreenPosObject = new Landmark_t();

                    landmarkScreenPosObject.ID       = landmark.Key;
                    landmarkScreenPosObject.position = Vector3ToList(landmark.Value);
                    state.landmarksInView.Add(landmarkScreenPosObject);
                }
            }

            results.Dispose();
            commands.Dispose();
        }
    }
    void setCameraPostProcessSettings()
    {
        state.cameras.ForEach(
            obj_state =>
        {
            // Get object
            ObjectState_t internal_object_state = internal_state.getWrapperObject(obj_state.ID, camera_template);
            GameObject obj = internal_object_state.gameObj;


            // Copy and save postProcessingProfile into internal_object_state.

            /*
             * var postBehaviour = obj.GetComponent<PostProcessingBehaviour>();
             * internal_object_state.postProcessingProfile = Instantiate(postBehaviour.profile);
             * postBehaviour.profile = internal_object_state.postProcessingProfile;
             */

            /*
             * // Enable depth if needed.
             * if (obj_state.isDepth)
             * {
             *
             *  var debugSettings = internal_object_state.postProcessingProfile.debugViews.settings;
             *
             *  debugSettings.mode = BuiltinDebugViewsModel.Mode.Depth;
             *  debugSettings.depth.scale = state.camDepthScale;
             *  // Save the settings.
             *  internal_object_state.postProcessingProfile.debugViews.settings = debugSettings;
             *
             *  // Disable AA
             *  CTAA_PC AA = obj.GetComponent<CTAA_PC>();
             *  // Check if AA object exists.
             *  if (AA != null)
             *  {
             *      AA.enabled = false;
             *  } else
             *  {
             *      // If CTAA is not installed on camera, fallback to PostProcessing FXAA.
             *      internal_object_state.postProcessingProfile.antialiasing.enabled = false;
             *  }
             *
             * } else */

            /*
             * {
             *  // Set CTAA settings
             *  CTAA_PC AA = obj.GetComponent<CTAA_PC>();
             *  // Check if AA object exists.
             *  if (AA != null)
             *  {
             *      AA.TemporalStability = state.temporalStability;
             *      AA.HdrResponse = state.hdrResponse;
             *      AA.Sharpness = state.sharpness;
             *      AA.AdaptiveEnhance = state.adaptiveEnhance;
             *      AA.TemporalJitterScale = state.temporalJitterScale;
             *      AA.MicroShimmerReduction = state.microShimmerReduction;
             *      AA.StaticStabilityPower = state.staticStabilityPower;
             *      AA.enabled = true;
             *  } else
             *  {
             *      // If CTAA is not installed on camera, fallback to PostProcessing FXAA.
             *      AntialiasingModel.Settings AASettings = internal_object_state.postProcessingProfile.antialiasing.settings;
             *
             *      AASettings.method = AntialiasingModel.Method.Fxaa;
             *      AASettings.fxaaSettings.preset = AntialiasingModel.FxaaPreset.ExtremeQuality;
             *
             *      // Save the settings.
             *      internal_object_state.postProcessingProfile.antialiasing.settings = AASettings;
             *      internal_object_state.postProcessingProfile.antialiasing.enabled = true;
             *
             *  }
             *
             *  // Ensure that Camera's RGB/Grayscale mode reflects the number of channels it has.
             *  ColorGradingModel.Settings colorGradingSettings = internal_object_state.postProcessingProfile.colorGrading.settings;
             *  float saturation = (obj_state.channels == 3) ? 1.0f : 0.0f;
             *
             *  colorGradingSettings.basic.saturation = saturation;
             *  // Save the settings.
             *  internal_object_state.postProcessingProfile.colorGrading.settings = colorGradingSettings;
             *
             * }*/
        });
        //
    }