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

            if (MyRenderer == null)
            {
                return;
            }

            float f = FXDataProvider.GetFloat(FloatToBind);

            float remapped = Remap(RemapParams.x, RemapParams.y, RemapParams.z, RemapParams.w, f);

            localValue += remapped;

            ShowWarning = false;
            if (!MyRenderer.sharedMaterial.HasProperty(FloatPropertyName))
            {
                ShowWarning = true;
            }
            else
            {
                MyRenderer.sharedMaterial.SetFloat(FloatPropertyName, localValue);
            }
        }
Exemplo n.º 2
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;
                }
            }
        }
Exemplo n.º 3
0
        Vector3 GetNewRandValueNotInsideTab(int i)
        {
            bool  bAlreadyIn = false;
            float amp        = Remap(0f, 1f, 0.5f, 1.0f, FXDataProvider.GetFloat(FXDataProvider.FLOAT_DATA_TYPE.AmplitudeSetting));

            float randX = Random.Range(-5.5f * amp, 5.5f * amp);
            float randY = Random.Range(-2f * amp, 4f * amp);

            for (int j = 0; j < stockPos.Length; j++)
            {
                if (stockPos[j].x == randX && stockPos[j].y == randY)
                {
                    bAlreadyIn = true;
                    break;
                }
            }

            if (!bAlreadyIn)
            {
                stockPos[i] = new Vector3(randX, randY, 10f);
            }
            else
            {
                //récursivité !
                stockPos[i] = GetNewRandValueNotInsideTab(i);
            }

            return(stockPos[i]);
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
0
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
Exemplo n.º 6
0
        public override void UpdateBinding(VisualEffect component)
        {
            Vector3 pos = FXDataProvider.GetJointPosition(Joint, userIndex);

            if (ProjectToPlane && ProjectionPlane != null && ProjectionCamera != null)
            {
                pos   = ProjectionCamera.WorldToViewportPoint(pos);
                pos.z = ProjectionPlane.position.z;
                pos   = ProjectionCamera.ViewportToWorldPoint(pos);
            }

            component.SetVector3(JointPositionProperty, pos);
            if (BindRotation)
            {
                component.SetVector3(JointPositionProperty, FXDataProvider.GetJointRotation(Joint, userIndex));
            }
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
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);
                    }
                }
            }
        }
        void Update()
        {
            if (MyRenderer == null)
            {
                GetRenderer();
            }

            if (MyRenderer == null)
            {
                return;
            }

            float f = FXDataProvider.GetFloat(FloatToBind);

            ShowWarning = false;
            if (!MyRenderer.sharedMaterial.HasProperty(FloatPropertyName))
            {
                ShowWarning = true;
            }
            else
            {
                MyRenderer.sharedMaterial.SetFloat(FloatPropertyName, f);
            }
        }
Exemplo n.º 10
0
 public override void UpdateBinding(VisualEffect component)
 {
     component.SetInt(IntProperty, FXDataProvider.GetInt(IntToBind));
 }
Exemplo n.º 11
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;
        }
Exemplo n.º 12
0
 public override void UpdateBinding(VisualEffect component)
 {
     component.SetTexture(TextureProperty, FXDataProvider.GetAllBonesTexture());
     component.SetInt(BoneCountProperty, FXDataProvider.GetInt(FXDataProvider.INT_DATA_TYPE.BoneCount));
 }
Exemplo n.º 13
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);
            }
        }
Exemplo n.º 14
0
 public override void UpdateBinding(VisualEffect component)
 {
     component.SetVector4(ColorProperty, FXDataProvider.GetColor(ColorToBind));
 }