virtualx-engine/modules/fbx/data/fbx_material.cpp

593 lines
23 KiB
C++
Raw Normal View History

Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
/*************************************************************************/
/* fbx_material.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "fbx_material.h"
#include "scene/resources/material.h"
#include "scene/resources/texture.h"
[fbx] bugfixes skinning, materials and debugging info, merry xmas 🎄 Better materials: - default values will no longer trigger things like emission, clear coat being enabled etc incorrectly, mostly importers misunderstand this value, a value of 1 is not actually enabled emission, it must have a non zero setting other than emission value for the emission flags to actually be enabled correctly in our engine #42386 - lambert materials are warned against significantly, do not use Lambert in Godot, use a PBR material like Ai Standard Surface (it's like going from low quality to high definition in terms of output in scenes and on assets) - roughness values are calculated correctly in this version Fixes for normal's array - some normal's from some files were dropped and generated, this is now fixed. - FBX indexing for items with (-1) index, for normal data is supported, this is super helpful at increasing our range of compatibility of FBX meshes. Fix bone rest data **no longer requiring go to bind pose in Maya and various applications** - Partial fix for #43688 Validation tools added for validating large projects Provide package name, vendor and FBX vendor in the log. Implemented metadata properties so we can read extra document info required for bug reporting **FBX 2011 (version 7200)** is unsupported now, you must re-export your file in Maya or Max to upgrade the file format. Fixes skin bind poses being generated based on node xforms in the scene Fixes duplicate bones being added to skin and prevents add_bones from registering skeleton bones it now registers skin bind poses, but this should really be documented in the engine correctly right now it doesn't tell you this is the case.
2020-12-02 16:38:11 +01:00
#include "tools/validation_tools.h"
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
String FBXMaterial::get_material_name() const {
return material_name;
}
void FBXMaterial::set_imported_material(FBXDocParser::Material *p_material) {
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
material = p_material;
}
void FBXMaterial::add_search_string(String p_filename, String p_current_directory, String search_directory, Vector<String> &texture_search_paths) {
if (search_directory.empty()) {
texture_search_paths.push_back(p_current_directory.get_base_dir().plus_file(p_filename));
} else {
texture_search_paths.push_back(p_current_directory.get_base_dir().plus_file(search_directory + "/" + p_filename));
texture_search_paths.push_back(p_current_directory.get_base_dir().plus_file("../" + search_directory + "/" + p_filename));
}
}
String find_file(const String &p_base, const String &p_file_to_find) {
_Directory dir;
dir.open(p_base);
dir.list_dir_begin();
String n = dir.get_next();
while (n != String()) {
if (n == "." || n == "..") {
n = dir.get_next();
continue;
}
if (dir.current_is_dir()) {
// Don't use `path_to` or the returned path will be wrong.
const String f = find_file(p_base + "/" + n, p_file_to_find);
if (f != "") {
return f;
}
} else if (n == p_file_to_find) {
return p_base + "/" + n;
}
n = dir.get_next();
}
dir.list_dir_end();
return String();
}
// fbx will not give us good path information and let's not regex them to fix them
// no relative paths are in fbx generally they have a rel field but it's populated incorrectly by the SDK.
String FBXMaterial::find_texture_path_by_filename(const String p_filename, const String p_current_directory) {
_Directory dir;
Vector<String> paths;
add_search_string(p_filename, p_current_directory, "", paths);
add_search_string(p_filename, p_current_directory, "texture", paths);
add_search_string(p_filename, p_current_directory, "textures", paths);
add_search_string(p_filename, p_current_directory, "Textures", paths);
add_search_string(p_filename, p_current_directory, "materials", paths);
add_search_string(p_filename, p_current_directory, "mats", paths);
add_search_string(p_filename, p_current_directory, "pictures", paths);
add_search_string(p_filename, p_current_directory, "images", paths);
for (int i = 0; i < paths.size(); i++) {
if (dir.file_exists(paths[i])) {
return paths[i];
}
}
// We were not able to find the texture in the common locations,
// try to find it into the project globally.
// The common textures can be stored into one of those folders:
// res://asset
// res://texture
// res://material
// res://mat
// res://image
// res://picture
//
// Note the folders can also be called with custom names, like:
// res://my_assets
// since the keyword `asset` is into the directory name the textures will be
// searched there too.
dir.open("res://");
dir.list_dir_begin();
String n = dir.get_next();
while (n != String()) {
if (n == "." || n == "..") {
n = dir.get_next();
continue;
}
if (dir.current_is_dir()) {
const String lower_n = n.to_lower();
if (
// Don't need to use plural.
lower_n.find("asset") >= 0 ||
lower_n.find("texture") >= 0 ||
lower_n.find("material") >= 0 ||
lower_n.find("mat") >= 0 ||
lower_n.find("image") >= 0 ||
lower_n.find("picture") >= 0) {
// Don't use `path_to` or the returned path will be wrong.
const String f = find_file(String("res://") + n, p_filename);
if (f != "") {
return f;
}
}
}
n = dir.get_next();
}
dir.list_dir_end();
return "";
}
FBXMaterial::MaterialInfo FBXMaterial::extract_material_info(const FBXDocParser::Material *material) const {
MaterialInfo mat_info;
// TODO Layered textures are a collection on textures stored into an array.
// Extract layered textures is not yet supported. Per each texture in the
// layered texture array you want to use the below method to extract those.
for (std::pair<std::string, const FBXDocParser::Texture *> texture : material->Textures()) {
const std::string &fbx_mapping_name = texture.first;
if (fbx_feature_mapping_desc.count(fbx_mapping_name) > 0) {
// This is a feature not a normal texture.
mat_info.features.push_back(fbx_feature_mapping_desc.at(fbx_mapping_name));
continue;
}
ERR_CONTINUE_MSG(fbx_texture_mapping_desc.count(fbx_mapping_name) <= 0, "This FBX has a material with mapping name: " + String(fbx_mapping_name.c_str()) + " which is not yet supported by this importer. Consider open an issue so we can support it.");
const String absoulte_fbx_file_path = texture.second->FileName().c_str();
const String file_extension = absoulte_fbx_file_path.get_extension().to_upper();
const String file_extension_uppercase = file_extension.to_upper();
// TODO: one day we can add this
if (file_extension.empty()) {
continue; // skip it
}
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
// TODO: we don't support EMBED for DDS and TGA.
ERR_CONTINUE_MSG(
file_extension_uppercase != "PNG" &&
file_extension_uppercase != "JPEG" &&
file_extension_uppercase != "JPG" &&
file_extension_uppercase != "TGA" &&
file_extension_uppercase != "WEBP" &&
file_extension_uppercase != "DDS",
"The FBX file contains a texture with an unrecognized extension: " + file_extension_uppercase);
const String texture_name = absoulte_fbx_file_path.get_file();
print_verbose("Getting FBX mapping mode for " + String(fbx_mapping_name.c_str()));
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
const SpatialMaterial::TextureParam mapping_mode = fbx_texture_mapping_desc.at(fbx_mapping_name);
print_verbose("Set FBX mapping mode to " + get_texture_param_name(mapping_mode));
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
TextureFileMapping file_mapping;
file_mapping.map_mode = mapping_mode;
file_mapping.name = texture_name;
file_mapping.texture = texture.second;
mat_info.textures.push_back(file_mapping);
// Make sure to active the various features.
switch (mapping_mode) {
case SpatialMaterial::TextureParam::TEXTURE_ALBEDO:
case SpatialMaterial::TextureParam::TEXTURE_METALLIC:
case SpatialMaterial::TextureParam::TEXTURE_ROUGHNESS:
case SpatialMaterial::TextureParam::TEXTURE_FLOWMAP:
case SpatialMaterial::TextureParam::TEXTURE_REFRACTION:
case SpatialMaterial::TextureParam::TEXTURE_MAX:
// No features required.
break;
case SpatialMaterial::TextureParam::TEXTURE_EMISSION:
mat_info.features.push_back(SpatialMaterial::Feature::FEATURE_EMISSION);
break;
case SpatialMaterial::TextureParam::TEXTURE_NORMAL:
mat_info.features.push_back(SpatialMaterial::Feature::FEATURE_NORMAL_MAPPING);
break;
case SpatialMaterial::TextureParam::TEXTURE_RIM:
mat_info.features.push_back(SpatialMaterial::Feature::FEATURE_RIM);
break;
case SpatialMaterial::TextureParam::TEXTURE_CLEARCOAT:
mat_info.features.push_back(SpatialMaterial::Feature::FEATURE_CLEARCOAT);
break;
case SpatialMaterial::TextureParam::TEXTURE_AMBIENT_OCCLUSION:
mat_info.features.push_back(SpatialMaterial::Feature::FEATURE_AMBIENT_OCCLUSION);
break;
case SpatialMaterial::TextureParam::TEXTURE_DEPTH:
mat_info.features.push_back(SpatialMaterial::Feature::FEATURE_DEPTH_MAPPING);
break;
case SpatialMaterial::TextureParam::TEXTURE_SUBSURFACE_SCATTERING:
mat_info.features.push_back(SpatialMaterial::Feature::FEATURE_SUBSURACE_SCATTERING);
break;
case SpatialMaterial::TextureParam::TEXTURE_TRANSMISSION:
mat_info.features.push_back(SpatialMaterial::Feature::FEATURE_TRANSMISSION);
break;
case SpatialMaterial::TextureParam::TEXTURE_DETAIL_ALBEDO:
case SpatialMaterial::TextureParam::TEXTURE_DETAIL_MASK:
case SpatialMaterial::TextureParam::TEXTURE_DETAIL_NORMAL:
mat_info.features.push_back(SpatialMaterial::Feature::FEATURE_DETAIL);
break;
}
}
return mat_info;
}
template <class T>
T extract_from_prop(FBXDocParser::PropertyPtr prop, const T &p_default, const std::string &p_name, const String &p_type) {
ERR_FAIL_COND_V_MSG(prop == nullptr, p_default, "invalid property passed to extractor");
const FBXDocParser::TypedProperty<T> *val = dynamic_cast<const FBXDocParser::TypedProperty<T> *>(prop);
ERR_FAIL_COND_V_MSG(val == nullptr, p_default, "The FBX is corrupted, the property `" + String(p_name.c_str()) + "` is a `" + String(typeid(*prop).name()) + "` but should be a " + p_type);
// Make sure to not lost any eventual opacity.
return val->Value();
}
Ref<SpatialMaterial> FBXMaterial::import_material(ImportState &state) {
ERR_FAIL_COND_V(material == nullptr, nullptr);
const String p_fbx_current_directory = state.path;
Ref<SpatialMaterial> spatial_material;
// read the material file
// is material two sided
// read material name
print_verbose("[material] material name: " + ImportUtils::FBXNodeToName(material->Name()));
material_name = ImportUtils::FBXNodeToName(material->Name());
// Extract info.
MaterialInfo material_info = extract_material_info(material);
// Extract other parameters info.
for (FBXDocParser::LazyPropertyMap::value_type iter : material->Props()->GetLazyProperties()) {
const std::string name = iter.first;
if (name.empty()) {
continue;
}
PropertyDesc desc = PROPERTY_DESC_NOT_FOUND;
if (fbx_properties_desc.count(name) > 0) {
desc = fbx_properties_desc.at(name);
}
// check if we can ignore this it will be done at the next phase
if (desc == PROPERTY_DESC_NOT_FOUND || desc == PROPERTY_DESC_IGNORE) {
// count the texture mapping references. Skip this one if it's found and we can't look up a property value.
if (fbx_texture_mapping_desc.count(name) > 0) {
continue; // safe to ignore it's a texture mapping.
}
}
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
if (desc == PROPERTY_DESC_IGNORE) {
[fbx] bugfixes skinning, materials and debugging info, merry xmas 🎄 Better materials: - default values will no longer trigger things like emission, clear coat being enabled etc incorrectly, mostly importers misunderstand this value, a value of 1 is not actually enabled emission, it must have a non zero setting other than emission value for the emission flags to actually be enabled correctly in our engine #42386 - lambert materials are warned against significantly, do not use Lambert in Godot, use a PBR material like Ai Standard Surface (it's like going from low quality to high definition in terms of output in scenes and on assets) - roughness values are calculated correctly in this version Fixes for normal's array - some normal's from some files were dropped and generated, this is now fixed. - FBX indexing for items with (-1) index, for normal data is supported, this is super helpful at increasing our range of compatibility of FBX meshes. Fix bone rest data **no longer requiring go to bind pose in Maya and various applications** - Partial fix for #43688 Validation tools added for validating large projects Provide package name, vendor and FBX vendor in the log. Implemented metadata properties so we can read extra document info required for bug reporting **FBX 2011 (version 7200)** is unsupported now, you must re-export your file in Maya or Max to upgrade the file format. Fixes skin bind poses being generated based on node xforms in the scene Fixes duplicate bones being added to skin and prevents add_bones from registering skeleton bones it now registers skin bind poses, but this should really be documented in the engine correctly right now it doesn't tell you this is the case.
2020-12-02 16:38:11 +01:00
//WARN_PRINT("[Ignored] The FBX material parameter: `" + String(name.c_str()) + "` is ignored.");
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
continue;
} else {
print_verbose("FBX Material parameter: " + String(name.c_str()));
[fbx] bugfixes skinning, materials and debugging info, merry xmas 🎄 Better materials: - default values will no longer trigger things like emission, clear coat being enabled etc incorrectly, mostly importers misunderstand this value, a value of 1 is not actually enabled emission, it must have a non zero setting other than emission value for the emission flags to actually be enabled correctly in our engine #42386 - lambert materials are warned against significantly, do not use Lambert in Godot, use a PBR material like Ai Standard Surface (it's like going from low quality to high definition in terms of output in scenes and on assets) - roughness values are calculated correctly in this version Fixes for normal's array - some normal's from some files were dropped and generated, this is now fixed. - FBX indexing for items with (-1) index, for normal data is supported, this is super helpful at increasing our range of compatibility of FBX meshes. Fix bone rest data **no longer requiring go to bind pose in Maya and various applications** - Partial fix for #43688 Validation tools added for validating large projects Provide package name, vendor and FBX vendor in the log. Implemented metadata properties so we can read extra document info required for bug reporting **FBX 2011 (version 7200)** is unsupported now, you must re-export your file in Maya or Max to upgrade the file format. Fixes skin bind poses being generated based on node xforms in the scene Fixes duplicate bones being added to skin and prevents add_bones from registering skeleton bones it now registers skin bind poses, but this should really be documented in the engine correctly right now it doesn't tell you this is the case.
2020-12-02 16:38:11 +01:00
// Check for Diffuse material system / lambert materials / legacy basically
if (name == "Diffuse" && !warning_non_pbr_material) {
ValidationTracker::get_singleton()->add_validation_error(state.path, "Invalid material settings change to Ai Standard Surface shader, mat name: " + material_name.c_escape());
warning_non_pbr_material = true;
}
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
}
// DISABLE when adding support for all weird and wonderful material formats
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
if (desc == PROPERTY_DESC_NOT_FOUND) {
continue;
}
ERR_CONTINUE_MSG(desc == PROPERTY_DESC_NOT_FOUND, "The FBX material parameter: `" + String(name.c_str()) + "` was not recognized. Please open an issue so we can add the support to it.");
const FBXDocParser::PropertyTable *tbl = material->Props();
FBXDocParser::PropertyPtr prop = tbl->Get(name);
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
ERR_CONTINUE_MSG(prop == nullptr, "This file may be corrupted because is not possible to extract the material parameter: " + String(name.c_str()));
if (spatial_material.is_null()) {
// Done here so if no data no material is created.
spatial_material.instance();
}
const FBXDocParser::TypedProperty<real_t> *real_value = dynamic_cast<const FBXDocParser::TypedProperty<real_t> *>(prop);
const FBXDocParser::TypedProperty<Vector3> *vector_value = dynamic_cast<const FBXDocParser::TypedProperty<Vector3> *>(prop);
if (!real_value && !vector_value) {
[fbx] bugfixes skinning, materials and debugging info, merry xmas 🎄 Better materials: - default values will no longer trigger things like emission, clear coat being enabled etc incorrectly, mostly importers misunderstand this value, a value of 1 is not actually enabled emission, it must have a non zero setting other than emission value for the emission flags to actually be enabled correctly in our engine #42386 - lambert materials are warned against significantly, do not use Lambert in Godot, use a PBR material like Ai Standard Surface (it's like going from low quality to high definition in terms of output in scenes and on assets) - roughness values are calculated correctly in this version Fixes for normal's array - some normal's from some files were dropped and generated, this is now fixed. - FBX indexing for items with (-1) index, for normal data is supported, this is super helpful at increasing our range of compatibility of FBX meshes. Fix bone rest data **no longer requiring go to bind pose in Maya and various applications** - Partial fix for #43688 Validation tools added for validating large projects Provide package name, vendor and FBX vendor in the log. Implemented metadata properties so we can read extra document info required for bug reporting **FBX 2011 (version 7200)** is unsupported now, you must re-export your file in Maya or Max to upgrade the file format. Fixes skin bind poses being generated based on node xforms in the scene Fixes duplicate bones being added to skin and prevents add_bones from registering skeleton bones it now registers skin bind poses, but this should really be documented in the engine correctly right now it doesn't tell you this is the case.
2020-12-02 16:38:11 +01:00
//WARN_PRINT("unsupported datatype in property: " + String(name.c_str()));
continue;
}
[fbx] bugfixes skinning, materials and debugging info, merry xmas 🎄 Better materials: - default values will no longer trigger things like emission, clear coat being enabled etc incorrectly, mostly importers misunderstand this value, a value of 1 is not actually enabled emission, it must have a non zero setting other than emission value for the emission flags to actually be enabled correctly in our engine #42386 - lambert materials are warned against significantly, do not use Lambert in Godot, use a PBR material like Ai Standard Surface (it's like going from low quality to high definition in terms of output in scenes and on assets) - roughness values are calculated correctly in this version Fixes for normal's array - some normal's from some files were dropped and generated, this is now fixed. - FBX indexing for items with (-1) index, for normal data is supported, this is super helpful at increasing our range of compatibility of FBX meshes. Fix bone rest data **no longer requiring go to bind pose in Maya and various applications** - Partial fix for #43688 Validation tools added for validating large projects Provide package name, vendor and FBX vendor in the log. Implemented metadata properties so we can read extra document info required for bug reporting **FBX 2011 (version 7200)** is unsupported now, you must re-export your file in Maya or Max to upgrade the file format. Fixes skin bind poses being generated based on node xforms in the scene Fixes duplicate bones being added to skin and prevents add_bones from registering skeleton bones it now registers skin bind poses, but this should really be documented in the engine correctly right now it doesn't tell you this is the case.
2020-12-02 16:38:11 +01:00
//
// Zero / default value properties
// TODO: implement fields correctly tomorrow so we check 'has x mapping' before 'read x mapping' etc.
// if(real_value)
// {
// if(real_value->Value() == 0 && !vector_value)
// {
// continue;
// }
// }
if (vector_value && !real_value) {
if (vector_value->Value() == Vector3(0, 0, 0) && !real_value) {
continue;
}
}
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
switch (desc) {
case PROPERTY_DESC_ALBEDO_COLOR: {
if (vector_value) {
const Vector3 &color = vector_value->Value();
// Make sure to not lost any eventual opacity.
[fbx] bugfixes skinning, materials and debugging info, merry xmas 🎄 Better materials: - default values will no longer trigger things like emission, clear coat being enabled etc incorrectly, mostly importers misunderstand this value, a value of 1 is not actually enabled emission, it must have a non zero setting other than emission value for the emission flags to actually be enabled correctly in our engine #42386 - lambert materials are warned against significantly, do not use Lambert in Godot, use a PBR material like Ai Standard Surface (it's like going from low quality to high definition in terms of output in scenes and on assets) - roughness values are calculated correctly in this version Fixes for normal's array - some normal's from some files were dropped and generated, this is now fixed. - FBX indexing for items with (-1) index, for normal data is supported, this is super helpful at increasing our range of compatibility of FBX meshes. Fix bone rest data **no longer requiring go to bind pose in Maya and various applications** - Partial fix for #43688 Validation tools added for validating large projects Provide package name, vendor and FBX vendor in the log. Implemented metadata properties so we can read extra document info required for bug reporting **FBX 2011 (version 7200)** is unsupported now, you must re-export your file in Maya or Max to upgrade the file format. Fixes skin bind poses being generated based on node xforms in the scene Fixes duplicate bones being added to skin and prevents add_bones from registering skeleton bones it now registers skin bind poses, but this should really be documented in the engine correctly right now it doesn't tell you this is the case.
2020-12-02 16:38:11 +01:00
if (color != Vector3(0, 0, 0)) {
Color c = Color();
c[0] = color[0];
c[1] = color[1];
c[2] = color[2];
spatial_material->set_albedo(c);
}
} else if (real_value) {
print_error("albedo is unsupported format?");
}
} break;
case PROPERTY_DESC_TRANSPARENT: {
if (real_value) {
const real_t opacity = real_value->Value();
if (opacity < (1.0 - CMP_EPSILON)) {
Color c = spatial_material->get_albedo();
[fbx] bugfixes skinning, materials and debugging info, merry xmas 🎄 Better materials: - default values will no longer trigger things like emission, clear coat being enabled etc incorrectly, mostly importers misunderstand this value, a value of 1 is not actually enabled emission, it must have a non zero setting other than emission value for the emission flags to actually be enabled correctly in our engine #42386 - lambert materials are warned against significantly, do not use Lambert in Godot, use a PBR material like Ai Standard Surface (it's like going from low quality to high definition in terms of output in scenes and on assets) - roughness values are calculated correctly in this version Fixes for normal's array - some normal's from some files were dropped and generated, this is now fixed. - FBX indexing for items with (-1) index, for normal data is supported, this is super helpful at increasing our range of compatibility of FBX meshes. Fix bone rest data **no longer requiring go to bind pose in Maya and various applications** - Partial fix for #43688 Validation tools added for validating large projects Provide package name, vendor and FBX vendor in the log. Implemented metadata properties so we can read extra document info required for bug reporting **FBX 2011 (version 7200)** is unsupported now, you must re-export your file in Maya or Max to upgrade the file format. Fixes skin bind poses being generated based on node xforms in the scene Fixes duplicate bones being added to skin and prevents add_bones from registering skeleton bones it now registers skin bind poses, but this should really be documented in the engine correctly right now it doesn't tell you this is the case.
2020-12-02 16:38:11 +01:00
c.a = opacity;
spatial_material->set_albedo(c);
material_info.features.push_back(SpatialMaterial::Feature::FEATURE_TRANSPARENT);
spatial_material->set_depth_draw_mode(SpatialMaterial::DEPTH_DRAW_ALPHA_OPAQUE_PREPASS);
}
} else if (vector_value) {
print_error("unsupported transparent desc type vector!");
}
} break;
case PROPERTY_DESC_SPECULAR: {
if (real_value) {
print_verbose("specular real value: " + rtos(real_value->Value()));
spatial_material->set_specular(MIN(1.0, real_value->Value()));
}
if (vector_value) {
print_error("unsupported specular vector value: " + vector_value->Value());
}
} break;
case PROPERTY_DESC_SPECULAR_COLOR: {
if (vector_value) {
print_error("unsupported specular color: " + vector_value->Value());
}
} break;
case PROPERTY_DESC_SHINYNESS: {
if (real_value) {
print_error("unsupported shinyness:" + rtos(real_value->Value()));
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
}
} break;
case PROPERTY_DESC_METALLIC: {
if (real_value) {
print_verbose("metallic real value: " + rtos(real_value->Value()));
spatial_material->set_metallic(MIN(1.0f, real_value->Value()));
} else {
print_error("unsupported value type for metallic");
}
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
} break;
case PROPERTY_DESC_ROUGHNESS: {
if (real_value) {
print_verbose("roughness real value: " + rtos(real_value->Value()));
spatial_material->set_roughness(MIN(1.0f, real_value->Value()));
} else {
print_error("unsupported value type for roughness");
}
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
} break;
case PROPERTY_DESC_COAT: {
if (real_value) {
material_info.features.push_back(SpatialMaterial::Feature::FEATURE_CLEARCOAT);
print_verbose("clearcoat real value: " + rtos(real_value->Value()));
spatial_material->set_clearcoat(MIN(1.0f, real_value->Value()));
} else {
print_error("unsupported value type for clearcoat");
}
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
} break;
case PROPERTY_DESC_COAT_ROUGHNESS: {
[fbx] bugfixes skinning, materials and debugging info, merry xmas 🎄 Better materials: - default values will no longer trigger things like emission, clear coat being enabled etc incorrectly, mostly importers misunderstand this value, a value of 1 is not actually enabled emission, it must have a non zero setting other than emission value for the emission flags to actually be enabled correctly in our engine #42386 - lambert materials are warned against significantly, do not use Lambert in Godot, use a PBR material like Ai Standard Surface (it's like going from low quality to high definition in terms of output in scenes and on assets) - roughness values are calculated correctly in this version Fixes for normal's array - some normal's from some files were dropped and generated, this is now fixed. - FBX indexing for items with (-1) index, for normal data is supported, this is super helpful at increasing our range of compatibility of FBX meshes. Fix bone rest data **no longer requiring go to bind pose in Maya and various applications** - Partial fix for #43688 Validation tools added for validating large projects Provide package name, vendor and FBX vendor in the log. Implemented metadata properties so we can read extra document info required for bug reporting **FBX 2011 (version 7200)** is unsupported now, you must re-export your file in Maya or Max to upgrade the file format. Fixes skin bind poses being generated based on node xforms in the scene Fixes duplicate bones being added to skin and prevents add_bones from registering skeleton bones it now registers skin bind poses, but this should really be documented in the engine correctly right now it doesn't tell you this is the case.
2020-12-02 16:38:11 +01:00
// meaning is that approx equal to zero is disabled not actually zero. ;)
if (real_value && Math::is_equal_approx(real_value->Value(), 0.0f)) {
print_verbose("clearcoat real value: " + rtos(real_value->Value()));
spatial_material->set_clearcoat_gloss(1.0 - real_value->Value());
material_info.features.push_back(SpatialMaterial::Feature::FEATURE_CLEARCOAT);
} else {
print_error("unsupported value type for clearcoat gloss");
}
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
} break;
case PROPERTY_DESC_EMISSIVE: {
[fbx] bugfixes skinning, materials and debugging info, merry xmas 🎄 Better materials: - default values will no longer trigger things like emission, clear coat being enabled etc incorrectly, mostly importers misunderstand this value, a value of 1 is not actually enabled emission, it must have a non zero setting other than emission value for the emission flags to actually be enabled correctly in our engine #42386 - lambert materials are warned against significantly, do not use Lambert in Godot, use a PBR material like Ai Standard Surface (it's like going from low quality to high definition in terms of output in scenes and on assets) - roughness values are calculated correctly in this version Fixes for normal's array - some normal's from some files were dropped and generated, this is now fixed. - FBX indexing for items with (-1) index, for normal data is supported, this is super helpful at increasing our range of compatibility of FBX meshes. Fix bone rest data **no longer requiring go to bind pose in Maya and various applications** - Partial fix for #43688 Validation tools added for validating large projects Provide package name, vendor and FBX vendor in the log. Implemented metadata properties so we can read extra document info required for bug reporting **FBX 2011 (version 7200)** is unsupported now, you must re-export your file in Maya or Max to upgrade the file format. Fixes skin bind poses being generated based on node xforms in the scene Fixes duplicate bones being added to skin and prevents add_bones from registering skeleton bones it now registers skin bind poses, but this should really be documented in the engine correctly right now it doesn't tell you this is the case.
2020-12-02 16:38:11 +01:00
if (real_value && Math::is_equal_approx(real_value->Value(), 0.0f)) {
print_verbose("Emissive real value: " + rtos(real_value->Value()));
spatial_material->set_emission_energy(real_value->Value());
material_info.features.push_back(SpatialMaterial::Feature::FEATURE_EMISSION);
[fbx] bugfixes skinning, materials and debugging info, merry xmas 🎄 Better materials: - default values will no longer trigger things like emission, clear coat being enabled etc incorrectly, mostly importers misunderstand this value, a value of 1 is not actually enabled emission, it must have a non zero setting other than emission value for the emission flags to actually be enabled correctly in our engine #42386 - lambert materials are warned against significantly, do not use Lambert in Godot, use a PBR material like Ai Standard Surface (it's like going from low quality to high definition in terms of output in scenes and on assets) - roughness values are calculated correctly in this version Fixes for normal's array - some normal's from some files were dropped and generated, this is now fixed. - FBX indexing for items with (-1) index, for normal data is supported, this is super helpful at increasing our range of compatibility of FBX meshes. Fix bone rest data **no longer requiring go to bind pose in Maya and various applications** - Partial fix for #43688 Validation tools added for validating large projects Provide package name, vendor and FBX vendor in the log. Implemented metadata properties so we can read extra document info required for bug reporting **FBX 2011 (version 7200)** is unsupported now, you must re-export your file in Maya or Max to upgrade the file format. Fixes skin bind poses being generated based on node xforms in the scene Fixes duplicate bones being added to skin and prevents add_bones from registering skeleton bones it now registers skin bind poses, but this should really be documented in the engine correctly right now it doesn't tell you this is the case.
2020-12-02 16:38:11 +01:00
} else if (vector_value && !vector_value->Value().is_equal_approx(Vector3(0, 0, 0))) {
const Vector3 &color = vector_value->Value();
Color c;
c[0] = color[0];
c[1] = color[1];
c[2] = color[2];
spatial_material->set_emission(c);
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
material_info.features.push_back(SpatialMaterial::Feature::FEATURE_EMISSION);
}
} break;
case PROPERTY_DESC_EMISSIVE_COLOR: {
[fbx] bugfixes skinning, materials and debugging info, merry xmas 🎄 Better materials: - default values will no longer trigger things like emission, clear coat being enabled etc incorrectly, mostly importers misunderstand this value, a value of 1 is not actually enabled emission, it must have a non zero setting other than emission value for the emission flags to actually be enabled correctly in our engine #42386 - lambert materials are warned against significantly, do not use Lambert in Godot, use a PBR material like Ai Standard Surface (it's like going from low quality to high definition in terms of output in scenes and on assets) - roughness values are calculated correctly in this version Fixes for normal's array - some normal's from some files were dropped and generated, this is now fixed. - FBX indexing for items with (-1) index, for normal data is supported, this is super helpful at increasing our range of compatibility of FBX meshes. Fix bone rest data **no longer requiring go to bind pose in Maya and various applications** - Partial fix for #43688 Validation tools added for validating large projects Provide package name, vendor and FBX vendor in the log. Implemented metadata properties so we can read extra document info required for bug reporting **FBX 2011 (version 7200)** is unsupported now, you must re-export your file in Maya or Max to upgrade the file format. Fixes skin bind poses being generated based on node xforms in the scene Fixes duplicate bones being added to skin and prevents add_bones from registering skeleton bones it now registers skin bind poses, but this should really be documented in the engine correctly right now it doesn't tell you this is the case.
2020-12-02 16:38:11 +01:00
if (vector_value && !vector_value->Value().is_equal_approx(Vector3(0, 0, 0))) {
const Vector3 &color = vector_value->Value();
Color c;
c[0] = color[0];
c[1] = color[1];
c[2] = color[2];
spatial_material->set_emission(c);
} else {
print_error("unsupported value type for emissive color");
}
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
} break;
case PROPERTY_DESC_NOT_FOUND:
case PROPERTY_DESC_IGNORE:
// Already checked, can't happen.
CRASH_NOW();
break;
}
}
// Set the material features.
for (int x = 0; x < material_info.features.size(); x++) {
if (spatial_material.is_null()) {
// Done here so if no textures no material is created.
spatial_material.instance();
}
spatial_material->set_feature(material_info.features[x], true);
}
// Set the textures.
for (int x = 0; x < material_info.textures.size(); x++) {
TextureFileMapping mapping = material_info.textures[x];
Ref<Texture> texture;
print_verbose("texture mapping name: " + mapping.name);
if (state.cached_image_searches.has(mapping.name)) {
texture = state.cached_image_searches[mapping.name];
} else {
String path = find_texture_path_by_filename(mapping.name, p_fbx_current_directory);
if (!path.empty()) {
Error err;
Ref<Texture> image_texture = ResourceLoader::load(path, "Texture", false, &err);
ERR_CONTINUE_MSG(err != OK, "unable to import image file not loaded yet: " + path);
ERR_CONTINUE(image_texture == nullptr || image_texture.is_null());
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
texture = image_texture;
state.cached_image_searches.insert(mapping.name, texture);
print_verbose("Created texture from loaded image file.");
} else if (mapping.texture != nullptr && mapping.texture->Media() != nullptr && mapping.texture->Media()->IsEmbedded()) {
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
// This is an embedded texture. Extract it.
Ref<Image> image;
image.instance();
const String extension = mapping.name.get_extension().to_upper();
if (extension == "PNG") {
// The stored file is a PNG.
image = Image::_png_mem_loader_func(mapping.texture->Media()->Content(), mapping.texture->Media()->ContentLength());
ERR_CONTINUE_MSG(image.is_valid() == false, "FBX Embedded PNG image load fail.");
} else if (
extension == "JPEG" ||
extension == "JPG") {
// The stored file is a JPEG.
image = Image::_jpg_mem_loader_func(mapping.texture->Media()->Content(), mapping.texture->Media()->ContentLength());
ERR_CONTINUE_MSG(image.is_valid() == false, "FBX Embedded JPEG image load fail.");
} else if (extension == "TGA") {
// The stored file is a TGA.
image = Image::_tga_mem_loader_func(mapping.texture->Media()->Content(), mapping.texture->Media()->ContentLength());
ERR_CONTINUE_MSG(image.is_valid() == false, "FBX Embedded TGA image load fail.");
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
} else if (extension == "WEBP") {
// The stored file is a WEBP.
image = Image::_webp_mem_loader_func(mapping.texture->Media()->Content(), mapping.texture->Media()->ContentLength());
ERR_CONTINUE_MSG(image.is_valid() == false, "FBX Embedded WEBP image load fail.");
// } else if (extension == "DDS") {
// // In this moment is not possible to extract a DDS from a buffer, TODO consider add it to godot. See `textureloader_dds.cpp::load().
// // The stored file is a DDS.
} else {
ERR_CONTINUE_MSG(true, "The embedded image with extension: " + extension + " is not yet supported. Open an issue please.");
}
Ref<ImageTexture> image_texture;
image_texture.instance();
image_texture->create_from_image(image);
const int32_t flags = Texture::FLAGS_DEFAULT;
image_texture->set_flags(flags);
texture = image_texture;
state.cached_image_searches[mapping.name] = texture;
print_verbose("Created texture from embedded image.");
} else {
ERR_CONTINUE_MSG(true, "The FBX texture, with name: `" + mapping.name + "`, is not found into the project nor is stored as embedded file. Make sure to insert the texture as embedded file or into the project, then reimport.");
}
}
if (spatial_material.is_null()) {
// Done here so if no textures no material is created.
spatial_material.instance();
}
switch (mapping.map_mode) {
case SpatialMaterial::TextureParam::TEXTURE_METALLIC:
if (mapping.name.to_lower().find("ser") >= 0) {
// SER shader.
spatial_material->set_metallic_texture_channel(SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_RED);
} else {
// Use grayscale as default.
spatial_material->set_metallic_texture_channel(SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_GRAYSCALE);
}
break;
case SpatialMaterial::TextureParam::TEXTURE_ROUGHNESS:
if (mapping.name.to_lower().find("ser") >= 0) {
// SER shader.
spatial_material->set_roughness_texture_channel(SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_BLUE);
} else {
// Use grayscale as default.
spatial_material->set_roughness_texture_channel(SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_GRAYSCALE);
}
break;
case SpatialMaterial::TextureParam::TEXTURE_AMBIENT_OCCLUSION:
// Use grayscale as default.
spatial_material->set_ao_texture_channel(SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_GRAYSCALE);
break;
case SpatialMaterial::TextureParam::TEXTURE_REFRACTION:
// Use grayscale as default.
spatial_material->set_refraction_texture_channel(SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_GRAYSCALE);
break;
default:
// Nothing to do.
break;
}
print_verbose("Texture mapping mode: " + itos(mapping.map_mode) + " name: " + get_texture_param_name(mapping.map_mode));
Rewrite FBX Importer to convert directly to Godot scene format 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>
2020-10-20 19:00:16 +02:00
spatial_material->set_texture(mapping.map_mode, texture);
}
if (spatial_material.is_valid()) {
spatial_material->set_name(material_name);
}
return spatial_material;
}