Skip to content

Commit

Permalink
Added support for scene conversion and transform baking
Browse files Browse the repository at this point in the history
  • Loading branch information
returnString committed Jul 25, 2012
1 parent 04e4d9f commit 0f676da
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Thumbs.db
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*
[Tt]est[Rr]esult*
Build/
Binary file removed Build/samplefile.FBX
Binary file not shown.
2 changes: 1 addition & 1 deletion ManagedFbx.Samples/ManagedFbx.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<OutputPath>..\Build\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
Expand Down
17 changes: 17 additions & 0 deletions ManagedFbx/ConversionTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

namespace ManagedFbx
{
public enum class UnitConversionType
{
Metres,
Centimetres
};

public enum class AxisConversionType
{
Max,
MayaYUp,
MayaZUp
};
}
14 changes: 11 additions & 3 deletions ManagedFbx/ManagedFbx.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
<CLRSupport>true</CLRSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v100</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<CLRSupport>true</CLRSupport>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand All @@ -52,6 +53,9 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>C:\Program Files\Autodesk\FBX\FBX SDK\2013.2\include\;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files\Autodesk\FBX\FBX SDK\2013.2\lib\vs2010\x86;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)Build\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -83,12 +87,16 @@
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>fbxsdk-2013.2-md.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBMCT</IgnoreSpecificDefaultLibraries>
<ProgramDatabaseFile />
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include=".\ConversionTypes.h" />
<ClInclude Include="Light.h" />
<ClInclude Include="Manager.h" />
<ClInclude Include="Mesh.h" />
Expand Down
1 change: 1 addition & 0 deletions ManagedFbx/ManagedFbx.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<ClInclude Include="Light.h">
<Filter>Attributes</Filter>
</ClInclude>
<ClInclude Include=".\ConversionTypes.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="Helpers">
Expand Down
20 changes: 13 additions & 7 deletions ManagedFbx/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,31 @@ array<Vector3> ^Mesh::Normals::get()
auto list = gcnew array<Vector3>(count);

for(int i = 0; i < count; i++)
{
list[i] = Vector3(normals->GetDirectArray().GetAt(i));
}

return list;
}

array<Vector2> ^Mesh::TextureCoords::get()
{
auto coords = m_nativeMesh->GetLayer(0)->GetUVs();
int count = coords->GetDirectArray().GetCount();
int count = coords == nullptr ? 0 : coords->GetDirectArray().GetCount();
auto list = gcnew array<Vector2>(count);

for(int i = 0; i < count; i++)
{
list[i] = Vector2(coords->GetDirectArray().GetAt(i));
}

return list;
}

array<int> ^Mesh::MaterialIDs::get()
{
auto materials = m_nativeMesh->GetLayer(0)->GetMaterials();
int count = materials == nullptr ? 0 : materials->GetIndexArray().GetCount();
auto list = gcnew array<int>(count);

for(int i = 0; i < count; i++)
list[i] = materials->GetIndexArray().GetAt(i);

return list;
}
Expand All @@ -101,9 +109,7 @@ array<Colour> ^Mesh::VertexColours::get()
auto list = gcnew array<Colour>(count);

for(int i = 0; i < count; i++)
{
list[i] = Colour(colours->GetDirectArray().GetAt(i));
}

return list;
}
1 change: 1 addition & 0 deletions ManagedFbx/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace ManagedFbx
property_r(array<Vector3>^, Normals);
property_r(array<Vector2>^, TextureCoords);
property_r(array<Colour>^, VertexColours);
property_r(array<int>^, MaterialIDs);

property_r(bool, HasOnlyTriangles);

Expand Down
78 changes: 78 additions & 0 deletions ManagedFbx/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,82 @@ string ^Scene::Name::get()
SceneNode ^Scene::RootNode::get()
{
return m_rootNode;
}

void Scene::Application::set(string ^value)
{
m_nativeScene->GetSceneInfo()->LastSaved_ApplicationName.Set(StringHelper::ToNative(value));
}

