Skip to content

Commit 8ff0683

Browse files
committed
Merge pull request #110949 from aaronfranke/const-ref-param-gltf
Use const ref parameters in the GLTF module
2 parents c6fe923 + dcb6431 commit 8ff0683

37 files changed

+197
-197
lines changed

modules/fbx/fbx_document.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,7 @@ void FBXDocument::_process_mesh_instances(Ref<FBXState> p_state, Node *p_scene_r
20212021
}
20222022
}
20232023

2024-
Error FBXDocument::_parse(Ref<FBXState> p_state, String p_path, Ref<FileAccess> p_file) {
2024+
Error FBXDocument::_parse(Ref<FBXState> p_state, const String &p_path, Ref<FileAccess> p_file) {
20252025
p_state->scene.reset();
20262026

20272027
Error err = ERR_INVALID_DATA;
@@ -2164,7 +2164,7 @@ Node *FBXDocument::generate_scene(Ref<GLTFState> p_state, float p_bake_fps, bool
21642164
return root;
21652165
}
21662166

2167-
Error FBXDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<GLTFState> p_state, uint32_t p_flags) {
2167+
Error FBXDocument::append_from_buffer(const PackedByteArray &p_bytes, const String &p_base_path, Ref<GLTFState> p_state, uint32_t p_flags) {
21682168
Ref<FBXState> state = p_state;
21692169
ERR_FAIL_COND_V(state.is_null(), ERR_INVALID_PARAMETER);
21702170
ERR_FAIL_NULL_V(p_bytes.ptr(), ERR_INVALID_DATA);
@@ -2259,7 +2259,7 @@ Error FBXDocument::_parse_fbx_state(Ref<FBXState> p_state, const String &p_searc
22592259
return OK;
22602260
}
22612261

2262-
Error FBXDocument::append_from_file(String p_path, Ref<GLTFState> p_state, uint32_t p_flags, String p_base_path) {
2262+
Error FBXDocument::append_from_file(const String &p_path, Ref<GLTFState> p_state, uint32_t p_flags, const String &p_base_path) {
22632263
Ref<FBXState> state = p_state;
22642264
ERR_FAIL_COND_V(state.is_null(), ERR_INVALID_PARAMETER);
22652265
ERR_FAIL_COND_V(p_path.is_empty(), ERR_FILE_NOT_FOUND);

modules/fbx/fbx_document.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class FBXDocument : public GLTFDocument {
5454
static String _gen_unique_name(HashSet<String> &unique_names, const String &p_name);
5555

5656
public:
57-
Error append_from_file(String p_path, Ref<GLTFState> p_state, uint32_t p_flags = 0, String p_base_path = String()) override;
58-
Error append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<GLTFState> p_state, uint32_t p_flags = 0) override;
57+
Error append_from_file(const String &p_path, Ref<GLTFState> p_state, uint32_t p_flags = 0, const String &p_base_path = String()) override;
58+
Error append_from_buffer(const PackedByteArray &p_bytes, const String &p_base_path, Ref<GLTFState> p_state, uint32_t p_flags = 0) override;
5959
Error append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint32_t p_flags = 0) override;
6060

6161
Node *generate_scene(Ref<GLTFState> p_state, float p_bake_fps = 30.0f, bool p_trimming = false, bool p_remove_immutable_tracks = true) override;
@@ -101,5 +101,5 @@ class FBXDocument : public GLTFDocument {
101101
void _generate_skeleton_bone_node(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root);
102102
void _import_animation(Ref<FBXState> p_state, AnimationPlayer *p_animation_player,
103103
const GLTFAnimationIndex p_index, const bool p_trimming, const bool p_remove_immutable_tracks);
104-
Error _parse(Ref<FBXState> p_state, String p_path, Ref<FileAccess> p_file);
104+
Error _parse(Ref<FBXState> p_state, const String &p_path, Ref<FileAccess> p_file);
105105
};

modules/gltf/extensions/gltf_document_extension.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void GLTFDocumentExtension::_bind_methods() {
5959
}
6060

6161
// Import process.
62-
Error GLTFDocumentExtension::import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions) {
62+
Error GLTFDocumentExtension::import_preflight(Ref<GLTFState> p_state, const Vector<String> &p_extensions) {
6363
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
6464
Error err = OK;
6565
GDVIRTUAL_CALL(_import_preflight, p_state, p_extensions, err);
@@ -72,11 +72,11 @@ Vector<String> GLTFDocumentExtension::get_supported_extensions() {
7272
return ret;
7373
}
7474

75-
Error GLTFDocumentExtension::parse_node_extensions(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &p_extensions) {
75+
Error GLTFDocumentExtension::parse_node_extensions(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, const Dictionary &p_extensions) {
7676
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
7777
ERR_FAIL_COND_V(p_gltf_node.is_null(), ERR_INVALID_PARAMETER);
7878
Error err = OK;
79-
GDVIRTUAL_CALL(_parse_node_extensions, p_state, p_gltf_node, p_extensions, err);
79+
GDVIRTUAL_CALL(_parse_node_extensions, p_state, p_gltf_node, Dictionary(p_extensions), err);
8080
return err;
8181
}
8282

@@ -98,7 +98,7 @@ Error GLTFDocumentExtension::parse_texture_json(Ref<GLTFState> p_state, const Di
9898
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
9999
ERR_FAIL_COND_V(r_gltf_texture.is_null(), ERR_INVALID_PARAMETER);
100100
Error err = OK;
101-
GDVIRTUAL_CALL(_parse_texture_json, p_state, p_texture_json, r_gltf_texture, err);
101+
GDVIRTUAL_CALL(_parse_texture_json, p_state, Dictionary(p_texture_json), r_gltf_texture, err);
102102
return err;
103103
}
104104

@@ -136,7 +136,7 @@ Error GLTFDocumentExtension::import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p
136136
ERR_FAIL_COND_V(p_gltf_node.is_null(), ERR_INVALID_PARAMETER);
137137
ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER);
138138
Error err = OK;
139-
GDVIRTUAL_CALL(_import_node, p_state, p_gltf_node, r_dict, p_node, err);
139+
GDVIRTUAL_CALL(_import_node, p_state, p_gltf_node, Dictionary(r_dict), p_node, err);
140140
return err;
141141
}
142142

@@ -193,11 +193,11 @@ Vector<String> GLTFDocumentExtension::get_saveable_image_formats() {
193193
return ret;
194194
}
195195

196-
PackedByteArray GLTFDocumentExtension::serialize_image_to_bytes(Ref<GLTFState> p_state, Ref<Image> p_image, Dictionary p_image_dict, const String &p_image_format, float p_lossy_quality) {
196+
PackedByteArray GLTFDocumentExtension::serialize_image_to_bytes(Ref<GLTFState> p_state, Ref<Image> p_image, Dictionary &r_image_dict, const String &p_image_format, float p_lossy_quality) {
197197
PackedByteArray ret;
198198
ERR_FAIL_COND_V(p_state.is_null(), ret);
199199
ERR_FAIL_COND_V(p_image.is_null(), ret);
200-
GDVIRTUAL_CALL(_serialize_image_to_bytes, p_state, p_image, p_image_dict, p_image_format, p_lossy_quality, ret);
200+
GDVIRTUAL_CALL(_serialize_image_to_bytes, p_state, p_image, Dictionary(r_image_dict), p_image_format, p_lossy_quality, ret);
201201
return ret;
202202
}
203203

@@ -209,19 +209,19 @@ Error GLTFDocumentExtension::save_image_at_path(Ref<GLTFState> p_state, Ref<Imag
209209
return ret;
210210
}
211211

212-
Error GLTFDocumentExtension::serialize_texture_json(Ref<GLTFState> p_state, Dictionary p_texture_json, Ref<GLTFTexture> p_gltf_texture, const String &p_image_format) {
212+
Error GLTFDocumentExtension::serialize_texture_json(Ref<GLTFState> p_state, Dictionary &r_texture_json, Ref<GLTFTexture> p_gltf_texture, const String &p_image_format) {
213213
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
214214
ERR_FAIL_COND_V(p_gltf_texture.is_null(), ERR_INVALID_PARAMETER);
215215
Error err = OK;
216-
GDVIRTUAL_CALL(_serialize_texture_json, p_state, p_texture_json, p_gltf_texture, p_image_format, err);
216+
GDVIRTUAL_CALL(_serialize_texture_json, p_state, Dictionary(r_texture_json), p_gltf_texture, p_image_format, err);
217217
return err;
218218
}
219219

220220
Error GLTFDocumentExtension::export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_dict, Node *p_node) {
221221
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
222222
ERR_FAIL_COND_V(p_gltf_node.is_null(), ERR_INVALID_PARAMETER);
223223
Error err = OK;
224-
GDVIRTUAL_CALL(_export_node, p_state, p_gltf_node, r_dict, p_node, err);
224+
GDVIRTUAL_CALL(_export_node, p_state, p_gltf_node, Dictionary(r_dict), p_node, err);
225225
return err;
226226
}
227227

modules/gltf/extensions/gltf_document_extension.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ class GLTFDocumentExtension : public Resource {
4242

4343
public:
4444
// Import process.
45-
virtual Error import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions);
45+
virtual Error import_preflight(Ref<GLTFState> p_state, const Vector<String> &p_extensions);
4646
virtual Vector<String> get_supported_extensions();
47-
virtual Error parse_node_extensions(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &p_extensions);
47+
virtual Error parse_node_extensions(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, const Dictionary &p_extensions);
4848
virtual Error parse_image_data(Ref<GLTFState> p_state, const PackedByteArray &p_image_data, const String &p_mime_type, Ref<Image> r_image);
4949
virtual String get_image_file_extension();
5050
virtual Error parse_texture_json(Ref<GLTFState> p_state, const Dictionary &p_texture_json, Ref<GLTFTexture> r_gltf_texture);
@@ -61,9 +61,9 @@ class GLTFDocumentExtension : public Resource {
6161
virtual Error export_preserialize(Ref<GLTFState> p_state);
6262
virtual Ref<GLTFObjectModelProperty> export_object_model_property(Ref<GLTFState> p_state, const NodePath &p_node_path, const Node *p_godot_node, GLTFNodeIndex p_gltf_node_index, const Object *p_target_object, int p_target_depth);
6363
virtual Vector<String> get_saveable_image_formats();
64-
virtual PackedByteArray serialize_image_to_bytes(Ref<GLTFState> p_state, Ref<Image> p_image, Dictionary p_image_dict, const String &p_image_format, float p_lossy_quality);
64+
virtual PackedByteArray serialize_image_to_bytes(Ref<GLTFState> p_state, Ref<Image> p_image, Dictionary &r_image_dict, const String &p_image_format, float p_lossy_quality);
6565
virtual Error save_image_at_path(Ref<GLTFState> p_state, Ref<Image> p_image, const String &p_file_path, const String &p_image_format, float p_lossy_quality);
66-
virtual Error serialize_texture_json(Ref<GLTFState> p_state, Dictionary p_texture_json, Ref<GLTFTexture> p_gltf_texture, const String &p_image_format);
66+
virtual Error serialize_texture_json(Ref<GLTFState> p_state, Dictionary &r_texture_json, Ref<GLTFTexture> p_gltf_texture, const String &p_image_format);
6767
virtual Error export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node);
6868
virtual Error export_post(Ref<GLTFState> p_state);
6969

modules/gltf/extensions/gltf_document_extension_texture_ktx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "gltf_document_extension_texture_ktx.h"
3232

3333
// Import process.
34-
Error GLTFDocumentExtensionTextureKTX::import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions) {
34+
Error GLTFDocumentExtensionTextureKTX::import_preflight(Ref<GLTFState> p_state, const Vector<String> &p_extensions) {
3535
if (!p_extensions.has("KHR_texture_basisu")) {
3636
return ERR_SKIP;
3737
}

modules/gltf/extensions/gltf_document_extension_texture_ktx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class GLTFDocumentExtensionTextureKTX : public GLTFDocumentExtension {
3737

3838
public:
3939
// Import process.
40-
Error import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions) override;
40+
Error import_preflight(Ref<GLTFState> p_state, const Vector<String> &p_extensions) override;
4141
Vector<String> get_supported_extensions() override;
4242
Error parse_image_data(Ref<GLTFState> p_state, const PackedByteArray &p_image_data, const String &p_mime_type, Ref<Image> r_image) override;
4343
Error parse_texture_json(Ref<GLTFState> p_state, const Dictionary &p_texture_json, Ref<GLTFTexture> r_gltf_texture) override;

modules/gltf/extensions/gltf_document_extension_texture_webp.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "gltf_document_extension_texture_webp.h"
3232

3333
// Import process.
34-
Error GLTFDocumentExtensionTextureWebP::import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions) {
34+
Error GLTFDocumentExtensionTextureWebP::import_preflight(Ref<GLTFState> p_state, const Vector<String> &p_extensions) {
3535
if (!p_extensions.has("EXT_texture_webp")) {
3636
return ERR_SKIP;
3737
}
@@ -76,12 +76,12 @@ Vector<String> GLTFDocumentExtensionTextureWebP::get_saveable_image_formats() {
7676
return ret;
7777
}
7878

79-
PackedByteArray GLTFDocumentExtensionTextureWebP::serialize_image_to_bytes(Ref<GLTFState> p_state, Ref<Image> p_image, Dictionary p_image_dict, const String &p_image_format, float p_lossy_quality) {
79+
PackedByteArray GLTFDocumentExtensionTextureWebP::serialize_image_to_bytes(Ref<GLTFState> p_state, Ref<Image> p_image, Dictionary &r_image_dict, const String &p_image_format, float p_lossy_quality) {
8080
if (p_image_format == "Lossless WebP") {
81-
p_image_dict["mimeType"] = "image/webp";
81+
r_image_dict["mimeType"] = "image/webp";
8282
return p_image->save_webp_to_buffer(false);
8383
} else if (p_image_format == "Lossy WebP") {
84-
p_image_dict["mimeType"] = "image/webp";
84+
r_image_dict["mimeType"] = "image/webp";
8585
return p_image->save_webp_to_buffer(true, p_lossy_quality);
8686
}
8787
ERR_FAIL_V(PackedByteArray());
@@ -98,12 +98,12 @@ Error GLTFDocumentExtensionTextureWebP::save_image_at_path(Ref<GLTFState> p_stat
9898
return ERR_INVALID_PARAMETER;
9999
}
100100

101-
Error GLTFDocumentExtensionTextureWebP::serialize_texture_json(Ref<GLTFState> p_state, Dictionary p_texture_json, Ref<GLTFTexture> p_gltf_texture, const String &p_image_format) {
101+
Error GLTFDocumentExtensionTextureWebP::serialize_texture_json(Ref<GLTFState> p_state, Dictionary &r_texture_json, Ref<GLTFTexture> p_gltf_texture, const String &p_image_format) {
102102
Dictionary ext_texture_webp;
103103
ext_texture_webp["source"] = p_gltf_texture->get_src_image();
104104
Dictionary texture_extensions;
105105
texture_extensions["EXT_texture_webp"] = ext_texture_webp;
106-
p_texture_json["extensions"] = texture_extensions;
106+
r_texture_json["extensions"] = texture_extensions;
107107
p_state->add_used_extension("EXT_texture_webp", true);
108108
return OK;
109109
}

modules/gltf/extensions/gltf_document_extension_texture_webp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class GLTFDocumentExtensionTextureWebP : public GLTFDocumentExtension {
3737

3838
public:
3939
// Import process.
40-
Error import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions) override;
40+
Error import_preflight(Ref<GLTFState> p_state, const Vector<String> &p_extensions) override;
4141
Vector<String> get_supported_extensions() override;
4242
Error parse_image_data(Ref<GLTFState> p_state, const PackedByteArray &p_image_data, const String &p_mime_type, Ref<Image> r_image) override;
4343
String get_image_file_extension() override;
4444
Error parse_texture_json(Ref<GLTFState> p_state, const Dictionary &p_texture_json, Ref<GLTFTexture> r_gltf_texture) override;
4545
// Export process.
4646
Vector<String> get_saveable_image_formats() override;
47-
PackedByteArray serialize_image_to_bytes(Ref<GLTFState> p_state, Ref<Image> p_image, Dictionary p_image_dict, const String &p_image_format, float p_lossy_quality) override;
47+
PackedByteArray serialize_image_to_bytes(Ref<GLTFState> p_state, Ref<Image> p_image, Dictionary &r_image_dict, const String &p_image_format, float p_lossy_quality) override;
4848
Error save_image_at_path(Ref<GLTFState> p_state, Ref<Image> p_image, const String &p_full_path, const String &p_image_format, float p_lossy_quality) override;
49-
Error serialize_texture_json(Ref<GLTFState> p_state, Dictionary p_texture_json, Ref<GLTFTexture> p_gltf_texture, const String &p_image_format) override;
49+
Error serialize_texture_json(Ref<GLTFState> p_state, Dictionary &r_texture_json, Ref<GLTFTexture> p_gltf_texture, const String &p_image_format) override;
5050
};

modules/gltf/extensions/gltf_light.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Light3D *GLTFLight::to_node() const {
186186
return light;
187187
}
188188

189-
Ref<GLTFLight> GLTFLight::from_dictionary(const Dictionary p_dictionary) {
189+
Ref<GLTFLight> GLTFLight::from_dictionary(const Dictionary &p_dictionary) {
190190
ERR_FAIL_COND_V_MSG(!p_dictionary.has("type"), Ref<GLTFLight>(), "Failed to parse glTF light, missing required field 'type'.");
191191
Ref<GLTFLight> light;
192192
light.instantiate();

modules/gltf/extensions/gltf_light.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class GLTFLight : public Resource {
7777
static Ref<GLTFLight> from_node(const Light3D *p_light);
7878
Light3D *to_node() const;
7979

80-
static Ref<GLTFLight> from_dictionary(const Dictionary p_dictionary);
80+
static Ref<GLTFLight> from_dictionary(const Dictionary &p_dictionary);
8181
Dictionary to_dictionary() const;
8282

8383
Variant get_additional_data(const StringName &p_extension_name);

0 commit comments

Comments
 (0)