Unity导入相机视图

时间:2013-12-10 21:29:01

标签: unity3d rhino3d

我从Rhino将我客户的3D模型导入Unity。他们给我从Rhino导出的fbx文件,我可以将它们导入Unity。现在我想为模型导入Camera视图。在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"

1 个答案:

答案 0 :(得分: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
    }
}