首页 > 解决方案 > 如何修复 ARCore 可以同时显示的预制件数量?(带图像识别)

问题描述

当前的应用程序允许您检测海报并以海报的大小显示启动视频的平面。

我的问题是视频中有声音,例如,如果你同时看 3 张海报,你就什么都听不懂了。

我正在尝试启用用户正在观看的视频的声音,或者限制同时显示的视频数量(比如在显示另一个视频之前等待第一个视频完成)

我目前正在使用 unity 2019.1.6 和 arcore 版本 1.10.0 进行 android 构建

我尝试通过触发器使用系统,然后通过Raycast但无事可做,我仍然有声音并且视频全部显示。

[SerializeField] private VideoClip[] videoClips;
public AugmentedImage Image;
private VideoPlayer video;

void Start()
{
    video = GetComponent<VideoPlayer>();
    video.loopPointReached += OnStop;
}

private void OnStop(VideoPlayer source)
{
    gameObject.SetActive(false);
}

void Update()
{
    if (Image == null || Image.TrackingState != TrackingState.Tracking)
    {
        return;
    }

    if (!video.isPlaying)
    {
        video.clip = videoClips[Image.DatabaseIndex];
        video.Play();
    }

    transform.localScale = new Vector3(Image.ExtentX - 1, Image.ExtentZ, 1);
}

我的结果很奇怪,要么视频不再出现但有视频的声音,要么什么都不显示。

你能帮我吗?

标签: unity3dvideoimage-recognitionarcore

解决方案


我不完全了解您的代码和设置,但我会简单地检查用户正在查看的方向与用户和图像之间的矢量之间的角度。像这样的东西

[Tooltip("Angle in degrees between view direction and positions vector has to be smaller than this to activate the video")]
[SerializeField] private float angleThreshold = 20f;

// if possible already reference this via the Inspector
[SerializeField] private Camera mainCamera;

void Start()
{
    if(!mainCamera) mainCamera = Camera.main;
}

void Update()
{
    // get positions vector
    var direction = (Image.CenterPose.position - mainCamera.transform.position).normalized;
    // get view direction
    var viewDirection = mainCamera.transform.forward;
    // get angle between them
    var angle = Vector3.Angle(viewDirection, direction);

    // optionally you could use only the X axis for the angle check 
    // by eliminating the Y value of both vectors
    // allowing the user to still look up and down 
    //direction = (new Vector3(Image.CenterPose.position.x, 0, Image.CenterPose.position.z) - new Vector3(mainCamera.transform.position.x, 0 , mainCamera.transform.position.z)).normalized;
    //viewDirection = new Vector3(viewDirection.x, 0, viewDirection.z);

    // also check the angle
    if (Image == null || Image.TrackingState != TrackingState.Tracking || angle > angleThreshold)
    {
        // optional: I would also stop the video if no longer in focus
        if (video.isPlaying && video.clip == videoClips[Image.DatabaseIndex]) video.Stop();
        return;
    }

    if (!video.isPlaying)
    {
        video.clip = videoClips[Image.DatabaseIndex];
        video.Play();
    }

    transform.localScale = new Vector3(Image.ExtentX - 1, Image.ExtentZ, 1);
}

推荐阅读