0

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"
Madhu
  • 1,209
  • 2
  • 22
  • 28
  • I see your data, but I'm not sure what you plan on *doing* with it. Could you elaborate on that? What is a model's "camera view" in terms a Unity developer might know? – rutter Dec 11 '13 at 00:43
  • In Unity these 3 should be added as 3 camera objects. At different times one of these camera's will be set as the main camera. So with each of these cameras we can see the 3D model in different angels. I can manually add 3 camera objects and set the position and rotation info by looking at the above and run it. But the requirement is to automatically import these info to unity and add the camera views to my scene. – Madhu Dec 11 '13 at 04:10

1 Answers1

1

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
    }
}
Jerdak
  • 3,997
  • 1
  • 24
  • 36