2019-08-30 01:21:40 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* import_state.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2019-08-30 01:21:40 +00: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef EDITOR_SCENE_IMPORT_STATE_H
|
|
|
|
#define EDITOR_SCENE_IMPORT_STATE_H
|
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/core_bind.h"
|
2019-08-30 01:21:40 +00:00
|
|
|
#include "core/io/resource_importer.h"
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/templates/vector.h"
|
2019-08-30 01:21:40 +00:00
|
|
|
#include "editor/import/resource_importer_scene.h"
|
|
|
|
#include "editor/project_settings_editor.h"
|
2020-03-26 21:49:16 +00:00
|
|
|
#include "scene/3d/mesh_instance_3d.h"
|
|
|
|
#include "scene/3d/node_3d.h"
|
|
|
|
#include "scene/3d/skeleton_3d.h"
|
2019-08-30 01:21:40 +00:00
|
|
|
#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
|
2019-11-05 17:54:34 +00:00
|
|
|
* This makes the code simpler and contains useful lookups.
|
|
|
|
*/
|
2019-08-30 01:21:40 +00:00
|
|
|
struct ImportState {
|
|
|
|
String path;
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3D *root;
|
2019-08-30 01:21:40 +00:00
|
|
|
const aiScene *assimp_scene;
|
|
|
|
uint32_t max_bone_weights;
|
|
|
|
|
2020-03-17 06:33:00 +00:00
|
|
|
Map<String, Ref<Mesh>> mesh_cache;
|
|
|
|
Map<int, Ref<Material>> material_cache;
|
2019-08-30 01:21:40 +00:00
|
|
|
Map<String, int> light_cache;
|
|
|
|
Map<String, int> camera_cache;
|
2019-11-05 17:54:34 +00:00
|
|
|
|
2019-08-30 01:21:40 +00:00
|
|
|
// very useful for when you need to ask assimp for the bone mesh
|
2019-11-05 17:54:34 +00:00
|
|
|
|
|
|
|
Map<const aiNode *, Node *> assimp_node_map;
|
2020-03-17 06:33:00 +00:00
|
|
|
Map<String, Ref<Image>> path_to_image_cache;
|
2019-11-05 17:54:34 +00:00
|
|
|
|
|
|
|
// Generation 3 - determinisitic iteration
|
|
|
|
// to lower potential recursion errors
|
|
|
|
List<const aiNode *> nodes;
|
2020-03-26 21:49:16 +00:00
|
|
|
Map<const aiNode *, Node3D *> flat_node_map;
|
2019-08-30 01:21:40 +00:00
|
|
|
AnimationPlayer *animation_player;
|
2019-11-05 17:54:34 +00:00
|
|
|
|
|
|
|
// Generation 3 - deterministic armatures
|
|
|
|
// list of armature nodes - flat and simple to parse
|
|
|
|
// assimp node, node in godot
|
|
|
|
List<aiNode *> armature_nodes;
|
2020-03-26 21:49:16 +00:00
|
|
|
Map<const aiNode *, Skeleton3D *> armature_skeletons;
|
|
|
|
Map<aiBone *, Skeleton3D *> skeleton_bone_map;
|
2019-11-05 17:54:34 +00:00
|
|
|
// Generation 3 - deterministic bone handling
|
|
|
|
// bones from the stack are popped when found
|
|
|
|
// this means we can detect
|
|
|
|
// what bones are for other armatures
|
|
|
|
List<aiBone *> bone_stack;
|
2020-05-23 23:02:48 +00:00
|
|
|
|
|
|
|
// EditorSceneImporter::ImportFlags
|
|
|
|
uint32_t import_flags;
|
2019-08-30 01:21:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct AssimpImageData {
|
|
|
|
Ref<Image> raw_image;
|
|
|
|
Ref<ImageTexture> texture;
|
2019-09-03 16:29:51 +00:00
|
|
|
aiTextureMapMode map_mode[2];
|
2019-08-30 01:21:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** 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 {
|
2019-11-05 17:54:34 +00:00
|
|
|
RecursiveState() {} // do not construct :)
|
2019-08-30 01:21:40 +00:00
|
|
|
RecursiveState(
|
|
|
|
Transform &_node_transform,
|
2020-03-26 21:49:16 +00:00
|
|
|
Skeleton3D *_skeleton,
|
|
|
|
Node3D *_new_node,
|
2019-11-05 17:54:34 +00:00
|
|
|
String &_node_name,
|
|
|
|
aiNode *_assimp_node,
|
2019-08-30 01:21:40 +00:00
|
|
|
Node *_parent_node,
|
2019-11-05 17:54:34 +00:00
|
|
|
aiBone *_bone) :
|
2019-08-30 01:21:40 +00:00
|
|
|
node_transform(_node_transform),
|
|
|
|
skeleton(_skeleton),
|
|
|
|
new_node(_new_node),
|
|
|
|
node_name(_node_name),
|
|
|
|
assimp_node(_assimp_node),
|
|
|
|
parent_node(_parent_node),
|
|
|
|
bone(_bone) {}
|
|
|
|
|
2019-11-05 17:54:34 +00:00
|
|
|
Transform node_transform;
|
2020-04-01 23:20:12 +00:00
|
|
|
Skeleton3D *skeleton = nullptr;
|
|
|
|
Node3D *new_node = nullptr;
|
2019-11-05 17:54:34 +00:00
|
|
|
String node_name;
|
2020-04-01 23:20:12 +00:00
|
|
|
aiNode *assimp_node = nullptr;
|
|
|
|
Node *parent_node = nullptr;
|
|
|
|
aiBone *bone = nullptr;
|
2019-08-30 01:21:40 +00:00
|
|
|
};
|
|
|
|
} // namespace AssimpImporter
|
|
|
|
|
|
|
|
#endif // EDITOR_SCENE_IMPORT_STATE_H
|