Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.3] FBX importer rewrite #42941

Merged
merged 1 commit into from Oct 30, 2020
Merged

Conversation

RevoluPowered
Copy link
Contributor

@RevoluPowered RevoluPowered commented Oct 20, 2020

Co-authored-by: Gordon MacPherson gordon@gordonite.tech
Co-authored-by: Andrea Catania info@andreacatania.com
Co-authored-by: K. S. Ernest (iFire) Lee ernest.lee@chibifire.com

This is a complete rewrite of the importer. It will give more deterministic behaviour and has been sponsored by IMVU inc, over 1 year has gone into the development of this importer to remove the burden of the FBX SDK.

This was my project for 1 entire year and I really enjoyed the opportunity to add to Godot.

Along the road of implementing fixes we implemented FBX pivots, animations and inheritance type handling, which in most cases works properly.

We have implemented animation and mesh skinning too this should work out of the box, if there are issues let us know.

It's designed so that you can expand this with ease, and fix bugs easily too.

It can import from Autodesk Maya and import into Godot, with pivots.

There are bits we could polish but for now this is good enough.

This was sponsored by IMVU, and a special thanks to everyone who supported this project.

Signed-off-by: Gordon MacPherson gordon@gordonite.tech

Additional fixes made before upstreaming:

  • fixed memory leaks
  • ensure consistent ordering on mac linux and windows for fbx tree. (very important for material import to be deterministic)
  • disabled incorrect warnings for fbx_material
  • added compatibility code for /RootNode/ so compat is not broken
  • Optimise FBX - directly import triangles
  • remove debug messages
  • add messages for mesh id, mesh re-import is sometimes slow and we need to know what mesh is being worked on
  • Document no longer uses unordered maps
  • Removed some usages of &GetRequiredToken replaced with safe *GetRequiredToken() function
  • Added parser debugging
  • Added ERR_FAIL_CONDS for unsupported mesh formats (we can add these later super easy to do now)
  • Add memory debugging for the Tokens and the TokenParser to make it safe
  • Add memory initialisation to mesh.cpp surface_tool.h and mesh.h
  • Initialise boolean flags properly
  • Refactored to correct naming for the fbx_mesh_data.h so you know what data you are working on
  • Disabled corruption caused by the FIXME:
  • Fixed document reading indexes and index_to_direct vs indexes mode
  • Fixed UV1 and UV2 coordinates
  • Fixed importer failing to import version 7700 files
  • Replaced memory handling in the FBX Document with pointers, before it was dereferencing invalid memory.
  • Fixed typed properties
  • Improved Document API
  • Fixed bug with ProcessDOMConnection() not working with the bool flag set to true.
  • Fixed FBX skinning not deforming for more than one single mesh
  • Fixed FBX skeleton mapping and skin mapping not being applied properly (now retrieved from document skin list)
  • Fixed set_bone_pose being used in final version()
  • Fixed material properties exceeding 1.0.
  • FBX Document parser revamped to use safe memory practices, and with graceful error messages.
  • ScopePtr, TokenPtr and various internal types have been fleshed out to use proper typedefs across the codebase.
  • Fixed memory leaks caused by token cleanup failing (now explicit cleanup step, no shared_ptr, etc)
  • Fixed bug with PropertyTable not reading all properties and not cleaning up properly.
  • Fixed smoothing groups not working
  • Fixed normal duplications
  • Fixed duplication check for pre-existing coordinates.
  • Fixed performance of vertex lookup in large meshes being slow, using lookup table separate to the data for indexing, this reduces import time from 10 minutes of bistro down to 30 seconds with NVIDIA bistro scene

Bugs/Features wish list:

  • locator bones
  • quat anim key interpolation (most fbx maya files have euler rotations from blender and maya, nobody uses this)
  • some rigs need skins tweaked
  • material mapping needs expanded, but this will be done for 4.0 as it requires rewrite.

Workarounds for issues found until we patch them:

  • mesh -> clear skin can resolve most of the bugs above.
  • locators can be worked around by removing them before exporting your rig.
  • some material properties wont always import, this is okay to override in the material properties.

