辅助相机无法统一渲染3D模型

问题描述 投票:-2回答:1

我正在通过Unity和Vuforia创建AR应用。在我的场景中,我有两个摄像头。第一台摄像机是ARCamera,第二台摄像机是SecondCamera。第二个Camera从AR摄像机获取其旋转和位置。它的移动和旋转都比AR相机平滑。

我有一个多维数据集作为ImageTarget的子级。我只想通过第二台摄像机渲染此立方体。我将新图层定义为ARCamIgnoreLayer,并将第二台相机的消隐蒙版设置为该图层。另外,我从AR相机的消隐蒙版字段中未选中ARCamIgnoreLayer。另外,我在第二台摄像机的RenderTexture字段中添加了target texture。我将此渲染纹理设置为平面材质的main texture。通过这种方式,我投影了第二台相机可以在此平面上看到的所有内容。

我将此平面放置在Vuforia的BackgroundPlane和AR相机之间。这样,最终我可以在game窗口(游戏视图)中看到某些AR摄像机在后台渲染而第二个摄像机在前景渲染的场景。

现在我有两个问题。消解其中一种意味着消解另一种。

  1. 这两个摄像机的理论渲染必须相同;因为我将第二台摄像机的field of view设置为与AR摄像机相同的数字。另外,正如我所说,这两个相机的位置和旋转方向相同。但是他们的渲染不匹配。我不明白这是怎么回事。

  2. 为了防止第一个问题,我从AR摄像机复制了Camera组件及其值,并将其粘贴到第二个摄像机。我想确保第二台摄像机的Camera组件的所有字段具有与AR摄像机的摄像机组件的所有字段相同的值。然后,我在运行时通过脚本更改了一些值(例如删除蒙版等)。现在第二台相机不渲染任何东西。它只是返回纯色。我也不知道这怎么了。

这里是代码:

1:

void CreateSecondCam()
{
    CopyComponent(_aRCam.GetComponent<Camera>(), gameObject);

}



T CopyComponent<T>(T original, GameObject destination) where T : Component
{
    System.Type type = original.GetType();
    var dst = destination.GetComponent(type) as T;
    if (!dst) dst = destination.AddComponent(type) as T;
    var fields = type.GetFields();
    foreach (var field in fields)
    {
        if (field.IsStatic) continue;
        field.SetValue(dst, field.GetValue(original));
    }
    var props = type.GetProperties();
    foreach (var prop in props)
    {
        if (!prop.CanWrite || prop.Name == "name") continue;
        prop.SetValue(dst, prop.GetValue(original, null), null);
    }
    return dst as T;
}

我的脚本的这一部分从AR相机复制相机组件并将其粘贴到第二台相机。

2:

void AssignSomeValues()
    {
        gameObject.GetComponent<Camera>().targetTexture = _chromaKeyRenderTexrture;
        gameObject.GetComponent<Camera>().backgroundColor = _defaultCameraBackgroundColor;
        gameObject.GetComponent<Camera>().cullingMask = 9 << 8;
    }

此功能为第二台摄像机的摄像机组件的某些字段分配一些值。

3:

void Update()
{
    gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, _aRCam.transform.position, _softness * Time.deltaTime);
    gameObject.transform.rotation = Quaternion.Slerp(gameObject.transform.rotation, _aRCam.transform.rotation, _softness * Time.deltaTime);
}

我已根据Update功能中的AR摄像机位置和旋转移动和旋转了第二个摄像机。

以下是屏幕截图:

1:

AR相机

AR camera inspector

2:

第二台摄像机

second camera inspector

3:

多维数据集

cube inspector

c# unity3d camera augmented-reality vuforia
1个回答
0
投票

我解决了。我改变了AR相机的Depth。我将AR相机的深度设置为-10。现在,第二个摄像头查看端口出现在AR摄像头查看端口的前面。它运作完美。

© www.soinside.com 2019 - 2024. All rights reserved.