Ejemplo n.º 1
0
        void Update()
        {
            if (MyRenderer == null)
            {
                GetRenderer();
            }

            if (MyRenderer == null)
            {
                return;
            }

            ShowWarning = false;

            Texture map = FXDataProvider.GetMap(TextureToBind);

            if (map == null)
            {
                return;
            }

            TextureScale = FXDataProvider.GetMapScale(TextureToBind);


            TextureSize.x = map.width;
            TextureSize.y = map.height;

            if (MyRenderer.sharedMaterial.HasProperty(TexturePropertyName))
            {
                MyRenderer.sharedMaterial.SetTexture(TexturePropertyName, map);
            }
            else
            {
                ShowWarning = true;
            }

            if (BindScale)
            {
                if (MyRenderer.sharedMaterial.HasProperty(TextureScalePropertyName))
                {
                    MyRenderer.sharedMaterial.SetVector(TextureScalePropertyName, TextureScale);
                }
                else
                {
                    ShowWarning = true;
                }
            }

            if (BindSize)
            {
                if (MyRenderer.sharedMaterial.HasProperty(TextureSizePropertyName))
                {
                    MyRenderer.sharedMaterial.SetVector(TextureSizePropertyName, TextureSize);
                }
                else
                {
                    ShowWarning = true;
                }
            }
        }
Ejemplo n.º 2
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.º 3
0
        private IEnumerator WaitForDepthImage()
        {
            bool isReady = false;

            while (!isReady)
            {
                LastedDepthTexture = FXDataProvider.GetMap(FXDataProvider.MAP_DATA_TYPE.UserMap);
                if (LastedDepthTexture == CVInterface.EmptyTexture)
                {
                    yield return(null);
                }
                else
                {
                    isReady = true;
                }
            }

            IsStarted = true;
        }
Ejemplo n.º 4
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.º 5
0
        public void InitColliders()
        {
            if (!IsStarted)
            {
                return;
            }

            LastedDepthTexture = FXDataProvider.GetMap(FXDataProvider.MAP_DATA_TYPE.UserMap);
            Vector2 TextureSize = new Vector2(LastedDepthTexture.width, LastedDepthTexture.height);

            if (TextureSize.y < 100)
            {
                if (CVInterface.LastUsersMapDimensions.y >= 100)
                {
                    TextureSize.Set(CVInterface.LastUsersMapDimensions.x, CVInterface.LastUsersMapDimensions.y);
                }
                else
                {
                    return;
                }
            }
            //Debug.Log("TEX SIZE = " + LastedDepthTexture.width + "/" + LastedDepthTexture.height);


            float worldScreenHeight;

            if (ExperienceCamera == null)
            {
                worldScreenHeight = 10f;
            }
            else
            {
                worldScreenHeight = ExperienceCamera.orthographicSize * 2f;
            }

            float textHeight = TextureSize.y;
            float scale      = worldScreenHeight / textHeight;

            float scaleX = 1.0f;
            float scaleY = 1.0f;

            if (!Stretch)
            {
                scaleX = scaleY = worldScreenHeight / textHeight;
            }
            else
            {
                scaleY = worldScreenHeight / textHeight;
                scaleX = scaleY * (TextureSize.x / TextureSize.y);
            }



            //Debug.Log("Scale = " + scale);

            SpawnZone = new Rect(-TextureSize.x / 2 * scaleX, -TextureSize.y / 2 * scaleY, TextureSize.x * scaleX, TextureSize.y * scaleY);

            int totalSamples = NbSamplesWidth * NbSamplesHeight;

            ColliderGOs = new GameObject[totalSamples];


            //Vector3 topleft = new Vector3(0f, 0f, ExperienceCamera.transform.position.z);
            //Vector3 lowerRight = new Vector3(Screen.width, Screen.height, ExperienceCamera.transform.position.z);
            int i = 0;
            int j = 0;

            for (j = 0; j < NbSamplesHeight; j++)
            {
                for (i = 0; i < NbSamplesWidth; i++)
                {
                    int        index = i * NbSamplesWidth + j;
                    GameObject go    = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                    go.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
                    go.transform.localScale    = new Vector3(ColliderRadius, 10f, ColliderRadius);
                    go.gameObject.tag          = "Player";
                    go.GetComponent <CapsuleCollider>().radius = Radius;
                    //go.GetComponent<CapsuleCollider>().isTrigger = true;


                    if (!visualDebugOn)
                    {
                        go.GetComponent <MeshRenderer>().enabled = false;
                    }
                    go.SetActive(false);


                    go.transform.parent = transform;
                    float posx = SpawnZone.x + (float)i / (float)NbSamplesWidth * (float)SpawnZone.width;
                    float posy = SpawnZone.y + (float)j / (float)NbSamplesHeight * (float)SpawnZone.height;

                    go.transform.localPosition = new Vector3(posx, posy, 0f);
                    ColliderGOs[index]         = go;
                }
            }
            CollidersCreated = true;
        }
Ejemplo n.º 6
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);
            }
        }