If you are having issues or need support fear not!
Please provide minimal rigs which can reproduce issues as we can't spend a lot of time investigating each rig. We need a small example which breaks and we can then sort the problem. In some cases this is not possible so its okay to privately send models to us via IRC or a ticket and we can provide an email address, we won't reveal or disclose privately sent rig files to any companies, or to companies I work for, they will not be shared, only tested and bugs will be drawn up from the conclusions. Also include identifying information about what you did and how it didn't work. Please file each file separately in a bug report, unless the problem is the same.

@Chaosus Chaosus added this to the 3.2 milestone Oct 20, 2020
@RevoluPowered RevoluPowered force-pushed the fbx-3-2-2020 branch 2 times, most recently from c113e52 to 18cde7f Compare October 20, 2020 17:21
@akien-mga akien-mga changed the title FBX 3.2 [3.2] FBX imported rewrite Oct 20, 2020
@akien-mga akien-mga changed the title [3.2] FBX imported rewrite [3.2] FBX importer rewrite Oct 20, 2020
@akien-mga akien-mga requested a review from reduz October 20, 2020 17:39
@RevoluPowered RevoluPowered force-pushed the fbx-3-2-2020 branch 2 times, most recently from 5af73c3 to 621398b Compare October 20, 2020 18:06
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look in depth at the actual code as it's not my area of expertise, so I mostly left formatting/style comments.

Please also amend thirdparty/README.md to properly document the provenance of the thirdparty/assimp_fbx/ files, which commit they're from, and how to sync with upstream.

Similarly, COPYRIGHT.txt should have a change from ./thirdparty/assimp/ to ./thirdparty/assimp_fbx/.

modules/fbx/register_types.cpp Outdated Show resolved Hide resolved
modules/fbx/register_types.h Show resolved Hide resolved
modules/fbx/editor_scene_importer_fbx.h Outdated Show resolved Hide resolved
modules/fbx/editor_scene_importer_fbx.h Outdated Show resolved Hide resolved
modules/fbx/editor_scene_importer_fbx.cpp Show resolved Hide resolved
modules/fbx/data/fbx_bone.h Outdated Show resolved Hide resolved
modules/fbx/data/fbx_material.cpp Outdated Show resolved Hide resolved
modules/fbx/data/fbx_mesh_data.cpp Show resolved Hide resolved
modules/fbx/data/fbx_mesh_data.cpp Outdated Show resolved Hide resolved
modules/fbx/data/fbx_mesh_data.h Outdated Show resolved Hide resolved
@RevoluPowered
Copy link
Contributor Author

RevoluPowered commented Oct 23, 2020

Please also amend thirdparty/README.md to properly document the provenance of the thirdparty/assimp_fbx/ files, which commit they're from, and how to sync with upstream.

@akien-mga This can never ever be sync'd with assimp this is our own parser there is literally no way to merge them, I will mention this in the readme. It is heavily rewritten in some areas and can't be patched from assimp.

We heavily customised the document parser to remove:

  • third-party dependencies
  • no longer returns ANY assimp types, uses Vector3, Vector2 and Transform where relevant.
  • bad code / unsafe memory access
  • assertions
  • assimp logging
  • simplified it
  • many other things

Will get on the rest of the review stuff though thanks, I appreciate you spending time doing this, as it's a lot to review I will get on these today.

The only reason it still exists in third party is the licensing requirements.

@RevoluPowered RevoluPowered force-pushed the fbx-3-2-2020 branch 5 times, most recently from 82db4e6 to 76aea78 Compare October 26, 2020 18:17
@RevoluPowered
Copy link
Contributor Author

OK ready for review again @akien-mga

Tested with bistro too @reduz so should be good :)

Will put a trailer out for this too. (video/YT)

@RevoluPowered
Copy link
Contributor Author

Removed some dead code I found while I was doing my own review

@RevoluPowered
Copy link
Contributor Author

Static checks are gonna fail this is WIP now for the refactoring required

@RevoluPowered RevoluPowered force-pushed the fbx-3-2-2020 branch 2 times, most recently from b762b97 to a355e0f Compare October 28, 2020 17:29
@RevoluPowered
Copy link
Contributor Author

Okay ready for round 2 reviews! @akien-mga @reduz

Copy link
Member

