├── .gitignore ├── ManagedFbx.Samples ├── FbxForm.Designer.cs ├── FbxForm.cs ├── FbxForm.resx ├── ManagedFbx.Samples.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── app.config ├── ManagedFbx.sln ├── ManagedFbx ├── AssemblyInfo.cpp ├── ConversionTypes.h ├── FbxException.h ├── Light.cpp ├── Light.h ├── ManagedFbx.vcxproj ├── ManagedFbx.vcxproj.filters ├── Manager.cpp ├── Manager.h ├── Mesh.cpp ├── Mesh.h ├── NativeString.h ├── NodeAttribute.cpp ├── NodeAttribute.h ├── Polygon.cpp ├── Polygon.h ├── Properties.h ├── Scene.cpp ├── Scene.h ├── SceneNode.cpp ├── SceneNode.h ├── Vector.h ├── stdafx.cpp └── stdafx.h ├── licence.md └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | #ignore thumbnails created by windows 2 | Thumbs.db 3 | #Ignore files build by Visual Studio 4 | *.obj 5 | *.exe 6 | *.pdb 7 | *.user 8 | *.aps 9 | *.pch 10 | *.vspscc 11 | *_i.c 12 | *_p.c 13 | *.ncb 14 | *.suo 15 | *.tlb 16 | *.tlh 17 | *.bak 18 | *.cache 19 | *.ilk 20 | *.log 21 | [Bb]in 22 | [Dd]ebug*/ 23 | *.lib 24 | *.sbr 25 | obj/ 26 | [Rr]elease*/ 27 | _ReSharper*/ 28 | [Tt]est[Rr]esult* 29 | Build/ -------------------------------------------------------------------------------- /ManagedFbx.Samples/FbxForm.Designer.cs: -------------------------------------------------------------------------------- 1 | partial class FbxForm 2 | { 3 | /// 4 | /// Required designer variable. 5 | /// 6 | private System.ComponentModel.IContainer components = null; 7 | 8 | /// 9 | /// Clean up any resources being used. 10 | /// 11 | /// true if managed resources should be disposed; otherwise, false. 12 | protected override void Dispose(bool disposing) 13 | { 14 | if(disposing && (components != null)) 15 | { 16 | components.Dispose(); 17 | } 18 | base.Dispose(disposing); 19 | } 20 | 21 | #region Windows Form Designer generated code 22 | 23 | /// 24 | /// Required method for Designer support - do not modify 25 | /// the contents of this method with the code editor. 26 | /// 27 | private void InitializeComponent() 28 | { 29 | this.uxFbxTree = new System.Windows.Forms.TreeView(); 30 | this.uxNodeInfo = new System.Windows.Forms.TextBox(); 31 | this.menuStrip1 = new System.Windows.Forms.MenuStrip(); 32 | this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 33 | this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 34 | this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 35 | this.menuStrip1.SuspendLayout(); 36 | this.SuspendLayout(); 37 | // 38 | // uxFbxTree 39 | // 40 | this.uxFbxTree.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 41 | | System.Windows.Forms.AnchorStyles.Left))); 42 | this.uxFbxTree.Location = new System.Drawing.Point(12, 27); 43 | this.uxFbxTree.Name = "uxFbxTree"; 44 | this.uxFbxTree.Size = new System.Drawing.Size(285, 427); 45 | this.uxFbxTree.TabIndex = 0; 46 | this.uxFbxTree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.OnTreeSelect); 47 | // 48 | // uxNodeInfo 49 | // 50 | this.uxNodeInfo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 51 | | System.Windows.Forms.AnchorStyles.Left) 52 | | System.Windows.Forms.AnchorStyles.Right))); 53 | this.uxNodeInfo.Location = new System.Drawing.Point(303, 27); 54 | this.uxNodeInfo.Multiline = true; 55 | this.uxNodeInfo.Name = "uxNodeInfo"; 56 | this.uxNodeInfo.ReadOnly = true; 57 | this.uxNodeInfo.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; 58 | this.uxNodeInfo.Size = new System.Drawing.Size(484, 427); 59 | this.uxNodeInfo.TabIndex = 3; 60 | this.uxNodeInfo.WordWrap = false; 61 | // 62 | // menuStrip1 63 | // 64 | this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 65 | this.fileToolStripMenuItem}); 66 | this.menuStrip1.Location = new System.Drawing.Point(0, 0); 67 | this.menuStrip1.Name = "menuStrip1"; 68 | this.menuStrip1.Size = new System.Drawing.Size(799, 24); 69 | this.menuStrip1.TabIndex = 4; 70 | this.menuStrip1.Text = "menuStrip1"; 71 | // 72 | // fileToolStripMenuItem 73 | // 74 | this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 75 | this.openToolStripMenuItem, 76 | this.saveToolStripMenuItem}); 77 | this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; 78 | this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); 79 | this.fileToolStripMenuItem.Text = "File"; 80 | // 81 | // openToolStripMenuItem 82 | // 83 | this.openToolStripMenuItem.Name = "openToolStripMenuItem"; 84 | this.openToolStripMenuItem.Size = new System.Drawing.Size(103, 22); 85 | this.openToolStripMenuItem.Text = "Open"; 86 | this.openToolStripMenuItem.Click += new System.EventHandler(this.LoadFile); 87 | // 88 | // saveToolStripMenuItem 89 | // 90 | this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; 91 | this.saveToolStripMenuItem.Size = new System.Drawing.Size(103, 22); 92 | this.saveToolStripMenuItem.Text = "Save"; 93 | this.saveToolStripMenuItem.Click += new System.EventHandler(this.SaveFile); 94 | // 95 | // FbxForm 96 | // 97 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 98 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 99 | this.ClientSize = new System.Drawing.Size(799, 466); 100 | this.Controls.Add(this.uxNodeInfo); 101 | this.Controls.Add(this.uxFbxTree); 102 | this.Controls.Add(this.menuStrip1); 103 | this.MainMenuStrip = this.menuStrip1; 104 | this.Name = "FbxForm"; 105 | this.Text = "FbxForm"; 106 | this.menuStrip1.ResumeLayout(false); 107 | this.menuStrip1.PerformLayout(); 108 | this.ResumeLayout(false); 109 | this.PerformLayout(); 110 | 111 | } 112 | 113 | #endregion 114 | 115 | private System.Windows.Forms.TreeView uxFbxTree; 116 | private System.Windows.Forms.TextBox uxNodeInfo; 117 | private System.Windows.Forms.MenuStrip menuStrip1; 118 | private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; 119 | private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem; 120 | private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem; 121 | 122 | } -------------------------------------------------------------------------------- /ManagedFbx.Samples/FbxForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | using System.Windows.Forms; 5 | using ManagedFbx; 6 | 7 | public partial class FbxForm : Form 8 | { 9 | public FbxForm() 10 | { 11 | InitializeComponent(); 12 | SetTitle("Untitled"); 13 | } 14 | 15 | public void Add(SceneNode node, TreeNode parentNode) 16 | { 17 | var item = new TreeNode(node.Name) { Tag = node }; 18 | 19 | if(parentNode == null) 20 | uxFbxTree.Nodes.Add(item); 21 | else 22 | parentNode.Nodes.Add(item); 23 | 24 | foreach(var sub in node.ChildNodes) 25 | { 26 | var subitem = new TreeNode(sub.Name) { Tag = sub }; 27 | Add(sub, item); 28 | } 29 | } 30 | 31 | private void OnTreeSelect(object sender, TreeViewEventArgs e) 32 | { 33 | var node = e.Node.Tag as SceneNode; 34 | 35 | if(node == null) 36 | return; 37 | 38 | var builder = new StringBuilder(); 39 | 40 | Action NewLine = () => builder.Append(Environment.NewLine); 41 | 42 | builder.Append("Position:\t{0}", node.Position); 43 | builder.Append("Rotation:\t{0}", node.Rotation); 44 | builder.Append("Scale:\t{0}", node.Scale); 45 | 46 | NewLine(); 47 | 48 | builder.Append("Found {0} attribute(s)", node.Attributes.Count()); 49 | 50 | foreach(var attr in node.Attributes) 51 | { 52 | NewLine(); 53 | builder.Append("Attribute type: {0}", attr.Type.ToString()); 54 | 55 | switch(attr.Type) 56 | { 57 | case NodeAttributeType.Mesh: 58 | { 59 | var mesh = node.Mesh; 60 | 61 | if(!mesh.Triangulated) 62 | { 63 | builder.Append("Quads/ngons found in list of total {0} polygons, triangulating", mesh.Polygons.Length); 64 | NewLine(); 65 | mesh = mesh.Triangulate(); 66 | } 67 | 68 | builder.Append("Found {0} triangles", mesh.Polygons.Length); 69 | NewLine(); 70 | 71 | for(var i = 0; i < mesh.Polygons.Length; i++) 72 | { 73 | var str = string.Empty; 74 | foreach(var index in mesh.Polygons[i].Indices) 75 | str += "\t" + index; 76 | 77 | builder.Append("{0}:{1}\t(UVs: {2}, {3}, {4}, Mat ID: {5})", i, str, mesh.GetUVIndex(i, 0), mesh.GetUVIndex(i, 1), mesh.GetUVIndex(i, 2), mesh.GetMaterialId(i)); 78 | } 79 | 80 | NewLine(); 81 | builder.Append("Found {0} vertices", mesh.Vertices.Length); 82 | NewLine(); 83 | 84 | for(var i = 0; i < mesh.Vertices.Length; i++) 85 | { 86 | var vertex = mesh.Vertices[i]; 87 | builder.Append("{0}:\t{1}\t{2}\t{3}", i, Math.Round(vertex.X, 2), Math.Round(vertex.Y, 2), Math.Round(vertex.Z, 2)); 88 | } 89 | 90 | NewLine(); 91 | builder.Append("Found {0} vertex normals", mesh.Normals.Length); 92 | NewLine(); 93 | 94 | for(var i = 0; i < mesh.Normals.Length; i++) 95 | { 96 | var normal = mesh.Normals[i]; 97 | builder.Append("{0}:\t{1}\t{2}\t{3}", i, Math.Round(normal.X, 2), Math.Round(normal.Y, 2), Math.Round(normal.Z, 2)); 98 | } 99 | 100 | NewLine(); 101 | builder.Append("Found {0} UV coords", mesh.TextureCoords.Length); 102 | NewLine(); 103 | 104 | for(var i = 0; i < mesh.TextureCoords.Length; i++) 105 | { 106 | var coord = mesh.TextureCoords[i]; 107 | builder.Append("{0}:\t{1}\t{2}", i, Math.Round(coord.X, 2), Math.Round(coord.Y, 2)); 108 | } 109 | 110 | NewLine(); 111 | builder.Append("Found {0} vertex colours", mesh.VertexColours.Length); 112 | NewLine(); 113 | 114 | for(var i = 0; i < mesh.VertexColours.Length; i++) 115 | { 116 | var colour = mesh.VertexColours[i]; 117 | builder.Append("{0}:\t{1}\t{2}\t{3}\t{4}", i, Math.Round(colour.R, 2), Math.Round(colour.G, 2), Math.Round(colour.B, 2), Math.Round(colour.A, 2)); 118 | } 119 | 120 | NewLine(); 121 | builder.Append("Found {0} material IDs", mesh.MaterialIDs.Length); 122 | NewLine(); 123 | 124 | for(var i = 0; i < mesh.MaterialIDs.Length; i++) 125 | { 126 | var id = mesh.MaterialIDs[i]; 127 | builder.Append("{0}:\t{1}", i.ToString(), id.ToString()); 128 | } 129 | } 130 | break; 131 | 132 | case NodeAttributeType.Light: 133 | { 134 | var light = node.Light; 135 | builder.Append("Found light of type {0}", light.Type); 136 | builder.Append("Colour is {0}", light.Colour); 137 | } 138 | break; 139 | } 140 | } 141 | 142 | uxNodeInfo.Text = builder.ToString(); 143 | } 144 | 145 | private void LoadFile(object sender, EventArgs e) 146 | { 147 | var dialog = new OpenFileDialog(); 148 | dialog.Filter = "FBX files (*.fbx)|*.fbx"; 149 | 150 | if(dialog.ShowDialog() == DialogResult.OK) 151 | { 152 | var scenePath = dialog.FileName; 153 | m_scene = Scene.Import(scenePath); 154 | uxFbxTree.Nodes.Clear(); 155 | Add(m_scene.RootNode, null); 156 | SetTitle(scenePath); 157 | } 158 | } 159 | 160 | private void SaveFile(object sender, EventArgs e) 161 | { 162 | var dialog = new SaveFileDialog(); 163 | dialog.Filter = "FBX file (*.fbx)|*.fbx"; 164 | 165 | if(dialog.ShowDialog() == DialogResult.OK) 166 | { 167 | var filePath = dialog.FileName; 168 | m_scene.Save(filePath); 169 | } 170 | } 171 | 172 | private void SetTitle(string filename) 173 | { 174 | Text = "FBX Viewer - " + filename; 175 | } 176 | 177 | private Scene m_scene; 178 | } 179 | 180 | public static class StringBuilderExtensions 181 | { 182 | public static void Append(this StringBuilder builder, string format, params object[] args) 183 | { 184 | builder.AppendLine(string.Format(format, args)); 185 | } 186 | } -------------------------------------------------------------------------------- /ManagedFbx.Samples/FbxForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | -------------------------------------------------------------------------------- /ManagedFbx.Samples/ManagedFbx.Samples.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC} 8 | WinExe 9 | Properties 10 | ManagedFbx.Samples 11 | ManagedFbx.Samples 12 | v4.0 13 | 512 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | false 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | false 36 | 37 | 38 | true 39 | ..\Build\ 40 | DEBUG;TRACE 41 | full 42 | x86 43 | prompt 44 | MinimumRecommendedRules.ruleset 45 | 46 | 47 | ..\Build\ 48 | TRACE 49 | true 50 | pdbonly 51 | x86 52 | prompt 53 | MinimumRecommendedRules.ruleset 54 | false 55 | 56 | 57 | Program 58 | 59 | 60 | 61 | ..\Build\ManagedFbx.dll 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | Form 75 | 76 | 77 | FbxForm.cs 78 | 79 | 80 | 81 | 82 | 83 | 84 | FbxForm.cs 85 | 86 | 87 | 88 | 89 | 90 | 91 | 98 | -------------------------------------------------------------------------------- /ManagedFbx.Samples/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using ManagedFbx; 4 | 5 | public class Program 6 | { 7 | [STAThread] 8 | public static void Main() 9 | { 10 | Application.EnableVisualStyles(); 11 | Application.Run(new FbxForm()); 12 | } 13 | } -------------------------------------------------------------------------------- /ManagedFbx.Samples/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Managed")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Managed")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e43b02f2-c8e6-4d25-ad63-b4a812fe2bec")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ManagedFbx.Samples/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ManagedFbx.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ManagedFbx", "ManagedFbx\ManagedFbx.vcxproj", "{163D9B5E-1A69-4821-89DE-298736F2C14E}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedFbx.Samples", "ManagedFbx.Samples\ManagedFbx.Samples.csproj", "{78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {163D9B5E-1A69-4821-89DE-298736F2C14E} = {163D9B5E-1A69-4821-89DE-298736F2C14E} 9 | EndProjectSection 10 | EndProject 11 | Global 12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 13 | Debug|Any CPU = Debug|Any CPU 14 | Debug|Mixed Platforms = Debug|Mixed Platforms 15 | Debug|Win32 = Debug|Win32 16 | Debug|x86 = Debug|x86 17 | Release|Any CPU = Release|Any CPU 18 | Release|Mixed Platforms = Release|Mixed Platforms 19 | Release|Win32 = Release|Win32 20 | Release|x86 = Release|x86 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Debug|Any CPU.ActiveCfg = Debug|Win32 24 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 25 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Debug|Mixed Platforms.Build.0 = Debug|Win32 26 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Debug|Win32.ActiveCfg = Debug|Win32 27 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Debug|Win32.Build.0 = Debug|Win32 28 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Debug|x86.ActiveCfg = Debug|Win32 29 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Debug|x86.Build.0 = Debug|Win32 30 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Release|Any CPU.ActiveCfg = Release|Win32 31 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Release|Mixed Platforms.ActiveCfg = Release|Win32 32 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Release|Mixed Platforms.Build.0 = Release|Win32 33 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Release|Win32.ActiveCfg = Release|Win32 34 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Release|Win32.Build.0 = Release|Win32 35 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Release|x86.ActiveCfg = Release|Win32 36 | {163D9B5E-1A69-4821-89DE-298736F2C14E}.Release|x86.Build.0 = Release|Win32 37 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 38 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Debug|Any CPU.Build.0 = Debug|Any CPU 39 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 40 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Debug|Mixed Platforms.Build.0 = Debug|x86 41 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Debug|Win32.ActiveCfg = Debug|x86 42 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Debug|Win32.Build.0 = Debug|x86 43 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Debug|x86.ActiveCfg = Debug|x86 44 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Debug|x86.Build.0 = Debug|x86 45 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Release|Any CPU.Build.0 = Release|Any CPU 47 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Release|Mixed Platforms.ActiveCfg = Release|x86 48 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Release|Mixed Platforms.Build.0 = Release|x86 49 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Release|Win32.ActiveCfg = Release|x86 50 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Release|Win32.Build.0 = Release|x86 51 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Release|x86.ActiveCfg = Release|x86 52 | {78BA3050-B035-46F5-AAC2-4B9B8A3CFDDC}.Release|x86.Build.0 = Release|x86 53 | EndGlobalSection 54 | GlobalSection(SolutionProperties) = preSolution 55 | HideSolutionNode = FALSE 56 | EndGlobalSection 57 | EndGlobal 58 | -------------------------------------------------------------------------------- /ManagedFbx/AssemblyInfo.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | using namespace System; 3 | 4 | [assembly: CLSCompliant(true)]; -------------------------------------------------------------------------------- /ManagedFbx/ConversionTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ManagedFbx 4 | { 5 | public enum class Unit 6 | { 7 | Metres, 8 | Centimetres 9 | }; 10 | 11 | public enum class AxisSystem 12 | { 13 | Max, 14 | MayaYUp, 15 | MayaZUp 16 | }; 17 | } -------------------------------------------------------------------------------- /ManagedFbx/FbxException.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ManagedFbx 4 | { 5 | public ref class FbxException : public System::Exception 6 | { 7 | public: 8 | FbxException(System::String ^message, ...array ^args) : Exception(System::String::Format(message, args)) 9 | { 10 | } 11 | }; 12 | } -------------------------------------------------------------------------------- /ManagedFbx/Light.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Light.h" 3 | 4 | using namespace ManagedFbx; 5 | 6 | Light::Light(FbxLight *nativeLight) 7 | { 8 | m_nativeLight = nativeLight; 9 | } 10 | 11 | LightType Light::Type::get() 12 | { 13 | return (LightType)m_nativeLight->LightType.Get(); 14 | } 15 | 16 | Vector3 Light::Colour::get() 17 | { 18 | return Vector3(m_nativeLight->Color.Get()); 19 | } -------------------------------------------------------------------------------- /ManagedFbx/Light.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ManagedFbx 4 | { 5 | public enum class LightType 6 | { 7 | Point = FbxLight::ePoint, 8 | Spot = FbxLight::eSpot, 9 | Directional = FbxLight::eDirectional 10 | }; 11 | 12 | public ref class Light 13 | { 14 | public: 15 | property_r(LightType, Type); 16 | property_r(Vector3, Colour); 17 | internal: 18 | Light(FbxLight *nativeLight); 19 | private: 20 | FbxLight *m_nativeLight; 21 | }; 22 | } -------------------------------------------------------------------------------- /ManagedFbx/ManagedFbx.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | $(VCTargetsPath11) 15 | 16 | 17 | {163D9B5E-1A69-4821-89DE-298736F2C14E} 18 | Win32Proj 19 | Native 20 | ManagedFbx 21 | 22 | 23 | 24 | DynamicLibrary 25 | true 26 | v100 27 | NotSet 28 | true 29 | 30 | 31 | DynamicLibrary 32 | false 33 | v100 34 | true 35 | Unicode 36 | true 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | true 50 | C:\Program Files\Autodesk\FBX\FBX SDK\2013.2\include\;$(IncludePath) 51 | C:\Program Files\Autodesk\FBX\FBX SDK\2013.2\lib\vs2010\x86;$(LibraryPath) 52 | $(SolutionDir)Build\ 53 | 54 | 55 | false 56 | C:\Program Files\Autodesk\FBX\FBX SDK\2013.2\include\;$(IncludePath) 57 | C:\Program Files\Autodesk\FBX\FBX SDK\2013.2\lib\vs2010\x86;$(LibraryPath) 58 | $(SolutionDir)Build\ 59 | 60 | 61 | 62 | Use 63 | Level3 64 | Disabled 65 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 66 | true 67 | MultiThreadedDebugDLL 68 | false 69 | true 70 | 71 | 72 | Console 73 | true 74 | fbxsdk-2013.2-mdd.lib;wininet.lib;%(AdditionalDependencies) 75 | LIBMCT 76 | 77 | 78 | 79 | 80 | Level3 81 | Use 82 | MaxSpeed 83 | true 84 | true 85 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 86 | true 87 | 88 | 89 | Console 90 | false 91 | true 92 | true 93 | fbxsdk-2013.2-md.lib;wininet.lib;%(AdditionalDependencies) 94 | LIBMCT 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | Create 124 | Create 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /ManagedFbx/ManagedFbx.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Helpers 7 | 8 | 9 | 10 | 11 | 12 | Attributes 13 | 14 | 15 | Attributes 16 | 17 | 18 | Attributes 19 | 20 | 21 | Properties 22 | 23 | 24 | 25 | 26 | 27 | Helpers 28 | 29 | 30 | 31 | Helpers 32 | 33 | 34 | Maths 35 | 36 | 37 | Exceptions 38 | 39 | 40 | 41 | Helpers 42 | 43 | 44 | 45 | Attributes 46 | 47 | 48 | Attributes 49 | 50 | 51 | Attributes 52 | 53 | 54 | 55 | 56 | 57 | {294b9ba4-ee57-4d5f-b87f-715a6ea77c8a} 58 | 59 | 60 | {9015aafe-42e1-4b07-bda4-9dd023a1aeda} 61 | 62 | 63 | {b6172554-dbf5-4472-89ce-76f3920496e0} 64 | 65 | 66 | {c1ff9a53-89e7-4ffe-874e-83ed0729ee95} 67 | 68 | 69 | {be407496-9238-483e-9e28-20a6d050c186} 70 | 71 | 72 | -------------------------------------------------------------------------------- /ManagedFbx/Manager.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Manager.h" 3 | 4 | using namespace ManagedFbx; 5 | 6 | Manager::Manager() 7 | { 8 | m_nativeManager = FbxManager::Create(); 9 | m_nativeImporter = FbxImporter::Create(m_nativeManager, "Importer"); 10 | m_nativeExporter = FbxExporter::Create(m_nativeManager, "Exporter"); 11 | m_nativeGeomConv = new FbxGeometryConverter(m_nativeManager); 12 | } 13 | 14 | FbxManager *Manager::GetInstance() 15 | { 16 | return m_nativeManager; 17 | } 18 | 19 | FbxImporter *Manager::GetImporter() 20 | { 21 | return m_nativeImporter; 22 | } 23 | 24 | FbxExporter *Manager::GetExporter() 25 | { 26 | return m_nativeExporter; 27 | } 28 | 29 | FbxGeometryConverter *Manager::GetGeomConverter() 30 | { 31 | return m_nativeGeomConv; 32 | } -------------------------------------------------------------------------------- /ManagedFbx/Manager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Scene.h" 4 | 5 | namespace ManagedFbx 6 | { 7 | ref class Manager abstract sealed 8 | { 9 | public: 10 | static Manager(); 11 | static FbxManager *GetInstance(); 12 | static FbxImporter *GetImporter(); 13 | static FbxExporter *GetExporter(); 14 | static FbxGeometryConverter *GetGeomConverter(); 15 | 16 | private: 17 | static FbxManager *m_nativeManager; 18 | static FbxImporter *m_nativeImporter; 19 | static FbxExporter *m_nativeExporter; 20 | static FbxGeometryConverter *m_nativeGeomConv; 21 | }; 22 | } -------------------------------------------------------------------------------- /ManagedFbx/Mesh.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Mesh.h" 3 | #include "Manager.h" 4 | 5 | using namespace ManagedFbx; 6 | 7 | Mesh::Mesh(FbxMesh *nativeMesh) 8 | { 9 | m_nativeMesh = nativeMesh; 10 | } 11 | 12 | Mesh ^Mesh::Triangulate() 13 | { 14 | auto mesh = gcnew Mesh(Manager::GetGeomConverter()->TriangulateMesh(m_nativeMesh)); 15 | mesh->UVLayer = UVLayer; 16 | return mesh; 17 | } 18 | 19 | bool Mesh::Triangulated::get() 20 | { 21 | return m_nativeMesh->IsTriangleMesh(); 22 | } 23 | 24 | array ^Mesh::Polygons::get() 25 | { 26 | int count = m_nativeMesh->GetPolygonCount(); 27 | auto list = gcnew array(count); 28 | 29 | for(int i = 0; i < count; i++) 30 | { 31 | auto poly = Polygon(); 32 | 33 | int indexCount = m_nativeMesh->GetPolygonSize(i); 34 | poly.Indices = gcnew array(indexCount); 35 | 36 | for(int j = 0; j < indexCount; j++) 37 | poly.Indices[j] = m_nativeMesh->GetPolygonVertex(i, j); 38 | 39 | list[i] = poly; 40 | } 41 | 42 | return list; 43 | } 44 | 45 | array ^Mesh::Vertices::get() 46 | { 47 | int count = m_nativeMesh->GetControlPointsCount(); 48 | auto list = gcnew array(count); 49 | 50 | for(int i = 0; i < count; i++) 51 | { 52 | auto point = m_nativeMesh->GetControlPointAt(i); 53 | list[i] = Vector3(point); 54 | } 55 | 56 | return list; 57 | } 58 | 59 | array ^Mesh::Normals::get() 60 | { 61 | auto normals = m_nativeMesh->GetLayer(0)->GetNormals(); 62 | int count = normals->GetDirectArray().GetCount(); 63 | auto list = gcnew array(count); 64 | 65 | for(int i = 0; i < count; i++) 66 | list[i] = Vector3(normals->GetDirectArray().GetAt(i)); 67 | 68 | return list; 69 | } 70 | 71 | array ^Mesh::TextureCoords::get() 72 | { 73 | auto layer = m_nativeMesh->GetLayer(UVLayer); 74 | 75 | if(!layer) 76 | return gcnew array(0); 77 | 78 | auto coords = layer->GetUVs(); 79 | int count = coords == nullptr ? 0 : coords->GetDirectArray().GetCount(); 80 | auto list = gcnew array(count); 81 | 82 | for(int i = 0; i < count; i++) 83 | list[i] = Vector2(coords->GetDirectArray().GetAt(i)); 84 | 85 | return list; 86 | } 87 | 88 | int Mesh::GetMaterialId(int polygon) 89 | { 90 | FbxLayerElementArrayTemplate *materials = nullptr; 91 | m_nativeMesh->GetMaterialIndices(&materials); 92 | return materials->GetAt(polygon); 93 | } 94 | 95 | array ^Mesh::MaterialIDs::get() 96 | { 97 | auto materials = m_nativeMesh->GetLayer(0)->GetMaterials(); 98 | int count = materials == nullptr ? 0 : materials->GetIndexArray().GetCount(); 99 | auto list = gcnew array(count); 100 | 101 | for(int i = 0; i < count; i++) 102 | list[i] = materials->GetIndexArray().GetAt(i); 103 | 104 | return list; 105 | } 106 | 107 | int Mesh::GetUVIndex(int polygon, int index) 108 | { 109 | return m_nativeMesh->GetTextureUVIndex(polygon, index); 110 | } 111 | 112 | Vector3 Mesh::GetVertexNormal(int polygon, int index) 113 | { 114 | FbxVector4 normal; 115 | m_nativeMesh->GetPolygonVertexNormal(polygon, index, normal); 116 | return Vector3(normal); 117 | } 118 | 119 | array ^Mesh::VertexColours::get() 120 | { 121 | auto colours = m_nativeMesh->GetLayer(0)->GetVertexColors(); 122 | int count = colours == nullptr ? 0 : colours->GetDirectArray().GetCount(); 123 | auto list = gcnew array(count); 124 | 125 | for(int i = 0; i < count; i++) 126 | list[i] = Colour(colours->GetDirectArray().GetAt(i)); 127 | 128 | return list; 129 | } -------------------------------------------------------------------------------- /ManagedFbx/Mesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Polygon.h" 4 | 5 | namespace ManagedFbx 6 | { 7 | public ref class Mesh 8 | { 9 | public: 10 | property_r(array^, Polygons); 11 | property_r(array^, Vertices); 12 | property_r(array^, Normals); 13 | property_r(array^, TextureCoords); 14 | property_r(array^, VertexColours); 15 | property_r(array^, MaterialIDs); 16 | property_r(bool, Triangulated); 17 | property int UVLayer; 18 | 19 | Mesh ^Triangulate(); 20 | 21 | int GetUVIndex(int polygon, int index); 22 | int GetMaterialId(int polygon); 23 | Vector3 GetVertexNormal(int polygon, int index); 24 | 25 | internal: 26 | Mesh(FbxMesh *nativeMesh); 27 | 28 | private: 29 | FbxMesh *m_nativeMesh; 30 | }; 31 | } -------------------------------------------------------------------------------- /ManagedFbx/NativeString.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | using namespace msclr::interop; 6 | 7 | ref class StringHelper 8 | { 9 | public: 10 | static const char *ToNative(System::String ^string) 11 | { 12 | if(!m_context) 13 | m_context = gcnew marshal_context(); 14 | 15 | return m_context->marshal_as(string); 16 | } 17 | 18 | private: 19 | static marshal_context ^m_context; 20 | }; -------------------------------------------------------------------------------- /ManagedFbx/NodeAttribute.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "NodeAttribute.h" 3 | 4 | using namespace ManagedFbx; 5 | 6 | NodeAttribute::NodeAttribute(FbxNodeAttribute *nativeAttr) 7 | { 8 | m_nativeAttribute = nativeAttr; 9 | } 10 | 11 | NodeAttributeType NodeAttribute::Type::get() 12 | { 13 | return (NodeAttributeType)m_nativeAttribute->GetAttributeType(); 14 | } 15 | 16 | string ^NodeAttribute::Name::get() 17 | { 18 | return gcnew string(m_nativeAttribute->GetName()); 19 | } 20 | 21 | void NodeAttribute::Name::set(string ^value) 22 | { 23 | m_nativeAttribute->SetName(StringHelper::ToNative(value)); 24 | } 25 | -------------------------------------------------------------------------------- /ManagedFbx/NodeAttribute.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ManagedFbx 4 | { 5 | public enum class NodeAttributeType 6 | { 7 | Unknown = FbxNodeAttribute::eUnknown, 8 | Null = FbxNodeAttribute::eNull, 9 | Marker = FbxNodeAttribute::eMarker, 10 | Skeleton = FbxNodeAttribute::eSkeleton, 11 | Mesh = FbxNodeAttribute::eMesh, 12 | Nurbs = FbxNodeAttribute::eNurbs, 13 | Patch = FbxNodeAttribute::ePatch, 14 | Camera = FbxNodeAttribute::eCamera, 15 | CameraStereo = FbxNodeAttribute::eCameraStereo, 16 | CameraSwitcher = FbxNodeAttribute::eCameraSwitcher, 17 | Light = FbxNodeAttribute::eLight, 18 | OpticalReference = FbxNodeAttribute::eOpticalReference, 19 | OpticalMarker = FbxNodeAttribute::eOpticalMarker, 20 | NurbsCurve = FbxNodeAttribute::eNurbsCurve, 21 | TrimNurbsSurface = FbxNodeAttribute::eTrimNurbsSurface, 22 | Boundary = FbxNodeAttribute::eBoundary, 23 | NurbsSurface = FbxNodeAttribute::eNurbsSurface, 24 | Shape = FbxNodeAttribute::eShape, 25 | LodGroup = FbxNodeAttribute::eLODGroup, 26 | Subdiv = FbxNodeAttribute::eSubDiv 27 | }; 28 | 29 | public ref class NodeAttribute 30 | { 31 | public: 32 | property_r(NodeAttributeType, Type); 33 | property_rw(string^, Name); 34 | 35 | internal: 36 | NodeAttribute(FbxNodeAttribute *nativeAttr); 37 | 38 | private: 39 | FbxNodeAttribute *m_nativeAttribute; 40 | }; 41 | } -------------------------------------------------------------------------------- /ManagedFbx/Polygon.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Polygon.h" 3 | 4 | using namespace ManagedFbx; 5 | 6 | array ^Polygon::Indices::get() 7 | { 8 | return m_indices; 9 | } 10 | 11 | void Polygon::Indices::set(array ^value) 12 | { 13 | m_indices = value; 14 | } -------------------------------------------------------------------------------- /ManagedFbx/Polygon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ManagedFbx 4 | { 5 | /// 6 | /// Represents a polygon. 7 | /// 8 | public value struct Polygon 9 | { 10 | public: 11 | /// 12 | /// Gets the array of indices which make up this polygon. 13 | /// 14 | property_ri(array^, Indices); 15 | 16 | private: 17 | array^ m_indices; 18 | }; 19 | } -------------------------------------------------------------------------------- /ManagedFbx/Properties.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Defines a read-only property. 4 | #define property_r(type, name)\ 5 | property type name\ 6 | {\ 7 | type get();\ 8 | } 9 | 10 | // Defines a property that is only writable internally. 11 | #define property_ri(type, name)\ 12 | property type name\ 13 | {\ 14 | type get();\ 15 | internal: void set(type value);\ 16 | } 17 | 18 | // Defines a readable and writable property. 19 | #define property_rw(type, name)\ 20 | property type name\ 21 | {\ 22 | type get();\ 23 | void set(type value);\ 24 | } -------------------------------------------------------------------------------- /ManagedFbx/Scene.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Scene.h" 3 | #include "Manager.h" 4 | 5 | using namespace ManagedFbx; 6 | 7 | Scene::Scene(string ^name) 8 | { 9 | m_nativeScene = FbxScene::Create(Manager::GetInstance(), StringHelper::ToNative(name)); 10 | m_rootNode = gcnew SceneNode(m_nativeScene->GetRootNode()); 11 | } 12 | 13 | Scene ^Scene::Import(string ^filename) 14 | { 15 | auto importer = Manager::GetImporter(); 16 | 17 | if(!importer->Initialize(StringHelper::ToNative(filename))) 18 | throw gcnew FbxException("Failed to initialise the FBX importer: {0}", gcnew string(importer->GetLastErrorString())); 19 | 20 | auto scene = gcnew Scene(""); 21 | 22 | if(!importer->Import(scene->m_nativeScene)) 23 | throw gcnew FbxException("Failed to import the scene: {0}", gcnew string(importer->GetLastErrorString())); 24 | 25 | // Needs refreshing 26 | scene->m_rootNode = gcnew SceneNode(scene->m_nativeScene->GetRootNode()); 27 | 28 | return scene; 29 | } 30 | 31 | void Scene::Save(string ^filename) 32 | { 33 | auto exporter = Manager::GetExporter(); 34 | 35 | if(!exporter->Initialize(StringHelper::ToNative(filename))) 36 | throw gcnew FbxException("Failed to initialise the FBX exporter: {0}", gcnew string(exporter->GetLastErrorString())); 37 | 38 | if(!exporter->Export(m_nativeScene)) 39 | throw gcnew FbxException("Failed to export the scene: {0}", gcnew string(exporter->GetLastErrorString())); 40 | } 41 | 42 | void Scene::Name::set(string ^value) 43 | { 44 | m_nativeScene->SetName(StringHelper::ToNative(value)); 45 | } 46 | 47 | string ^Scene::Name::get() 48 | { 49 | return gcnew string(m_nativeScene->GetName()); 50 | } 51 | 52 | SceneNode ^Scene::RootNode::get() 53 | { 54 | return m_rootNode; 55 | } 56 | 57 | void Scene::Application::set(string ^value) 58 | { 59 | m_nativeScene->GetSceneInfo()->LastSaved_ApplicationName.Set(StringHelper::ToNative(value)); 60 | } 61 | 62 | string ^Scene::Application::get() 63 | { 64 | auto name = m_nativeScene->GetSceneInfo()->LastSaved_ApplicationName.Get().Buffer(); 65 | return gcnew string(name); 66 | } 67 | 68 | string ^Scene::UnitType::get() 69 | { 70 | return gcnew string(m_nativeScene->GetGlobalSettings().GetSystemUnit().GetScaleFactorAsString_Plurial()); 71 | } 72 | 73 | void Scene::ConvertUnits(Unit units) 74 | { 75 | switch(units) 76 | { 77 | case Unit::Metres: 78 | FbxSystemUnit::m.ConvertScene(m_nativeScene); 79 | break; 80 | 81 | case Unit::Centimetres: 82 | FbxSystemUnit::cm.ConvertScene(m_nativeScene); 83 | break; 84 | 85 | default: 86 | throw gcnew NotImplementedException("The supplied unit type is not currently supported for conversion."); 87 | } 88 | } 89 | 90 | void Scene::ConvertAxes(AxisSystem axis) 91 | { 92 | switch(axis) 93 | { 94 | case AxisSystem::Max: 95 | FbxAxisSystem::Max.ConvertScene(m_nativeScene); 96 | break; 97 | 98 | case AxisSystem::MayaYUp: 99 | FbxAxisSystem::MayaYUp.ConvertScene(m_nativeScene); 100 | break; 101 | 102 | case AxisSystem::MayaZUp: 103 | FbxAxisSystem::MayaZUp.ConvertScene(m_nativeScene); 104 | break; 105 | 106 | default: 107 | throw gcnew NotImplementedException("The supplied axis type is not currently supported for conversion."); 108 | } 109 | } 110 | 111 | void Scene::BakeTransform(SceneNode ^node) 112 | { 113 | for each(SceneNode ^node in node->ChildNodes) 114 | BakeTransform(node); 115 | 116 | auto native = node->m_nativeNode; 117 | auto mesh = native->GetMesh(); 118 | 119 | if(!mesh) 120 | return; 121 | 122 | FbxAMatrix geometry(native->GetGeometricTranslation(FbxNode::eSourcePivot), 123 | native->GetGeometricRotation(FbxNode::eSourcePivot), 124 | native->GetGeometricScaling(FbxNode::eSourcePivot)); 125 | 126 | auto total = m_nativeScene->GetEvaluator()->GetNodeGlobalTransform(native) * geometry; 127 | 128 | for(int i = 0; i < mesh->GetControlPointsCount(); i++) 129 | { 130 | auto pos = mesh->GetControlPointAt(i); 131 | mesh->SetControlPointAt(total.MultT(pos), i); 132 | } 133 | } -------------------------------------------------------------------------------- /ManagedFbx/Scene.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SceneNode.h" 4 | #include "ConversionTypes.h" 5 | 6 | using namespace System::Collections::Generic; 7 | 8 | namespace ManagedFbx 9 | { 10 | /// 11 | /// Represents an FBX scene. 12 | /// 13 | public ref class Scene 14 | { 15 | public: 16 | /// 17 | /// Constructs a new empty scene with the given name. 18 | /// 19 | Scene(string ^name); 20 | 21 | /// 22 | /// Imports a scene from a file. 23 | /// 24 | static Scene ^Import(string ^filepath); 25 | 26 | /// 27 | /// Saves the scene to a file. 28 | /// 29 | void Save(string ^filepath); 30 | 31 | /// 32 | /// Converts the scene to a given unit system. 33 | /// 34 | void ConvertUnits(Unit units); 35 | 36 | /// 37 | /// Converts the scene to a given orientation. 38 | /// 39 | void ConvertAxes(AxisSystem axis); 40 | 41 | /// 42 | /// Bakes node transforms into vertex positions. 43 | /// 44 | void BakeTransform(SceneNode ^node); 45 | 46 | /// 47 | /// Gets the root node of this scene. 48 | /// 49 | property_r(SceneNode^, RootNode); 50 | 51 | /// 52 | /// Gets and sets the name of this scene. 53 | /// 54 | property_rw(string^, Name); 55 | 56 | /// 57 | /// Gets and sets the name of the application used to create this scene. 58 | /// 59 | property_rw(string^, Application); 60 | 61 | property_r(string^, UnitType); 62 | 63 | private: 64 | FbxScene *m_nativeScene; 65 | SceneNode ^m_rootNode; 66 | FbxManager *m_manager; 67 | }; 68 | } -------------------------------------------------------------------------------- /ManagedFbx/SceneNode.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SceneNode.h" 3 | 4 | using namespace ManagedFbx; 5 | 6 | SceneNode::SceneNode(FbxNode *node) 7 | { 8 | m_nativeNode = node; 9 | 10 | m_children = gcnew List(); 11 | m_attributes = gcnew List(); 12 | 13 | for(int i = 0; i < m_nativeNode->GetChildCount(); i++) 14 | { 15 | auto sub = m_nativeNode->GetChild(i); 16 | m_children->Add(gcnew SceneNode(sub)); 17 | } 18 | 19 | for(int i = 0; i < m_nativeNode->GetNodeAttributeCount(); i++) 20 | { 21 | auto attr = m_nativeNode->GetNodeAttributeByIndex(i); 22 | m_attributes->Add(gcnew NodeAttribute(attr)); 23 | } 24 | } 25 | 26 | IEnumerable^ SceneNode::ChildNodes::get() 27 | { 28 | return m_children->AsReadOnly(); 29 | } 30 | 31 | IEnumerable^ SceneNode::Attributes::get() 32 | { 33 | return m_attributes->AsReadOnly(); 34 | } 35 | 36 | string ^SceneNode::Name::get() 37 | { 38 | return gcnew string(m_nativeNode->GetName()); 39 | } 40 | 41 | void SceneNode::Name::set(string ^value) 42 | { 43 | m_nativeNode->SetName(StringHelper::ToNative(value)); 44 | } 45 | 46 | void SceneNode::AddChild(SceneNode ^node) 47 | { 48 | m_nativeNode->AddChild(node->m_nativeNode); 49 | m_children->Add(node); 50 | } 51 | 52 | void SceneNode::Position::set(Vector3 value) 53 | { 54 | m_nativeNode->LclTranslation.Set(value); 55 | } 56 | 57 | void SceneNode::Rotation::set(Vector3 value) 58 | { 59 | m_nativeNode->LclRotation.Set(value); 60 | } 61 | 62 | void SceneNode::Scale::set(Vector3 value) 63 | { 64 | m_nativeNode->LclScaling.Set(value); 65 | } 66 | 67 | Vector3 SceneNode::Position::get() 68 | { 69 | return Vector3(m_nativeNode->LclTranslation.Get()); 70 | } 71 | 72 | Vector3 SceneNode::Rotation::get() 73 | { 74 | return Vector3(m_nativeNode->LclRotation.Get()); 75 | } 76 | 77 | Vector3 SceneNode::Scale::get() 78 | { 79 | return Vector3(m_nativeNode->LclScaling.Get()); 80 | } 81 | 82 | Mesh ^SceneNode::Mesh::get() 83 | { 84 | return gcnew ManagedFbx::Mesh(m_nativeNode->GetMesh()); 85 | } 86 | 87 | Light ^SceneNode::Light::get() 88 | { 89 | return gcnew ManagedFbx::Light(m_nativeNode->GetLight()); 90 | } -------------------------------------------------------------------------------- /ManagedFbx/SceneNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "NodeAttribute.h" 4 | #include "Mesh.h" 5 | #include "Light.h" 6 | 7 | using namespace System::Collections::Generic; 8 | 9 | namespace ManagedFbx 10 | { 11 | /// 12 | /// Represents a single node in the FBX scene graph. 13 | /// 14 | public ref class SceneNode 15 | { 16 | public: 17 | /// 18 | /// Gets and sets the name of this node. 19 | /// 20 | property_rw(string^, Name); 21 | 22 | /// 23 | /// Gets the direct children of this node. 24 | /// 25 | property_r(IEnumerable^, ChildNodes); 26 | 27 | /// 28 | /// Gets a collection of FBX attributes for this node. 29 | /// 30 | property_r(IEnumerable^, Attributes); 31 | 32 | /// 33 | /// Gets and sets the position of this node. 34 | /// 35 | property_rw(Vector3, Position); 36 | 37 | /// 38 | /// Gets and sets the rotation of this node. 39 | /// 40 | property_rw(Vector3, Rotation); 41 | 42 | /// 43 | /// Gets and sets the scale of this node. 44 | /// 45 | property_rw(Vector3, Scale); 46 | 47 | /// 48 | /// Gets the first mesh attribute of this node if it exists, otherwise null. 49 | /// 50 | property_r(ManagedFbx::Mesh^, Mesh); 51 | 52 | /// 53 | /// Gets the first light attribute of this node if it exists, otherwise null. 54 | /// 55 | property_r(ManagedFbx::Light^, Light); 56 | 57 | /// 58 | /// Adds an existing node as a child of this node. 59 | /// 60 | void AddChild(SceneNode ^node); 61 | 62 | internal: 63 | SceneNode(FbxNode *node); 64 | FbxNode *m_nativeNode; 65 | 66 | private: 67 | List ^m_children; 68 | List ^m_attributes; 69 | }; 70 | } -------------------------------------------------------------------------------- /ManagedFbx/Vector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Properties.h" 5 | 6 | using namespace System; 7 | 8 | namespace ManagedFbx 9 | { 10 | public value struct Colour 11 | { 12 | public: 13 | Colour(double r, double g, double b, double a) 14 | { 15 | R = r; 16 | G = g; 17 | B = b; 18 | A = a; 19 | } 20 | 21 | property double R; 22 | property double G; 23 | property double B; 24 | property double A; 25 | 26 | operator FbxColor() 27 | { 28 | return FbxColor(R, G, B, A); 29 | } 30 | 31 | virtual String ^ToString() override 32 | { 33 | return String::Format("{0}, {1}, {2}, {3}", Math::Round(R, 3), Math::Round(G, 3), Math::Round(B, 3), Math::Round(A, 3)); 34 | } 35 | 36 | internal: 37 | Colour(FbxColor fbxColour) 38 | { 39 | R = fbxColour.mRed; 40 | G = fbxColour.mGreen; 41 | B = fbxColour.mBlue; 42 | A = fbxColour.mAlpha; 43 | } 44 | }; 45 | 46 | public value struct Vector3 47 | { 48 | public: 49 | Vector3(double x, double y, double z) 50 | { 51 | X = x; 52 | Y = y; 53 | Z = z; 54 | } 55 | 56 | property double X; 57 | property double Y; 58 | property double Z; 59 | 60 | operator FbxDouble3() 61 | { 62 | return FbxDouble3(X, Y, Z); 63 | } 64 | 65 | virtual String ^ToString() override 66 | { 67 | return String::Format("{0}, {1}, {2}", Math::Round(X, 3), Math::Round(Y, 3), Math::Round(Z, 3)); 68 | } 69 | 70 | static Vector3 operator *(Vector3 self, float value) 71 | { 72 | self.X *= value; 73 | self.Y *= value; 74 | self.Z *= value; 75 | return self; 76 | } 77 | 78 | internal: 79 | Vector3(FbxDouble3 fbxDouble) 80 | { 81 | X = fbxDouble[0]; 82 | Y = fbxDouble[1]; 83 | Z = fbxDouble[2]; 84 | } 85 | }; 86 | 87 | public value struct Vector2 88 | { 89 | Vector2(double x, double y) 90 | { 91 | X = x; 92 | Y = y; 93 | } 94 | 95 | operator FbxDouble2() 96 | { 97 | return FbxDouble2(X, Y); 98 | } 99 | 100 | virtual String ^ToString() override 101 | { 102 | return String::Format("{0}, {1}", Math::Round(X, 3), Math::Round(Y, 3)); 103 | } 104 | 105 | property double X; 106 | property double Y; 107 | 108 | internal: 109 | Vector2(FbxVector2 vector) 110 | { 111 | X = vector[0]; 112 | Y = vector[1]; 113 | } 114 | }; 115 | 116 | public value struct Vector4 117 | { 118 | Vector4(double w, double x, double y, double z) 119 | { 120 | W = w; 121 | X = x; 122 | Y = y; 123 | Z = z; 124 | } 125 | 126 | operator FbxDouble4() 127 | { 128 | return FbxDouble4(X, Y, Z, W); 129 | } 130 | 131 | virtual String ^ToString() override 132 | { 133 | return String::Format("{0}, {1}, {2}, {3}", Math::Round(W, 3), Math::Round(X, 3), Math::Round(Y, 3), Math::Round(Z, 3)); 134 | } 135 | 136 | property double W; 137 | property double X; 138 | property double Y; 139 | property double Z; 140 | }; 141 | } -------------------------------------------------------------------------------- /ManagedFbx/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" -------------------------------------------------------------------------------- /ManagedFbx/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define FBXSDK_NEW_API 4 | #include 5 | #include "NativeString.h" 6 | #include "FbxException.h" 7 | #include "Vector.h" 8 | 9 | typedef System::String string; -------------------------------------------------------------------------------- /licence.md: -------------------------------------------------------------------------------- 1 | The source code for CryEngine.RC is available to anyone to download, edit and redistribute under these simple conditions: 2 | 3 | * The software is only available for non-commercial entities, and may not be relicensed. 4 | * You must make changes available to the public. 5 | * In the rare event that we meet, you owe me a pint. 6 | 7 | This software contains Autodesk® FBX® code developed by Autodesk, Inc. Copyright Autodesk, Inc. All rights, reserved. Such code is provided “as is” and Autodesk, Inc. disclaims any and all warranties, whether express or implied, including without limitation the implied warranties of merchantability, fitness for a particular purpose or non-infringement of third party rights. In no event shall Autodesk, Inc. be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of such code. -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ManagedFBX is a .NET wrapper for Autodesk's FBX SDK, written in C++/CLI. 2 | 3 | # Building from source 4 | 5 | * Install the [FBX SDK](http://usa.autodesk.com/adsk/servlet/pc/item?siteID=123112&id=10775847) 6 | * Ensure that the ManagedFbx project is pointing at the correct library and headers for the SDK 7 | * Build the solution and verify it's working correctly by running the sample project provided --------------------------------------------------------------------------------