Simplest Webcam Test in Unity

livestreaming

#1

Although I’m completely new to Unity and don’t know C#, I managed to install Unity, get WiFi streaming working and play a 360 video onto a sphere in Unity.

I tried tethered live streaming with Unity, but I wasn’t able to understand what was going on.

I decided to start with the basics and simply get the THETA playing as a webcam in Unity in dual fisheye.

First, I wanted to make sure I could detect the THETA. I created a test script and attached it to an Empty GameObject.

using UnityEngine;
using System.Collections;

public class testScriptBasic : MonoBehaviour {
    
	void Start () {
        WebCamDevice[] devices = WebCamTexture.devices;
        Debug.Log("Number of web cams connected: " + devices.Length);
        string camName = devices[1].name;
        Debug.Log("The webcam name is " + camName);
        
	}
}

I pressed the Play button in Unity and was pleasantly surprised to see that the webcam was detected. :slight_smile: Note that I have two webcams on my computer. I know from a prior test run that the THETA is the second webcam.

I created a 3D plane in Unity and extended my script to play and render the video stream.

using UnityEngine;
using System.Collections;

public class testScript : MonoBehaviour {
    
	void Start () {
        WebCamDevice[] devices = WebCamTexture.devices;
        Debug.Log("Number of web cams connected: " + devices.Length);
        Renderer rend = this.GetComponentInChildren<Renderer>();

        WebCamTexture mycam = new WebCamTexture();
        string camName = devices[1].name;
        Debug.Log("The webcam name is " + camName);
        mycam.deviceName = camName;
        rend.material.mainTexture = mycam;

        mycam.Play();
	}    	
}

I dragged my script onto the plane. I was surprised to see that the dual-fisheye video screen came up with no problem.

I then created a sphere and repeated the test.

I now have a full sphere that I can rotate. I’m going to experiment more with these simple tests on different objects and then make another attempt to use the shader packs that Goroman built.

In the current basic test, the edges of the spheres don’t match. This is a side view of the two spheres.

The problem can be largely solved with Goroman’s shader packs, but I’m building up to that solution.


#2

Now works with no gaps using registry hack.


#3

Testing with THETA V

Perfect sphere with no gaps. Mac OS X 10.12.5

using UnityEngine;
using System.Collections;

public class testScriptBasic : MonoBehaviour {

	void Start () {
		WebCamDevice[] devices = WebCamTexture.devices;
		Debug.Log("Number of web cams connected: " + devices.Length);
		Renderer rend = this.GetComponentInChildren<Renderer>();

		WebCamTexture mycam = new WebCamTexture();
		string camName = devices[0].name;
		Debug.Log("The webcam name is " + camName);
		mycam.deviceName = camName;
		rend.material.mainTexture = mycam;

		mycam.Play();
	}    	
}

#4

Woohoo! That’s exciting!