@reduz reduz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are not really using Assimp, I would probably get rid of the namespace.

modules/fbx/fbx_parser/ByteSwapper.h Outdated Show resolved Hide resolved
@RevoluPowered
Copy link
Contributor Author

Additionally to my last review, please also update COPYRIGHT.txt in the root folder with:

diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt
index e72cbf606b..2cd1c6a63f 100644
--- a/COPYRIGHT.txt
+++ b/COPYRIGHT.txt
@@ -55,6 +55,13 @@ Comment: Godot Engine logo
 Copyright: 2017, Andrea Calabró
 License: CC-BY-3.0
 
+Files: ./modules/fbx/fbx_parser/
+Comment: Open Asset Import Library (assimp)
+Copyright: 2006-2016, assimp team
+ 2007-2020, Juan Linietsky, Ariel Manzur.
+ 2014-2020, Godot Engine contributors.
+License: BSD-3-clause and Expat
+
 Files: ./platform/android/java/aidl/com/android/vending/billing/IInAppBillingService.aidl
  ./platform/android/java/res/layout/status_bar_ongoing_event_progress_bar.xml
  ./platform/android/java/src/com/google/android/vending/expansion/downloader/*
@@ -110,11 +117,6 @@ Copyright: 2007, Starbreeze Studios
  2014-2020, Godot Engine contributors.
 License: Expat and Zlib
 
-Files: ./thirdparty/assimp/
-Comment: Open Asset Import Library (assimp)
-Copyright: 2006-2016, assimp team
-License: BSD-3-clause
-
 Files: ./thirdparty/bullet/
 Comment: Bullet Continuous Collision Detection and Physics Library
 Copyright: 2003-2013, Erwin Coumans

Done :)

Co-authored-by: Gordon MacPherson <gordon@gordonite.tech>
Co-authored-by: Andrea Catania <info@andreacatania.com>
Co-authored-by: K. S. Ernest (iFire) Lee <ernest.lee@chibifire.com>

This is a complete rewrite of the importer. It will give more deterministic behaviour and has been sponsored by IMVU inc, over 1 year has gone into the development of this importer to remove the burden of the FBX SDK.
This was my project for 1 entire year and I really enjoyed the opportunity to add to Godot.

Along the road of implementing fixes we implemented fbx pivots, animations and inheritance type handling, which in most cases works properly.
We have implemented animation and mesh skinning too this should work out of the box, if there are issues let us know.
It's designed so that you can expand this with ease, and fix bugs easily too.
It can import from Autodesk Maya and import into Godot, with pivots.
There are bits we could polish but for now this is good enough.

Additional fixes made before upstreaming:
- fixed memory leaks
- ensure consistent ordering on mac linux and windows for fbx tree. (very important for material import to be deterministic)
- disabled incorrect warnings for fbx_material
- added compatibility code for /RootNode/ so compat is not broken
- Optimise FBX - directly import triangles
- remove debug messages
- add messages for mesh id, mesh re-import is sometimes slow and we need to know what mesh is being worked on
- Document no longer uses unordered maps
- Removed some usages of &GetRequiredToken replaced with safe *GetRequiredToken() function
- Added parser debugging
- Added ERR_FAIL_CONDS for unsupported mesh formats (we can add these later super easy to do now)
- Add memory debugging for the Tokens and the TokenParser to make it safe
- Add memory initialisation to mesh.cpp surface_tool.h and mesh.h
- Initialise boolean flags properly
- Refactored to correct naming for the fbx_mesh_data.h so you know what data you are working on
- Disabled corruption caused by the FIXME:
- Fixed document reading indexes and index_to_direct vs indexes mode
- Fixed UV1 and UV2 coordinates
- Fixed importer failing to import version 7700 files
- Replaced memory handling in the FBX Document with pointers, before it was dereferencing invalid memory.
- Fixed typed properties
- Improved Document API
- Fixed bug with ProcessDOMConnection() not working with the bool flag set to true.
- Fixed FBX skinning not deforming for more than one single mesh
- Fixed FBX skeleton mapping and skin mapping not being applied properly (now retrieved from document skin list)
- Fixed set_bone_pose being used in final version()
- Fixed material properties exceeding 1.0.
- FBX Document parser revamped to use safe memory practices, and with graceful error messages.
- ScopePtr, TokenPtr and various internal types have been fleshed out to use proper typedefs across the codebase.
- Fixed memory leaks caused by token cleanup failing (now explicit cleanup step, no shared_ptr, etc)
- Fixed bug with PropertyTable not reading all properties and not cleaning up properly.
- Fixed smoothing groups not working
- Fixed normal duplications
- Fixed duplication check for pre-existing coordinates.
- Fixed performance of vertex lookup in large meshes being slow, using lookup table separate to the data for indexing, this reduces import time from 10 minutes of bistro down to 30 seconds.
- Fixed includes requiring absolute path in headers and cpp files using CPPPath.

Bugs/Features wish list:
- locator bones
- quat anim key interpolation (most fbx maya files have euler rotations from blender and maya, nobody uses this)
- some rigs skins scale up when SSC enabled inconsistently per bone
- some skins can disappear entirely
- material mapping needs expanded, but this will be done for 4.0 as it requires rewrite.

Workarounds for issues found until we patch them:
- mesh -> clear skin can resolve most of the bugs above.
- locators can be worked around by removing them before exporting your rig.
- some material properties wont always import, this is okay to override in the material properties.

**If you are having issues or need support fear not!**
Please provide minimal rigs which can reproduce issues as we can't spend a lot of time investigating each rig. We need a small example which breaks and we can then sort the problem. In some cases this is not possible so its okay to privately send models to us via IRC or a ticket and we can provide an email address, we won't reveal or disclose privately sent rig files to any companies, or to companies I work for, they will not be shared, only tested and bugs will be drawn up from the conclusions. Also include identifying information about what you did and how it didn't work. Please file each file separately in a bug report, unless the problem is the same.
This was sponsored by IMVU, and a special thanks to everyone who supported this project.

Signed-off-by: Gordon MacPherson <gordon@gordonite.tech>
@RevoluPowered
Copy link
Contributor Author

RevoluPowered commented Oct 30, 2020

Fixed file-format (i added newlines to make the file width better for git) in README.md

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

@akien-mga akien-mga merged commit 4f908fb into godotengine:3.2 Oct 30, 2020
@akien-mga
Copy link
Member

Thanks a ton for this huge and amazing improvement!

@RevoluPowered
Copy link
Contributor Author

<3 so happy

@NathanWarden
Copy link
Contributor

Yes, awesome job!!!

@Sslaxx
Copy link

Sslaxx commented Oct 30, 2020

Any of this going to be upstreamed to mainline assimp?

@barbaros83
Copy link

great work !, does gltf also depend on assimp ? and if so is there going to be a rewrite for gltf aswel ?

@aaronfranke
Copy link
Member

Why was this PR merged into 3.2 instead of master? This is a huge change so it's extremely likely to cause regressions (and it has). Such things are not really appropriate for a stable branch. Additionally, regardless of whether it would be accepted into 3.2, PRs should target master as that's where development happens and the source of all future stable release branches (see here).

@akien-mga
Copy link
Member

@aaronfranke Because we decided to make an exception. I know the policy, I wrote it.

There's a matching PR for the master branch: #41985. We trust that @RevoluPowered will keep updating it to match the latest state of the 3.2 PR, fix master-specific issues, and additionally add fixes for any regressions that will have been identified in the 3.2.4 beta builds.

Godot 4.0 changes things significantly around the import pipeline, which makes the two versions of the PR difficult to keep in sync at all times, and there are outstanding issues that @RevoluPowered needs to solve in the master branch. On the other hand, the 3.2 branch is where all the main development was done for this feature over one year, and has been heavily tested in production on hundreds of models. The master branch is too unreliable to even do reliable testing of asset imports due to many bugs related to its pre-alpha status. Finally, 3.2.4 is planned to be a feature-heavy release with a longer development cycle, and many similarly big features have been merged like GLES3 batching, which will imply several beta builds, and plenty of time to iron out issues created by this PR.

TL;DR: @reduz and I agreed to make an exception to the policy. That doesn't change the policy.

@akien-mga
Copy link
Member

Why should I have to justify release management decisions all the time?

@reduz
Copy link
Member

reduz commented Oct 31, 2020

Geez guys, can you have a bit more common sense instead of wasting time discussing rules for the sake of it? FBX is almost unusable in its current state. Anything not a box will most likely break when you import it.

This PR fixes pretty much every problem and lets you import massively complex scenes without issue. Yes, it may break compatibility a bit, but do you think any user really cares about that when in exchange they can have an importer that will work with anything they throw at?

It also needs testing as soon as possible because there is a company paying for it that will fix any further problem that users have wit it. If we wait until 4.0 is out, it may no longer be the case by then. This is why the PR is aimed mainly at 3.2 and then it will be ported to 4.0 as an exception.

Really, just try to make an effort to see the whole picture before going into pointless rants. This is not the first time it happens, so If you need us explaining you the decisions all the time while others seem to grasp them fine, either try to get more involved in the development process so you can understand them better too or, if this is not possible, then at least try to assume that those deciding on these things have a good judgment and trust them. If you have any doubts about it, simply ask them privately or better yet, on IRC,, so any other contributor can answer you too.

@aaronfranke
Copy link
Member

This PR fixes pretty much every problem and lets you import massively complex scenes without issue. Yes, it may break compatibility a bit, but do you think any user really cares about that when in exchange they can have an importer that will work with anything they throw at?

The same can be said about the new navigation system, but this wasn't backported to 3.2.

@akien-mga As you said, this is an exception. I am not questioning whether or not you know the policy you wrote, I am questioning the exceptions. The explanation you gave is perfectly fine.

@reduz I don't really see the problem with asking this publicly on GitHub, other people may have the same concerns and not everyone uses IRC. For archival purposes, it's also much more difficult to dig up an IRC log instead of just looking at the PR. Sometimes @akien-mga posts IRC snippets on GitHub, perhaps this should be done more often?

@Calinou
Copy link
Member

Calinou commented Oct 31, 2020

The navigation system, while not really usable for complex use cases in 3.2.x, is still relied on by many people in production for various needs. The new NavigationServer API isn't quite comparable at all, so upgrading can take a while. It's a bit different from the current FBX support, as I believe nobody was relying on it beforehand.

@Duroxxigar
Copy link
Contributor

Duroxxigar commented Oct 31, 2020

@Calinou The new navigation system can be used in roughly the same manner as it is today. Bake navmesh -> call get_simple_path(), handle how you see fit. You even set up the scene tree in the same manner if you so choose. It just also provides much much more. There may be a few API changes, but the benefits far outweigh the cost in my opinion.

With the announcement that 4.0 will only have Vulkan, users who cannot use Vulkan and will be stuck on 3.x version will not have this until they can update to 4.1 which will be 2022 at best.

@akien-mga
Copy link
Member

This is not the topic, but I don't remember ever saying that the new NavigationServer API couldn't be backported to the 3.2 branch. On the other hand, the current implementation fully broke compatibility with the previous API and cannot be backported as is. It's also not something that I would work on myself.

So if a contributor wants to make a backport that doesn't break compatibility for 3.2 users, then it can be considered to be integrated in a 3.2.x release eventually. (Not making any promise here, but it can be assessed in the PR.)

@akien-mga akien-mga modified the milestones: 3.2, 3.3 Apr 21, 2021
@Gusher
Copy link

Gusher commented Nov 10, 2021

Is embedded collision support being planned? Example, mymodel, mymodel_collision .. mymodel2, mymodel2_collision and so on.,,,, will embedded standard pbr maps be detected automatically?

@Calinou
Copy link
Member

Calinou commented Nov 10, 2021

Is embedded collision support being planned? Example, mymodel, mymodel_collision .. mymodel2, mymodel2_collision and so on.,,,, will embedded standard pbr maps be detected automatically?

The FBX importer currently doesn't have any active maintainer, so I wouldn't expect new features to be added to it anytime soon (not for 4.0 at least).

@aaronfranke
Copy link
Member

@Gusher Not FBX, but I implemented support for importing and exporting physics collisions in GLTF in #69266. This may be suitable for your uses if you want to store physics information in a 3D model file.

@aaronfranke aaronfranke changed the title [3.2] FBX importer rewrite [3.3] FBX importer rewrite Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet