是否可以将设备摄像头中的视频设置为Unity3d中的背景?

时间:2012-06-13 16:28:47

标签: unity3d

我正在实施增强现实原型。但我还没弄清楚如何将视频设置为背景。有一个WebCamTexture类可以设置为GUITexture的纹理。但在这种情况下,其他3d对象不可见。

3 个答案:

答案 0 :(得分:1)

  1. 创建一架飞机
  2. 将其附加到摄像机节点
  3. GameObject->将视图与选定对齐
  4. 将飞机翻译为900
  5. 缩放平面以适应屏幕。

答案 1 :(得分:0)

创建2个摄像头,一个用于查看所有3d对象,另一个用于GUITexture。

答案 2 :(得分:0)

将以下代码附加到您的主摄像机即可完成

public class webcam_example : MonoBehaviour
{
    WebCamTexture webcamTexture;
    bool webcam_ok = false;
    void Start()
    {
        WebCamDevice[] webCams = WebCamTexture.devices;
        if (webCams.Length > 0) {
           webcamTexture = new WebCamTexture();
           webcamTexture.Play();
           webcam_ok = true;
        }
    }

    void OnPreRender()
    {
        if (webcam_ok)
        {
            Graphics.Blit(webcamTexture, (RenderTexture)null);
        }
    }
}