fbx® - a platform-independent 3d data interchange...
TRANSCRIPT
FBX® - A Platform-Independent 3D Data Interchange
Technology Cyrille Fauvel - Autodesk
CP4466 - Exchanging 3D data between applications is becoming increasingly important. The FBX exchange technology already facilitates high-fidelity data exchange between several Autodesk® content creation packages, but can be extended to include your proprietary information or be the foundation of complex workflows and save you a lot of time. During this class, we will start with an overview of the capabilities of the SDK and how it can be extended to streamline your workflows. Then we will provide an introduction to using the SDK C++ and Python libraries for plug-in development. To complete the class, we will introduce you to the various FBX tools included with the SDK as well as teaching you ways that FBX can be customized and programmed.
Learning Objectives - At the end of this class, you will be able to:
Explain what FBX is about and its integration in Autodesk products
Be able to decide whether FBX is a solution to your workflow issue
Explain the advantages / inconvenient of using FBX versus a private file format
Create FBX plug-in extension to support your private data in existing pipelines
Connect your application (or pipeline) to FBX
Publish / Import FBX file into your application / (or pipeline)
About the Speaker
Cyrille is a member of the M&E workgroup of the Autodesk Developer Network
(ADN) team, providing developer support, training, and conference presentations on
AutoCAD, RealDWG, Inventor, MapGuide, Maya, and FBX API.
He joined Autodesk in 1994 as an AutoCAD developer based in Switzerland and
California, USA. Later moved to the Developer Support group, and Consulting
division.
Cyrille graduated in Mechanics and Electronics in France, worked as a teacher and C++ developer for a
3rd party developer on AutoCAD. He is fluent in six programming languages, tries to learn Japanese, has
two kids, plays the guitar and trying piano, likes reading, love sailing on oceans, sports, and hand-ball in
particular.
FBX® - A Platform-Independent 3D Data Interchange Technology
2
Introduction to Autodesk Developer Network If you are not already an Autodesk Developer Network (ADN) member, and are interested in more
information, please see:
www.autodesk.com/adn - information about ADN
We also post periodically SDK updates and other FBX development information to this location:
www.autodesk.com/developfbx - information about FBX development
Note about Sample Code The sample code that accompanies this course is meant mainly to illustrate the presentation in an easy
to understand the FBX file format and SDK. Because of this, there is minimal error checking and
exception handling. If reusing any of the sample code in your production code, please remember to add
appropriate error handling.
FBX® - A Platform-Independent 3D Data Interchange Technology
3
Contents
Learning Objectives - ............................................................................................................... 1
About the Speaker ..................................................................................................................... 1
Introduction to Autodesk Developer Network ............................................................................. 2
Note about Sample Code ........................................................................................................... 2
Overview .................................................................................................................................... 4
Getting Started Working with FBX .............................................................................................. 4
The Challenges .......................................................................................................................... 5
Challenge 1 – 3D modeling .................................................................................................... 5
AutoCAD tessellation example using the Brep library ......................................................... 6
Inventor tessellation example .............................................................................................10
Challenge 2 – Materials .........................................................................................................13
RealDWG versus FBX ...........................................................................................................14
FBX Extension SDK ..................................................................................................................15
Additional Information & Material ..............................................................................................15
Significant 3rd Parties using FBX ..........................................................................................15
Download the FBX SDK and tools .........................................................................................16
Get Help on FBX ...................................................................................................................16
Feedback ..................................................................................................................................17
FBX® - A Platform-Independent 3D Data Interchange Technology
4
Overview Platform-Independent 3D Data Interchange Technology Autodesk® FBX® asset exchange technology facilitates higher-fidelity data exchange between several Autodesk content creation packages — Autodesk® 3ds Max®, Autodesk® Maya®, Autodesk® MotionBuilder®, Autodesk® Mudbox™, and Autodesk® Softimage® software — and provides support for certain third-party and proprietary applications. Whether you are using FBX within an entertainment pipeline or as part of design production, files are more seamlessly transferred, more data is retained, and workflows are more efficient. FBX was originally designed to be ‘MotionBuilder’ file format, but it actually been expanded to do more. It is now used by many M&E packages to exchange information and share models. For example, when you want to edit a character asset created in Maya into Mudbox, FBX is the foundation for transferring this asset information. FBX is not only a file format; it is also an SDK which is multi-platform. The FBX SDK is available on the 3 major OS (Windows, MacOS & Linux) and come with tools to help you working with asset file.
Getting Started Working with FBX The first thing you need to start integrating FBX into your application or pipeline is, of course, the FBX
SDK. Well, you don’t really need the FBX SDK if you do not intend to programmatically read or write FBX
information in an FBX file. It’s worth pointing out that many 3D applications do support FBX natively and
you can already create FBX file without the SDK itself. For example, Maya, 3ds Max, AutoCAD, Revit from
Autodesk, Unity3d for Unity Studios, and many others, do have import/export FBX functionally.
Something important to note is that the FBX file format is open, and the SDK is free – your application
(or pipeline) can make a free use of that technology and get linked to the rest of the world.
Creating an application that accesses FBX information from inside any application is actually very
straightforward with the Autodesk FBX SDK.
1. Install the latest SDK from http://www.autodesk.com/fbx or www.autodesk.com/developfbx
2. Launch Visual Studio 2005, 2008 or 2010 and create a new project if using C++
3. Include the <fbxsdk.h> header
4. Copy and paste the following code into the main function:
int main (int argc, char **argv) {
KFbxSdkManager *lSdkManager =NULL ;
KFbxScene *lScene =NULL ;
// Prepare the FBX SDK.
InitializeSdkObjects (lSdkManager, lScene) ; // Do something like reading a FBX file or creating a new scene.
// Destroy all objects created by the FBX SDK.
DestroySdkObjects (lSdkManager) ;
FBX® - A Platform-Independent 3D Data Interchange Technology
5
return (0) ;
}
You can also use Python if you are not a fan of C++. In this case:
1. Install the latest Python SDK from http://www.autodesk.com/fbx or
www.autodesk.com/developfbx
2. Copy the fbx.pyd and sip.pyd into your Python site-packages directory
3. Use your favorite Python editor (or notepad)
4. Copy and paste the following code into the main function:
from fbx import * import sys if __name__ == "__main__": # Prepare the FBX SDK. (lSdkManager, lScene) = FbxCommon.InitializeSdkObjects() # Do something like reading a FBX file or creating a new scene. # Destroy all objects created by the FBX SDK. lSdkManager.Destroy() sys.exit(0)
This code (which is identical in both C++ and Python) is the very minimal code you need to use the FBX SDK. It does not do anything yet, but you have all you need to start reading a file or writing a file. We will go into a deeper example later.
The Challenges
Challenge 1 – 3D modeling AutoCAD & Inventor, the 2 major 3D modeler engines from Autodesk for design are using the Autodesk
Shape Manager (ASM). ASM is capable of building manifold, non-manifold 3d geometry as boundary
representation topological model. Their main goal is accuracy and precision. While speed is important
this is a less important criteria than measurement precision. ASM precision for ASM is from 1e-6 to 1e+4
which is very common in mechanical design.
In computer-aided design the constructed design is represented by a boundary representation
topological model, where analytical 3D surfaces and curves, limited to faces and edges constitute a
continuous boundary of a 3D body. Arbitrary 3D bodies are often too complicated to analyze directly. So
they are approximated (tessellated) with a mesh of small, easy-to-analyze pieces of 3D volume —
usually either irregular tetrahedrons, or irregular hexahedrons.
FBX® - A Platform-Independent 3D Data Interchange Technology
6
M&E Autodesk products, such as Maya, 3ds Max, Mudbox & SoftImage, are all using Meshes and Nurbs
(but people mainly use mesh). Measurement is less important than speed and ‘beauty’ (and by beauty I
mean texture, material, artistic deformation of solids, etc…) ASM is that case does not fit well, as being
too rigid for on propose for mechanical design.
Unfortunately, after tessellation, it is not possible to come back. AutoCAD & Inventor will work well with
meshes, so someone may say you can come back, but you would not come back to a boundary
representation of the original solid.
Tessellation techniques are often used to manage datasets of polygons and divide them into suitable
structures for rendering. Normally, at least for real-time rendering, the data is tessellated into triangles,
which are sometimes referred to as triangulation.
AutoCAD tessellation example using the Brep library
Using ObjectARX AcDbObjectPointer<AcDb3dSolid> pSolid (myAsmId, AcDb::kForRead) ;
//- Calculate the approximate size of our solid
AcDbExtents extents ;
pSolid->getGeomExtents (extents) ;
AcGeVector3d v0 =extents.maxPoint () - extents.minPoint () ;
double length =v0.length () ;
AcBrBrep brp ;
brp.set (*((AcDbEntity *)pSolid.object ())) ;
//- Create and set our mesh control object
AcBrMesh2dControl mc ;
//- These settings seem extreme, but only result
//- in ~500 faces for a sphere (during my testing,
//- anyway). Other control settings are available
mc.setMaxNodeSpacing (length / 10000) ;
mc.setMaxSubdivisions (100000000) ;
//- Create a mesh filter object
FBX® - A Platform-Independent 3D Data Interchange Technology
7
AcBrMesh2dFilter mf ;
//- Use it to map our control settings to the Brep
//- VC8:Used const pointer to resolve conversion error
const AcBrEntity *meshEnt =(AcBrEntity *)&brp ;
mf.insert (make_pair (meshEnt, (const AcBrMesh2dControl)mc)) ;
//- Generate a mesh using the filter
AcBrMesh2d m ;
m.generate (mf) ;
//- Extract individual faces from the mesh data
AcBrMesh2dElement2dTraverser it ;
it.setMesh (m) ;
AcGePoint3dArray ptsAll ;
AcGeVector3dArray normalAll ;
while ( !it.done () ) {
AcGePoint3dArray pts ;
AcBrElement2d elt ;
it.getElement (elt) ;
AcGeVector3d normal ;
elt.getNormal (normal) ;
normalAll.append (normal) ;
AcBrElement2dNodeTraverser eltNodeIt ;
eltNodeIt.setElement (it) ;
while ( !eltNodeIt.done () ) {
AcBrNode node ;
eltNodeIt.getNode (node) ;
AcGePoint3d nodePoint ;
node.getPoint (nodePoint) ;
pts.append ((const AcGePoint3d &)nodePoint) ;
eltNodeIt.next () ;
}
//- A face could be a triangle or a quadrilateral
if ( pts.logicalLength () == 4 ) {
//- A quadrilateral face
} else {
//- A triangle face
}
it.next () ;
}
Using .Net
http://through-the-interface.typepad.com/through_the_interface/2011/03/generating-a-mesh-for-
a-3d-solid-using-autocads-brep-api-from-net.html
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.BoundaryRepresentation;
using Autodesk.AutoCAD.DatabaseServices;
FBX® - A Platform-Independent 3D Data Interchange Technology
8
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
namespace MeshSolid
{
public class MeshCreator
{
// Mesh a selected solid
[CommandMethod("SOLMESH")]
static public void MeshFromSolid()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// Ask the user to select a solid
PromptEntityOptions peo =
new PromptEntityOptions("Select a 3D solid");
peo.SetRejectMessage("\nA 3D solid must be selected.");
peo.AddAllowedClass(typeof(Solid3d), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
Transaction tr =
db.TransactionManager.StartTransaction();
using (tr)
{
BlockTable bt =
(BlockTable)tr.GetObject(
db.BlockTableId,
OpenMode.ForRead,
false
);
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite,
false
);
Solid3d sol =
tr.GetObject(
per.ObjectId,
OpenMode.ForRead
) as Solid3d;
// Calculate the approximate size of our solid
double length =
FBX® - A Platform-Independent 3D Data Interchange Technology
9
sol.GeometricExtents.MinPoint.GetVectorTo(
sol.GeometricExtents.MaxPoint
).Length;
try
{
using (Brep brp = new Brep(sol))
{
// Create and set our mesh control object
using (Mesh2dControl mc = new Mesh2dControl())
{
// These settings seem extreme, but only result
// in ~500 faces for a sphere (during my testing,
// anyway). Other control settings are available
mc.MaxNodeSpacing = length / 10000;
mc.MaxSubdivisions = 100000000;
// Create a mesh filter object
using (Mesh2dFilter mf = new Mesh2dFilter())
{
// Use it to map our control settings to the Brep
mf.Insert(brp, mc);
// Generate a mesh using the filter
using (Mesh2d m = new Mesh2d(mf))
{
// Extract individual faces from the mesh data
foreach (Element2d e in m.Element2ds)
{
Point3dCollection pts = new Point3dCollection();
foreach (Node n in e.Nodes)
{
pts.Add(n.Point);
n.Dispose();
}
e.Dispose();
// A face could be a triangle or a quadrilateral
// (the Booleans indicate the edge visibility)
AcDb.Face face = null;
if (pts.Count == 3)
face =
new AcDb.Face(
pts[0], pts[1], pts[2],
true, true, true, true
);
else if (pts.Count == 4)
face =
new AcDb.Face(
pts[0], pts[1], pts[2], pts[3],
true, true, true, true
);
// If we have a valid face, add it to the
// database and the transaction
if (face != null)
{
FBX® - A Platform-Independent 3D Data Interchange Technology
10
// Make each face yellow for visibility
face.ColorIndex = 2;
btr.AppendEntity(face);
tr.AddNewlyCreatedDBObject(face, true);
}
}
}
}
}
}
tr.Commit();
}
catch (System.Exception ex)
{
ed.WriteMessage("Exception: {0}", ex.Message);
}
}
}
}
}
Inventor tessellation example Public Sub GenerateFacets()
Dim doc As Document
doc = ThisApplication.ActiveDocument
Dim body As SurfaceBody
body = doc.ComponentDefinition.SurfaceBodies(1)
Dim tolerance As Double
Dim VertexCount As Long
Dim FacetCount As Long
Dim VertexCoords() As Double
Dim normals() As Double
Dim Indices() As Long
tolerance = 0.003
Call body.CalculateFacets(tolerance, VertexCount, FacetCount,
VertexCoords, normals, Indices)
Dim nbTriangles As Long
nbTriangles = 0
Dim i As Integer
For i = 0 To UBound(Indices) Step 3
Dim vIndex1 As Integer
Dim vIndex2 As Integer
Dim vIndex3 As Integer
vIndex1 = (Indices(i) - 1) * 3
vIndex2 = (Indices(i + 1) - 1) * 3
FBX® - A Platform-Independent 3D Data Interchange Technology
11
vIndex3 = (Indices(i + 2) - 1) * 3
Dim vertex1(2) As Double
Dim vertex2(2) As Double
Dim vertex3(2) As Double
vertex1(0) = VertexCoords(vIndex1)
vertex1(1) = VertexCoords(vIndex1 + 1)
vertex1(2) = VertexCoords(vIndex1 + 2)
vertex2(0) = VertexCoords(vIndex2)
vertex2(1) = VertexCoords(vIndex2 + 1)
vertex2(2) = VertexCoords(vIndex2 + 2)
vertex3(0) = VertexCoords(vIndex3)
vertex3(1) = VertexCoords(vIndex3 + 1)
vertex3(2) = VertexCoords(vIndex3 + 2)
'Call custom method to visualize facet edges
Call DrawLineGraphics(vertex1, vertex2)
Call DrawLineGraphics(vertex2, vertex3)
Call DrawLineGraphics(vertex3, vertex1)
nbTriangles = nbTriangles + 1
Next
ThisApplication.ActiveView.Update()
End Sub
Public Sub DrawLineGraphics(ByVal startpt() As Double, ByVal endpt() As
Double)
Dim doc As Document
doc = ThisApplication.ActiveDocument
Dim compDef As ComponentDefinition
compDef = doc.ComponentDefinition
On Error Resume Next
Dim dataSets As GraphicsDataSets
dataSets = doc.GraphicsDataSetsCollection("LineGraphics")
Dim clientGraphics As clientGraphics
clientGraphics = compDef.ClientGraphicsCollection("LineGraphics")
If Err Then
Err.clear()
dataSets = doc.GraphicsDataSetsCollection.Add("LineGraphics")
clientGraphics = compDef.ClientGraphicsCollection.Add("LineGraphics")
Call dataSets.CreateCoordinateSet(1)
FBX® - A Platform-Independent 3D Data Interchange Technology
12
Call clientGraphics.AddNode(1)
Call clientGraphics(1).AddLineGraphics()
End If
On Error GoTo 0
Dim coordSet As GraphicsCoordinateSet
coordSet = dataSets(1)
Dim coords() As Double
Call coordSet.GetCoordinates(coords)
Dim idx As Long
idx = 3 * coordSet.Count
ReDim Preserve coords(0 To idx + 5)
coords(idx) = startpt(0)
coords(idx + 1) = startpt(1)
coords(idx + 2) = startpt(2)
coords(idx + 3) = endpt(0)
coords(idx + 4) = endpt(1)
coords(idx + 5) = endpt(2)
Call coordSet.PutCoordinates(coords)
Dim lineGraphics As lineGraphics
lineGraphics = clientGraphics(1).item(1)
lineGraphics.CoordinateSet = coordSet
End Sub
Public Function deleteGraphics(ByVal name As String)
Dim doc As Document
doc = ThisApplication.ActiveDocument
Dim compDef As ComponentDefinition
compDef = doc.ComponentDefinition
On Error Resume Next
Dim dataSets As GraphicsDataSets
dataSets = doc.GraphicsDataSetsCollection(name)
Dim clientGraphics As clientGraphics
clientGraphics = compDef.ClientGraphicsCollection(name)
If Err Then
Exit Function
End If
FBX® - A Platform-Independent 3D Data Interchange Technology
13
On Error GoTo 0
clientGraphics.Delete()
dataSets.Delete()
ThisApplication.ActiveView.Update()
End Function
Challenge 2 – Materials All Autodesk software has been written at different time, but different company which became Autodesk later. Because of this, they all are using a different material library which may create issues when transferring object with material from one application to another. Material properties usually transfer in the FBX file properly, but that does not mean the target application will handle them properly.
Another little issue is that they are also all using different renderer, so even if the material imports well, they may not look exactly the same.
Nowadays, Autodesk applications have a Consistent Material Library, but legacy assets may still be using older definition, so be careful.
FBX® - A Platform-Independent 3D Data Interchange Technology
14
Autodesk workflow
In short DirectConnect’s job is to prepare complex data to be able to be read into a visualization
application. It has 2 parts:
1- The first part is where it tries to keep as rich as possible data model, this is based on ISO10303
and is a standard for moving CAD data around. From there it can process the data either
producing a NURBS or Mesh representation. It does this respecting the topology information of
the CAD original CAD data. It can also produce a stitched model (i.e. add topology) for
unorganized data (Alias Studio). This allows a visualization application to display it without
“cracks”. Importers for original CAD data can easily be written to populate the first data
structure.
2- The second part is a fast access data model that is tuned to supply data to the visualization
application. This is what most applications write an API to, including Showcase and 3ds Max. DC
takes the CAD data and produces data in this form in an .apf file. This supports demand loading,
instances (assemblies). At this point the API can give the user the geometry in a form of a NURB
or a mesh.
RealDWG versus FBX RealDWG is the AutoCAD DWG file format SDK, whereas FBX is also an SDK but does not share the same
file format. They do not really compete as they are addressing different problems. Here is below a quick
comparison of the 2 SDK:
FBX® - A Platform-Independent 3D Data Interchange Technology
15
RealDWG FBX
AutoCAD native file format
ASM ( manifold, non-manifold 3d
geometry )
Accuracy / Precision versus Realistic
Windows only
Not Free
MotionBuilder file format
Mesh, Nurbs
Tessellation
Speed / Rendering versus Precision
Multi-platform
Free
Not Round-trip with ASM
Layered Animation evaluation engine
o Solvers
o PhysX
FBX Extension SDK The FBX Extensions SDK is a set of callback functions that you can define in a dynamically loaded library
(.dll) to customize the behavior of the FBX importing and exporting functionality of 3ds Max, Maya, and
MotionBuilder for example.
The FBX Extensions SDK comes packaged with:
Source code for reading and writing scenes to FBX and Collada files. This source code can be
modified to extend these file formats for your own needs.
Samples to help you read and write in a custom file format.
Source code for sample FBX extensions to 3ds Max, Maya and MotionBuilder.
In short, you do not need to rewrite a complete importer / exporter to customize the FBX file with your
custom data. During an import / export, you can be callback for each FBX node and manipulate the
nodes and/or add your custom information. Unlike the FBX SDK, the FBX Extension SDK is C++ only.
Additional Information & Material
Significant 3rd Parties using FBX EIDOS
Illuminate Labs
Quest3D
Microsoft XNA
SideEffects
Maxon
Luxology
Epic (Unreal)
FBX® - A Platform-Independent 3D Data Interchange Technology
16
Unity
JDA
DigitalExtremes
EuroCom
PixelActive (CityScape)
Goalem
and more…
Download the FBX SDK and tools Visit http://www.autodesk.com/fbx & www.autodesk.com/developfbx
The Autodesk FBX SDK and tools are updated regularly with new features and bugfixes.
Get Help on FBX Forums on Autodesk AREA http://area.autodesk.com/
http://area.autodesk.com/forum/autodesk-fbx/
http://area.autodesk.com/blogs/chris
Support
for FBX plug-ins - [email protected]
for the FBX SDK - [email protected]
Online documentation available and updated regularly here
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=16707768
Become an ADN member
http://www.autodesk.com/joinadn
FBX® - A Platform-Independent 3D Data Interchange Technology
17
Feedback If you have any feedback or questions on FBX or this presentation, please email [email protected].