Cleaned GLTFDocumentExtensionConvertImporterMesh too.

This commit is contained in:
Relintai 2022-08-08 00:43:26 +02:00
parent 5e5ae40009
commit 53fcf8b2d3
4 changed files with 20 additions and 10 deletions

View File

@ -10,6 +10,8 @@ env_gltf.add_source_files(env.modules_sources, "register_types.cpp")
env_gltf.add_source_files(env.modules_sources, "gltf_state.cpp") env_gltf.add_source_files(env.modules_sources, "gltf_state.cpp")
env_gltf.add_source_files(env.modules_sources, "gltf_document_extension.cpp") env_gltf.add_source_files(env.modules_sources, "gltf_document_extension.cpp")
env_gltf.add_source_files(env.modules_sources, "gltf_document_extension_convert_importer_mesh.cpp")
#env_gltf.add_source_files(env.modules_sources, "*.cpp") #env_gltf.add_source_files(env.modules_sources, "*.cpp")
env_gltf.add_source_files(env.modules_sources, "extensions/*.cpp") env_gltf.add_source_files(env.modules_sources, "extensions/*.cpp")

View File

@ -35,22 +35,26 @@
#include "core/error_macros.h" #include "core/error_macros.h"
#include "scene/3d/mesh_instance.h" #include "scene/3d/mesh_instance.h"
#include "scene/resources/importer_mesh.h" #include "scene/resources/importer_mesh.h"
#include "scene/3d/importer_mesh_instance_3d.h"
#include "scene/3d/mesh_instance.h"
#include "scene/main/node.h"
void GLTFDocumentExtensionConvertImporterMesh::_bind_methods() { void GLTFDocumentExtensionConvertImporterMesh::_bind_methods() {
} }
Error GLTFDocumentExtensionConvertImporterMesh::import_post(Ref<GLTFState> p_state, Node *p_root) { Error GLTFDocumentExtensionConvertImporterMesh::import_post(Ref<GLTFState> p_state, Node *p_root) {
ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER); ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER);
ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
List<Node *> queue; List<Node *> queue;
queue.push_back(p_root); queue.push_back(p_root);
List<Node *> delete_queue; List<Node *> delete_queue;
while (!queue.is_empty()) { while (!queue.empty()) {
List<Node *>::Element *E = queue.front(); List<Node *>::Element *E = queue.front();
Node *node = E->get(); Node *node = E->get();
ImporterMeshInstance3D *mesh_3d = cast_to<ImporterMeshInstance3D>(node); ImporterMeshInstance3D *mesh_3d = cast_to<ImporterMeshInstance3D>(node);
if (mesh_3d) { if (mesh_3d) {
MeshInstance3D *mesh_instance_node_3d = memnew(MeshInstance3D); MeshInstance *mesh_instance_node_3d = memnew(MeshInstance);
Ref<ImporterMesh> mesh = mesh_3d->get_mesh(); Ref<ImporterMesh> mesh = mesh_3d->get_mesh();
if (mesh.is_valid()) { if (mesh.is_valid()) {
Ref<ArrayMesh> array_mesh = mesh->get_mesh(); Ref<ArrayMesh> array_mesh = mesh->get_mesh();
@ -71,11 +75,13 @@ Error GLTFDocumentExtensionConvertImporterMesh::import_post(Ref<GLTFState> p_sta
} }
queue.pop_front(); queue.pop_front();
} }
while (!queue.is_empty()) {
while (!queue.empty()) {
List<Node *>::Element *E = delete_queue.front(); List<Node *>::Element *E = delete_queue.front();
Node *node = E->get(); Node *node = E->get();
memdelete(node); memdelete(node);
delete_queue.pop_front(); delete_queue.pop_front();
} }
return OK; return OK;
} }

View File

@ -31,11 +31,12 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#include "core/reference.h"
#include "gltf_document_extension.h" #include "gltf_document_extension.h"
#include "scene/3d/importer_mesh_instance_3d.h" class GLTFState;
#include "scene/3d/mesh_instance.h" class Node;
#include "scene/resources/importer_mesh.h"
class GLTFDocumentExtensionConvertImporterMesh : public GLTFDocumentExtension { class GLTFDocumentExtensionConvertImporterMesh : public GLTFDocumentExtension {
GDCLASS(GLTFDocumentExtensionConvertImporterMesh, GLTFDocumentExtension); GDCLASS(GLTFDocumentExtensionConvertImporterMesh, GLTFDocumentExtension);
@ -44,7 +45,7 @@ protected:
static void _bind_methods(); static void _bind_methods();
public: public:
Error import_post(Ref<GLTFState> p_state, Node *p_root) override; Error import_post(Ref<GLTFState> p_state, Node *p_root);
}; };
#endif // GLTF_DOCUMENT_EXTENSION_CONVERT_IMPORTER_MESH_H #endif // GLTF_DOCUMENT_EXTENSION_CONVERT_IMPORTER_MESH_H

View File

@ -46,6 +46,7 @@
#include "extensions/gltf_spec_gloss.h" #include "extensions/gltf_spec_gloss.h"
#include "gltf_document_extension.h" #include "gltf_document_extension.h"
#include "gltf_document_extension_convert_importer_mesh.h"
#include "gltf_state.h" #include "gltf_state.h"
void register_gltf_types() { void register_gltf_types() {
@ -64,7 +65,7 @@ void register_gltf_types() {
//ClassDB::register_class<GLTFDocument>(); //ClassDB::register_class<GLTFDocument>();
ClassDB::register_class<GLTFDocumentExtension>(); ClassDB::register_class<GLTFDocumentExtension>();
//ClassDB::register_class<GLTFDocumentExtensionConvertImporterMesh>(); ClassDB::register_class<GLTFDocumentExtensionConvertImporterMesh>();
ClassDB::register_class<GLTFState>(); ClassDB::register_class<GLTFState>();
} }
@ -74,7 +75,7 @@ void unregister_gltf_types() {
/* /*
#include "gltf_document.h" #include "gltf_document.h"
#include "gltf_document_extension_convert_importer_mesh.h"