An FBX file is a format used to exchange 3D geometry and animation data. The FBX files are used in film, game and augmented reality and virtual reality (AR/VR) development. Also, in order to open, edit, and export FBX files to high-fidelity 2D and 3D files, we need some third-party software like Autodesk FBX Review,etc. Whereas, OBJ is a much simpler format that only keeps geometry (vertex, normals, etc) and is often for raw polygon data, some simple materials. So we may have a requirement to render FBX files to OBJ format. In this article, we are going to learn about the steps on how to programmatically convert FBX files to OBJ files using REST API.
3D File Processing API
In order to programmatically create & process 3D models, objects, and entities including Box, Cylinder, Sphere, Torus, and Plane, we have created a REST-based API named Aspose.3D Cloud. Perform all operations like transformation & translation, scaling, Parametric Modeling, rotation of 3D objects, and even work with Triangulate Meshes without any software installation. Since it’s based on REST architecture, so the API can be used in Desktop, Web, Mobile, and in hybrid applications.
In this article, we are going to discuss the conversion of the FBX file to OBJ format using the C# .NET code snippet, so we need to focus on Aspose.3D Cloud SDK for .NET. The SDK is a wrapper around REST so that you get all the features of 3D file processing right within your favorite IDE.
Installation
The first step in using the SDK is its installation. The Cloud SDK is available for download over NuGet and GitHub. So in order to install the SDK from NuGet, please consider executing the following command in the terminal.
nuget install Aspose.3D-Cloud
NuGet Package Manager
You may also consider executing the following command in Package Manager Console in Visual Studio to fetch & reference Aspose.3D assembly in your project.
PM> Install-Package Aspose.3D-Cloud
Visual Studio
Another approach is the installation directly within Visual Studio solution:
- Open the Solution Explorer.
- Expand the project and Right-click Packages folder within your solution.
- Select Manage NuGet Packages… option
- Click on the Browse tab and search for “Aspose.3D-Cloud“
- Click on the Aspose.3D-Cloud package from search results
- Select the appropriate version in the right-tab and click Install button.
Cloud Dashboard
At Aspose, the Confidentiality, Integrity, and Availability of data are of utmost importance. Therefore, only authorized persons can access the Cloud APIs as well as the files stored over Cloud storage. The next important step is the creation of a free subscription account over Aspose.Cloud dashboard. The subscription is free and no credit card or payment details are required. Under the free subscription account, you can perform up to 150 Free document processing requests.
Now use your GitHub or Google account, simply Sign Up. Otherwise, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.
FBX to OBJ in C#
Please follow the steps specified below to perform the conversion of FBX to OBJ format using the C# .NET code snippet.
- First we need to create an instance of ThreeDCloudApi class while passing Client ID and Client Secret as arguments
- Secondly, load the input FBX file from local system into FileStream object
- Now upload the file to cloud storage using UploadFile(…) method of ThreeDCloudApi class
- Next step is to call PostConvertByFormatWithHttpInfo(…) method which takes input file name, output format and resultant file name as arguments
- Finally, print the success message in console and at this time, the output would be saved in Cloud storage
For your reference, the sample files used in above example are uploaded over Wolf-Blender-2.82a.fbx and resultant.obj.
Convert FBX to OBJ using cURL Command
The REST architecture of Cloud APIs enables you to access them through cURL commands, so we can also access Aspose.3D Cloud via cURL commands. At the same time, our APIs are only accessible to authorized persons, so we need to first generate a JWT access token based on our personalized client credentials. Please execute the following command for JWT access token generation.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=4db2f826-bf9c-42e7-8b2a-8cbca2d15553&client_secret=d757548a9f2558c39c2feebdf85b4c44" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Now we need to upload the file to cloud storage while executing the following command.
curl -X PUT "https://api.aspose.cloud/v3.0/3d/storage/file/Esso.3ds" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>" \
-H "Content-Type: multipart/form-data" \
-d {"File":{c:\Users\shahbnay\Esso.3ds}} -v
Once the JWT access token is generated, please execute the following command to convert the FBX file to OBJ format. Given below are the details of parameters accepted by PostConvertByFormat API
- name - The name of the source file.
- newformat - The format of the new file.
- newfilename - The name of the new file.
- folder (optional) - The folder of the source file.
- IsOverwrite (optional) - Overwrite the source file? (default value is false)
- storage (optional) - The storage type.
curl -X POST "https://api.aspose.cloud/v3.0/3d/saveas/newformat?name=Wolf-Blender-2.82a.fbx&newformat=wavefrontobj&newfilename=Converted.obj&IsOverwrite=true" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>" \
-v
Request URL
https://api.aspose.cloud/v3.0/3d/saveas/newformat?name=Esso.3ds&newformat=FBX&newfilename=Iphone.fbx&IsOverwrite=false
Conclusion
In this article, we have discussed the steps on how to convert the FBX file to OBJ format using the C# .NET code snippet and using the cURL commands. Furthermore, our Cloud SDKs are developed under the Opensource licensing model, so the complete source code can be downloaded from GitHub.
To recap, we have listed below the 3D formats currently supported by Cloud API
Additive Manufacturing Format AMF, 3D Studio 3DS, AVEVA RVM, Google Draco DRC, Collada DAE, AutoCAD DXF, Autodesk FBX, Wavefront OBJ, 3D PDF, Polygon File Format PLY, Standard Triangle Language STL, Universal3D U3D, GL Transmission Format GLTF
We encourage you to try using our API and in case you encounter any issues or you have any related queries, please feel free to contact us via the Free support forum.
Related articles
We also recommend visiting the following links and learning more about the capabilities of our award-winning APIs