Пример #1
0
        /// <summary>
        /// Captures a camera render and writes out the color and depth channels to a file.
        /// </summary>
        /// <param name="camera"> The Camera to capture data from. </param>
        /// <param name="colorFormat"> The pixel format to capture in. </param>
        /// <param name="colorPath"> The location of the file to write out. </param>
        /// <param name="colorImageFormat"> The image format to write the data out in. </param>
        /// <param name="depthFormat"> The pixel format to capture in. </param>
        /// <param name="depthPath"> The location of the file to write out. </param>
        /// <param name="depthImageFormat"> The image format to write the data out in. </param>
        /// <returns>AsyncRequest&lt;CaptureState&gt;</returns>
        public static AsyncRequest <CaptureState> CaptureColorAndDepthToFile
        (
            Camera camera,
            GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_UNorm,
            string colorPath           = null,
            CaptureImageEncoder.ImageFormat colorImageFormat = CaptureImageEncoder.ImageFormat.Jpg,
            GraphicsFormat depthFormat = GraphicsFormat.R16_UNorm,
            string depthPath           = null,
            CaptureImageEncoder.ImageFormat depthImageFormat = CaptureImageEncoder.ImageFormat.Raw
        )
        {
            Debug.Assert(camera != null, "CaptureColorAndDepthToFile camera cannot be null");

            Func <AsyncRequest <CaptureState>, AsyncRequest <CaptureState> .Result> colorFunctor = null;
            Func <AsyncRequest <CaptureState>, AsyncRequest <CaptureState> .Result> depthFunctor = null;

            var width  = camera.pixelWidth;
            var height = camera.pixelHeight;

            bool flipY = ShouldFlipY(camera);

            if (colorPath != null)
            {
                colorFunctor = (AsyncRequest <CaptureState> r) =>
                {
                    colorPath = CaptureImageEncoder.EnforceFileExtension(colorPath, colorImageFormat);
                    var result = FileProducer.Write(colorPath, CaptureImageEncoder.EncodeArray(r.data.colorBuffer as Array, width, height, colorFormat, colorImageFormat));
                    return(result ? AsyncRequest.Result.Completed : AsyncRequest.Result.Error);
                };
            }

            if (depthPath != null)
            {
                depthFunctor = (AsyncRequest <CaptureState> r) =>
                {
                    depthPath = CaptureImageEncoder.EnforceFileExtension(depthPath, depthImageFormat);
                    var result = FileProducer.Write(depthPath, CaptureImageEncoder.EncodeArray(r.data.depthBuffer as Array, width, height, depthFormat, depthImageFormat));
                    return(result ? AsyncRequest <CaptureState> .Result.Completed : AsyncRequest <CaptureState> .Result.Error);
                };
            }

            return(Capture(camera, colorFunctor, colorFormat, depthFunctor, depthFormat, flipY: flipY));
        }
Пример #2
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);
        }
Пример #3
0
 /// <summary>
 /// Captures a camera render and writes out the depth channel to a file.
 /// </summary>
 /// <param name="camera"> The Camera to capture data from. </param>
 /// <param name="depthFormat"> The pixel format to capture in. </param>
 /// <param name="depthPath"> The location of the file to write out. </param>
 /// <param name="depthImageFormat"> The image format to write the data out in. </param>
 /// <returns>AsyncRequest&lt;CaptureState&gt;</returns>
 public static AsyncRequest <CaptureState> CaptureDepthToFile(Camera camera, GraphicsFormat depthFormat, string depthPath, CaptureImageEncoder.ImageFormat depthImageFormat = CaptureImageEncoder.ImageFormat.Raw)
 {
     return(CaptureColorAndDepthToFile(camera, depthFormat: depthFormat, depthPath: depthPath, depthImageFormat: depthImageFormat));
 }
Пример #4
0
 /// <summary>
 /// Captures a camera render and writes out the color channel to a file.
 /// </summary>
 /// <param name="camera"> The Camera to capture data from. </param>
 /// <param name="colorFormat"> The color pixel format to capture in. </param>
 /// <param name="colorPath"> The location of the file to write out. </param>
 /// <param name="colorImageFormat"> The image format to write the data out in. </param>
 /// <returns>AsyncRequest&lt;CaptureState&gt;</returns>
 public static AsyncRequest <CaptureState> CaptureColorToFile(Camera camera, GraphicsFormat colorFormat, string colorPath, CaptureImageEncoder.ImageFormat colorImageFormat = CaptureImageEncoder.ImageFormat.Jpg)
 {
     return(CaptureColorAndDepthToFile(camera, colorFormat, colorPath, colorImageFormat));
 }