diff options
Diffstat (limited to 'editor/import')
-rw-r--r-- | editor/import/editor_import_collada.cpp | 1 | ||||
-rw-r--r-- | editor/import/editor_import_collada.h | 1 | ||||
-rw-r--r-- | editor/import/editor_import_plugin.cpp | 1 | ||||
-rw-r--r-- | editor/import/editor_import_plugin.h | 1 | ||||
-rw-r--r-- | editor/import/editor_scene_importer_gltf.cpp | 86 | ||||
-rw-r--r-- | editor/import/editor_scene_importer_gltf.h | 35 | ||||
-rw-r--r-- | editor/import/resource_importer_bitmask.cpp | 91 | ||||
-rw-r--r-- | editor/import/resource_importer_bitmask.h | 29 | ||||
-rw-r--r-- | editor/import/resource_importer_csv_translation.cpp | 1 | ||||
-rw-r--r-- | editor/import/resource_importer_csv_translation.h | 1 | ||||
-rw-r--r-- | editor/import/resource_importer_obj.cpp | 1 | ||||
-rw-r--r-- | editor/import/resource_importer_obj.h | 1 | ||||
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 1 | ||||
-rw-r--r-- | editor/import/resource_importer_scene.h | 1 | ||||
-rw-r--r-- | editor/import/resource_importer_texture.cpp | 1 | ||||
-rw-r--r-- | editor/import/resource_importer_texture.h | 1 | ||||
-rw-r--r-- | editor/import/resource_importer_wav.cpp | 15 | ||||
-rw-r--r-- | editor/import/resource_importer_wav.h | 1 |
18 files changed, 250 insertions, 19 deletions
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 52659b360f..869500a6b6 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #include "editor_import_collada.h" #include "editor/collada/collada.h" diff --git a/editor/import/editor_import_collada.h b/editor/import/editor_import_collada.h index 004b07b5be..5dd3ff58fa 100644 --- a/editor/import/editor_import_collada.h +++ b/editor/import/editor_import_collada.h @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #ifndef EDITOR_IMPORT_COLLADA_H #define EDITOR_IMPORT_COLLADA_H diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp index 6297e1eca6..07c77a9df0 100644 --- a/editor/import/editor_import_plugin.cpp +++ b/editor/import/editor_import_plugin.cpp @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #include "editor_import_plugin.h" #include "core/script_language.h" diff --git a/editor/import/editor_import_plugin.h b/editor/import/editor_import_plugin.h index 9f860401ed..61a0a944f5 100644 --- a/editor/import/editor_import_plugin.h +++ b/editor/import/editor_import_plugin.h @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #ifndef EDITOR_IMPORT_PLUGIN_H #define EDITOR_IMPORT_PLUGIN_H diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 189e98ea68..1c4617c353 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -1,3 +1,33 @@ +/*************************************************************************/ +/* editor_scene_importer_gltf.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + #include "editor_scene_importer_gltf.h" #include "io/json.h" #include "math_defs.h" @@ -880,18 +910,24 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { { //gltf does not seem to normalize the weights for some reason.. int wc = weights.size(); PoolVector<float>::Write w = weights.write(); - for (int i = 0; i < wc; i += 4) { + + //PoolVector<int> v = array[Mesh::ARRAY_BONES]; + //PoolVector<int>::Read r = v.read(); + + for (int j = 0; j < wc; j += 4) { float total = 0.0; - total += w[i + 0]; - total += w[i + 1]; - total += w[i + 2]; - total += w[i + 3]; + total += w[j + 0]; + total += w[j + 1]; + total += w[j + 2]; + total += w[j + 3]; if (total > 0.0) { - w[i + 0] /= total; - w[i + 1] /= total; - w[i + 2] /= total; - w[i + 3] /= total; + w[j + 0] /= total; + w[j + 1] /= total; + w[j + 2] /= total; + w[j + 3] /= total; } + + //print_line(itos(j / 4) + ": " + itos(r[j + 0]) + ":" + rtos(w[j + 0]) + ", " + itos(r[j + 1]) + ":" + rtos(w[j + 1]) + ", " + itos(r[j + 2]) + ":" + rtos(w[j + 2]) + ", " + itos(r[j + 3]) + ":" + rtos(w[j + 3])); } } array[Mesh::ARRAY_WEIGHTS] = weights; @@ -1338,6 +1374,10 @@ Error EditorSceneImporterGLTF::_parse_skins(GLTFState &state) { //state.nodes[skeleton]->skeleton_skin = state.skins.size(); print_line("setting skeleton skin to" + itos(skeleton)); skin.skeleton = skeleton; + if (!state.skeleton_nodes.has(skeleton)) { + state.skeleton_nodes[skeleton] = Vector<int>(); + } + state.skeleton_nodes[skeleton].push_back(i); } if (d.has("name")) { @@ -1641,7 +1681,8 @@ void EditorSceneImporterGLTF::_generate_node(GLTFState &state, int p_node, Node MeshInstance *mi = Object::cast_to<MeshInstance>(node); //move skeleton around and place it on node, as the node _is_ a skeleton. Skeleton *s = skeletons[n->skin]; - mi->set_skeleton_path(mi->get_path_to(s)); + state.paths_to_skeleton[mi] = s; + //move it later, as skeleton may be moved around first } #if 0 @@ -1655,16 +1696,27 @@ void EditorSceneImporterGLTF::_generate_node(GLTFState &state, int p_node, Node #endif for (int i = 0; i < n->children.size(); i++) { if (state.nodes[n->children[i]]->joints.size()) { - _generate_bone(state, n->children[i], skeletons, Vector<int>()); + _generate_bone(state, n->children[i], skeletons, Vector<int>(), node); } else { _generate_node(state, n->children[i], node, p_owner, skeletons); } } } -void EditorSceneImporterGLTF::_generate_bone(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, const Vector<int> &p_parent_bones) { +void EditorSceneImporterGLTF::_generate_bone(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, const Vector<int> &p_parent_bones, Node *p_parent_node) { ERR_FAIL_INDEX(p_node, state.nodes.size()); + if (state.skeleton_nodes.has(p_node)) { + //reparent skeletons to proper place + Vector<int> nodes = state.skeleton_nodes[p_node]; + for (int i = 0; i < nodes.size(); i++) { + Node *owner = skeletons[i]->get_owner(); + skeletons[i]->get_parent()->remove_child(skeletons[i]); + p_parent_node->add_child(skeletons[i]); + skeletons[i]->set_owner(owner); + } + } + GLTFNode *n = state.nodes[p_node]; Vector<int> parent_bones; @@ -1684,7 +1736,7 @@ void EditorSceneImporterGLTF::_generate_bone(GLTFState &state, int p_node, Vecto } for (int i = 0; i < n->children.size(); i++) { - _generate_bone(state, n->children[i], skeletons, parent_bones); + _generate_bone(state, n->children[i], skeletons, parent_bones, p_parent_node); } } @@ -2000,12 +2052,18 @@ Spatial *EditorSceneImporterGLTF::_generate_scene(GLTFState &state, int p_bake_f } for (int i = 0; i < state.root_nodes.size(); i++) { if (state.nodes[state.root_nodes[i]]->joints.size()) { - _generate_bone(state, state.root_nodes[i], skeletons, Vector<int>()); + _generate_bone(state, state.root_nodes[i], skeletons, Vector<int>(), root); } else { _generate_node(state, state.root_nodes[i], root, root, skeletons); } } + for (Map<Node *, Skeleton *>::Element *E = state.paths_to_skeleton.front(); E; E = E->next()) { + MeshInstance *mi = Object::cast_to<MeshInstance>(E->key()); + ERR_CONTINUE(!mi); + mi->set_skeleton_path(mi->get_path_to(E->get())); + } + for (int i = 0; i < skeletons.size(); i++) { skeletons[i]->localize_rests(); } diff --git a/editor/import/editor_scene_importer_gltf.h b/editor/import/editor_scene_importer_gltf.h index abbdfa418b..088036ce75 100644 --- a/editor/import/editor_scene_importer_gltf.h +++ b/editor/import/editor_scene_importer_gltf.h @@ -1,3 +1,33 @@ +/*************************************************************************/ +/* editor_scene_importer_gltf.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + #ifndef EDITOR_SCENE_IMPORTER_GLTF_H #define EDITOR_SCENE_IMPORTER_GLTF_H @@ -244,6 +274,9 @@ class EditorSceneImporterGLTF : public EditorSceneImporter { Vector<GLTFAnimation> animations; + Map<int, Vector<int> > skeleton_nodes; + Map<Node *, Skeleton *> paths_to_skeleton; + //Map<int, Vector<int> > skin_users; //cache skin users ~GLTFState() { @@ -278,7 +311,7 @@ class EditorSceneImporterGLTF : public EditorSceneImporter { Vector<Basis> _decode_accessor_as_basis(GLTFState &state, int p_accessor, bool p_for_vertex); Vector<Transform> _decode_accessor_as_xform(GLTFState &state, int p_accessor, bool p_for_vertex); - void _generate_bone(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, const Vector<int> &p_parent_bones); + void _generate_bone(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, const Vector<int> &p_parent_bones, Node *p_parent_node); void _generate_node(GLTFState &state, int p_node, Node *p_parent, Node *p_owner, Vector<Skeleton *> &skeletons); void _import_animation(GLTFState &state, AnimationPlayer *ap, int index, int bake_fps, Vector<Skeleton *> skeletons); diff --git a/editor/import/resource_importer_bitmask.cpp b/editor/import/resource_importer_bitmask.cpp new file mode 100644 index 0000000000..a5d3959952 --- /dev/null +++ b/editor/import/resource_importer_bitmask.cpp @@ -0,0 +1,91 @@ +#include "resource_importer_bitmask.h" +#include "core/image.h" +#include "editor/editor_file_system.h" +#include "editor/editor_node.h" +#include "io/config_file.h" +#include "io/image_loader.h" +#include "scene/resources/bit_mask.h" +#include "scene/resources/texture.h" + +String ResourceImporterBitMap::get_importer_name() const { + + return "bitmap"; +} + +String ResourceImporterBitMap::get_visible_name() const { + + return "BitMap"; +} +void ResourceImporterBitMap::get_recognized_extensions(List<String> *p_extensions) const { + + ImageLoader::get_recognized_extensions(p_extensions); +} +String ResourceImporterBitMap::get_save_extension() const { + return "res"; +} + +String ResourceImporterBitMap::get_resource_type() const { + + return "BitMap"; +} + +bool ResourceImporterBitMap::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { + + return true; +} + +int ResourceImporterBitMap::get_preset_count() const { + return 0; +} +String ResourceImporterBitMap::get_preset_name(int p_idx) const { + + return String(); +} + +void ResourceImporterBitMap::get_import_options(List<ImportOption> *r_options, int p_preset) const { + + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "create_from", PROPERTY_HINT_ENUM, "Black & White,Alpha"), 0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "threshold", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.5)); +} + +Error ResourceImporterBitMap::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { + + int create_from = p_options["create_from"]; + float threshold = p_options["threshold"]; + Ref<Image> image; + image.instance(); + Error err = ImageLoader::load_image(p_source_file, image); + if (err != OK) + return err; + + int w = image->get_width(); + int h = image->get_height(); + + Ref<BitMap> bitmap; + bitmap.instance(); + bitmap->create(Size2(w, h)); + image->lock(); + + for (int i = 0; i < h; i++) { + for (int j = 0; j < w; j++) { + + bool bit; + Color c = image->get_pixel(j, i); + if (create_from == 0) { //b&W + bit = c.get_v() > threshold; + } else { + bit = c.a > threshold; + } + + bitmap->set_bit(Vector2(j, i), bit); + } + } + + return ResourceSaver::save(p_save_path + ".res", bitmap); +} + +ResourceImporterBitMap::ResourceImporterBitMap() { +} + +ResourceImporterBitMap::~ResourceImporterBitMap() { +} diff --git a/editor/import/resource_importer_bitmask.h b/editor/import/resource_importer_bitmask.h new file mode 100644 index 0000000000..8a3cafa7ce --- /dev/null +++ b/editor/import/resource_importer_bitmask.h @@ -0,0 +1,29 @@ +#ifndef RESOURCE_IMPORTER_BITMASK_H +#define RESOURCE_IMPORTER_BITMASK_H + +#include "image.h" +#include "io/resource_import.h" + +class StreamBitMap; + +class ResourceImporterBitMap : public ResourceImporter { + GDCLASS(ResourceImporterBitMap, ResourceImporter) + +public: + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; + virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); + + ResourceImporterBitMap(); + ~ResourceImporterBitMap(); +}; +#endif // RESOURCE_IMPORTER_BITMASK_H diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index 70093d13a7..22c32f5fc9 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #include "resource_importer_csv_translation.h" #include "compressed_translation.h" diff --git a/editor/import/resource_importer_csv_translation.h b/editor/import/resource_importer_csv_translation.h index ca6e63f8aa..f5f230c6bd 100644 --- a/editor/import/resource_importer_csv_translation.h +++ b/editor/import/resource_importer_csv_translation.h @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #ifndef RESOURCEIMPORTERCSVTRANSLATION_H #define RESOURCEIMPORTERCSVTRANSLATION_H diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index d2cdfb5013..78fc9ec9bd 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #include "resource_importer_obj.h" #include "io/resource_saver.h" diff --git a/editor/import/resource_importer_obj.h b/editor/import/resource_importer_obj.h index 8710432aa1..3f6d1104d7 100644 --- a/editor/import/resource_importer_obj.h +++ b/editor/import/resource_importer_obj.h @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #ifndef RESOURCEIMPORTEROBJ_H #define RESOURCEIMPORTEROBJ_H diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index d36cb5cb59..060953d36a 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #include "resource_importer_scene.h" #include "editor/editor_node.h" diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index 4d0e236cf1..d5f9d53e91 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #ifndef RESOURCEIMPORTERSCENE_H #define RESOURCEIMPORTERSCENE_H diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index 45ce347244..8119b84b7e 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #include "resource_importer_texture.h" #include "editor/editor_file_system.h" diff --git a/editor/import/resource_importer_texture.h b/editor/import/resource_importer_texture.h index 3d9e657017..fd6f75c3f4 100644 --- a/editor/import/resource_importer_texture.h +++ b/editor/import/resource_importer_texture.h @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #ifndef RESOURCEIMPORTTEXTURE_H #define RESOURCEIMPORTTEXTURE_H diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index de82c12b98..03155b3a48 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #include "resource_importer_wav.h" #include "io/marshalls.h" @@ -267,9 +268,15 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s for (int i = 0; i < 10; i++) file->get_32(); // i wish to know why should i do this... no doc! - loop = file->get_32() ? AudioStreamSample::LOOP_PING_PONG : AudioStreamSample::LOOP_FORWARD; - loop_begin = file->get_32(); - loop_end = file->get_32(); + // only read 0x00 (loop forward) and 0x01 (loop ping-pong) and skip anything else because + // it's not supported (loop backward), reserved for future uses or sampler specific + // from https://sites.google.com/site/musicgapi/technical-documents/wav-file-format#smpl (loop type values table) + int loop_type = file->get_32(); + if (loop_type == 0x00 || loop_type == 0x01) { + loop = loop_type ? AudioStreamSample::LOOP_PING_PONG : AudioStreamSample::LOOP_FORWARD; + loop_begin = file->get_32(); + loop_end = file->get_32(); + } } file->seek(file_pos + chunksize); } @@ -386,7 +393,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s Vector<float> new_data; new_data.resize((last - first + 1) * format_channels); - for (int i = first * format_channels; i <= last * format_channels; i++) { + for (int i = first * format_channels; i < (last + 1) * format_channels; i++) { new_data[i - first * format_channels] = data[i]; } diff --git a/editor/import/resource_importer_wav.h b/editor/import/resource_importer_wav.h index 89a6bfb015..cfce5a31ee 100644 --- a/editor/import/resource_importer_wav.h +++ b/editor/import/resource_importer_wav.h @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #ifndef RESOURCEIMPORTWAV_H #define RESOURCEIMPORTWAV_H |