GithubHelp home page GithubHelp logo

fbx-extract's Introduction

fbx-extract

This program parses an FBX file and writes six types of output files.

  1. An OBJ file of the mesh
  2. An ASCII file with skinning information
  3. An ASCII file with the skeletal animation information
  4. Texture files
  5. An ASCII file with the input information
  6. Four ASCII files with the local transforms for each joint in skeletal animation information

The input FBX file can be downloaded from Mixamo.

Authors:

  • Shinjiro Sueda
  • Ziyan Xiong

Building and running

This project builds on top of the following projects:

To build the project, run cmake and make, and then run with the FBX file as an argument:

> mkdir build
> cd build
> cmake ..
> make
> ./fbx-extract ../data/bigvegas_Walking.fbx

Output files

Geometry

  • A standard OBJ file with vertex positions, normals, and texture coordinates.
  • Faces are triangulated.
  • Common vertices are merged.

Skinning weights

  • Filename ends with _skin.txt.
  • Comments start with #.
  • The first line has three integers:
    • Vertex count: should be the same as the corresponding OBJ file
    • Bone count: the number of bones in the animation
    • Max influences: this is the maximum number of non-zero weights per vertex
  • Each subsequent line corresponds to a vertex.
    • In each line, the first number is the number of bone influences for the vertex.
    • The next numbers are "influence" pairs of {bone index, bone weight}. The bone index is 0-indexed.
4583 82 9
1 20 1.000000 
1 20 1.000000 
2 19 0.037664 20 0.962336 

Skeletal animation

  • Filename ends with _skel.txt.
  • Comments start with #.
  • The first line has two integers:
    • Frame count: the number of frames in the animation
    • Bone count: the number of bones in the animation
  • Each subsequent line is a frame with "boneCount" sets of quaternions (x,y,z,w) and positions (x,y,z).
  • The first frame is for the rest pose, so there are actually frameCount + 1 lines.
27 82
0.000000 0.000000 0.000000 1.000000 0.000000 96.330055 9.825774 ...
0.008630 0.039924 0.024404 0.998867 0.657645 87.535782 2.391427 ...

Textures

  • All of the textures contained in the input FBX file, usually are PNG or JPG files.
  • The files downloaded from Mixamo may not contain any textures. The steps to solve this are (thanks to Yuanlong Zhou):
    • Click "Characters" from the tab on the Mixamo website.
    • Choose your favorite character and then choose its corresponding "Animations."
    • Download the .fbx file, rather than downloading it directly from the main page.

Input file

  • The input information for this Assignment.
  • This file only lists the name of the first extracted texture. If it is not the ideal one, please edit it manually.

Local transforms

  • There are four ASCII files storing the local transforms information, so we can convert them back without loss.
  • The world transform can be restored using: WorldTransform = ParentWorldTransform * T * Roff * Rp * Rpre * R * Rpost^-1 * Rp^-1 * Soff * Sp * S * Sp^-1, described here.
  • Comments start with '#'.
  1. *_static_transforms.txt contains the static transforms between the joints.
  • The first line contains the number of joints.
  • Each line next contains 8 matrices: T Roff Rp Rpre Rpost Soff Sp S.
  • Each matrix has 7 numbers: 4 for quaternion (x, y, z, w) and 3 for position (x, y, z), so that each line has 7 * 8 = 56 numbers.
83
0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 ...
0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 ...
0.000000 0.000000 0.000000 1.000000 18.735231 -5.666687 -4.541196 ...
  1. *_skel_local.txt contains the Euler angles of local transformation for each joint in each frame.
  • The first line has two integers: frameCount and boneCount, which are the same as the skeletal animation file.
  • Each subsequent line is a frame with boneCount sets of Euler angles.
  • The rotation order of the Euler angles is stored in the next file.
  • The root joint contains Euler angles and positions, while all other joints contain just Euler angles. There will be 3 + 3 * boneCount numbers on each line.
