예제 #1
0
    void Start()
    {
        WebCamDevice[] devices = WebCamTexture.devices;
        webcam = new WebCamTexture(WebCamTexture.devices [0].name, 640, 480, 60);
        if (devices.Length > 0)
        {
            webcam.deviceName = devices[0].name;
            GetComponent <Renderer>().material.mainTexture = webcam;
            webcam.Play();
        }

        //ws = new WebSocket("ws://localhost:10000/");
        ws             = new WebSocket("127.0.0.1:5000/");
        currentTexture = new Texture2D(webcam.width, webcam.height);

        colorArray        = new Color32Array();
        colorArray.colors = new Color32[webcam.width * webcam.height];
        ws.OnOpen        += OnOpenHandler;
        ws.OnMessage     += OnMessageHandler;
        // ws.OnClose += OnCloseHandler;
        InvokeRepeating("sendvid", 2.0f, 0.1f);
        // Invoke("sendvid",2.0f);
        ws.ConnectAsync();
        // StartCoroutine("sendvid");
    }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="texture"></param>
        /// <returns></returns>
        public static Texture2D ToTexture2D(this WebCamTexture texture)
        {
            var color_array = new Color32Array {
                colors = new Color32[texture.width * texture.height]
            };

            texture.GetPixels32(color_array.colors);
            var tex = new Texture2D(2, 2);

            tex.LoadRawTextureData(color_array.byteArray);
            tex.Apply();

            return(tex);

            /*
             * var ntv_p = texture.GetNativeTexturePtr();
             *
             * return Texture2D.CreateExternalTexture(texture.width,
             *                                     texture.height,
             *                                     TextureFormat.RGBAFloat,
             *                                     false,
             *                                     true,
             *                                     ntv_p);
             */
        }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        WebCamDevice[] devices = WebCamTexture.devices;
        deviceName        = devices[0].name;
        wct               = new WebCamTexture(deviceName, 640, 480, 60);
        colorArray        = new Color32Array();
        colorArray.colors = new Color32[wct.width * wct.height];
        data              = new Color32[wct.width * wct.height];
        wct               = new WebCamTexture();
        //GetComponent<Renderer>().material.mainTexture = wct;

        //RawImage.material.mainTexture = wct;
        wct.Play();
    }