string ^Scene::Application::get()
{
auto name = m_nativeScene->GetSceneInfo()->LastSaved_ApplicationName.Get().Buffer();
return gcnew string(name);
}

string ^Scene::UnitType::get()
{
return gcnew string(m_nativeScene->GetGlobalSettings().GetSystemUnit().GetScaleFactorAsString_Plurial());
}

void Scene::ConvertUnits(UnitConversionType units)
{
switch(units)
{
case UnitConversionType::Metres:
FbxSystemUnit::m.ConvertScene(m_nativeScene);
break;

case UnitConversionType::Centimetres:
FbxSystemUnit::cm.ConvertScene(m_nativeScene);
break;

default:
throw gcnew NotImplementedException("The supplied unit type is not currently supported for conversion.");
}
}

void Scene::ConvertAxes(AxisConversionType axis)
{
switch(axis)
{
case AxisConversionType::Max:
FbxAxisSystem::Max.ConvertScene(m_nativeScene);
break;

case AxisConversionType::MayaYUp:
FbxAxisSystem::MayaYUp.ConvertScene(m_nativeScene);
break;

case AxisConversionType::MayaZUp:
FbxAxisSystem::MayaZUp.ConvertScene(m_nativeScene);
break;

default:
throw gcnew NotImplementedException("The supplied axis type is not currently supported for conversion.");
}
}

void Scene::BakeTransform(SceneNode ^node)
{
for each(SceneNode ^node in node->ChildNodes)
BakeTransform(node);

auto native = node->m_nativeNode;
auto mesh = native->GetMesh();

if(!mesh)
return;

FbxAMatrix geometry(native->GetGeometricTranslation(FbxNode::eSourcePivot),
native->GetGeometricRotation(FbxNode::eSourcePivot),
native->GetGeometricScaling(FbxNode::eSourcePivot));

auto total = m_nativeScene->GetEvaluator()->GetNodeGlobalTransform(native) * geometry;

for(int i = 0; i < mesh->GetControlPointsCount(); i++)
{
auto pos = mesh->GetControlPointAt(i);
mesh->SetControlPointAt(total.MultT(pos), i);
}
}
24 changes: 24 additions & 0 deletions ManagedFbx/Scene.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "SceneNode.h"
#include "ConversionTypes.h"

using namespace System::Collections::Generic;

Expand All @@ -27,6 +28,21 @@ namespace ManagedFbx
/// </summary>
void Save(string ^filepath);

/// <summary>
/// Converts the scene to a given unit system.
/// </summary>
void ConvertUnits(UnitConversionType units);

/// <summary>
/// Converts the scene to a given orientation.
/// </summary>
void ConvertAxes(AxisConversionType axis);

/// <summary>
/// Bakes node transforms into vertex positions.
/// </summary>
void BakeTransform(SceneNode ^node);

/// <summary>
/// Gets the root node of this scene.
/// </summary>
Expand All @@ -37,8 +53,16 @@ namespace ManagedFbx
/// </summary>
property_rw(string^, Name);

/// <summary>
/// Gets and sets the name of the application used to create this scene.
/// </summary>
property_rw(string^, Application);

property_r(string^, UnitType);

private:
FbxScene *m_nativeScene;
SceneNode ^m_rootNode;
FbxManager *m_manager;
};
}
2 changes: 1 addition & 1 deletion ManagedFbx/SceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ namespace ManagedFbx

internal:
SceneNode(FbxNode *node);
FbxNode *m_nativeNode;

private:
FbxNode *m_nativeNode;
List<SceneNode^> ^m_children;
List<NodeAttribute^> ^m_attributes;
};
Expand Down
8 changes: 8 additions & 0 deletions ManagedFbx/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ namespace ManagedFbx
{
return String::Format("{0}, {1}, {2}", Math::Round(X, 3), Math::Round(Y, 3), Math::Round(Z, 3));
}

static Vector3 operator *(Vector3 self, float value)
{
self.X *= value;
self.Y *= value;
self.Z *= value;
return self;
}

internal:
Vector3(FbxDouble3 fbxDouble)
Expand Down

0 comments on commit 0f676da

Please sign in to comment.