mirror of
https://github.com/godotengine/godot.git
synced 2024-12-21 10:25:24 +08:00
ad214c0356
Issues fixed: - Updated assimp to latest and backported fixes into godot. - Fixed file scale being ignored from FBX file. - Fixed bone removal - Implemented proper armature binding - Fixed recursion not always going through the entire path - Implemented assimp global scaling system - Fixed assimp global scale process to support unit conversion - Implemented proper fbx scaling - Fixed asserts caused by missing faces in some models which could crash - Fixed valid bone removal - Fixed root node being overwriten by assimp which caused data loss - Fixed armature construction so that it works with multiple roots - Implemented basic support for FBX standard materials - Refactoring to improve code quality and improve function reuse. - Simplified node creation from assimp scene into subsections: create_light, create_mesh, create_bone. - Creating meshes is now done after hierarchy is created so that the skeleton is always available. - Added support to assimp to support file scale in all formats which call SetFileScale. - Many other fixes provided into assimp. Known issues: - FBX pivots from Maya do not currently work. (workaround: for now use blender import and export to remove pivot tracks) - Hierarchy creates an extra node for each mesh - this was done intentionally but we intended to do a pass to remove these as they're a required node. - When an animated mesh has not executed any animation the rest pose is wrong. Co-authored-by: K. S. Ernest (iFire) Lee <ernest.lee@chibifire.com>
116 lines
4.6 KiB
C++
116 lines
4.6 KiB
C++
/*************************************************************************/
|
|
/* import_state.h */
|
|
/*************************************************************************/
|
|
/* This file is part of: */
|
|
/* GODOT ENGINE */
|
|
/* https://godotengine.org */
|
|
/*************************************************************************/
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
|
/* */
|
|
/* 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. */
|
|
/*************************************************************************/
|
|
|
|
#ifndef EDITOR_SCENE_IMPORT_STATE_H
|
|
#define EDITOR_SCENE_IMPORT_STATE_H
|
|
|
|
#include "core/bind/core_bind.h"
|
|
#include "core/io/resource_importer.h"
|
|
#include "core/vector.h"
|
|
#include "editor/import/resource_importer_scene.h"
|
|
#include "editor/project_settings_editor.h"
|
|
#include "scene/3d/mesh_instance.h"
|
|
#include "scene/3d/skeleton.h"
|
|
#include "scene/3d/spatial.h"
|
|
#include "scene/animation/animation_player.h"
|
|
#include "scene/resources/animation.h"
|
|
#include "scene/resources/surface_tool.h"
|
|
|
|
#include <assimp/matrix4x4.h>
|
|
#include <assimp/scene.h>
|
|
#include <assimp/types.h>
|
|
#include <assimp/DefaultLogger.hpp>
|
|
#include <assimp/LogStream.hpp>
|
|
#include <assimp/Logger.hpp>
|
|
|
|
namespace AssimpImporter {
|
|
/** Import state is for global scene import data
|
|
* This makes the code simpler and contains useful lookups.
|
|
*/
|
|
struct ImportState {
|
|
|
|
String path;
|
|
const aiScene *assimp_scene;
|
|
uint32_t max_bone_weights;
|
|
|
|
Spatial *root;
|
|
Map<String, Ref<Mesh> > mesh_cache;
|
|
Map<int, Ref<Material> > material_cache;
|
|
Map<String, int> light_cache;
|
|
Map<String, int> camera_cache;
|
|
//Vector<Skeleton *> skeletons;
|
|
Map<Skeleton *, const Spatial *> armature_skeletons; // maps skeletons based on their armature nodes.
|
|
Map<const aiBone *, Skeleton *> bone_to_skeleton_lookup; // maps bones back into their skeleton
|
|
// very useful for when you need to ask assimp for the bone mesh
|
|
Map<String, Node *> node_map;
|
|
Map<const aiNode *, const Node *> assimp_node_map;
|
|
Map<String, Ref<Image> > path_to_image_cache;
|
|
bool fbx; //for some reason assimp does some things different for FBX
|
|
AnimationPlayer *animation_player;
|
|
};
|
|
|
|
struct AssimpImageData {
|
|
Ref<Image> raw_image;
|
|
Ref<ImageTexture> texture;
|
|
aiTextureMapMode *map_mode = NULL;
|
|
};
|
|
|
|
/** Recursive state is used to push state into functions instead of specifying them
|
|
* This makes the code easier to handle too and add extra arguments without breaking things
|
|
*/
|
|
struct RecursiveState {
|
|
RecursiveState(
|
|
Transform &_node_transform,
|
|
Skeleton *_skeleton,
|
|
Spatial *_new_node,
|
|
const String &_node_name,
|
|
const aiNode *_assimp_node,
|
|
Node *_parent_node,
|
|
const aiBone *_bone) :
|
|
node_transform(_node_transform),
|
|
skeleton(_skeleton),
|
|
new_node(_new_node),
|
|
node_name(_node_name),
|
|
assimp_node(_assimp_node),
|
|
parent_node(_parent_node),
|
|
bone(_bone) {}
|
|
|
|
Transform &node_transform;
|
|
Skeleton *skeleton;
|
|
Spatial *new_node;
|
|
const String &node_name;
|
|
const aiNode *assimp_node;
|
|
Node *parent_node;
|
|
const aiBone *bone;
|
|
};
|
|
} // namespace AssimpImporter
|
|
|
|
#endif // EDITOR_SCENE_IMPORT_STATE_H
|