首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何确定ARCore可以同时显示的预制件数量?(使用图像识别)

如何确定ARCore可以同时显示的预制件数量?(使用图像识别)
EN

Stack Overflow用户
提问于 2019-08-01 11:06:55
回答 1查看 36关注 0票数 1

当前的应用程序允许您检测海报并以海报的大小显示视频在其上发射的平面。

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

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

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

我试着通过触发器使用系统,然后通过Raycast,但没有做任何事情,我仍然有声音和视频都显示出来。

代码语言:javascript
运行
复制
[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);
}

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

你能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2019-08-01 14:29:13

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

代码语言:javascript
运行
复制
[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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57301310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档