From d53389bd79ff7aef09847cfbec66de3161b51b2c Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Tue, 6 Apr 2021 05:38:35 -0700 Subject: [PATCH 1/3] Move gltf to core. --- editor/editor_node.cpp | 2 +- editor/import/editor_import_collada.cpp | 2 +- editor/import/editor_importer_bake_reset.cpp | 2 +- editor/import/resource_importer_obj.cpp | 4 +- editor/import/resource_importer_scene.cpp | 2 +- editor/import/resource_importer_scene.h | 1 + editor/import/scene_import_settings.cpp | 2 +- modules/fbx/data/fbx_mesh_data.h | 2 +- modules/fbx/editor_scene_importer_fbx.cpp | 3 +- modules/gltf/config.py | 2 +- modules/gltf/editor_scene_importer_gltf.cpp | 3 + modules/gltf/gltf_document.cpp | 195 ++++++++++++++++-- modules/gltf/gltf_document.h | 16 +- modules/gltf/gltf_mesh.cpp | 2 +- modules/gltf/gltf_mesh.h | 2 +- .../3d}/scene_importer_mesh_node_3d.cpp | 0 .../3d}/scene_importer_mesh_node_3d.h | 2 +- .../resources}/scene_importer_mesh.cpp | 0 .../resources}/scene_importer_mesh.h | 0 19 files changed, 210 insertions(+), 32 deletions(-) rename {editor/import => scene/3d}/scene_importer_mesh_node_3d.cpp (100%) rename {editor/import => scene/3d}/scene_importer_mesh_node_3d.h (98%) rename {editor/import => scene/resources}/scene_importer_mesh.cpp (100%) rename {editor/import => scene/resources}/scene_importer_mesh.h (100%) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index f86a36df2f67..6b7572a514ca 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -113,7 +113,6 @@ #include "editor/import/resource_importer_texture_atlas.h" #include "editor/import/resource_importer_wav.h" #include "editor/import/scene_import_settings.h" -#include "editor/import/scene_importer_mesh_node_3d.h" #include "editor/import_dock.h" #include "editor/multi_node_edit.h" #include "editor/node_dock.h" @@ -190,6 +189,7 @@ #include "editor/quick_open.h" #include "editor/register_exporters.h" #include "editor/settings_config_dialog.h" +#include "scene/3d/scene_importer_mesh_node_3d.h" #include #include diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 7ab80ac3b451..0a0c5d2ed49d 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -33,12 +33,12 @@ #include "core/os/os.h" #include "editor/editor_node.h" #include "editor/import/collada.h" -#include "editor/import/scene_importer_mesh_node_3d.h" #include "scene/3d/camera_3d.h" #include "scene/3d/light_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/node_3d.h" #include "scene/3d/path_3d.h" +#include "scene/3d/scene_importer_mesh_node_3d.h" #include "scene/3d/skeleton_3d.h" #include "scene/animation/animation_player.h" #include "scene/resources/animation.h" diff --git a/editor/import/editor_importer_bake_reset.cpp b/editor/import/editor_importer_bake_reset.cpp index 00dce6850e2c..00d40c7b5823 100644 --- a/editor/import/editor_importer_bake_reset.cpp +++ b/editor/import/editor_importer_bake_reset.cpp @@ -33,10 +33,10 @@ #include "core/error/error_list.h" #include "core/error/error_macros.h" #include "core/math/transform_3d.h" -#include "editor/import/scene_importer_mesh_node_3d.h" #include "resource_importer_scene.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/node_3d.h" +#include "scene/3d/scene_importer_mesh_node_3d.h" #include "scene/3d/skeleton_3d.h" #include "scene/animation/animation_player.h" diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 34bc0a7d8dea..0ca4d0f232da 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -32,11 +32,11 @@ #include "core/io/file_access.h" #include "core/io/resource_saver.h" -#include "editor/import/scene_importer_mesh.h" -#include "editor/import/scene_importer_mesh_node_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/node_3d.h" +#include "scene/3d/scene_importer_mesh_node_3d.h" #include "scene/resources/mesh.h" +#include "scene/resources/scene_importer_mesh.h" #include "scene/resources/surface_tool.h" uint32_t EditorOBJImporter::get_import_flags() const { diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index c2244befa1ad..314868686826 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -34,12 +34,12 @@ #include "editor/editor_node.h" #include "editor/import/editor_importer_bake_reset.h" #include "editor/import/scene_import_settings.h" -#include "editor/import/scene_importer_mesh_node_3d.h" #include "scene/3d/area_3d.h" #include "scene/3d/collision_shape_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/navigation_region_3d.h" #include "scene/3d/physics_body_3d.h" +#include "scene/3d/scene_importer_mesh_node_3d.h" #include "scene/3d/vehicle_body_3d.h" #include "scene/animation/animation_player.h" #include "scene/resources/animation.h" diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index 542959be02e5..8082bd9fc888 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -33,6 +33,7 @@ #include "core/io/resource_importer.h" #include "scene/3d/node_3d.h" +#include "scene/3d/scene_importer_mesh_node_3d.h" #include "scene/resources/animation.h" #include "scene/resources/mesh.h" #include "scene/resources/shape_3d.h" diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp index 19a8f209bbc2..7e01a8c1aed8 100644 --- a/editor/import/scene_import_settings.cpp +++ b/editor/import/scene_import_settings.cpp @@ -31,7 +31,7 @@ #include "scene_import_settings.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" -#include "editor/import/scene_importer_mesh_node_3d.h" +#include "scene/3d/scene_importer_mesh_node_3d.h" #include "scene/resources/surface_tool.h" class SceneImportSettingsData : public Object { diff --git a/modules/fbx/data/fbx_mesh_data.h b/modules/fbx/data/fbx_mesh_data.h index 24db4a54692d..293cc6c3168f 100644 --- a/modules/fbx/data/fbx_mesh_data.h +++ b/modules/fbx/data/fbx_mesh_data.h @@ -35,8 +35,8 @@ #include "core/templates/local_vector.h" #include "core/templates/ordered_hash_map.h" #include "editor/import/resource_importer_scene.h" -#include "editor/import/scene_importer_mesh_node_3d.h" #include "scene/3d/mesh_instance_3d.h" +#include "scene/3d/scene_importer_mesh_node_3d.h" #include "scene/resources/surface_tool.h" #include "fbx_bone.h" diff --git a/modules/fbx/editor_scene_importer_fbx.cpp b/modules/fbx/editor_scene_importer_fbx.cpp index e3f36ef3e3ec..0b16ede4744c 100644 --- a/modules/fbx/editor_scene_importer_fbx.cpp +++ b/modules/fbx/editor_scene_importer_fbx.cpp @@ -40,10 +40,11 @@ #include "editor/editor_log.h" #include "editor/editor_node.h" #include "editor/import/resource_importer_scene.h" -#include "editor/import/scene_importer_mesh_node_3d.h" #include "scene/3d/bone_attachment_3d.h" #include "scene/3d/camera_3d.h" #include "scene/3d/light_3d.h" +#include "scene/3d/mesh_instance_3d.h" +#include "scene/3d/scene_importer_mesh_node_3d.h" #include "scene/main/node.h" #include "scene/resources/material.h" diff --git a/modules/gltf/config.py b/modules/gltf/config.py index 52a97c93aa8b..eb6fa76847ec 100644 --- a/modules/gltf/config.py +++ b/modules/gltf/config.py @@ -1,5 +1,5 @@ def can_build(env, platform): - return env["tools"] and not env["disable_3d"] + return not env["disable_3d"] def configure(env): diff --git a/modules/gltf/editor_scene_importer_gltf.cpp b/modules/gltf/editor_scene_importer_gltf.cpp index 12796c41d787..d9d04c5e86e0 100644 --- a/modules/gltf/editor_scene_importer_gltf.cpp +++ b/modules/gltf/editor_scene_importer_gltf.cpp @@ -37,6 +37,8 @@ #include "scene/animation/animation_player.h" #include "scene/resources/animation.h" +#ifdef TOOLS_ENABLED +#include "modules/gltf/editor_scene_importer_gltf.h" uint32_t EditorSceneImporterGLTF::get_import_flags() const { return ImportFlags::IMPORT_SCENE | ImportFlags::IMPORT_ANIMATION; } @@ -60,3 +62,4 @@ Ref EditorSceneImporterGLTF::import_animation(const String &p_path, int p_bake_fps) { return Ref(); } +#endif \ No newline at end of file diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index d307bda85cad..c8174b3809c1 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -53,7 +53,6 @@ #include "core/version.h" #include "core/version_hash.gen.h" #include "drivers/png/png_driver_common.h" -#include "editor/import/resource_importer_scene.h" #include "scene/2d/node_2d.h" #include "scene/3d/camera_3d.h" #include "scene/3d/multimesh_instance_3d.h" @@ -235,7 +234,6 @@ Error GLTFDocument::_parse_json(const String &p_path, Ref state) { f->get_buffer(array.ptrw(), array.size()); String text; text.parse_utf8((const char *)array.ptr(), array.size()); - JSON json; err = json.parse(text); if (err != OK) { @@ -4911,7 +4909,30 @@ GLTFMeshIndex GLTFDocument::_convert_mesh_instance(Ref state, MeshIns return mesh_i; } -EditorSceneImporterMeshNode3D *GLTFDocument::_generate_mesh_instance(Ref state, Node *scene_parent, const GLTFNodeIndex node_index) { +MeshInstance3D *GLTFDocument::_generate_mesh_instance_3d(Ref state, Node *scene_parent, const GLTFNodeIndex node_index, bool p_importer_mesh) { + Ref gltf_node = state->nodes[node_index]; + + ERR_FAIL_INDEX_V(gltf_node->mesh, state->meshes.size(), nullptr); + + MeshInstance3D *mi = memnew(MeshInstance3D); + print_verbose("glTF: Creating mesh for: " + gltf_node->get_name()); + + Ref mesh = state->meshes.write[gltf_node->mesh]; + if (mesh.is_null()) { + return mi; + } + Ref import_mesh = mesh->get_mesh(); + if (import_mesh.is_null()) { + return mi; + } + mi->set_mesh(import_mesh->get_mesh()); + for (int i = 0; i < mesh->get_blend_weights().size(); i++) { + mi->set("blend_shapes/" + mesh->get_mesh()->get_blend_shape_name(i), mesh->get_blend_weights()[i]); + } + return mi; +} + +EditorSceneImporterMeshNode3D *GLTFDocument::_generate_importer_mesh_3d(Ref state, Node *scene_parent, const GLTFNodeIndex node_index, bool p_importer_mesh) { Ref gltf_node = state->nodes[node_index]; ERR_FAIL_INDEX_V(gltf_node->mesh, state->meshes.size(), nullptr); @@ -5079,7 +5100,7 @@ void GLTFDocument::_convert_spatial(Ref state, Node3D *p_spatial, Ref p_node->translation = xform.origin; } -Node3D *GLTFDocument::_generate_spatial(Ref state, Node *scene_parent, const GLTFNodeIndex node_index) { +Node3D *GLTFDocument::_generate_spatial(Ref state, Node *scene_parent, const GLTFNodeIndex node_index, bool p_importer_mesh) { Ref gltf_node = state->nodes[node_index]; Node3D *spatial = memnew(Node3D); @@ -5352,11 +5373,11 @@ void GLTFDocument::_convert_mesh_to_gltf(Node *p_scene_parent, Ref st } } -void GLTFDocument::_generate_scene_node(Ref state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index) { +void GLTFDocument::_generate_scene_node(Ref state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index, bool p_importer_mesh) { Ref gltf_node = state->nodes[node_index]; if (gltf_node->skeleton >= 0) { - _generate_skeleton_bone_node(state, scene_parent, scene_root, node_index); + _generate_skeleton_bone_node(state, scene_parent, scene_root, node_index, p_importer_mesh); return; } @@ -5383,7 +5404,7 @@ void GLTFDocument::_generate_scene_node(Ref state, Node *scene_parent scene_parent = bone_attachment; } if (gltf_node->mesh >= 0) { - current_node = _generate_mesh_instance(state, scene_parent, node_index); + current_node = _generate_mesh_instance_3d(state, scene_parent, node_index, p_importer_mesh); } else if (gltf_node->camera >= 0) { current_node = _generate_camera(state, scene_parent, node_index); } else if (gltf_node->light >= 0) { @@ -5392,7 +5413,7 @@ void GLTFDocument::_generate_scene_node(Ref state, Node *scene_parent // We still have not managed to make a node. if (!current_node) { - current_node = _generate_spatial(state, scene_parent, node_index); + current_node = _generate_spatial(state, scene_parent, node_index, p_importer_mesh); } scene_parent->add_child(current_node); @@ -5405,11 +5426,11 @@ void GLTFDocument::_generate_scene_node(Ref state, Node *scene_parent state->scene_nodes.insert(node_index, current_node); for (int i = 0; i < gltf_node->children.size(); ++i) { - _generate_scene_node(state, current_node, scene_root, gltf_node->children[i]); + _generate_scene_node(state, current_node, scene_root, gltf_node->children[i], p_importer_mesh); } } -void GLTFDocument::_generate_skeleton_bone_node(Ref state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index) { +void GLTFDocument::_generate_skeleton_bone_node(Ref state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index, bool p_importer_mesh) { Ref gltf_node = state->nodes[node_index]; Node3D *current_node = nullptr; @@ -5466,7 +5487,11 @@ void GLTFDocument::_generate_skeleton_bone_node(Ref state, Node *scen // We still have not managed to make a node if (gltf_node->mesh >= 0) { - current_node = _generate_mesh_instance(state, scene_parent, node_index); + if (p_importer_mesh) { + current_node = _generate_importer_mesh_3d(state, scene_parent, node_index, p_importer_mesh); + } else { + current_node = _generate_mesh_instance_3d(state, scene_parent, node_index, p_importer_mesh); + } } else if (gltf_node->camera >= 0) { current_node = _generate_camera(state, scene_parent, node_index); } else if (gltf_node->light >= 0) { @@ -5484,7 +5509,7 @@ void GLTFDocument::_generate_skeleton_bone_node(Ref state, Node *scen state->scene_nodes.insert(node_index, current_node); for (int i = 0; i < gltf_node->children.size(); ++i) { - _generate_scene_node(state, active_skeleton, scene_root, gltf_node->children[i]); + _generate_scene_node(state, active_skeleton, scene_root, gltf_node->children[i], p_importer_mesh); } } @@ -6520,6 +6545,152 @@ Error GLTFDocument::parse(Ref state, String p_path, bool p_read_binar return OK; } +Error GLTFDocument::parse_buffers(Ref state, const PackedByteArray &p_bytes) { + ERR_FAIL_COND_V(p_bytes.size() < 4, FAILED); + Error err; + Ref stream; + stream.instantiate(); + stream->set_data_array(p_bytes); + uint32_t magic = stream->get_32(); + if (magic != 0x46546C67) { + return FAILED; + } + stream->get_32(); // version + stream->get_32(); // length + + uint32_t chunk_length = stream->get_32(); + uint32_t chunk_type = stream->get_32(); + + ERR_FAIL_COND_V(chunk_type != 0x4E4F534A, ERR_PARSE_ERROR); //JSON + Vector json_data; + json_data.resize(chunk_length); + + int32_t len = 0; + err = stream->get_partial_data(json_data.ptrw(), chunk_length, len); + ERR_FAIL_COND_V(int64_t(len) != int64_t(chunk_length), ERR_FILE_CORRUPT); + + String text; + text.parse_utf8((const char *)json_data.ptr(), json_data.size()); + JSON json; + err = json.parse(text); + + ERR_FAIL_COND_V_MSG(err != OK, ERR_PARSE_ERROR, "Mal-formed message!"); + state->json = json.get_data(); + + chunk_length = stream->get_32(); + chunk_type = stream->get_32(); + + if (stream->get_available_bytes()) { + ERR_FAIL_COND_V(chunk_type != 0x004E4942, ERR_PARSE_ERROR); //BIN + state->glb_data.resize(chunk_length); + len = 0; + err = stream->get_partial_data(state->glb_data.ptrw(), chunk_length, len); + ERR_FAIL_COND_V(int64_t(len) != int64_t(chunk_length), ERR_FILE_CORRUPT); + + err = OK; + if (err) { + return FAILED; + } + } + + ERR_FAIL_COND_V(!state->json.has("asset"), Error::FAILED); + + Dictionary asset = state->json["asset"]; + + ERR_FAIL_COND_V(!asset.has("version"), Error::FAILED); + + String version = asset["version"]; + + state->major_version = version.get_slice(".", 0).to_int(); + state->minor_version = version.get_slice(".", 1).to_int(); + + /* STEP 0 PARSE SCENE */ + err = _parse_scenes(state); + if (err != OK) + return Error::FAILED; + + /* STEP 1 PARSE NODES */ + err = _parse_nodes(state); + if (err != OK) + return Error::FAILED; + + /* STEP 2 PARSE BUFFERS */ + err = _parse_buffers(state, ""); + if (err != OK) + return Error::FAILED; + + /* STEP 3 PARSE BUFFER VIEWS */ + err = _parse_buffer_views(state); + if (err != OK) + return Error::FAILED; + + /* STEP 4 PARSE ACCESSORS */ + err = _parse_accessors(state); + if (err != OK) + return Error::FAILED; + + /* STEP 5 PARSE IMAGES */ + err = _parse_images(state, ""); + if (err != OK) + return Error::FAILED; + + /* STEP 6 PARSE TEXTURES */ + err = _parse_textures(state); + if (err != OK) + return Error::FAILED; + + /* STEP 7 PARSE TEXTURES */ + err = _parse_materials(state); + if (err != OK) + return Error::FAILED; + + /* STEP 9 PARSE SKINS */ + err = _parse_skins(state); + if (err != OK) + return Error::FAILED; + + /* STEP 10 DETERMINE SKELETONS */ + err = _determine_skeletons(state); + if (err != OK) + return Error::FAILED; + + /* STEP 11 CREATE SKELETONS */ + err = _create_skeletons(state); + if (err != OK) + return Error::FAILED; + + /* STEP 12 CREATE SKINS */ + err = _create_skins(state); + if (err != OK) + return Error::FAILED; + + /* STEP 13 PARSE MESHES (we have enough info now) */ + err = _parse_meshes(state); + if (err != OK) + return Error::FAILED; + + /* STEP 14 PARSE LIGHTS */ + err = _parse_lights(state); + if (err != OK) { + return Error::FAILED; + } + + /* STEP 15 PARSE CAMERAS */ + err = _parse_cameras(state); + if (err != OK) + return Error::FAILED; + + /* STEP 16 PARSE ANIMATIONS */ + err = _parse_animations(state); + if (err != OK) + return Error::FAILED; + + /* STEP 17 ASSIGN SCENE NAMES */ + _assign_scene_names(state); + + return OK; +} + Dictionary GLTFDocument::_serialize_texture_transform_uv2(Ref p_material) { Dictionary extension; Ref mat = p_material; diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index fb798a055a99..e033e70c0bf6 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -33,14 +33,15 @@ #include "gltf_animation.h" -#include "editor/import/scene_importer_mesh_node_3d.h" #include "scene/3d/bone_attachment_3d.h" #include "scene/3d/light_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/node_3d.h" +#include "scene/3d/scene_importer_mesh_node_3d.h" #include "scene/3d/skeleton_3d.h" #include "scene/animation/animation_player.h" #include "scene/resources/material.h" +#include "scene/resources/scene_importer_mesh.h" #include "scene/resources/texture.h" #include "modules/modules_enabled.gen.h" @@ -270,16 +271,17 @@ class GLTFDocument : public Resource { Error _parse_lights(Ref state); Error _parse_animations(Ref state); Error _serialize_animations(Ref state); + EditorSceneImporterMeshNode3D *_generate_importer_mesh_3d(Ref, Node *, GLTFNodeIndex, bool p_importer_mesh); BoneAttachment3D *_generate_bone_attachment(Ref state, Skeleton3D *skeleton, const GLTFNodeIndex node_index, const GLTFNodeIndex bone_index); - EditorSceneImporterMeshNode3D *_generate_mesh_instance(Ref state, Node *scene_parent, const GLTFNodeIndex node_index); + EditorSceneImporterMeshNode3D *_generate_mesh_instance(Ref state, Node *scene_parent, const GLTFNodeIndex node_index, bool p_importer_mesh); Camera3D *_generate_camera(Ref state, Node *scene_parent, const GLTFNodeIndex node_index); Node3D *_generate_light(Ref state, Node *scene_parent, const GLTFNodeIndex node_index); Node3D *_generate_spatial(Ref state, Node *scene_parent, - const GLTFNodeIndex node_index); + const GLTFNodeIndex node_index, bool p_importer_mesh); void _assign_scene_names(Ref state); template T _interpolate_track(const Vector &p_times, const Vector &p_values, @@ -374,11 +376,10 @@ class GLTFDocument : public Resource { static float get_max_component(const Color &p_color); public: + void _generate_scene_node(Ref state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index, bool p_importer_mesh); void _process_mesh_instances(Ref state, Node *scene_root); - void _generate_scene_node(Ref state, Node *scene_parent, - Node3D *scene_root, - const GLTFNodeIndex node_index); - void _generate_skeleton_bone_node(Ref state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index); + MeshInstance3D *_generate_mesh_instance_3d(Ref state, Node *scene_parent, const GLTFNodeIndex node_index, bool p_importer_mesh); + void _generate_skeleton_bone_node(Ref state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index, bool p_importer_mesh); void _import_animation(Ref state, AnimationPlayer *ap, const GLTFAnimationIndex index, const int bake_fps); GLTFMeshIndex _convert_mesh_instance(Ref state, @@ -443,6 +444,7 @@ class GLTFDocument : public Resource { String p_animation_track_name); Error serialize(Ref state, Node *p_root, const String &p_path); Error parse(Ref state, String p_paths, bool p_read_binary = false); + Error parse_buffers(Ref state, const PackedByteArray &p_bytes); }; #endif // GLTF_DOCUMENT_H diff --git a/modules/gltf/gltf_mesh.cpp b/modules/gltf/gltf_mesh.cpp index 8c10e42c8936..bc20be3fdc4e 100644 --- a/modules/gltf/gltf_mesh.cpp +++ b/modules/gltf/gltf_mesh.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "gltf_mesh.h" -#include "editor/import/scene_importer_mesh.h" +#include "scene/resources/scene_importer_mesh.h" void GLTFMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("get_mesh"), &GLTFMesh::get_mesh); diff --git a/modules/gltf/gltf_mesh.h b/modules/gltf/gltf_mesh.h index 0fc750fc9f39..bc0d09d0eeac 100644 --- a/modules/gltf/gltf_mesh.h +++ b/modules/gltf/gltf_mesh.h @@ -33,8 +33,8 @@ #include "core/io/resource.h" #include "editor/import/resource_importer_scene.h" -#include "editor/import/scene_importer_mesh.h" #include "scene/resources/mesh.h" +#include "scene/resources/scene_importer_mesh.h" class GLTFMesh : public Resource { GDCLASS(GLTFMesh, Resource); diff --git a/editor/import/scene_importer_mesh_node_3d.cpp b/scene/3d/scene_importer_mesh_node_3d.cpp similarity index 100% rename from editor/import/scene_importer_mesh_node_3d.cpp rename to scene/3d/scene_importer_mesh_node_3d.cpp diff --git a/editor/import/scene_importer_mesh_node_3d.h b/scene/3d/scene_importer_mesh_node_3d.h similarity index 98% rename from editor/import/scene_importer_mesh_node_3d.h rename to scene/3d/scene_importer_mesh_node_3d.h index dec1717c9987..6384ab0b446d 100644 --- a/editor/import/scene_importer_mesh_node_3d.h +++ b/scene/3d/scene_importer_mesh_node_3d.h @@ -31,8 +31,8 @@ #ifndef EDITOR_SCENE_IMPORTER_MESH_NODE_3D_H #define EDITOR_SCENE_IMPORTER_MESH_NODE_3D_H -#include "editor/import/scene_importer_mesh.h" #include "scene/3d/node_3d.h" +#include "scene/resources/scene_importer_mesh.h" #include "scene/resources/skin.h" class EditorSceneImporterMesh; diff --git a/editor/import/scene_importer_mesh.cpp b/scene/resources/scene_importer_mesh.cpp similarity index 100% rename from editor/import/scene_importer_mesh.cpp rename to scene/resources/scene_importer_mesh.cpp diff --git a/editor/import/scene_importer_mesh.h b/scene/resources/scene_importer_mesh.h similarity index 100% rename from editor/import/scene_importer_mesh.h rename to scene/resources/scene_importer_mesh.h From 9adfe951073f5703ddbccbf54f62f9e2e9d54f44 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Wed, 8 Sep 2021 11:22:36 -0700 Subject: [PATCH 2/3] Rename to node3d. --- modules/gltf/gltf_document.cpp | 2 +- modules/gltf/gltf_document.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index c8174b3809c1..71dc8461a67e 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -5100,7 +5100,7 @@ void GLTFDocument::_convert_spatial(Ref state, Node3D *p_spatial, Ref p_node->translation = xform.origin; } -Node3D *GLTFDocument::_generate_spatial(Ref state, Node *scene_parent, const GLTFNodeIndex node_index, bool p_importer_mesh) { +Node3D *GLTFDocument::_generate_node_3d(Ref state, Node *scene_parent, const GLTFNodeIndex node_index, bool p_importer_mesh) { Ref gltf_node = state->nodes[node_index]; Node3D *spatial = memnew(Node3D); diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index e033e70c0bf6..9ffbef272c04 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -280,7 +280,7 @@ class GLTFDocument : public Resource { Camera3D *_generate_camera(Ref state, Node *scene_parent, const GLTFNodeIndex node_index); Node3D *_generate_light(Ref state, Node *scene_parent, const GLTFNodeIndex node_index); - Node3D *_generate_spatial(Ref state, Node *scene_parent, + Node3D *_generate_node_3d(Ref state, Node *scene_parent, const GLTFNodeIndex node_index, bool p_importer_mesh); void _assign_scene_names(Ref state); template From 8a6de7337ce4011f74316ae5f06fdd86d7894e80 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Wed, 8 Sep 2021 11:24:01 -0700 Subject: [PATCH 3/3] Rename functions to proper names. --- modules/gltf/gltf_document.cpp | 16 ++++++++-------- modules/gltf/gltf_document.h | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 71dc8461a67e..c1140e304e46 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -4845,7 +4845,7 @@ void GLTFDocument::_assign_scene_names(Ref state) { } } -BoneAttachment3D *GLTFDocument::_generate_bone_attachment(Ref state, Skeleton3D *skeleton, const GLTFNodeIndex node_index, const GLTFNodeIndex bone_index) { +BoneAttachment3D *GLTFDocument::_generate_bone_attachment_3d(Ref state, Skeleton3D *skeleton, const GLTFNodeIndex node_index, const GLTFNodeIndex bone_index) { Ref gltf_node = state->nodes[node_index]; Ref bone_node = state->nodes[bone_index]; BoneAttachment3D *bone_attachment = memnew(BoneAttachment3D); @@ -4955,7 +4955,7 @@ EditorSceneImporterMeshNode3D *GLTFDocument::_generate_importer_mesh_3d(Ref state, Node *scene_parent, const GLTFNodeIndex node_index) { +Node3D *GLTFDocument::_generate_light_3d(Ref state, Node *scene_parent, const GLTFNodeIndex node_index) { Ref gltf_node = state->nodes[node_index]; ERR_FAIL_INDEX_V(gltf_node->light, state->lights.size(), nullptr); @@ -5007,7 +5007,7 @@ Node3D *GLTFDocument::_generate_light(Ref state, Node *scene_parent, return memnew(Node3D); } -Camera3D *GLTFDocument::_generate_camera(Ref state, Node *scene_parent, const GLTFNodeIndex node_index) { +Camera3D *GLTFDocument::_generate_camera_3d(Ref state, Node *scene_parent, const GLTFNodeIndex node_index) { Ref gltf_node = state->nodes[node_index]; ERR_FAIL_INDEX_V(gltf_node->camera, state->cameras.size(), nullptr); @@ -5391,7 +5391,7 @@ void GLTFDocument::_generate_scene_node(Ref state, Node *scene_parent // skinned meshes must not be placed in a bone attachment. if (non_bone_parented_to_skeleton && gltf_node->skin < 0) { // Bone Attachment - Parent Case - BoneAttachment3D *bone_attachment = _generate_bone_attachment(state, active_skeleton, node_index, gltf_node->parent); + BoneAttachment3D *bone_attachment = _generate_bone_attachment_3d(state, active_skeleton, node_index, gltf_node->parent); scene_parent->add_child(bone_attachment); bone_attachment->set_owner(scene_root); @@ -5406,7 +5406,7 @@ void GLTFDocument::_generate_scene_node(Ref state, Node *scene_parent if (gltf_node->mesh >= 0) { current_node = _generate_mesh_instance_3d(state, scene_parent, node_index, p_importer_mesh); } else if (gltf_node->camera >= 0) { - current_node = _generate_camera(state, scene_parent, node_index); + current_node = _generate_camera_3d(state, scene_parent, node_index); } else if (gltf_node->light >= 0) { current_node = _generate_light(state, scene_parent, node_index); } @@ -5444,7 +5444,7 @@ void GLTFDocument::_generate_skeleton_bone_node(Ref state, Node *scen if (active_skeleton != skeleton) { if (active_skeleton) { // Bone Attachment - Direct Parented Skeleton Case - BoneAttachment3D *bone_attachment = _generate_bone_attachment(state, active_skeleton, node_index, gltf_node->parent); + BoneAttachment3D *bone_attachment = _generate_bone_attachment_3d(state, active_skeleton, node_index, gltf_node->parent); scene_parent->add_child(bone_attachment); bone_attachment->set_owner(scene_root); @@ -5472,7 +5472,7 @@ void GLTFDocument::_generate_skeleton_bone_node(Ref state, Node *scen // skinned meshes must not be placed in a bone attachment. if (!is_skinned_mesh) { // Bone Attachment - Same Node Case - BoneAttachment3D *bone_attachment = _generate_bone_attachment(state, active_skeleton, node_index, node_index); + BoneAttachment3D *bone_attachment = _generate_bone_attachment_3d(state, active_skeleton, node_index, node_index); scene_parent->add_child(bone_attachment); bone_attachment->set_owner(scene_root); @@ -5493,7 +5493,7 @@ void GLTFDocument::_generate_skeleton_bone_node(Ref state, Node *scen current_node = _generate_mesh_instance_3d(state, scene_parent, node_index, p_importer_mesh); } } else if (gltf_node->camera >= 0) { - current_node = _generate_camera(state, scene_parent, node_index); + current_node = _generate_camera_3d(state, scene_parent, node_index); } else if (gltf_node->light >= 0) { current_node = _generate_light(state, scene_parent, node_index); } diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index 9ffbef272c04..94020542769d 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -272,14 +272,14 @@ class GLTFDocument : public Resource { Error _parse_animations(Ref state); Error _serialize_animations(Ref state); EditorSceneImporterMeshNode3D *_generate_importer_mesh_3d(Ref, Node *, GLTFNodeIndex, bool p_importer_mesh); - BoneAttachment3D *_generate_bone_attachment(Ref state, + BoneAttachment3D *_generate_bone_attachment_3d(Ref state, Skeleton3D *skeleton, const GLTFNodeIndex node_index, const GLTFNodeIndex bone_index); EditorSceneImporterMeshNode3D *_generate_mesh_instance(Ref state, Node *scene_parent, const GLTFNodeIndex node_index, bool p_importer_mesh); - Camera3D *_generate_camera(Ref state, Node *scene_parent, + Camera3D *_generate_camera_3d(Ref state, Node *scene_parent, const GLTFNodeIndex node_index); - Node3D *_generate_light(Ref state, Node *scene_parent, const GLTFNodeIndex node_index); + Node3D *_generate_light_3d(Ref state, Node *scene_parent, const GLTFNodeIndex node_index); Node3D *_generate_node_3d(Ref state, Node *scene_parent, const GLTFNodeIndex node_index, bool p_importer_mesh); void _assign_scene_names(Ref state);