18
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【THETA V】ライブストリーミングの映像をUnityで表示

Posted at

準備

RICOH THETA Vで4Kライブストリーミングをしよう

Skybox版

  • MainCameraにSkyboxを追加。
  • [Custom Skybox]にStereoarts HomepageThetaRealtimeSkyboxを設定。
  • MainCameraに以下のWebCamDrawer.csをアタッチ。

Sphere版

映像を描画するスクリプト

THETA SからOculus RiftへUSBライブストリーミング with Unity (Skybox編)よりWebCamDrawer.csを拝借、少し手を加えたスクリプト。

WebCamDrawer.cs
using UnityEngine;
using System.Collections;

public class WebCamDrawer : MonoBehaviour {
	public string deviceNameKeyword = "THETA";

	void Start() {
		StartStreaming();
	}

	void StartStreaming() {
		WebCamDevice device = new WebCamDevice();
		// 参照渡しでdeviceを書き換え
		if (!FindDevice (ref device)) {
			Debug.LogError("<"+deviceNameKeyword+">を含むWebカメラが検出できませんでした。");
			return;
		}
		WebCamTexture webcamTexture = new WebCamTexture(device.name);
		Material mat = GetTargetMaterial ();
		if (mat == null) {
			return;
		}
		mat.mainTexture = webcamTexture;
		webcamTexture.Play();
	}

	bool FindDevice(ref WebCamDevice target) {
		bool deviceExists = false;
		WebCamDevice[] devices = WebCamTexture.devices;
        foreach (WebCamDevice device in devices) {
			Debug.Log("device.name => " + device.name);
			if (device.name.Contains(deviceNameKeyword)) {
				target = device;
				deviceExists = true;
			}
        }
		return deviceExists;
	}

	Material GetTargetMaterial() {
		Skybox skybox = GetComponent<Skybox> ();
		if (skybox != null) {
			return skybox.material;
		}
		Renderer renderer = GetComponent<Renderer> ();
		if (renderer != null) {
			return renderer.material;
		}
		Debug.LogError ("Renderer/Skyboxコンポーネントがありません。");
		return null;
	}
}

参考
WebCamTexture

windowsのエラー

Could not connect pins - RenderStream()
UnityEngine.WebCamTexture:Play()

こんなエラーが出てくるので、以下のURLを参考に進める。
Solved: Unity Can’t Display THETA V Live Stream on Windows 10

レジストリエディターからDevicePathを追加する。
2018-02-03.png

WebCamDrawer.csのデバイスの名前を、Macの場合はTHETA、Windowsの場合はTHETA V FullHDと使い分ける。
2018-02-03 (1).png

18
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?