void Update()
        {
            _elapsedTime += Time.deltaTime;
            if (_elapsedTime > _screenCaptureInterval)
            {
                _elapsedTime -= _screenCaptureInterval;

                string path = "";
                for (var i = 0; i < _cameraSources.Length; i++)
                {
#if UNITY_2019_3_OR_NEWER
                    if (_nameGenerator != null)
                    {
                        path = _nameGenerator.Generate(Path.Combine(_baseDirectory, $"{_cameraSources[i].name}.{_imageFormat.ToString().ToLower()}"));
                    }
                    else
#endif
                    path = Path.Combine(_baseDirectory, _cameraSources[i].name + "_" + _sequence + "." + _imageFormat.ToString().ToLower());

                    CaptureCamera.CaptureColorToFile(_cameraSources[i], _format, path, _imageFormat);
                }

                ++_sequence;
            }
        }
        void Update()
        {
            _elapsedTime += Time.deltaTime;
            if (_elapsedTime > _screenCaptureInterval)
            {
                _elapsedTime -= _screenCaptureInterval;

                if (Application.isBatchMode && _camera.targetTexture == null)
                {
                    _camera.targetTexture = new RenderTexture(_camera.pixelWidth, _camera.pixelHeight, 0, _format);
                }

                CaptureCamera.CaptureDepthToFile
                (
                    _camera,
                    _format,
                    Path.Combine(_baseDirectory, _camera.name + "_depth_" + _sequence + "." + _imageFormat.ToString().ToLower()),
                    _imageFormat
                );

                if (!_camera.enabled)
                {
                    _camera.Render();
                }

                ++_sequence;
            }
        }
예제 #3
0
        /// <summary>
        /// Capture Screenshot asynchronously for a given source camera
        /// </summary>
        /// <param name="sourceCamera">Source camera for which the screen capture is to be performed</param>
        /// <param name="renderTextureFormat">Render Texture format for the screen capture</param>
        /// <param name="path">Path where the image is to be saved</param>
        /// <param name="format">Image format in which the file is to be saved. Default is set to RAW</param>
        public void ScreenCaptureAsync <T>(Camera sourceCamera, GraphicsFormat renderTextureFormat, string path, CaptureImageEncoder.ImageFormat format = CaptureImageEncoder.ImageFormat.Raw) where T : struct
        {
            Debug.Assert((sourceCamera != null), "Source Camera cannot be null");
            Debug.Assert(GraphicsUtilities.SupportsRenderTextureFormat(renderTextureFormat));

            Func <AsyncRequest <CaptureCamera.CaptureState>, AsyncRequest <CaptureCamera.CaptureState> .Result> functor = (AsyncRequest <CaptureCamera.CaptureState> r) =>
            {
                r.data.colorBuffer = CaptureImageEncoder.EncodeArray(r.data.colorBuffer as Array, sourceCamera.pixelWidth, sourceCamera.pixelHeight, GraphicsFormat.R8G8B8A8_UNorm, format);
                var result = Unity.Simulation.FileProducer.Write(GetPath(), r.data.colorBuffer as Array);
                return(result ? AsyncRequest <CaptureCamera.CaptureState> .Result.Completed : AsyncRequest <CaptureCamera.CaptureState> .Result.Error);
            };

            CaptureCamera.Capture(sourceCamera, functor, forceFlip: ForceFlip.None);
        }
        void Update()
        {
            _elapsedTime += Time.deltaTime;
            if (_elapsedTime > _screenCaptureInterval)
            {
                _elapsedTime -= _screenCaptureInterval;

                for (var i = 0; i < _cameraSources.Length; i++)
                {
                    CaptureCamera.CaptureColorToFile(_cameraSources[i], _format, Path.Combine(_baseDirectory, _cameraSources[i].name + "_" + _sequence + "." + _imageFormat.ToString().ToLower()), _imageFormat);
                }

                ++_sequence;
            }
        }
예제 #5
0
        void Update()
        {
            _elapsedTime += Time.deltaTime;
            if (_elapsedTime > _screenCaptureInterval)
            {
                _elapsedTime -= _screenCaptureInterval;

                string path = "";
#if UNITY_2019_3_OR_NEWER
                if (_nameGenerator != null)
                {
                    path = _nameGenerator.Generate(Path.Combine(_baseDirectory, $"{_camera.name}.{_imageFormat.ToString().ToLower()}"));
                }
                else
#endif
                path = Path.Combine(_baseDirectory, _camera.name + _channel.ToString().ToLower() + _sequence + "." + _imageFormat.ToString().ToLower());

                switch (_channel)
                {
                case CaptureCamera.Channel.Color:
                    CaptureCamera.Capture(_camera, colorFunctor: request => { WriteChannelToPath(path, (byte[])request.data.colorBuffer); return(AsyncRequest.Result.Completed); }, colorFormat: _format, forceFlip: ForceFlip.None);
                    break;

                case CaptureCamera.Channel.Depth:
                    CaptureCamera.Capture(_camera, depthFunctor: request => { WriteChannelToPath(path, (byte[])request.data.depthBuffer); return(AsyncRequest.Result.Completed); }, depthFormat: _format, forceFlip: ForceFlip.None);
                    break;

                case CaptureCamera.Channel.Normal:
                    CaptureCamera.Capture(_camera, normalFunctor: request => { WriteChannelToPath(path, (byte[])request.data.normalBuffer); return(AsyncRequest.Result.Completed); }, normalFormat: _format, forceFlip: ForceFlip.None);
                    break;

                case CaptureCamera.Channel.Motion:
                    CaptureCamera.Capture(_camera, motionFunctor: request => { WriteChannelToPath(path, (byte[])request.data.motionBuffer); return(AsyncRequest.Result.Completed); }, motionFormat: _format, forceFlip: ForceFlip.None);
                    break;
                }

                if (!_camera.enabled)
                {
                    _camera.Render();
                }

                ++_sequence;
            }
        }
        void Update()
        {
            _elapsedTime += Time.deltaTime;
            if (_elapsedTime > _screenCaptureInterval)
            {
                _elapsedTime -= _screenCaptureInterval;

                if (Application.isBatchMode && _camera.targetTexture == null)
                {
                    _camera.targetTexture = new RenderTexture(_camera.pixelWidth, _camera.pixelHeight, 0, _format);
                }

                string path = "";
#if UNITY_2019_3_OR_NEWER
                if (_nameGenerator != null)
                {
                    path = _nameGenerator.Generate(Path.Combine(_baseDirectory, $"{_camera.name}.{_imageFormat.ToString().ToLower()}"));
                }
                else
#endif
                path = Path.Combine(_baseDirectory, _camera.name + "_depth_" + _sequence + "." + _imageFormat.ToString().ToLower());

                CaptureCamera.CaptureDepthToFile
                (
                    _camera,
                    _format,
                    path,
                    _imageFormat
                );

                if (!_camera.enabled)
                {
                    _camera.Render();
                }

                ++_sequence;
            }
        }