// Update loop that is used by continous executions such as raytracing with point cloud rendering. Deals with updating transform matrices, distance culling and point cloud updating, all at a user-defined frame rate
        private IEnumerator RaytracingCoroutine(OptixPointCloud optixPointCloud)
        {
            Debug.Log("Started RaytracingCoroutine");
            while (isRaytracing)
            {
                if (!CheckOptixSensorComponentDirty())
                {
                    CheckOptixSensorTransformDirty();
                }

                CheckEnabledStatusChanged();
                CheckMatrixChanged();

                if (sceneChanged)
                {
                    Debug.Log(this.name + " detected scene change");
                    sceneChanged = false;
                    FireSensorAndUpdatePointCloud(optixPointCloud);
                }

                if (_optixTargetFPS == 0) // Prevents dividing by 0 error
                {
                    yield return(null);
                }
                else
                {
                    yield return(new WaitForSeconds(1 / _optixTargetFPS));
                }
            }
        }
Example #2
0
        private unsafe void FireSensorAndUpdatePointCloud(OptixPointCloud optixPointCloud)
        {
            Vector3 *returnHitPositions;
            int      returnHitPositionCount;

            using (OptixLibraryInterface.SensorFireAndReturnHitPositions(out returnHitPositions, out returnHitPositionCount))
            {
                optixPointCloud.UpdatePositions(returnHitPositions, returnHitPositionCount);
            }
        }
Example #3
0
        private void Start()
        {
            // Cache all Optix Sensors in the scene
            sensors = FindObjectsOfType <OptixSensor>();

            optixController = gameObject.AddComponent <OptixController>();
            optixController.Init(optixTargetFPS, optixTargetLayerMask, optixTargetTag, optixOrigin, optixMaxDistanceFromOrigin);

            optixPointCloud = gameObject.AddComponent <OptixPointCloud>();
            optixPointCloud.Init(instanceMesh, instanceMaterial, pointCloudPointColour, pointCloudPointSize);

            sensorTriggerButton.onClick.AddListener(ButtonClick);
        }
        /// <summary>
        /// Renders the hit positions from single/multiple optix sensors into a point cloud. Runs continually until stopped by EndRaytracing().
        /// </summary>
        public void RenderPointCloudFromSensorsContinuous(OptixSensor[] optixSensors, OptixPointCloud optixPointCloud)
        {
            this.optixSensors = optixSensors;
            OptixLibraryInterface.SetAllSensorsFromUnity(optixSensors.Length, GetBaseValuesFromSensors(optixSensors));

            if (isRaytracing)
            {
                Debug.LogWarning("Attempting to start raytracing even though it is already executing.");
                return;
            }

            if (optixSensors == null)
            {
                Debug.LogWarning("Cannot have optixSensors set to null. Cancelling raytracing.");
                return;
            }

            isRaytracing = true;

            StartCoroutine(RaytracingCoroutine(optixPointCloud));
        }