Пример #1
0
        void CheckTexture()
        {
            if (!Distorted || !Fisheye) // No-distortion and non-fisheye distortion use Camera.Render().
            {
                // if this is not first time
                if (renderTarget != null)
                {
                    if (!renderTarget.IsValid(RenderTextureWidth, RenderTextureHeight))
                    {
                        // if camera capture size has changed or we have lost rendertexture due to Unity window resizing or otherwise
                        renderTarget.Release();
                        renderTarget = null;
                    }
                }

                if (renderTarget == null)
                {
                    renderTarget = SensorRenderTarget.Create2D(RenderTextureWidth, RenderTextureHeight, GraphicsFormat.R8G8B8A8_SRGB);
                    SensorCamera.targetTexture = renderTarget;
                }
            }
            else
            {
                CheckCubemapTexture();
            }

            if (Distorted)
            {
                // if this is not first time
                if (DistortedTexture != null)
                {
                    if (SizeChanged)
                    {
                        // if camera capture size has changed
                        DistortedTexture.Release();
                        DistortedTexture = null;
                    }
                    else if (!DistortedTexture.IsCreated())
                    {
                        // if we have lost DistortedTexture due to Unity window resizing or otherwise
                        DistortedTexture.Release();
                        DistortedTexture = null;
                    }
                }
                if (DistortedTexture == null)
                {
                    DistortedTexture = new RenderTexture(Width, Height, 24, RenderTextureFormat.ARGB32, CameraTargetTextureReadWriteType)
                    {
                        dimension         = TextureDimension.Tex2D,
                        antiAliasing      = 1,
                        useMipMap         = false,
                        useDynamicScale   = false,
                        wrapMode          = TextureWrapMode.Clamp,
                        filterMode        = FilterMode.Bilinear,
                        enableRandomWrite = true,
                    };
                    DistortedTexture.Create();
                }
            }
        }
Пример #2
0
        bool BeginReadRequest(int count, ref ReadRequest req)
        {
            if (count == 0)
            {
                return(false);
            }

            BeginReadMarker.Begin();

            SensorRenderTarget renderTarget = null;

            if (AvailableRenderTextures.Count != 0)
            {
                renderTarget = AvailableRenderTextures.Pop();
            }

            if (renderTarget == null)
            {
                renderTarget = SensorRenderTarget.Create2D(RenderTextureWidth, RenderTextureHeight);
            }
            else if (!renderTarget.IsValid(RenderTextureWidth, RenderTextureHeight))
            {
                renderTarget.Release();
                renderTarget = SensorRenderTarget.Create2D(RenderTextureWidth, RenderTextureHeight);
            }

            activeTarget = renderTarget;
            SensorCamera.targetTexture = renderTarget;
            SensorCamera.Render();

            req = new ReadRequest()
            {
                TextureSet = renderTarget,
                Index      = CurrentIndex,
                Count      = count,
                Origin     = SensorCamera.transform.position,

                CameraToWorldMatrix = SensorCamera.cameraToWorldMatrix,
            };

            if (!Compensated)
            {
                req.Transform = transform.worldToLocalMatrix;
            }

            BeginReadMarker.End();

            CurrentIndex = (CurrentIndex + count) % CurrentMeasurementsPerRotation;

            return(true);
        }
Пример #3
0
        private void CheckTexture()
        {
            if (renderTarget != null && (!renderTarget.IsCube || !renderTarget.IsValid(CubemapSize, CubemapSize)))
            {
                renderTarget.Release();
                renderTarget = null;
            }

            if (renderTarget == null)
            {
                renderTarget = SensorRenderTarget.CreateCube(CubemapSize, CubemapSize, faceMask);
                SensorCamera.targetTexture = null;
            }
        }
Пример #4
0
        void CheckTexture()
        {
            // if this is not first time
            if (renderTarget != null)
            {
                if (!renderTarget.IsValid(Width, Height))
                {
                    // if camera capture size has changed or we have lost rendertexture due to Unity window resizing or otherwise
                    renderTarget.Release();
                    renderTarget = null;
                }
            }

            if (renderTarget == null)
            {
                renderTarget = SensorRenderTarget.Create2D(Width, Height);
                SensorCamera.targetTexture = renderTarget;
            }
        }
