protected override void Update()
        {
            base.Update();

            if (changeReader == null)
            {
                changeReader = new P3dReader();

                changeReader.OnComplete += HandleCompleteChange;
            }

            if (changeReader.Requested == false && registeredPaintableTexture != null && registeredPaintableTexture.Activated == true)
            {
                if (P3dReader.NeedsUpdating(changeReader, changePixels, registeredPaintableTexture.Current, downsampleSteps) == true || changeDirty == true)
                {
                    changeDirty = false;

                    var desc          = registeredPaintableTexture.Current.descriptor; desc.useMipMap = false;
                    var renderTexture = P3dHelper.GetRenderTexture(desc);

                    P3dCommandReplace.Blit(renderTexture, texture, color);

                    // Request new change
                    changeReader.Request(renderTexture, DownsampleSteps, Async);

                    P3dHelper.ReleaseRenderTexture(renderTexture);
                }
            }

            changeReader.UpdateRequest();
        }
示例#2
0
        public static bool NeedsUpdating <T>(P3dReader reader, NativeArray <T> array, RenderTexture texture, int downsampleSteps)
            where T : struct
        {
            if (array.IsCreated == false || reader.DownsampledSize.x * reader.DownsampledSize.y != array.Length)
            {
                return(true);
            }

            var originalSize    = Vector2Int.zero;
            var downsampledSize = Vector2Int.zero;

            originalSize.x = downsampledSize.x = texture.width;
            originalSize.y = downsampledSize.y = texture.height;

            for (var i = 0; i < downsampleSteps; i++)
            {
                if (downsampledSize.x > 2)
                {
                    downsampledSize.x /= 2;
                }

                if (downsampledSize.y > 2)
                {
                    downsampledSize.y /= 2;
                }
            }

            return(reader.OriginalSize != originalSize || reader.DownsampledSize != downsampledSize);
        }
示例#3
0
        protected override void Update()
        {
            base.Update();

            if (maskReader == null)
            {
                maskReader = new P3dReader();

                maskReader.OnComplete += HandleCompleteMask;
            }

            if (maskReader.Requested == false && registeredPaintableTexture != null && registeredPaintableTexture.Activated == true)
            {
                if (P3dReader.NeedsUpdating(maskReader, maskPixels, registeredPaintableTexture.Current, downsampleSteps) == true || maskDirty == true)
                {
                    maskDirty = false;

                    var desc          = registeredPaintableTexture.Current.descriptor; desc.useMipMap = false;
                    var renderTexture = P3dHelper.GetRenderTexture(desc);

                    if (maskTexture != null)
                    {
                        P3dBlit.Texture(renderTexture, P3dHelper.GetQuadMesh(), 0, maskTexture, P3dCoord.First);
                    }
                    else
                    {
                        P3dBlit.White(renderTexture, maskMesh, 0, registeredPaintableTexture.Coord);
                    }

                    // Request new mask
                    maskReader.Request(renderTexture, DownsampleSteps, Async);

                    P3dHelper.ReleaseRenderTexture(renderTexture);
                }
            }

            maskReader.UpdateRequest();
        }
示例#4
0
        protected virtual void Update()
        {
            if (currentReader == null)
            {
                currentReader = new P3dReader();

                currentReader.OnComplete += HandleCompleteCurrent;
            }

            cooldown -= Time.deltaTime;

            if (cooldown <= 0.0f && currentReader.Requested == false && registeredPaintableTexture != null && registeredPaintableTexture.Activated == true)
            {
                if (P3dReader.NeedsUpdating(currentReader, currentPixels, registeredPaintableTexture.Current, downsampleSteps) == true || currentDirty == true)
                {
                    cooldown     = interval;
                    currentDirty = false;

                    currentReader.Request(registeredPaintableTexture.Current, downsampleSteps, async);
                }
            }

            currentReader.UpdateRequest();
        }