27 83
0.019251 0.079420 0.049618 0.657645 87.535782 2.391427 ...
0.016953 0.083084 0.038091 0.214333 87.434326 2.976235 ...
  1. *_hierarchy.txt contains the parent-child hierarchy for each joint in each frame.
  • The first line contains the number of joints.
  • Each subsequent line is in the form of <JOINT INDEX> <PARENT INDEX> <ROTATION ORDER> <JOINT NAME>
  • If a joint has -1 as its parent index, then it is the root joint.
83
0 -1 EULER_XYZ newVegas:Hips
1 0 EULER_XYZ newVegas:Pelvis
  1. _binding_pose_local.txt contains the Euler angle of local transformation for each joint of the binding pose.
  • It has the same format as the _skel_local.txt file.
27 83
0.000000 0.000000 0.000000 0.000000 96.330055 9.825774...

TODO

  • Add support for using FBX files with only skeletal animation data. Currently, the FBX file must contain geometry, skinning, and animation data. This means that to download new animations for an existing character, you need to download another FBX file with redundant information.

fbx-extract's People

Contributors

sueda avatar ziyanxiong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fbx-extract's Issues

how to use skeletal animation

Hi, I tried to visualize the extracted skeletal animation. For the rest pose (1st frame), directly visualizing the bone positions (x,y,z) gives me a rest pose skeleton. For the animation frames, visualizing the bone positions does not give any meaningful skeleton. I am curious how can I get the correct skeleton sequence from the extracted skeletal animation.

I tried to guess the meaning of per frame rotation and translation (e.g. joint coordinate to world coordinate transform, world coordinate to joint coordinate transform, product of transformation matrix and bind matrix etc) and compute the per frame skeleton accordingly, but none of it correct. Maybe I am missing something.

BTW, my fbx file is downloaded from mixamo.

Texture extraction

  • If there are multiple texture files, the generated input.txt does not match the texture to the correct mesh.
  • The texture names may contain spaces, which may cause the parser to treat them as two separate entities.

Off-by-1 error due to Undefined Behavior

In fbx-extract on line 539 you have limbMap[limb] = (int)limbMap.size();
This has undefined behavior on which call (limbMap[limb] or limbMap.size()) gets evaluated first. This off-by-1 error causes a segfault error at line 807 if the order is not what is expected.
Fixing the code to look like:

int limbMapSize = (int)limbMap.size();
limbMap[limb] = limbMapSize;

solves the crashing problem with my machine and compiler.

CMake Error: Environment variable for GLM_INCLUDE_DIR

I git cloned the GLM library to the same directory that I've cloned fbx-extract. I went into the glm library and performed the cmake command:

/usr/include/glm/cmake$ cmake ..
-- GLM: Version 0.9.9.9
GLM: GCC - GNU compiler
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/include/glm/cmake

Following your instructions, I get a CMake error:

/usr/include/fbx-extract/build$ sudo cmake ..
CMake Error at CMakeLists.txt:31 (MESSAGE):
  Please point the environment variable GLM_INCLUDE_DIR to the root directory
  of your GLM installation.


-- Configuring incomplete, errors occurred!
See also "/usr/include/fbx-extract/build/CMakeFiles/CMakeOutput.log".

I'm using Ubuntu on Windows. Here is the end of my ~/.profile file:
export GLM_INCLUDE_DIR="/usr/include/glm"

And a sanity check:

/usr/include/fbx-extract/build$ echo $GLM_INCLUDE_DIR
/usr/include/glm

What have I done wrong?

run it on Linux

Hi, I would really like to try this out.

could you please give us more info how to make it run ?

I would like to run it on a Linux environment if that's possible.

Best,
Albion

Segmentation fault error

Hello, thank you for creating wonderful program.

I have a question.
I tried this program but segmentation fault error occurred.

My fbx file is simple.
My fbx file has 3d object data, skin and animation.

If you know this error, Please give me something suggests.

=== geometry ===
pSphere1: 2280 verts, 439 unique

pSphere2: 2280 verts, 439 unique
Saving to bone_pSphere1.obj
Saving to bone_pSphere2.obj
=== skin ===
pSphere1: 2280 vertices
pSphere2: 2280 vertices
Saving to bone_pSphere1_skin.txt
Saving to bone_pSphere2_skin.txt
=== skeleton ===
2 clusters
zsh: segmentation fault ./fbx-extract