Пример #5
0
        void CheckTexture()
        {
            var targetWidth  = -1;
            var targetHeight = -1;

            if (Distorted)
            {
                // Distorted + fisheye - render to cubemap, then distort to sensor-sized texture
                if (Fisheye)
                {
                    if (renderTarget != null && (!renderTarget.IsCube || !renderTarget.IsValid(CubemapSize, CubemapSize)))
                    {
                        renderTarget.Release();
                        renderTarget = null;
                    }
                    if (renderTarget == null)
                    {
                        renderTarget = SensorRenderTarget.CreateCube(CubemapSize, CubemapSize, faceMask);
                        SensorCamera.targetTexture = null;
                    }
                }
                // Distorted - render to larger texture, then distort to sensor-sized one
                else
                {
                    targetWidth  = LensDistortion.ActualWidth;
                    targetHeight = LensDistortion.ActualHeight;
                }

                if (DistortedHandle != null && !DistortedHandle.IsValid(Width, Height))
                {
                    DistortedHandle.Release();
                    DistortedHandle = null;
                }

                if (DistortedHandle == null)
                {
                    DistortedHandle = SensorRenderTarget.Create2D(Width, Height, GraphicsFormat.R8G8B8A8_SRGB, true);
                }
            }
            else
            {
                // Undistorted - use only sensor-sized texture
                if (DistortedHandle != null)
                {
                    DistortedHandle.Release();
                    DistortedHandle = null;
                }

                targetWidth  = Width;
                targetHeight = Height;
            }

            if (targetWidth > 0)
            {
                if (renderTarget != null && !renderTarget.IsValid(targetWidth, targetHeight))
                {
                    renderTarget.Release();
                    renderTarget = null;
                }
                if (renderTarget == null)
                {
                    renderTarget = SensorRenderTarget.Create2D(targetWidth, targetHeight, GraphicsFormat.R8G8B8A8_SRGB, !Distorted);
                    SensorCamera.targetTexture = renderTarget;
                }
            }
        }
Пример #6
0
        void CheckTexture()
        {
            if (!Distorted || !Fisheye) // No-distortion and non-fisheye distortion use Camera.Render().
            {
                // if this is not first time
                if (renderTarget != null)
                {
                    if (!renderTarget.IsValid(RenderTextureWidth, RenderTextureHeight))
                    {
                        // if camera capture size has changed or we have lost rendertexture due to Unity window resizing or otherwise
                        renderTarget.Release();
                        renderTarget = null;
                    }
                }

                if (renderTarget == null)
                {
                    renderTarget = SensorRenderTarget.Create2D(RenderTextureWidth, RenderTextureHeight);
                    SensorCamera.targetTexture = renderTarget;
                }
            }
            else // Fisheye camera uses Camera.RenderToCubemap(...), and thus do not need normal RenderTexture.
            {
                // Although Camera.RenderToCubemap has its own target texture as parameter,
                // setting Camera.targetTexture will still affect its result.
                // So we set Camera.targetTexture to null to make sure its result is correct.
                SensorCamera.targetTexture = null;

                if (CurrentCubemapSize != CubemapSize)
                {
                    CubemapTexture.Release();
                    CubemapTexture = null;
                }
                if (CubemapTexture == null)
                {
                    CubemapTexture = new RenderTexture(CubemapSize, CubemapSize, 24, RenderTextureFormat.ARGB32, CameraTargetTextureReadWriteType)
                    {
                        dimension       = TextureDimension.Cube,
                        antiAliasing    = 1,
                        useMipMap       = false,
                        useDynamicScale = false,
                        wrapMode        = TextureWrapMode.Clamp,
                        filterMode      = FilterMode.Bilinear,
                    };
                    CubemapTexture.Create();
                }
            }

            if (Distorted)
            {
                // if this is not first time
                if (DistortedTexture != null)
                {
                    if (SizeChanged)
                    {
                        // if camera capture size has changed
                        DistortedTexture.Release();
                        DistortedTexture = null;
                    }
                    else if (!DistortedTexture.IsCreated())
                    {
                        // if we have lost DistortedTexture due to Unity window resizing or otherwise
                        DistortedTexture.Release();
                        DistortedTexture = null;
                    }
                }
                if (DistortedTexture == null)
                {
                    DistortedTexture = new RenderTexture(Width, Height, 24, RenderTextureFormat.ARGB32, CameraTargetTextureReadWriteType)
                    {
                        dimension         = TextureDimension.Tex2D,
                        antiAliasing      = 1,
                        useMipMap         = false,
                        useDynamicScale   = false,
                        wrapMode          = TextureWrapMode.Clamp,
                        filterMode        = FilterMode.Bilinear,
                        enableRandomWrite = true,
                    };
                    DistortedTexture.Create();
                }
            }
        }