LoginSignup
daimoe
@daimoe

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

RICOH THETA V ライブ映像 を Unity で 映したい

解決したいこと

RICOH THETA V ライブ映像 を Unity で 映したいが
WebCamTexture could not find a supported resolution for the selected webcam.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
web:StartStreaming () (at Assets/web.cs:41)
web:Start () (at Assets/web.cs:12)
というエラーが出て反映されない

自分で試したこと

  1. theta V をライブモードにする
  2. RICOH THETA V を選択するようにして下記で実行

デフォルトの3dシーンにplane を追加 planeにweb.cs を追加
スクリーンショット 2024-05-09 153929.png

コード

web.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class web : MonoBehaviour
{
    public string deviceNameKeyword = "RICOH THETA V";
    private WebCamTexture webcamTexture;

    void Start()
    {
        StartStreaming();
    }

    void StartStreaming()
    {
        WebCamDevice device = new WebCamDevice();
        if (!FindDevice(ref device))
        {
            Debug.LogError($"キーワード: {deviceNameKeyword} を含むウェブカメラが見つかりませんでした");
            return;
        }

        if (webcamTexture != null)
        {
            webcamTexture.Stop();
            Destroy(webcamTexture);
        }
        
        webcamTexture = new WebCamTexture(device.name);

    

        Material mat = GetTargetMaterial();
        if (mat == null)
        {
            return;
        }

        mat.mainTexture = webcamTexture;
        webcamTexture.Play();
        Debug.Log($"デバイスからストリーミング中: {device.name}");
    }

    bool FindDevice(ref WebCamDevice target)
    {
        bool i = false;
        WebCamDevice[] devices = WebCamTexture.devices;
        Debug.Log(devices);
        foreach (WebCamDevice device in devices)
        {
            Debug.Log($"利用可能なデバイス: {device.name},{device.availableResolutions},33333");
            if (device.name.Contains(deviceNameKeyword))
            {
                target = device;
                i=true;
            }
        }
        return i;
    }

    Material GetTargetMaterial()
    {
        Skybox skybox = GetComponent<Skybox>();
        if (skybox != null)
        {
            Debug.Log("ssssssssss");
            return skybox.material;
        }

        Renderer renderer = GetComponent<Renderer>();
        if (renderer != null)
        {
            Debug.Log("sss333333333");
            return renderer.material;
        }

        Debug.LogError("Renderer または Skybox コンポーネントがありません");
        return null;
    }
}

0

2Answer

本件と関係あるかちょっと分からないですけど、こちらの記事ではstart()直後は初期化が終わってなくて正しい解像度が取れないとかなんとか書いてありますね。

0

WebCamTexture could not find a supported resolution for the selected webcam.

WebCamTextureは使ったことはありませんが、コンストラクタで解像度を指定できる(マニュアル)ようですから、WebCamDevice.availableResolutionsのいずれかをコンストラクタで指定してみたらいかがですか。

0

Your answer might help someone💌