Screen Shot 2022-01-09 at 0 55 52

missing <cstring> library in main.cpp?

Running the make command in the build instructions produces an Error 2 in the make file, and the traceback suggests that you need to append #include to the header of main.cpp.

/usr/include/fbx-extract$ sudo make
[ 25%] Building CXX object CMakeFiles/fbx-extract.dir/src/main.cpp.o
/usr/include/fbx-extract/src/main.cpp: In function ‘bool saveSkin(const ofbx::IScene*)’:
/usr/include/fbx-extract/src/main.cpp:453:20: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
  453 |   fprintf(fp, "%d %d %d\n", vertex_count, limbVec.size(), mesh.maxInfluences);
      |                   ~^                      ~~~~~~~~~~~~~~
      |                    |                                  |
      |                    int                                std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |                   %ld
/usr/include/fbx-extract/src/main.cpp: In function ‘bool saveAnim(const ofbx::IScene*)’:
/usr/include/fbx-extract/src/main.cpp:727:9: error: ‘strcmp’ was not declared in this scope
  727 |      if(strcmp(child->name, "R") == 0) {
      |         ^~~~~~
/usr/include/fbx-extract/src/main.cpp:18:1: note: ‘strcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
   17 | #include <math.h>
  +++ |+#include <cstring>
   18 |
/usr/include/fbx-extract/src/main.cpp:828:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
  828 |  fprintf(fp, "%d %d\n", key_count_max, limbVec.size());
      |                  ~^                    ~~~~~~~~~~~~~~
      |                   |                                |
      |                   int                              std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |                  %ld
/usr/include/fbx-extract/src/main.cpp: In function ‘bool saveInputfile()’:
/usr/include/fbx-extract/src/main.cpp:878:33: warning: format not a string literal and no format arguments [-Wformat-security]
  878 |  fprintf(fp, TEXTURENAME.c_str());
      |                                 ^
/usr/include/fbx-extract/src/main.cpp:881:31: warning: format not a string literal and no format arguments [-Wformat-security]
  881 |  fprintf(fp, file_name.c_str());
      |                               ^
/usr/include/fbx-extract/src/main.cpp:887:33: warning: format not a string literal and no format arguments [-Wformat-security]
  887 |   fprintf(fp, input_line.c_str());
      |                                 ^
/usr/include/fbx-extract/src/main.cpp: In function ‘bool saveLocalTransfomfile()’:
/usr/include/fbx-extract/src/main.cpp:1022:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
 1022 |  fprintf(fp, "%d\n",limbVec.size());
      |               ~^    ~~~~~~~~~~~~~~
      |                |                |
      |                int              std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |               %ld
/usr/include/fbx-extract/src/main.cpp:1035:20: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
 1035 |  fprintf(fp2, "%d %d\n", key_count_max, limbVec.size());
      |                   ~^                    ~~~~~~~~~~~~~~
      |                    |                                |
      |                    int                              std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |                   %ld
/usr/include/fbx-extract/src/main.cpp:1082:10: error: ‘strcmp’ was not declared in this scope
 1082 |      if (strcmp(child->name, "R") == 0) {
      |          ^~~~~~
/usr/include/fbx-extract/src/main.cpp:1082:10: note: ‘strcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
/usr/include/fbx-extract/src/main.cpp:1181:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
 1181 |  fprintf(fp, "%d\n", limbVec.size());
      |               ~^     ~~~~~~~~~~~~~~
      |                |                 |
      |                int               std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |               %ld
/usr/include/fbx-extract/src/main.cpp:1196:28: warning: format not a string literal and no format arguments [-Wformat-security]
 1196 |    fprintf(fp, limbVec[j]->name);
/usr/include/fbx-extract/src/main.cpp:1217:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
 1217 |  fprintf(fp, "%d %d\n", key_count_max, limbVec.size());
      |                  ~^                    ~~~~~~~~~~~~~~
      |                   |                                |
      |                   int                              std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |                  %ld
make[2]: *** [CMakeFiles/fbx-extract.dir/build.make:63: CMakeFiles/fbx-extract.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/fbx-extract.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
```/usr/include/fbx-extract$ sudo make
[ 25%] Building CXX object CMakeFiles/fbx-extract.dir/src/main.cpp.o
/usr/include/fbx-extract/src/main.cpp: In function ‘bool saveSkin(const ofbx::IScene*)’:
/usr/include/fbx-extract/src/main.cpp:453:20: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
  453 |   fprintf(fp, "%d %d %d\n", vertex_count, limbVec.size(), mesh.maxInfluences);
      |                   ~^                      ~~~~~~~~~~~~~~
      |                    |                                  |
      |                    int                                std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |                   %ld
/usr/include/fbx-extract/src/main.cpp: In function ‘bool saveAnim(const ofbx::IScene*)’:
/usr/include/fbx-extract/src/main.cpp:727:9: error: ‘strcmp’ was not declared in this scope
  727 |      if(strcmp(child->name, "R") == 0) {
      |         ^~~~~~
/usr/include/fbx-extract/src/main.cpp:18:1: note: ‘strcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
   17 | #include <math.h>
  +++ |+#include <cstring>
   18 |
/usr/include/fbx-extract/src/main.cpp:828:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
  828 |  fprintf(fp, "%d %d\n", key_count_max, limbVec.size());
      |                  ~^                    ~~~~~~~~~~~~~~
      |                   |                                |
      |                   int                              std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |                  %ld
/usr/include/fbx-extract/src/main.cpp: In function ‘bool saveInputfile()’:
/usr/include/fbx-extract/src/main.cpp:878:33: warning: format not a string literal and no format arguments [-Wformat-security]
  878 |  fprintf(fp, TEXTURENAME.c_str());
      |                                 ^
/usr/include/fbx-extract/src/main.cpp:881:31: warning: format not a string literal and no format arguments [-Wformat-security]
  881 |  fprintf(fp, file_name.c_str());
      |                               ^
/usr/include/fbx-extract/src/main.cpp:887:33: warning: format not a string literal and no format arguments [-Wformat-security]
  887 |   fprintf(fp, input_line.c_str());
      |                                 ^
/usr/include/fbx-extract/src/main.cpp: In function ‘bool saveLocalTransfomfile()’:
/usr/include/fbx-extract/src/main.cpp:1022:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
 1022 |  fprintf(fp, "%d\n",limbVec.size());
      |               ~^    ~~~~~~~~~~~~~~
      |                |                |
      |                int              std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |               %ld
/usr/include/fbx-extract/src/main.cpp:1035:20: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
 1035 |  fprintf(fp2, "%d %d\n", key_count_max, limbVec.size());
      |                   ~^                    ~~~~~~~~~~~~~~
      |                    |                                |
      |                    int                              std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |                   %ld
/usr/include/fbx-extract/src/main.cpp:1082:10: error: ‘strcmp’ was not declared in this scope
 1082 |      if (strcmp(child->name, "R") == 0) {
      |          ^~~~~~
/usr/include/fbx-extract/src/main.cpp:1082:10: note: ‘strcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
/usr/include/fbx-extract/src/main.cpp:1181:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
 1181 |  fprintf(fp, "%d\n", limbVec.size());
      |               ~^     ~~~~~~~~~~~~~~
      |                |                 |
      |                int               std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |               %ld
/usr/include/fbx-extract/src/main.cpp:1196:28: warning: format not a string literal and no format arguments [-Wformat-security]
 1196 |    fprintf(fp, limbVec[j]->name);
/usr/include/fbx-extract/src/main.cpp:1217:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘std::vector<const ofbx::Object*>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
 1217 |  fprintf(fp, "%d %d\n", key_count_max, limbVec.size());
      |                  ~^                    ~~~~~~~~~~~~~~
      |                   |                                |
      |                   int                              std::vector<const ofbx::Object*>::size_type {aka long unsigned int}
      |                  %ld
make[2]: *** [CMakeFiles/fbx-extract.dir/build.make:63: CMakeFiles/fbx-extract.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/fbx-extract.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.