Unity Community

Results 1 to 6 of 6

  1. Posts

    using data aquired by WebCamTexture.GetPixels32

    Hi there,

    I'm slowly learning to program, but have many (probably silly) questions ... I'm playing with the new Unity 3.5 webcam possibilities, and have the following code (mostly from the 'scripting reference'):

    1. var webcamTexture : WebCamTexture;
    2. var data : Color32[];
    5. function Start () {
    6. // Start web cam feed
    7. webcamTexture = WebCamTexture(160, 120, 15);
    8. webcamTexture.Play();
    9. data = new Color32[webcamTexture.width * webcamTexture.height];
    12. var cube : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
    13. cube.transform.renderer.material.color = Color(data[0]);
    14. }
    16. function Update () {
    17. webcamTexture.GetPixels32 (data);
    18. // Do processing of data here.
    19. print(data[0]);
    20. }

    What I am trying to do here is... store the webcam data in an array (resolution 160x120), create a cube and give this the first color stored in the array. I can print the rgba data of this color, but don't know how to apply it to the cube. What I do on line 13 is obviously wrong... How do you do this?


  2. Location
    Zürich, Switzerland
    add a texture to the cube and then use SetPixels32(data) and Apply on it.

    Or simply apply webcamTexture to the cube directly instaed of trying to GET SET Apply

  3. Posts
    Hi Dreamora,

    Thanks for your reply! I'm not sure if I understand your feedback correctly... I'm not trying to apply the whole webcam-image to the cube, but only the rgba value of one 'pixel' of it. For that I need WebCamTexture.GetPixels32 right, not just WebCamTexture? And do I need a texture? I just want to apply the rgba data to material.color.
    Maybe I should explain what I'm trying to achieve a bit better. I want to create a grid of 160x120 cubes, each cube displaying a color of the 160x120 webcam-feed. Understanding the problem mentioned above would be a first step to achieve this I figured...
    Thanks again!

  4. Posts
    Got some help from a friend, in case other people want to know:

    cube.transform.renderer.material.color = Color(data[0]);
    should be:
    cube.transform.renderer.material.color = data[0];

    Works fine now!

  5. If you're simply looking for the color of one pixel, it will be more efficient to use the WebCamTexture.GetPixel function. This will return the color of the specified pixel.

  6. Posts
    It was as simple as setting the texture and stop the device.
    Thank you dreamora I was looking for that info.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts