Ejemplo n.º 1
0
        private void UpdateColliderPositions()
        {
            if (ColliderGOs != null && ColliderGOs.Length > 0)
            {
                LastedDepthTexture = FXDataProvider.GetMap(FXDataProvider.MAP_DATA_TYPE.UserMap);
                if (LastedDepthTexture == CVInterface.EmptyTexture)
                {
                    return;
                }
                Texture2D t2d    = TextureToTexture2D(LastedDepthTexture);
                Vector2   tscale = FXDataProvider.GetMapScale(FXDataProvider.MAP_DATA_TYPE.UserMap);

                int i = 0;
                int j = 0;
                for (j = 0; j < NbSamplesHeight; j++)
                {
                    for (i = 0; i < NbSamplesWidth; i++)
                    {
                        int index = i * NbSamplesWidth + j;
                        int px;
                        if (tscale.x > 0)
                        {
                            px = Mathf.FloorToInt((float)i / (float)NbSamplesWidth * (float)LastedDepthTexture.width);
                        }
                        else
                        {
                            px = (LastedDepthTexture.width - 1) - Mathf.FloorToInt((float)i / (float)NbSamplesWidth * (float)LastedDepthTexture.width);
                        }
                        int py = 0;
                        if (tscale.y > 0)
                        {
                            py = Mathf.FloorToInt((float)j / (float)NbSamplesHeight * (float)LastedDepthTexture.height);
                        }
                        else
                        {
                            py = (LastedDepthTexture.height - 1) - Mathf.FloorToInt((float)j / (float)NbSamplesHeight * (float)LastedDepthTexture.height);
                        }

                        Color col = t2d.GetPixel(px, py);
                        if (col.r + col.g + col.b > 0)
                        {
                            ColliderGOs[index].SetActive(true);
                        }
                        else
                        {
                            ColliderGOs[index].SetActive(false);
                        }
                    }
                }
            }
            else
            {
                InitColliders();
            }
        }
Ejemplo n.º 2
0
        public override void UpdateBinding(VisualEffect component)
        {
            if (component != null)
            {
                Texture t = FXDataProvider.GetMap(TextureToBind);
                if (t == null)
                {
                    return;
                }

                component.SetTexture(TextureProperty, t);

                if (BindSize)
                {
                    _Size = FXDataProvider.GetMapSize(TextureToBind);
                    if (_Size != null)
                    {
                        component.SetVector2(TextureSizeProperty, _Size);
                    }
                    else
                    {
                        component.SetVector2(TextureSizeProperty, Vector2.one);
                    }
                }

                if (BindScale)
                {
                    _Scale = FXDataProvider.GetMapScale(TextureToBind);
                    if (_Scale != null)
                    {
                        component.SetVector2(TextureScaleProperty, _Scale);
                    }
                    else
                    {
                        component.SetVector2(TextureScaleProperty, Vector2.one);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override void UpdateBinding(VisualEffect component)
        {
            LastedDepthTexture = FXDataProvider.GetMap(TextureToBind);
            if (LastedDepthTexture == CVInterface.EmptyTexture)
            {
                return;
            }
            Texture2D t2d    = TextureToTexture2D(LastedDepthTexture);
            Vector2   tscale = FXDataProvider.GetMapScale(TextureToBind);

            int i = 0;
            int j = 0;

            countTop     = countDown = countLeft = countRight = countActivity = 0;
            minLeft      = NbSamplesWidth;
            maxRight     = 0;
            totalSamples = NbSamplesWidth * NbSamplesHeight;
            boolActive   = new bool[totalSamples];

            for (j = 0; j < NbSamplesHeight; j++)
            {
                for (i = 0; i < NbSamplesWidth; i++)
                {
                    int index = i * NbSamplesWidth + j;
                    int px;
                    if (tscale.x > 0)
                    {
                        px = Mathf.FloorToInt((float)i / (float)NbSamplesWidth * (float)LastedDepthTexture.width);
                    }
                    else
                    {
                        px = (LastedDepthTexture.width - 1) - Mathf.FloorToInt((float)i / (float)NbSamplesWidth * (float)LastedDepthTexture.width);
                    }
                    int py = 0;
                    if (tscale.y > 0)
                    {
                        py = Mathf.FloorToInt((float)j / (float)NbSamplesHeight * (float)LastedDepthTexture.height);
                    }
                    else
                    {
                        py = (LastedDepthTexture.height - 1) - Mathf.FloorToInt((float)j / (float)NbSamplesHeight * (float)LastedDepthTexture.height);
                    }

                    Color col = t2d.GetPixel(px, py);
                    if (col.r + col.g + col.b > 0)
                    {
                        boolActive[index] = true;
                        if (i < (NbSamplesWidth * 0.5))
                        {
                            countLeft += 1;
                        }
                        else
                        {
                            countRight += 1;
                        }

                        if (j < (NbSamplesHeight * 0.5))
                        {
                            countTop += 1;
                        }
                        else
                        {
                            countDown += 1;
                        }

                        if (j > 2 && j < NbSamplesHeight - 3)
                        {
                            if (i < minLeft)
                            {
                                minLeft = i;
                            }
                            if (i > maxRight)
                            {
                                maxRight = i;
                            }
                        }
                    }
                    else
                    {
                        boolActive[index] = false;
                    }

                    if (oldBoolActive != null && oldBoolActive.Length > 0)
                    {
                        if (oldBoolActive[index] != boolActive[index])
                        {
                            countActivity += 1;
                        }
                    }
                }
            }
            oldBoolActive = new bool[totalSamples];
            System.Array.Copy(boolActive, oldBoolActive, totalSamples);
            //oldBoolActive = (bool[]) boolActive.Clone();

            /*if(oldBoolActive != null)
             * {
             *      int rand = Random.Range(0, totalSamples-1);
             *      Debug.Log( "coucou " + rand + "   " + boolActive[rand] + "   " + oldBoolActive[rand]);
             * }*/

            float countTotalActive;

            percent = 0.0f;

            if (BindClutterHorizontal)
            {
                countTotalActive = countLeft + countRight;
                if (countTotalActive == 0)
                {
                    percent = 0.0f;
                }
                else
                {
                    percent = countLeft / countTotalActive;
                }

                component.SetFloat(HorizontalProperty, percent);
            }

            if (BindClutterVertical)
            {
                countTotalActive = countTop + countDown;
                if (countTotalActive == 0)
                {
                    percent = 0.0f;
                }
                else
                {
                    percent = countDown / countTotalActive;
                }

                component.SetFloat(VerticalProperty, percent);
            }

            if (BindClutterTotal)
            {
                countTotalActive = countTop + countDown;
                if (countTotalActive == 0)
                {
                    percent = 0.0f;
                }
                else
                {
                    percent = countTotalActive / totalSamples;
                }

                component.SetFloat(TotalProperty, percent);
            }

            if (BindClutterDeltaHorizontal)
            {
                countTotalActive = countTop + countDown;
                if (countTotalActive == 0)
                {
                    percent = 0.0f;
                }
                else
                {
                    percent = (maxRight - minLeft) / NbSamplesWidth;
                }

                component.SetFloat(DeltaHorizontalProperty, percent);
            }

            if (BindClutterActivity)
            {
                percent = countActivity / totalSamples;
                component.SetFloat(ActivityProperty, percent);
            }
        }