diff options
Diffstat (limited to 'modules')
41 files changed, 327 insertions, 259 deletions
diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index a5b3db89d9..25772bebbe 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -1052,7 +1052,7 @@ void CSGSphere3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_material", "material"), &CSGSphere3D::set_material); ClassDB::bind_method(D_METHOD("get_material"), &CSGSphere3D::get_material); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.001,100.0,0.001"), "set_radius", "get_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.001,100.0,0.001,suffix:m"), "set_radius", "get_radius"); ADD_PROPERTY(PropertyInfo(Variant::INT, "radial_segments", PROPERTY_HINT_RANGE, "1,100,1"), "set_radial_segments", "get_radial_segments"); ADD_PROPERTY(PropertyInfo(Variant::INT, "rings", PROPERTY_HINT_RANGE, "1,100,1"), "set_rings", "get_rings"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); @@ -1225,7 +1225,7 @@ void CSGBox3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_material", "material"), &CSGBox3D::set_material); ClassDB::bind_method(D_METHOD("get_material"), &CSGBox3D::get_material); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size", PROPERTY_HINT_NONE, "suffix:m"), "set_size", "get_size"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); } @@ -1405,8 +1405,8 @@ void CSGCylinder3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_smooth_faces", "smooth_faces"), &CSGCylinder3D::set_smooth_faces); ClassDB::bind_method(D_METHOD("get_smooth_faces"), &CSGCylinder3D::get_smooth_faces); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_radius", "get_radius"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_height", "get_height"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp,suffix:m"), "set_radius", "get_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp,suffix:m"), "set_height", "get_height"); ADD_PROPERTY(PropertyInfo(Variant::INT, "sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_sides", "get_sides"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cone"), "set_cone", "is_cone"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); @@ -1630,8 +1630,8 @@ void CSGTorus3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_smooth_faces", "smooth_faces"), &CSGTorus3D::set_smooth_faces); ClassDB::bind_method(D_METHOD("get_smooth_faces"), &CSGTorus3D::get_smooth_faces); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inner_radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_inner_radius", "get_inner_radius"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "outer_radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_outer_radius", "get_outer_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inner_radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp,suffix:m"), "set_inner_radius", "get_inner_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "outer_radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp,suffix:m"), "set_outer_radius", "get_outer_radius"); ADD_PROPERTY(PropertyInfo(Variant::INT, "sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_sides", "get_sides"); ADD_PROPERTY(PropertyInfo(Variant::INT, "ring_sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_ring_sides", "get_ring_sides"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); diff --git a/modules/csg/editor/csg_gizmos.cpp b/modules/csg/editor/csg_gizmos.cpp index 4d972e46c6..6442ff71fc 100644 --- a/modules/csg/editor/csg_gizmos.cpp +++ b/modules/csg/editor/csg_gizmos.cpp @@ -349,9 +349,11 @@ void CSGShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { if (cs->is_root_shape()) { Array csg_meshes = cs->get_meshes(); - Ref<Mesh> csg_mesh = csg_meshes[1]; - if (csg_mesh.is_valid()) { - p_gizmo->add_collision_triangles(csg_mesh->generate_triangle_mesh()); + if (csg_meshes.size() == 2) { + Ref<Mesh> csg_mesh = csg_meshes[1]; + if (csg_mesh.is_valid()) { + p_gizmo->add_collision_triangles(csg_mesh->generate_triangle_mesh()); + } } } diff --git a/modules/gdscript/editor/gdscript_translation_parser_plugin.h b/modules/gdscript/editor/gdscript_translation_parser_plugin.h index 4633a431d8..969a50f48c 100644 --- a/modules/gdscript/editor/gdscript_translation_parser_plugin.h +++ b/modules/gdscript/editor/gdscript_translation_parser_plugin.h @@ -31,7 +31,7 @@ #ifndef GDSCRIPT_TRANSLATION_PARSER_PLUGIN_H #define GDSCRIPT_TRANSLATION_PARSER_PLUGIN_H -#include "core/templates/rb_set.h" +#include "core/templates/hash_set.h" #include "editor/editor_translation_parser.h" #include "modules/gdscript/gdscript_parser.h" @@ -44,9 +44,9 @@ class GDScriptEditorTranslationParserPlugin : public EditorTranslationParserPlug // List of patterns used for extracting translation strings. StringName tr_func = "tr"; StringName trn_func = "tr_n"; - RBSet<StringName> assignment_patterns; - RBSet<StringName> first_arg_patterns; - RBSet<StringName> second_arg_patterns; + HashSet<StringName> assignment_patterns; + HashSet<StringName> first_arg_patterns; + HashSet<StringName> second_arg_patterns; // FileDialog patterns. StringName fd_add_filter = "add_filter"; StringName fd_set_filter = "set_filters"; diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 25f4823d92..066b772227 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -788,7 +788,7 @@ void GDScript::update_exports() { return; } - RBSet<ObjectID> copy = inheriters_cache; //might get modified + HashSet<ObjectID> copy = inheriters_cache; //might get modified for (const ObjectID &E : copy) { Object *id = ObjectDB::get_instance(E); @@ -937,7 +937,7 @@ void GDScript::get_constants(HashMap<StringName, Variant> *p_constants) { } } -void GDScript::get_members(RBSet<StringName> *p_members) { +void GDScript::get_members(HashSet<StringName> *p_members) { if (p_members) { for (const StringName &E : members) { p_members->insert(E); @@ -1916,7 +1916,7 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so #ifdef TOOLS_ENABLED while (script->placeholders.size()) { - Object *obj = script->placeholders.front()->get()->get_owner(); + Object *obj = (*script->placeholders.begin())->get_owner(); //save instance info if (obj->get_script_instance()) { @@ -1926,7 +1926,7 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so obj->set_script(Variant()); } else { // no instance found. Let's remove it so we don't loop forever - script->placeholders.erase(script->placeholders.front()->get()); + script->placeholders.erase(*script->placeholders.begin()); } } diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 5199d3215d..80f187a375 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -37,6 +37,7 @@ #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" #include "core/object/script_language.h" +#include "core/templates/rb_set.h" #include "gdscript_function.h" class GDScriptNativeClass : public RefCounted { @@ -80,7 +81,7 @@ class GDScript : public Script { GDScript *_base = nullptr; //fast pointer access GDScript *_owner = nullptr; //for subclasses - RBSet<StringName> members; //members are just indices to the instantiated script. + HashSet<StringName> members; //members are just indices to the instantiated script. HashMap<StringName, Variant> constants; HashMap<StringName, GDScriptFunction *> member_functions; HashMap<StringName, MemberInfo> member_indices; //members are just indices to the instantiated script. @@ -95,7 +96,7 @@ class GDScript : public Script { List<PropertyInfo> members_cache; HashMap<StringName, Variant> member_default_values_cache; Ref<GDScript> base_cache; - RBSet<ObjectID> inheriters_cache; + HashSet<ObjectID> inheriters_cache; bool source_changed_cache = false; bool placeholder_fallback_enabled = false; void _update_exports_values(HashMap<StringName, Variant> &values, List<PropertyInfo> &propnames); @@ -139,7 +140,7 @@ class GDScript : public Script { String _get_debug_path() const; #ifdef TOOLS_ENABLED - RBSet<PlaceHolderScriptInstance *> placeholders; + HashSet<PlaceHolderScriptInstance *> placeholders; //void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override; #endif @@ -178,7 +179,7 @@ public: const HashMap<StringName, Ref<GDScript>> &get_subclasses() const { return subclasses; } const HashMap<StringName, Variant> &get_constants() const { return constants; } - const RBSet<StringName> &get_members() const { return members; } + const HashSet<StringName> &get_members() const { return members; } const GDScriptDataType &get_member_type(const StringName &p_member) const { CRASH_COND(!member_indices.has(p_member)); return member_indices[p_member].data_type; @@ -246,7 +247,7 @@ public: } virtual void get_constants(HashMap<StringName, Variant> *p_constants) override; - virtual void get_members(RBSet<StringName> *p_members) override; + virtual void get_members(HashSet<StringName> *p_members) override; virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const override; @@ -449,7 +450,7 @@ public: virtual bool is_using_templates() override; virtual Ref<Script> make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const override; virtual Vector<ScriptTemplate> get_built_in_templates(StringName p_object) override; - virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, RBSet<int> *r_safe_lines = nullptr) const override; + virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const override; virtual Script *create_script() const override; virtual bool has_named_classes() const override; virtual bool supports_builtin_mode() const override; diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 32fa3b8c87..3976bde8c9 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -898,7 +898,7 @@ void GDScriptAnalyzer::resolve_class_body(GDScriptParser::ClassNode *p_class) { } #ifdef DEBUG_ENABLED - RBSet<uint32_t> previously_ignored = parser->ignored_warning_codes; + HashSet<uint32_t> previously_ignored = parser->ignored_warning_codes; for (uint32_t ignored_warning : member.function->ignored_warnings) { parser->ignored_warning_codes.insert(ignored_warning); } @@ -947,7 +947,7 @@ void GDScriptAnalyzer::resolve_class_body(GDScriptParser::ClassNode *p_class) { GDScriptParser::ClassNode::Member member = p_class->members[i]; if (member.type == GDScriptParser::ClassNode::Member::VARIABLE) { #ifdef DEBUG_ENABLED - RBSet<uint32_t> previously_ignored = parser->ignored_warning_codes; + HashSet<uint32_t> previously_ignored = parser->ignored_warning_codes; for (uint32_t ignored_warning : member.function->ignored_warnings) { parser->ignored_warning_codes.insert(ignored_warning); } @@ -1279,7 +1279,7 @@ void GDScriptAnalyzer::resolve_suite(GDScriptParser::SuiteNode *p_suite) { } #ifdef DEBUG_ENABLED - RBSet<uint32_t> previously_ignored = parser->ignored_warning_codes; + HashSet<uint32_t> previously_ignored = parser->ignored_warning_codes; for (uint32_t ignored_warning : stmt->ignored_warnings) { parser->ignored_warning_codes.insert(ignored_warning); } diff --git a/modules/gdscript/gdscript_analyzer.h b/modules/gdscript/gdscript_analyzer.h index 5b03f6dbb4..3966b81b6e 100644 --- a/modules/gdscript/gdscript_analyzer.h +++ b/modules/gdscript/gdscript_analyzer.h @@ -33,7 +33,7 @@ #include "core/object/object.h" #include "core/object/ref_counted.h" -#include "core/templates/rb_set.h" +#include "core/templates/hash_set.h" #include "gdscript_cache.h" #include "gdscript_parser.h" diff --git a/modules/gdscript/gdscript_cache.cpp b/modules/gdscript/gdscript_cache.cpp index bd98d66fcc..4c15fca91e 100644 --- a/modules/gdscript/gdscript_cache.cpp +++ b/modules/gdscript/gdscript_cache.cpp @@ -223,13 +223,13 @@ Error GDScriptCache::finish_compiling(const String &p_owner) { singleton->full_gdscript_cache[p_owner] = script.ptr(); singleton->shallow_gdscript_cache.erase(p_owner); - RBSet<String> depends = singleton->dependencies[p_owner]; + HashSet<String> depends = singleton->dependencies[p_owner]; Error err = OK; - for (const RBSet<String>::Element *E = depends.front(); E != nullptr; E = E->next()) { + for (const String &E : depends) { Error this_err = OK; // No need to save the script. We assume it's already referenced in the owner. - get_full_script(E->get(), this_err); + get_full_script(E, this_err); if (this_err != OK) { err = this_err; diff --git a/modules/gdscript/gdscript_cache.h b/modules/gdscript/gdscript_cache.h index 8abae7d4ad..b971bdd984 100644 --- a/modules/gdscript/gdscript_cache.h +++ b/modules/gdscript/gdscript_cache.h @@ -34,7 +34,7 @@ #include "core/object/ref_counted.h" #include "core/os/mutex.h" #include "core/templates/hash_map.h" -#include "core/templates/rb_set.h" +#include "core/templates/hash_set.h" #include "gdscript.h" class GDScriptAnalyzer; @@ -74,7 +74,7 @@ class GDScriptCache { HashMap<String, GDScriptParserRef *> parser_map; HashMap<String, GDScript *> shallow_gdscript_cache; HashMap<String, GDScript *> full_gdscript_cache; - HashMap<String, RBSet<String>> dependencies; + HashMap<String, HashSet<String>> dependencies; friend class GDScript; friend class GDScriptParserRef; diff --git a/modules/gdscript/gdscript_compiler.h b/modules/gdscript/gdscript_compiler.h index c9ffb04fb8..4841884e2d 100644 --- a/modules/gdscript/gdscript_compiler.h +++ b/modules/gdscript/gdscript_compiler.h @@ -31,7 +31,7 @@ #ifndef GDSCRIPT_COMPILER_H #define GDSCRIPT_COMPILER_H -#include "core/templates/rb_set.h" +#include "core/templates/hash_set.h" #include "gdscript.h" #include "gdscript_codegen.h" #include "gdscript_function.h" @@ -39,8 +39,8 @@ class GDScriptCompiler { const GDScriptParser *parser = nullptr; - RBSet<GDScript *> parsed_classes; - RBSet<GDScript *> parsing_classes; + HashSet<GDScript *> parsed_classes; + HashSet<GDScript *> parsing_classes; GDScript *main_script = nullptr; struct CodeGen { diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 72f54626e3..5b63fe7466 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -110,7 +110,7 @@ static void get_function_names_recursively(const GDScriptParser::ClassNode *p_cl } } -bool GDScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, RBSet<int> *r_safe_lines) const { +bool GDScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, HashSet<int> *r_safe_lines) const { GDScriptParser parser; GDScriptAnalyzer analyzer(&parser); @@ -159,7 +159,7 @@ bool GDScriptLanguage::validate(const String &p_script, const String &p_path, Li #ifdef DEBUG_ENABLED if (r_safe_lines) { - const RBSet<int> &unsafe_lines = parser.get_unsafe_lines(); + const HashSet<int> &unsafe_lines = parser.get_unsafe_lines(); for (int i = 1; i <= parser.get_last_line_number(); i++) { if (!unsafe_lines.has(i)) { r_safe_lines->insert(i); diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 17f87edeeb..96b9a10d3c 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -1205,9 +1205,9 @@ private: List<ParserError> errors; #ifdef DEBUG_ENABLED List<GDScriptWarning> warnings; - RBSet<String> ignored_warnings; - RBSet<uint32_t> ignored_warning_codes; - RBSet<int> unsafe_lines; + HashSet<String> ignored_warnings; + HashSet<uint32_t> ignored_warning_codes; + HashSet<int> unsafe_lines; #endif GDScriptTokenizer tokenizer; @@ -1419,7 +1419,7 @@ public: } #ifdef DEBUG_ENABLED const List<GDScriptWarning> &get_warnings() const { return warnings; } - const RBSet<int> &get_unsafe_lines() const { return unsafe_lines; } + const HashSet<int> &get_unsafe_lines() const { return unsafe_lines; } int get_last_line_number() const { return current.end_line; } #endif diff --git a/modules/gdscript/gdscript_tokenizer.h b/modules/gdscript/gdscript_tokenizer.h index ad818cf812..7fb715f2c8 100644 --- a/modules/gdscript/gdscript_tokenizer.h +++ b/modules/gdscript/gdscript_tokenizer.h @@ -32,8 +32,8 @@ #define GDSCRIPT_TOKENIZER_H #include "core/templates/hash_map.h" +#include "core/templates/hash_set.h" #include "core/templates/list.h" -#include "core/templates/rb_set.h" #include "core/templates/vector.h" #include "core/variant/variant.h" diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index ffd3cfa907..8d484a43b3 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -784,7 +784,7 @@ GDScriptWorkspace::GDScriptWorkspace() { } GDScriptWorkspace::~GDScriptWorkspace() { - RBSet<String> cached_parsers; + HashSet<String> cached_parsers; for (const KeyValue<String, ExtendGDScriptParser *> &E : parse_results) { cached_parsers.insert(E.key); diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 7cedbda804..b230c6ba36 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -70,7 +70,7 @@ class EditorExportGDScript : public EditorExportPlugin { GDCLASS(EditorExportGDScript, EditorExportPlugin); public: - virtual void _export_file(const String &p_path, const String &p_type, const RBSet<String> &p_features) override { + virtual void _export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) override { int script_mode = EditorExportPreset::MODE_SCRIPT_COMPILED; String script_key; diff --git a/modules/gltf/doc_classes/GLTFDocumentExtension.xml b/modules/gltf/doc_classes/GLTFDocumentExtension.xml index 03b4380ff4..3c28546ad7 100644 --- a/modules/gltf/doc_classes/GLTFDocumentExtension.xml +++ b/modules/gltf/doc_classes/GLTFDocumentExtension.xml @@ -7,65 +7,52 @@ <tutorials> </tutorials> <methods> - <method name="export_post"> - <return type="int" enum="Error" /> - <argument index="0" name="document" type="GLTFDocument" /> + <method name="_export_node" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="state" type="GLTFState" /> + <argument index="1" name="gltf_node" type="GLTFNode" /> + <argument index="2" name="json" type="Dictionary" /> + <argument index="3" name="node" type="Node" /> <description> </description> </method> - <method name="export_preflight"> - <return type="int" enum="Error" /> - <argument index="0" name="document" type="GLTFDocument" /> - <argument index="1" name="node" type="Node" /> + <method name="_export_post" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="state" type="GLTFState" /> <description> </description> </method> - <method name="get_export_setting" qualifiers="const"> - <return type="Variant" /> - <argument index="0" name="key" type="StringName" /> + <method name="_export_preflight" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="root" type="Node" /> <description> </description> </method> - <method name="get_export_setting_keys" qualifiers="const"> - <return type="Array" /> + <method name="_import_node" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="state" type="GLTFState" /> + <argument index="1" name="gltf_node" type="GLTFNode" /> + <argument index="2" name="json" type="Dictionary" /> + <argument index="3" name="node" type="Node" /> <description> </description> </method> - <method name="get_import_setting" qualifiers="const"> - <return type="Variant" /> - <argument index="0" name="key" type="StringName" /> + <method name="_import_post" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="state" type="GLTFState" /> + <argument index="1" name="root" type="Node" /> <description> </description> </method> - <method name="get_import_setting_keys" qualifiers="const"> - <return type="Array" /> + <method name="_import_post_parse" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="state" type="GLTFState" /> <description> </description> </method> - <method name="import_post"> - <return type="int" enum="Error" /> - <argument index="0" name="document" type="GLTFDocument" /> - <argument index="1" name="node" type="Node" /> - <description> - </description> - </method> - <method name="import_preflight"> - <return type="int" enum="Error" /> - <argument index="0" name="document" type="GLTFDocument" /> - <description> - </description> - </method> - <method name="set_export_setting"> - <return type="void" /> - <argument index="0" name="key" type="StringName" /> - <argument index="1" name="value" type="Variant" /> - <description> - </description> - </method> - <method name="set_import_setting"> - <return type="void" /> - <argument index="0" name="key" type="StringName" /> - <argument index="1" name="value" type="Variant" /> + <method name="_import_preflight" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="state" type="GLTFState" /> <description> </description> </method> diff --git a/modules/gltf/doc_classes/GLTFState.xml b/modules/gltf/doc_classes/GLTFState.xml index a59fa900bc..44a1723563 100644 --- a/modules/gltf/doc_classes/GLTFState.xml +++ b/modules/gltf/doc_classes/GLTFState.xml @@ -192,6 +192,8 @@ </method> </methods> <members> + <member name="base_path" type="String" setter="set_base_path" getter="get_base_path" default=""""> + </member> <member name="buffers" type="Array" setter="set_buffers" getter="get_buffers" default="[]"> </member> <member name="glb_data" type="PackedByteArray" setter="set_glb_data" getter="get_glb_data" default="PackedByteArray()"> diff --git a/modules/gltf/editor/editor_scene_importer_gltf.cpp b/modules/gltf/editor/editor_scene_importer_gltf.cpp index d5b247fc6e..3fadec5167 100644 --- a/modules/gltf/editor/editor_scene_importer_gltf.cpp +++ b/modules/gltf/editor/editor_scene_importer_gltf.cpp @@ -35,7 +35,6 @@ #include "../gltf_document.h" #include "../gltf_state.h" -#include "scene/main/node.h" #include "scene/resources/animation.h" uint32_t EditorSceneFormatImporterGLTF::get_import_flags() const { diff --git a/modules/gltf/editor/editor_scene_importer_gltf.h b/modules/gltf/editor/editor_scene_importer_gltf.h index edca038532..b17a1e4eaa 100644 --- a/modules/gltf/editor/editor_scene_importer_gltf.h +++ b/modules/gltf/editor/editor_scene_importer_gltf.h @@ -33,6 +33,9 @@ #ifdef TOOLS_ENABLED +#include "../gltf_document_extension.h" +#include "../gltf_state.h" + #include "editor/import/resource_importer_scene.h" class Animation; diff --git a/modules/gltf/gltf_accessor.h b/modules/gltf/gltf_accessor.h index 6bf1bf543a..f412dc2c7f 100644 --- a/modules/gltf/gltf_accessor.h +++ b/modules/gltf/gltf_accessor.h @@ -34,7 +34,6 @@ #include "core/io/resource.h" #include "gltf_document.h" -#include "gltf_document_extension.h" struct GLTFAccessor : public Resource { GDCLASS(GLTFAccessor, Resource); diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index f440a29f28..2017355717 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -128,10 +128,10 @@ Error GLTFDocument::_serialize(Ref<GLTFState> state, const String &p_path) { state->buffers.push_back(Vector<uint8_t>()); } - /* STEP 1 CONVERT MESH INSTANCES */ + /* STEP CONVERT MESH INSTANCES */ _convert_mesh_instances(state); - /* STEP 2 SERIALIZE CAMERAS */ + /* STEP SERIALIZE CAMERAS */ Error err = _serialize_cameras(state); if (err != OK) { return Error::FAILED; @@ -143,37 +143,37 @@ Error GLTFDocument::_serialize(Ref<GLTFState> state, const String &p_path) { return Error::FAILED; } - /* STEP 5 SERIALIZE MESHES (we have enough info now) */ + /* STEP SERIALIZE MESHES (we have enough info now) */ err = _serialize_meshes(state); if (err != OK) { return Error::FAILED; } - /* STEP 6 SERIALIZE TEXTURES */ + /* STEP SERIALIZE TEXTURES */ err = _serialize_materials(state); if (err != OK) { return Error::FAILED; } - /* STEP 7 SERIALIZE ANIMATIONS */ + /* STEP SERIALIZE ANIMATIONS */ err = _serialize_animations(state); if (err != OK) { return Error::FAILED; } - /* STEP 8 SERIALIZE ACCESSORS */ + /* STEP SERIALIZE ACCESSORS */ err = _encode_accessors(state); if (err != OK) { return Error::FAILED; } - /* STEP 9 SERIALIZE IMAGES */ + /* STEP SERIALIZE IMAGES */ err = _serialize_images(state, p_path); if (err != OK) { return Error::FAILED; } - /* STEP 10 SERIALIZE TEXTURES */ + /* STEP SERIALIZE TEXTURES */ err = _serialize_textures(state); if (err != OK) { return Error::FAILED; @@ -183,42 +183,49 @@ Error GLTFDocument::_serialize(Ref<GLTFState> state, const String &p_path) { state->buffer_views.write[i]->buffer = 0; } - /* STEP 11 SERIALIZE BUFFER VIEWS */ + /* STEP SERIALIZE BUFFER VIEWS */ err = _encode_buffer_views(state); if (err != OK) { return Error::FAILED; } - /* STEP 12 SERIALIZE NODES */ + /* STEP SERIALIZE NODES */ err = _serialize_nodes(state); if (err != OK) { return Error::FAILED; } - /* STEP 13 SERIALIZE SCENE */ + /* STEP SERIALIZE SCENE */ err = _serialize_scenes(state); if (err != OK) { return Error::FAILED; } - /* STEP 14 SERIALIZE SCENE */ + /* STEP SERIALIZE SCENE */ err = _serialize_lights(state); if (err != OK) { return Error::FAILED; } - /* STEP 15 SERIALIZE EXTENSIONS */ + /* STEP SERIALIZE EXTENSIONS */ err = _serialize_extensions(state); if (err != OK) { return Error::FAILED; } - /* STEP 16 SERIALIZE VERSION */ + /* STEP SERIALIZE VERSION */ err = _serialize_version(state); if (err != OK) { return Error::FAILED; } + for (int32_t ext_i = 0; ext_i < document_extensions.size(); ext_i++) { + Ref<GLTFDocumentExtension> ext = document_extensions[ext_i]; + ERR_CONTINUE(ext.is_null()); + err = ext->export_post(state); + ERR_FAIL_COND_V(err != OK, err); + } + return OK; } @@ -442,6 +449,15 @@ Error GLTFDocument::_serialize_nodes(Ref<GLTFState> state) { } node["children"] = children; } + + for (int32_t ext_i = 0; ext_i < document_extensions.size(); ext_i++) { + Ref<GLTFDocumentExtension> ext = document_extensions[ext_i]; + ERR_CONTINUE(ext.is_null()); + ERR_CONTINUE(!state->scene_nodes.find(i)); + Error err = ext->export_node(state, n, state->json, state->scene_nodes[i]); + ERR_CONTINUE(err != OK); + } + nodes.push_back(node); } state->json["nodes"] = nodes; @@ -5658,7 +5674,7 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> state, Node *scene_parent if (!current_node) { current_node = _generate_spatial(state, node_index); } - scene_parent->add_child(current_node); + scene_parent->add_child(current_node, true); if (current_node != scene_root) { current_node->set_owner(scene_root); } @@ -6642,8 +6658,8 @@ Error GLTFDocument::_parse(Ref<GLTFState> state, String p_path, Ref<FileAccess> for (int32_t ext_i = 0; ext_i < document_extensions.size(); ext_i++) { Ref<GLTFDocumentExtension> ext = document_extensions[ext_i]; ERR_CONTINUE(ext.is_null()); - err = ext->import_preflight(this); - ERR_FAIL_COND_V(err != OK, FAILED); + err = ext->import_preflight(state); + ERR_FAIL_COND_V(err != OK, err); } err = _parse_gltf_state(state, p_path, p_bake_fps); ERR_FAIL_COND_V(err != OK, err); @@ -6870,12 +6886,10 @@ PackedByteArray GLTFDocument::generate_buffer(Ref<GLTFState> state) { Error GLTFDocument::write_to_filesystem(Ref<GLTFState> state, const String &p_path) { ERR_FAIL_NULL_V(state, ERR_INVALID_PARAMETER); - Error err = _serialize(state, p_path); if (err != OK) { return err; } - err = _serialize_file(state, p_path); if (err != OK) { return Error::FAILED; @@ -6886,6 +6900,7 @@ Error GLTFDocument::write_to_filesystem(Ref<GLTFState> state, const String &p_pa Node *GLTFDocument::generate_scene(Ref<GLTFState> state, int32_t p_bake_fps) { ERR_FAIL_NULL_V(state, nullptr); ERR_FAIL_INDEX_V(0, state->root_nodes.size(), nullptr); + Error err = OK; GLTFNodeIndex gltf_root = state->root_nodes.write[0]; Node *gltf_root_node = state->get_scene_node(gltf_root); Node *root = gltf_root_node->get_parent(); @@ -6899,12 +6914,26 @@ Node *GLTFDocument::generate_scene(Ref<GLTFState> state, int32_t p_bake_fps) { _import_animation(state, ap, i, p_bake_fps); } } - + for (KeyValue<GLTFNodeIndex, Node *> E : state->scene_nodes) { + ERR_CONTINUE(!E.value); + for (int32_t ext_i = 0; ext_i < document_extensions.size(); ext_i++) { + Ref<GLTFDocumentExtension> ext = document_extensions[ext_i]; + ERR_CONTINUE(ext.is_null()); + ERR_CONTINUE(!state->json.has("nodes")); + Array nodes = state->json["nodes"]; + ERR_CONTINUE(E.key >= nodes.size()); + ERR_CONTINUE(E.key < 0); + Dictionary node_json = nodes[E.key]; + Ref<GLTFNode> gltf_node = state->nodes[E.key]; + err = ext->import_node(state, gltf_node, node_json, E.value); + ERR_CONTINUE(err != OK); + } + } for (int32_t ext_i = 0; ext_i < document_extensions.size(); ext_i++) { Ref<GLTFDocumentExtension> ext = document_extensions[ext_i]; ERR_CONTINUE(ext.is_null()); - Error err = ext->import_post(this, root); - ERR_FAIL_COND_V(err != OK, nullptr); + err = ext->import_post(state, root); + ERR_CONTINUE(err != OK); } ERR_FAIL_NULL_V(root, nullptr); return root; @@ -6919,13 +6948,23 @@ Error GLTFDocument::append_from_scene(Node *p_node, Ref<GLTFState> state, uint32 if (!state->buffers.size()) { state->buffers.push_back(Vector<uint8_t>()); } + for (int32_t ext_i = 0; ext_i < document_extensions.size(); ext_i++) { + Ref<GLTFDocumentExtension> ext = document_extensions[ext_i]; + ERR_CONTINUE(ext.is_null()); + } - /* STEP 1 CONVERT MESH INSTANCES */ - _convert_mesh_instances(state); + for (int32_t ext_i = 0; ext_i < document_extensions.size(); ext_i++) { + Ref<GLTFDocumentExtension> ext = document_extensions[ext_i]; + ERR_CONTINUE(ext.is_null()); + Error err = ext->export_preflight(p_node); + ERR_FAIL_COND_V(err != OK, FAILED); + } + _convert_scene_node(state, p_node, -1, -1); + if (!state->buffers.size()) { + state->buffers.push_back(Vector<uint8_t>()); + } - /* STEP 2 CREATE SKINS */ - Error err = _serialize_skins(state); - return err; + return OK; } Error GLTFDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<GLTFState> state, uint32_t p_flags, int32_t p_bake_fps) { @@ -6938,8 +6977,15 @@ Error GLTFDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_pa Ref<FileAccessMemory> file_access; file_access.instantiate(); file_access->open_custom(p_bytes.ptr(), p_bytes.size()); - err = _parse(state, p_base_path.get_base_dir(), file_access, p_bake_fps); - ERR_FAIL_COND_V(err != OK, FAILED); + state->base_path = p_base_path.get_base_dir(); + err = _parse(state, state->base_path, file_access, p_bake_fps); + ERR_FAIL_COND_V(err != OK, err); + for (int32_t ext_i = 0; ext_i < document_extensions.size(); ext_i++) { + Ref<GLTFDocumentExtension> ext = document_extensions[ext_i]; + ERR_CONTINUE(ext.is_null()); + err = ext->import_post_parse(state); + ERR_FAIL_COND_V(err != OK, err); + } return OK; } @@ -7030,6 +7076,7 @@ Error GLTFDocument::_parse_gltf_state(Ref<GLTFState> state, const String &p_sear for (int32_t root_i = 0; root_i < state->root_nodes.size(); root_i++) { _generate_scene_node(state, root, root, state->root_nodes[root_i]); } + return OK; } @@ -7049,9 +7096,16 @@ Error GLTFDocument::append_from_file(String p_path, Ref<GLTFState> r_state, uint if (base_path.is_empty()) { base_path = p_path.get_base_dir(); } + r_state->base_path = base_path; err = _parse(r_state, base_path, f, p_bake_fps); - ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); - return err; + ERR_FAIL_COND_V(err != OK, err); + for (int32_t ext_i = 0; ext_i < document_extensions.size(); ext_i++) { + Ref<GLTFDocumentExtension> ext = document_extensions[ext_i]; + ERR_CONTINUE(ext.is_null()); + err = ext->import_post_parse(r_state); + ERR_FAIL_COND_V(err != OK, err); + } + return OK; } Error GLTFDocument::_parse_gltf_extensions(Ref<GLTFState> state) { diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index 9db824a0d4..2f61210ff9 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -33,19 +33,12 @@ #include "gltf_animation.h" -#include "core/error/error_list.h" -#include "core/variant/dictionary.h" -#include "core/variant/variant.h" -#include "gltf_document_extension_convert_importer_mesh.h" #include "scene/3d/bone_attachment_3d.h" #include "scene/3d/importer_mesh_instance_3d.h" #include "scene/3d/light_3d.h" #include "scene/3d/mesh_instance_3d.h" -#include "scene/3d/node_3d.h" -#include "scene/3d/skeleton_3d.h" #include "scene/animation/animation_player.h" #include "scene/resources/material.h" -#include "scene/resources/texture.h" #include "modules/modules_enabled.gen.h" // For csg, gridmap. @@ -135,12 +128,12 @@ private: } template <class T> - static Array to_array(const RBSet<T> &p_inp) { + static Array to_array(const HashSet<T> &p_inp) { Array ret; - typename RBSet<T>::Element *elem = p_inp.front(); + typename HashSet<T>::Iterator elem = p_inp.begin(); while (elem) { - ret.push_back(elem->get()); - elem = elem->next(); + ret.push_back(*elem); + ++elem; } return ret; } @@ -154,7 +147,7 @@ private: } template <class T> - static void set_from_array(RBSet<T> &r_out, const Array &p_inp) { + static void set_from_array(HashSet<T> &r_out, const Array &p_inp) { r_out.clear(); for (int i = 0; i < p_inp.size(); i++) { r_out.insert(p_inp[i]); diff --git a/modules/gltf/gltf_document_extension.cpp b/modules/gltf/gltf_document_extension.cpp index 192a1d347c..d0bd7651e0 100644 --- a/modules/gltf/gltf_document_extension.cpp +++ b/modules/gltf/gltf_document_extension.cpp @@ -30,59 +30,79 @@ #include "gltf_document_extension.h" -#include "gltf_document.h" - void GLTFDocumentExtension::_bind_methods() { - // Import - ClassDB::bind_method(D_METHOD("get_import_setting_keys"), - &GLTFDocumentExtension::get_import_setting_keys); - ClassDB::bind_method(D_METHOD("import_preflight", "document"), - &GLTFDocumentExtension::import_preflight); - ClassDB::bind_method(D_METHOD("get_import_setting", "key"), - &GLTFDocumentExtension::get_import_setting); - ClassDB::bind_method(D_METHOD("set_import_setting", "key", "value"), - &GLTFDocumentExtension::set_import_setting); - ClassDB::bind_method(D_METHOD("import_post", "document", "node"), - &GLTFDocumentExtension::import_post); - // Export - ClassDB::bind_method(D_METHOD("get_export_setting_keys"), - &GLTFDocumentExtension::get_export_setting_keys); - ClassDB::bind_method(D_METHOD("get_export_setting", "key"), - &GLTFDocumentExtension::get_export_setting); - ClassDB::bind_method(D_METHOD("set_export_setting", "key", "value"), - &GLTFDocumentExtension::set_export_setting); - ClassDB::bind_method(D_METHOD("export_preflight", "document", "node"), - &GLTFDocumentExtension::export_preflight); - ClassDB::bind_method(D_METHOD("export_post", "document"), - &GLTFDocumentExtension::export_post); + GDVIRTUAL_BIND(_import_preflight, "state"); + GDVIRTUAL_BIND(_import_post_parse, "state"); + GDVIRTUAL_BIND(_import_node, "state", "gltf_node", "json", "node"); + GDVIRTUAL_BIND(_import_post, "state", "root"); + GDVIRTUAL_BIND(_export_preflight, "root"); + GDVIRTUAL_BIND(_export_node, "state", "gltf_node", "json", "node"); + GDVIRTUAL_BIND(_export_post, "state"); } -Array GLTFDocumentExtension::get_import_setting_keys() const { - return import_settings.keys(); +Error GLTFDocumentExtension::import_post(Ref<GLTFState> p_state, Node *p_root) { + ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER); + ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); + int err = OK; + if (GDVIRTUAL_CALL(_import_post, p_state, p_root, err)) { + return Error(err); + } + return OK; } -Variant GLTFDocumentExtension::get_import_setting(const StringName &p_key) const { - if (!import_settings.has(p_key)) { - return Variant(); +Error GLTFDocumentExtension::import_preflight(Ref<GLTFState> p_state) { + ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); + int err = OK; + if (GDVIRTUAL_CALL(_import_preflight, p_state, err)) { + return Error(err); } - return import_settings[p_key]; + return OK; } -void GLTFDocumentExtension::set_import_setting(const StringName &p_key, Variant p_var) { - import_settings[p_key] = p_var; +Error GLTFDocumentExtension::import_post_parse(Ref<GLTFState> p_state) { + ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); + int err = OK; + if (GDVIRTUAL_CALL(_import_post_parse, p_state, err)) { + return Error(err); + } + return OK; } -Array GLTFDocumentExtension::get_export_setting_keys() const { - return import_settings.keys(); +Error GLTFDocumentExtension::export_post(Ref<GLTFState> p_state) { + ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); + int err = OK; + if (GDVIRTUAL_CALL(_export_post, p_state, err)) { + return Error(err); + } + return OK; +} +Error GLTFDocumentExtension::export_preflight(Node *p_root) { + ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER); + int err = OK; + if (GDVIRTUAL_CALL(_export_preflight, p_root, err)) { + return Error(err); + } + return OK; } -Variant GLTFDocumentExtension::get_export_setting(const StringName &p_key) const { - if (!import_settings.has(p_key)) { - return Variant(); +Error GLTFDocumentExtension::import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_dict, Node *p_node) { + ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); + ERR_FAIL_NULL_V(p_gltf_node, ERR_INVALID_PARAMETER); + ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER); + int err = OK; + if (GDVIRTUAL_CALL(_import_node, p_state, p_gltf_node, r_dict, p_node, err)) { + return Error(err); } - return import_settings[p_key]; + return OK; } -void GLTFDocumentExtension::set_export_setting(const StringName &p_key, Variant p_var) { - import_settings[p_key] = p_var; +Error GLTFDocumentExtension::export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_dict, Node *p_node) { + ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); + ERR_FAIL_NULL_V(p_gltf_node, ERR_INVALID_PARAMETER); + ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER); + int err = OK; + if (GDVIRTUAL_CALL(_export_node, p_state, p_gltf_node, r_dict, p_node, err)) { + return Error(err); + } + return OK; } diff --git a/modules/gltf/gltf_document_extension.h b/modules/gltf/gltf_document_extension.h index f7a3531282..556f79e887 100644 --- a/modules/gltf/gltf_document_extension.h +++ b/modules/gltf/gltf_document_extension.h @@ -31,33 +31,31 @@ #ifndef GLTF_DOCUMENT_EXTENSION_H #define GLTF_DOCUMENT_EXTENSION_H -#include "core/io/resource.h" -#include "core/variant/dictionary.h" -#include "core/variant/typed_array.h" -#include "core/variant/variant.h" -class GLTFDocument; +#include "gltf_accessor.h" +#include "gltf_node.h" +#include "gltf_state.h" + class GLTFDocumentExtension : public Resource { GDCLASS(GLTFDocumentExtension, Resource); - Dictionary import_settings; - Dictionary export_settings; - protected: static void _bind_methods(); public: - virtual Array get_import_setting_keys() const; - virtual Variant get_import_setting(const StringName &p_key) const; - virtual void set_import_setting(const StringName &p_key, Variant p_var); - virtual Error import_preflight(Ref<GLTFDocument> p_document) { return OK; } - virtual Error import_post(Ref<GLTFDocument> p_document, Node *p_node) { return OK; } - -public: - virtual Array get_export_setting_keys() const; - virtual Variant get_export_setting(const StringName &p_key) const; - virtual void set_export_setting(const StringName &p_key, Variant p_var); - virtual Error export_preflight(Ref<GLTFDocument> p_document, Node *p_node) { return OK; } - virtual Error export_post(Ref<GLTFDocument> p_document) { return OK; } + virtual Error import_preflight(Ref<GLTFState> p_state); + virtual Error import_post_parse(Ref<GLTFState> p_state); + virtual Error export_post(Ref<GLTFState> p_state); + virtual Error import_post(Ref<GLTFState> p_state, Node *p_node); + virtual Error export_preflight(Node *p_state); + virtual Error import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node); + virtual Error export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node); + GDVIRTUAL1R(int, _import_preflight, Ref<GLTFState>); + GDVIRTUAL1R(int, _import_post_parse, Ref<GLTFState>); + GDVIRTUAL4R(int, _import_node, Ref<GLTFState>, Ref<GLTFNode>, Dictionary, Node *); + GDVIRTUAL2R(int, _import_post, Ref<GLTFState>, Node *); + GDVIRTUAL1R(int, _export_preflight, Node *); + GDVIRTUAL4R(int, _export_node, Ref<GLTFState>, Ref<GLTFNode>, Dictionary, Node *); + GDVIRTUAL1R(int, _export_post, Ref<GLTFState>); }; #endif // GLTF_DOCUMENT_EXTENSION_H diff --git a/modules/gltf/gltf_document_extension_convert_importer_mesh.cpp b/modules/gltf/gltf_document_extension_convert_importer_mesh.cpp index 47a3e5598f..1620900a04 100644 --- a/modules/gltf/gltf_document_extension_convert_importer_mesh.cpp +++ b/modules/gltf/gltf_document_extension_convert_importer_mesh.cpp @@ -29,41 +29,40 @@ /*************************************************************************/ #include "gltf_document_extension_convert_importer_mesh.h" + +#include "gltf_state.h" + #include "core/error/error_macros.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/resources/importer_mesh.h" -#include <cstddef> - void GLTFDocumentExtensionConvertImporterMesh::_bind_methods() { } -Error GLTFDocumentExtensionConvertImporterMesh::import_post(Ref<GLTFDocument> p_document, Node *p_node) { - ERR_FAIL_NULL_V(p_document, ERR_INVALID_PARAMETER); - ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER); +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_state, ERR_INVALID_PARAMETER); List<Node *> queue; - queue.push_back(p_node); + queue.push_back(p_root); List<Node *> delete_queue; while (!queue.is_empty()) { List<Node *>::Element *E = queue.front(); Node *node = E->get(); - { - ImporterMeshInstance3D *mesh_3d = cast_to<ImporterMeshInstance3D>(node); - if (mesh_3d) { - MeshInstance3D *mesh_instance_node_3d = memnew(MeshInstance3D); - Ref<ImporterMesh> mesh = mesh_3d->get_mesh(); - if (mesh.is_valid()) { - Ref<ArrayMesh> array_mesh = mesh->get_mesh(); - mesh_instance_node_3d->set_name(node->get_name()); - mesh_instance_node_3d->set_transform(mesh_3d->get_transform()); - mesh_instance_node_3d->set_mesh(array_mesh); - mesh_instance_node_3d->set_skin(mesh_3d->get_skin()); - mesh_instance_node_3d->set_skeleton_path(mesh_3d->get_skeleton_path()); - node->replace_by(mesh_instance_node_3d); - delete_queue.push_back(node); - } else { - memdelete(mesh_instance_node_3d); - } + ImporterMeshInstance3D *mesh_3d = cast_to<ImporterMeshInstance3D>(node); + if (mesh_3d) { + MeshInstance3D *mesh_instance_node_3d = memnew(MeshInstance3D); + Ref<ImporterMesh> mesh = mesh_3d->get_mesh(); + if (mesh.is_valid()) { + Ref<ArrayMesh> array_mesh = mesh->get_mesh(); + mesh_instance_node_3d->set_name(node->get_name()); + mesh_instance_node_3d->set_transform(mesh_3d->get_transform()); + mesh_instance_node_3d->set_mesh(array_mesh); + mesh_instance_node_3d->set_skin(mesh_3d->get_skin()); + mesh_instance_node_3d->set_skeleton_path(mesh_3d->get_skeleton_path()); + node->replace_by(mesh_instance_node_3d); + delete_queue.push_back(node); + } else { + memdelete(mesh_instance_node_3d); } } int child_count = node->get_child_count(); diff --git a/modules/gltf/gltf_document_extension_convert_importer_mesh.h b/modules/gltf/gltf_document_extension_convert_importer_mesh.h index 2d51143140..4c9e42a00f 100644 --- a/modules/gltf/gltf_document_extension_convert_importer_mesh.h +++ b/modules/gltf/gltf_document_extension_convert_importer_mesh.h @@ -31,14 +31,10 @@ #ifndef GLTF_EXTENSION_EDITOR_H #define GLTF_EXTENSION_EDITOR_H -#include "core/io/resource.h" -#include "core/variant/dictionary.h" - -#include "gltf_document.h" #include "gltf_document_extension.h" + #include "scene/3d/importer_mesh_instance_3d.h" #include "scene/3d/mesh_instance_3d.h" -#include "scene/main/node.h" #include "scene/resources/importer_mesh.h" class GLTFDocumentExtension; @@ -50,6 +46,6 @@ protected: static void _bind_methods(); public: - Error import_post(Ref<GLTFDocument> p_document, Node *p_node) override; + Error import_post(Ref<GLTFState> p_state, Node *p_root) override; }; #endif // GLTF_EXTENSION_EDITOR_H diff --git a/modules/gltf/gltf_skeleton.h b/modules/gltf/gltf_skeleton.h index 4dcee41465..92ee6e6234 100644 --- a/modules/gltf/gltf_skeleton.h +++ b/modules/gltf/gltf_skeleton.h @@ -50,7 +50,7 @@ private: Skeleton3D *godot_skeleton = nullptr; // Set of unique bone names for the skeleton - RBSet<String> unique_names; + HashSet<String> unique_names; HashMap<int32_t, GLTFNodeIndex> godot_bone_node; diff --git a/modules/gltf/gltf_state.cpp b/modules/gltf/gltf_state.cpp index e959a640b4..989fa476c2 100644 --- a/modules/gltf/gltf_state.cpp +++ b/modules/gltf/gltf_state.cpp @@ -57,6 +57,8 @@ void GLTFState::_bind_methods() { ClassDB::bind_method(D_METHOD("set_materials", "materials"), &GLTFState::set_materials); ClassDB::bind_method(D_METHOD("get_scene_name"), &GLTFState::get_scene_name); ClassDB::bind_method(D_METHOD("set_scene_name", "scene_name"), &GLTFState::set_scene_name); + ClassDB::bind_method(D_METHOD("get_base_path"), &GLTFState::get_base_path); + ClassDB::bind_method(D_METHOD("set_base_path", "base_path"), &GLTFState::set_base_path); ClassDB::bind_method(D_METHOD("get_root_nodes"), &GLTFState::get_root_nodes); ClassDB::bind_method(D_METHOD("set_root_nodes", "root_nodes"), &GLTFState::set_root_nodes); ClassDB::bind_method(D_METHOD("get_textures"), &GLTFState::get_textures); @@ -93,6 +95,7 @@ void GLTFState::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "meshes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_meshes", "get_meshes"); // Vector<Ref<GLTFMesh>> ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "materials", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_materials", "get_materials"); // Vector<Ref<Material> ADD_PROPERTY(PropertyInfo(Variant::STRING, "scene_name"), "set_scene_name", "get_scene_name"); // String + ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_path"), "set_base_path", "get_base_path"); // String ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "root_nodes"), "set_root_nodes", "get_root_nodes"); // Vector<int> ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "textures", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_textures", "get_textures"); // Vector<Ref<GLTFTexture>> ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "images", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_images", "get_images"); // Vector<Ref<Texture> @@ -313,3 +316,11 @@ void GLTFState::set_discard_meshes_and_materials(bool p_discard_meshes_and_mater bool GLTFState::get_discard_meshes_and_materials() { return discard_meshes_and_materials; } + +String GLTFState::get_base_path() { + return base_path; +} + +void GLTFState::set_base_path(String p_base_path) { + base_path = p_base_path; +} diff --git a/modules/gltf/gltf_state.h b/modules/gltf/gltf_state.h index f695b20b49..2fdef19038 100644 --- a/modules/gltf/gltf_state.h +++ b/modules/gltf/gltf_state.h @@ -44,10 +44,7 @@ #include "gltf_skin.h" #include "gltf_texture.h" -#include "core/io/resource.h" -#include "core/templates/pair.h" #include "core/templates/rb_map.h" -#include "core/templates/vector.h" #include "scene/animation/animation_player.h" #include "scene/resources/texture.h" @@ -56,6 +53,7 @@ class GLTFState : public Resource { friend class GLTFDocument; String filename; + String base_path; Dictionary json; int major_version = 0; int minor_version = 0; @@ -83,8 +81,8 @@ class GLTFState : public Resource { Vector<Ref<GLTFSkin>> skins; Vector<Ref<GLTFCamera>> cameras; Vector<Ref<GLTFLight>> lights; - RBSet<String> unique_names; - RBSet<String> unique_animation_names; + HashSet<String> unique_names; + HashSet<String> unique_animation_names; Vector<Ref<GLTFSkeleton>> skeletons; HashMap<GLTFSkeletonIndex, GLTFNodeIndex> skeleton_to_node; @@ -137,6 +135,9 @@ public: String get_scene_name(); void set_scene_name(String p_scene_name); + String get_base_path(); + void set_base_path(String p_base_path); + Array get_root_nodes(); void set_root_nodes(Array p_root_nodes); diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 88e16bce82..d0872a839b 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -113,7 +113,7 @@ class GridMap : public Node3D { }; Vector<MultimeshInstance> multimesh_instances; - RBSet<IndexKey> cells; + HashSet<IndexKey> cells; RID collision_debug; RID collision_debug_instance; diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index d0140f117c..bee4e0e1fb 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -875,7 +875,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { // Script::instances are deleted during managed object disposal, which happens on domain finalize. // Only placeholders are kept. Therefore we need to keep a copy before that happens. - for (Object *&obj : script->instances) { + for (Object *obj : script->instances) { script->pending_reload_instances.insert(obj->get_instance_id()); RefCounted *rc = Object::cast_to<RefCounted>(obj); @@ -885,7 +885,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { } #ifdef TOOLS_ENABLED - for (PlaceHolderScriptInstance *&script_instance : script->placeholders) { + for (PlaceHolderScriptInstance *script_instance : script->placeholders) { Object *obj = script_instance->get_owner(); script->pending_reload_instances.insert(obj->get_instance_id()); @@ -899,7 +899,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { // Save state and remove script from instances RBMap<ObjectID, CSharpScript::StateBackup> &owners_map = script->pending_reload_state; - for (Object *&obj : script->instances) { + for (Object *obj : script->instances) { ERR_CONTINUE(!obj->get_script_instance()); CSharpInstance *csi = static_cast<CSharpInstance *>(obj->get_script_instance()); @@ -922,8 +922,8 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { // After the state of all instances is saved, clear scripts and script instances for (Ref<CSharpScript> &script : scripts) { - while (script->instances.front()) { - Object *obj = script->instances.front()->get(); + while (script->instances.begin()) { + Object *obj = *script->instances.begin(); obj->set_script(Ref<RefCounted>()); // Remove script and existing script instances (placeholder are not removed before domain reload) } @@ -2315,9 +2315,9 @@ CSharpInstance::~CSharpInstance() { #ifdef DEBUG_ENABLED // CSharpInstance must not be created unless it's going to be added to the list for sure - RBSet<Object *>::Element *match = script->instances.find(owner); + HashSet<Object *>::Iterator match = script->instances.find(owner); CRASH_COND(!match); - script->instances.erase(match); + script->instances.remove(match); #else script->instances.erase(owner); #endif @@ -2572,7 +2572,7 @@ bool CSharpScript::_update_exports(PlaceHolderScriptInstance *p_instance_to_upda _update_exports_values(values, propnames); if (changed) { - for (PlaceHolderScriptInstance *&script_instance : placeholders) { + for (PlaceHolderScriptInstance *script_instance : placeholders) { script_instance->update(propnames, values); } } else { @@ -3574,7 +3574,7 @@ CSharpScript::~CSharpScript() { #endif } -void CSharpScript::get_members(RBSet<StringName> *p_members) { +void CSharpScript::get_members(HashSet<StringName> *p_members) { #if defined(TOOLS_ENABLED) || defined(DEBUG_ENABLED) if (p_members) { for (const StringName &member_name : exported_members_names) { diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index 6e600bb47a..69bd8703aa 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -110,7 +110,7 @@ private: Ref<CSharpScript> base_cache; // TODO what's this for? - RBSet<Object *> instances; + HashSet<Object *> instances; #ifdef GD_MONO_HOT_RELOAD struct StateBackup { @@ -121,7 +121,7 @@ private: List<Pair<StringName, Array>> event_signals; }; - RBSet<ObjectID> pending_reload_instances; + HashSet<ObjectID> pending_reload_instances; RBMap<ObjectID, StateBackup> pending_reload_state; StringName tied_class_name_for_reload; StringName tied_class_namespace_for_reload; @@ -141,7 +141,7 @@ private: #ifdef TOOLS_ENABLED List<PropertyInfo> exported_members_cache; // members_cache HashMap<StringName, Variant> exported_members_defval_cache; // member_default_values_cache - RBSet<PlaceHolderScriptInstance *> placeholders; + HashSet<PlaceHolderScriptInstance *> placeholders; bool source_changed_cache = false; bool placeholder_fallback_enabled = false; bool exports_invalidated = true; @@ -151,7 +151,7 @@ private: #endif #if defined(TOOLS_ENABLED) || defined(DEBUG_ENABLED) - RBSet<StringName> exported_members_names; + HashSet<StringName> exported_members_names; #endif HashMap<StringName, PropertyInfo> member_info; @@ -218,7 +218,7 @@ public: void get_script_property_list(List<PropertyInfo> *r_list) const override; void update_exports() override; - void get_members(RBSet<StringName> *p_members) override; + void get_members(HashSet<StringName> *p_members) override; bool is_tool() const override { return tool; } bool is_valid() const override { return valid; } @@ -467,7 +467,7 @@ public: virtual Ref<Script> make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const override; virtual Vector<ScriptTemplate> get_built_in_templates(StringName p_object) override; /* TODO */ bool validate(const String &p_script, const String &p_path, List<String> *r_functions, - List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, RBSet<int> *r_safe_lines = nullptr) const override { + List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const override { return true; } String validate_path(const String &p_path) const override; diff --git a/modules/raycast/lightmap_raycaster.cpp b/modules/raycast/lightmap_raycaster.cpp index fc9ac416b7..9b35b5616e 100644 --- a/modules/raycast/lightmap_raycaster.cpp +++ b/modules/raycast/lightmap_raycaster.cpp @@ -152,7 +152,7 @@ void LightmapRaycasterEmbree::commit() { rtcCommitScene(embree_scene); } -void LightmapRaycasterEmbree::set_mesh_filter(const RBSet<int> &p_mesh_ids) { +void LightmapRaycasterEmbree::set_mesh_filter(const HashSet<int> &p_mesh_ids) { for (const int &E : p_mesh_ids) { rtcDisableGeometry(rtcGetGeometry(embree_scene, E)); } diff --git a/modules/raycast/lightmap_raycaster.h b/modules/raycast/lightmap_raycaster.h index 4c52758fd8..4266b46ea8 100644 --- a/modules/raycast/lightmap_raycaster.h +++ b/modules/raycast/lightmap_raycaster.h @@ -53,7 +53,7 @@ private: static void filter_function(const struct RTCFilterFunctionNArguments *p_args); HashMap<unsigned int, AlphaTextureData> alpha_textures; - RBSet<int> filter_meshes; + HashSet<int> filter_meshes; public: virtual bool intersect(Ray &p_ray) override; @@ -64,7 +64,7 @@ public: virtual void set_mesh_alpha_texture(Ref<Image> p_alpha_texture, unsigned int p_id) override; virtual void commit() override; - virtual void set_mesh_filter(const RBSet<int> &p_mesh_ids) override; + virtual void set_mesh_filter(const HashSet<int> &p_mesh_ids) override; virtual void clear_mesh_filter() override; static LightmapRaycaster *create_embree_raycaster(); diff --git a/modules/raycast/raycast_occlusion_cull.h b/modules/raycast/raycast_occlusion_cull.h index 779f6fb3c4..4474031991 100644 --- a/modules/raycast/raycast_occlusion_cull.h +++ b/modules/raycast/raycast_occlusion_cull.h @@ -86,11 +86,13 @@ private: RID scenario; RID instance; - bool operator<(const InstanceID &rhs) const { - if (instance == rhs.instance) { - return rhs.scenario < scenario; - } - return instance < rhs.instance; + static uint32_t hash(const InstanceID &p_ins) { + uint32_t h = hash_djb2_one_64(p_ins.scenario.get_id()); + return hash_djb2_one_64(p_ins.instance.get_id(), h); + } + bool operator==(const InstanceID &rhs) const { + return instance == rhs.instance && rhs.scenario == scenario; + ; } InstanceID() {} @@ -101,7 +103,7 @@ private: struct Occluder { PackedVector3Array vertices; PackedInt32Array indices; - RBSet<InstanceID> users; + HashSet<InstanceID, InstanceID> users; }; struct OccluderInstance { @@ -136,7 +138,7 @@ private: int current_scene_idx = 0; HashMap<RID, OccluderInstance> instances; - RBSet<RID> dirty_instances; // To avoid duplicates + HashSet<RID> dirty_instances; // To avoid duplicates LocalVector<RID> dirty_instances_array; // To iterate and split into threads LocalVector<RID> removed_instances; diff --git a/modules/raycast/static_raycaster.cpp b/modules/raycast/static_raycaster.cpp index 5d2dedf1a4..7659eea27f 100644 --- a/modules/raycast/static_raycaster.cpp +++ b/modules/raycast/static_raycaster.cpp @@ -94,7 +94,7 @@ void StaticRaycasterEmbree::commit() { rtcCommitScene(embree_scene); } -void StaticRaycasterEmbree::set_mesh_filter(const RBSet<int> &p_mesh_ids) { +void StaticRaycasterEmbree::set_mesh_filter(const HashSet<int> &p_mesh_ids) { for (const int &E : p_mesh_ids) { rtcDisableGeometry(rtcGetGeometry(embree_scene, E)); } diff --git a/modules/raycast/static_raycaster.h b/modules/raycast/static_raycaster.h index b52b5bccfc..e2909f9b56 100644 --- a/modules/raycast/static_raycaster.h +++ b/modules/raycast/static_raycaster.h @@ -41,7 +41,7 @@ private: static RTCDevice embree_device; RTCScene embree_scene; - RBSet<int> filter_meshes; + HashSet<int> filter_meshes; public: virtual bool intersect(Ray &p_ray) override; @@ -50,7 +50,7 @@ public: virtual void add_mesh(const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices, unsigned int p_id) override; virtual void commit() override; - virtual void set_mesh_filter(const RBSet<int> &p_mesh_ids) override; + virtual void set_mesh_filter(const HashSet<int> &p_mesh_ids) override; virtual void clear_mesh_filter() override; static StaticRaycaster *create_embree_raycaster(); diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index ef7807ca5d..0f45855a76 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -5589,7 +5589,7 @@ PackedInt32Array TextServerAdvanced::string_get_word_breaks(const String &p_stri // Convert to UTF-16. Char16String utf16 = p_string.utf16(); - RBSet<int> breaks; + HashSet<int> breaks; UErrorCode err = U_ZERO_ERROR; UBreakIterator *bi = ubrk_open(UBRK_LINE, p_language.ascii().get_data(), (const UChar *)utf16.ptr(), utf16.length(), &err); if (U_FAILURE(err)) { diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index 897c27b6fa..fe1d4bdcbf 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -126,7 +126,7 @@ class TextServerAdvanced : public TextServerExtension { _THREAD_SAFE_CLASS_ struct NumSystemData { - RBSet<StringName> lang; + HashSet<StringName> lang; String digits; String percent_sign; String exp; @@ -235,7 +235,7 @@ class TextServerAdvanced : public TextServerExtension { HashMap<Vector2i, FontDataForSizeAdvanced *, VariantHasher, VariantComparator> cache; bool face_init = false; - RBSet<uint32_t> supported_scripts; + HashSet<uint32_t> supported_scripts; Dictionary supported_features; Dictionary supported_varaitions; Dictionary feature_overrides; diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 7c15651fa2..24bb22960e 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -2223,7 +2223,7 @@ Ref<Script> VisualScriptLanguage::make_template(const String &p_template, const return script; } -bool VisualScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, RBSet<int> *r_safe_lines) const { +bool VisualScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, HashSet<int> *r_safe_lines) const { return false; } diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index c28ec2268b..0f3b8de3fc 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -36,6 +36,7 @@ #include "core/doc_data.h" #include "core/object/script_language.h" #include "core/os/thread.h" +#include "core/templates/rb_set.h" class VisualScriptInstance; class VisualScriptNodeInstance; @@ -570,7 +571,7 @@ public: virtual void get_string_delimiters(List<String> *p_delimiters) const override; virtual bool is_using_templates() override; virtual Ref<Script> make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const override; - virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, RBSet<int> *r_safe_lines = nullptr) const override; + virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const override; virtual Script *create_script() const override; virtual bool has_named_classes() const override; virtual bool supports_builtin_mode() const override; |