Skip to content

Commit

Permalink
Added export support
Browse files Browse the repository at this point in the history
  • Loading branch information
returnString committed Jul 11, 2012
1 parent a712a72 commit 39c36ac
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 10 deletions.
12 changes: 11 additions & 1 deletion ManagedFbx.Samples/FbxForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions ManagedFbx.Samples/FbxForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,25 @@ private void LoadFile(object sender, EventArgs e)
if(dialog.ShowDialog() == DialogResult.OK)
{
var scenePath = dialog.FileName;
var scene = Scene.Import(scenePath);
m_scene = Scene.Import(scenePath);
uxFbxTree.Nodes.Clear();
Add(scene.RootNode, null);
Add(m_scene.RootNode, null);
}
}

private void SaveFile(object sender, EventArgs e)
{
var dialog = new SaveFileDialog();
dialog.Filter = "FBX file (*.fbx)|*.fbx";

if(dialog.ShowDialog() == DialogResult.OK)
{
var filePath = dialog.FileName;
m_scene.Save(filePath);
}
}

private Scene m_scene;
}

public static class StringBuilderExtensions
Expand Down
12 changes: 9 additions & 3 deletions ManagedFbx/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@

using namespace ManagedFbx;

static Manager::Manager()
Manager::Manager()
{
m_nativeManager = FbxManager::Create();
m_nativeImporter = FbxImporter::Create(m_nativeManager, "Importer");
m_nativeExporter = FbxExporter::Create(m_nativeManager, "Exporter");
}

FbxManager *Manager::GetFbxManager()
FbxManager *Manager::GetInstance()
{
return m_nativeManager;
}

FbxImporter *Manager::GetFbxImporter()
FbxImporter *Manager::GetImporter()
{
return m_nativeImporter;
}

FbxExporter *Manager::GetExporter()
{
return m_nativeExporter;
}
6 changes: 4 additions & 2 deletions ManagedFbx/Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ namespace ManagedFbx
{
public:
static Manager();
static FbxManager *GetFbxManager();
static FbxImporter *GetFbxImporter();
static FbxManager *GetInstance();
static FbxImporter *GetImporter();
static FbxExporter *GetExporter();

private:
static FbxManager *m_nativeManager;
static FbxImporter *m_nativeImporter;
static FbxExporter *m_nativeExporter;
};
}
15 changes: 13 additions & 2 deletions ManagedFbx/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ using namespace ManagedFbx;

Scene::Scene(string ^name)
{
m_nativeScene = FbxScene::Create(Manager::GetFbxManager(), StringHelper::ToNative(name));
m_nativeScene = FbxScene::Create(Manager::GetInstance(), StringHelper::ToNative(name));
m_rootNode = gcnew SceneNode(m_nativeScene->GetRootNode());
}

Scene ^Scene::Import(string ^filename)
{
auto importer = Manager::GetFbxImporter();
auto importer = Manager::GetImporter();

if(!importer->Initialize(StringHelper::ToNative(filename)))
throw gcnew FbxException("Failed to initialise the FBX importer: {0}", gcnew string(importer->GetLastErrorString()));
Expand All @@ -28,6 +28,17 @@ Scene ^Scene::Import(string ^filename)
return scene;
}

void Scene::Save(string ^filename)
{
auto exporter = Manager::GetExporter();

if(!exporter->Initialize(StringHelper::ToNative(filename)))
throw gcnew FbxException("Failed to initialise the FBX exporter: {0}", gcnew string(exporter->GetLastErrorString()));

if(!exporter->Export(m_nativeScene))
throw gcnew FbxException("Failed to export the scene: {0}", gcnew string(exporter->GetLastErrorString()));
}

void Scene::Name::set(string ^value)
{
m_nativeScene->SetName(StringHelper::ToNative(value));
Expand Down
22 changes: 22 additions & 0 deletions ManagedFbx/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,35 @@ using namespace System::Collections::Generic;

namespace ManagedFbx
{
/// <summary>
/// Represents an FBX scene.
/// </summary>
public ref class Scene
{
public:
/// <summary>
/// Constructs a new empty scene with the given name.
/// </summary>
Scene(string ^name);

/// <summary>
/// Imports a scene from a file.
/// </summary>
static Scene ^Import(string ^filepath);

/// <summary>
/// Saves the scene to a file.
/// </summary>
void Save(string ^filepath);

/// <summary>
/// Gets the root node of this scene.
/// </summary>
property_r(SceneNode^, RootNode);

/// <summary>
/// Gets and sets the name of this scene.
/// </summary>
property_rw(string^, Name);

private:
Expand Down

0 comments on commit 39c36ac

Please sign in to comment.