0

我正在将客户的 3D 模型从 Rhino 导入 Unity。他们给了我从 Rhino 导出的 fbx 文件,我可以将它们导入 Unity。现在我想为模型导入相机视图。在 Rhino 中,他们无法将相机视图导出为 fbx 的一部分。因此,他们将其作为脚本提供给我,信息如下所示,用于 3 个相机视图示例。现在我需要找到一种使用这些信息在 Unity 中添加相机视图的方法。我们不能手动完成,它应该是自动化的,因为我们必须对许多 fbx 模型进行操作。我能想到的一种方法是编写一个脚本,使用这些值将摄像机添加到场景中。但它会在运行时发生。还有其他更好的选择吗?

谢谢

  camName "Name View 1"
  camGroup "Name View 1_Grp"
  focalLen "49"
  Cx "29.1070392477262"
  Cy "32.2508470958018"
  Cz "89.5861273886465"
  Tx "0"
  Ty "0"
  Tz "0"

  camName "Name View 2"
  camGroup "Name View 2_Grp"
  focalLen "49"
  Cx "2.9038526478832"
  Cy "99.2149465666948"
  Cz "7.80852804487048"
  Tx "0"
  Ty "0"
  Tz "0"

  camName "Side View"
  camGroup "Side View_Grp"
  focalLen "49"
  Cx "82.9710911032618"
  Cy "31.0804895092999"
  Cz "14.463142097058"
  Tx "10.4951110723463"
  Ty "0.999934019398793"
  Tz "-4.14650803054286"
4

1 回答 1

1

编辑器脚本怎么样?为简洁起见,我将留给您解析您自己的文件并弄清楚您的值的含义,但下面的代码应该可以满足您的需求。

示例(未经测试):

using UnityEngine;
using UnityEngine;
using UnityEditor;
using System.Collections;

public class LoadCameras : ScriptableObject
{
    [MenuItem ("CameraLoader/Load")]
    static void MenuCameraLoader()
    {
        var path = EditorUtility.OpenFilePanel(
                "Load cameras",
                "",
                "txt");
        if(path.length!=0){
            // * parse the file here for your values
            // * assume we get a position and orientation
            // * for each camName call
            //   CreateCamera(camName,position,orientation/*, other stuff*/);
        }

    }
    static void CreateCamera(string name,Vector3 position, Quaternion rotation /*, other props*/){
        GameObject newCamera = new GameObject(name);
        newChild.AddComponent(Camera);

        newCamera.transform.position = position;
        newCamera.transform.rotation = rotation;
        // load camera with other properties
    }
}
于 2013-12-12T00:53:04.250 回答