Unity import camera views

887 views Asked by At

I'm importing my client's 3D models to Unity from Rhino. They give me the fbx file exported from the Rhino and I can import them to Unity. Now I want to import the Camera views for a model. In Rhino they can't export the camera views as part of the fbx. So they give it to me as a script and the info look like below for a sample 3 camera views. Now I need to find a way to add camera views in Unity using these info. We can't do it manually, it should be automated as we have to do it for many fbx models. One way I can think of is to write a script to add cameras to the scene using these values. But then it'll happen in the run time. Is there any other better option to do this?

Thanks

  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

There are 1 answers

0
Jerdak On

How about an editor script? For brevity sake I'll leave it to you to parse your own file and figure out what your values mean but the code below should get you what you need.

Example (untested):

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
    }
}