summaryrefslogtreecommitdiff
path: root/editor/import
diff options
context:
space:
mode:
Diffstat (limited to 'editor/import')
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp33
-rw-r--r--editor/import/editor_scene_importer_gltf.h1
-rw-r--r--editor/import/resource_importer_scene.cpp1
-rw-r--r--editor/import/resource_importer_wav.cpp40
4 files changed, 50 insertions, 25 deletions
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index 7cdac7da33..e6e29df133 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -1697,6 +1697,22 @@ void EditorSceneImporterGLTF::_assign_scene_names(GLTFState &state) {
}
}
+void EditorSceneImporterGLTF::_reparent_skeleton(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, Node *p_parent_node) {
+ //reparent skeletons to proper place
+ Vector<int> nodes = state.skeleton_nodes[p_node];
+ for (int i = 0; i < nodes.size(); i++) {
+ Skeleton *skeleton = skeletons[nodes[i]];
+ Node *owner = skeleton->get_owner();
+ skeleton->get_parent()->remove_child(skeleton);
+ p_parent_node->add_child(skeleton);
+ skeleton->set_owner(owner);
+ //may have meshes as children, set owner in them too
+ for (int j = 0; j < skeleton->get_child_count(); j++) {
+ skeleton->get_child(j)->set_owner(owner);
+ }
+ }
+}
+
void EditorSceneImporterGLTF::_generate_node(GLTFState &state, int p_node, Node *p_parent, Node *p_owner, Vector<Skeleton *> &skeletons) {
ERR_FAIL_INDEX(p_node, state.nodes.size());
@@ -1768,24 +1784,17 @@ void EditorSceneImporterGLTF::_generate_node(GLTFState &state, int p_node, Node
_generate_node(state, n->children[i], node, p_owner, skeletons);
}
}
+
+ if (state.skeleton_nodes.has(p_node)) {
+ _reparent_skeleton(state, p_node, skeletons, node);
+ }
}
void EditorSceneImporterGLTF::_generate_bone(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, 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);
- //may have meshes as children, set owner in them too
- for (int j = 0; j < skeletons[i]->get_child_count(); j++) {
- skeletons[i]->get_child(j)->set_owner(owner);
- }
- }
+ _reparent_skeleton(state, p_node, skeletons, p_parent_node);
}
GLTFNode *n = state.nodes[p_node];
diff --git a/editor/import/editor_scene_importer_gltf.h b/editor/import/editor_scene_importer_gltf.h
index 0dff45abaf..ebf20e122a 100644
--- a/editor/import/editor_scene_importer_gltf.h
+++ b/editor/import/editor_scene_importer_gltf.h
@@ -310,6 +310,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 _reparent_skeleton(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, Node *p_parent_node);
void _generate_bone(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, 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_scene.cpp b/editor/import/resource_importer_scene.cpp
index 5eb1d2ec6c..fb2e3c0401 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -942,6 +942,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
old_anim->copy_track(i, anim);
}
}
+ anim->set_loop(old_anim->has_loop());
}
}
diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp
index 857d8992fd..52dec47343 100644
--- a/editor/import/resource_importer_wav.cpp
+++ b/editor/import/resource_importer_wav.cpp
@@ -35,6 +35,9 @@
#include "core/os/file_access.h"
#include "scene/resources/audio_stream_sample.h"
+const float TRIM_DB_LIMIT = -50;
+const int TRIM_FADE_OUT_FRAMES = 500;
+
String ResourceImporterWAV::get_importer_name() const {
return "wav";
@@ -393,31 +396,42 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
if (trim && !loop && format_channels > 0) {
int first = 0;
- int last = (frames * format_channels) - 1;
+ int last = (frames / format_channels) - 1;
bool found = false;
- float limit = Math::db2linear((float)-30);
- for (int i = 0; i < data.size(); i++) {
- float amp = Math::abs(data[i]);
+ float limit = Math::db2linear(TRIM_DB_LIMIT);
+
+ for (int i = 0; i < data.size() / format_channels; i++) {
+ float ampChannelSum = 0;
+ for (int j = 0; j < format_channels; j++) {
+ ampChannelSum += Math::abs(data[(i * format_channels) + j]);
+ }
+
+ float amp = Math::abs(ampChannelSum / (float)format_channels);
if (!found && amp > limit) {
- first = i;
+ first = i / format_channels;
found = true;
}
if (found && amp > limit) {
- last = i;
+ last = i / format_channels;
}
}
- first /= format_channels;
- last /= format_channels;
-
if (first < last) {
-
Vector<float> new_data;
- new_data.resize((last - first + 1) * format_channels);
- for (int i = first * format_channels; i < (last + 1) * format_channels; i++) {
- new_data.write[i - first * format_channels] = data[i];
+ new_data.resize((last - first) * format_channels);
+ for (int i = first; i < last; i++) {
+
+ float fadeOutMult = 1;
+
+ if (last - i < TRIM_FADE_OUT_FRAMES) {
+ fadeOutMult = ((float)(last - i - 1) / (float)TRIM_FADE_OUT_FRAMES);
+ }
+
+ for (int j = 0; j < format_channels; j++) {
+ new_data.write[((i - first) * format_channels) + j] = data[(i * format_channels) + j] * fadeOutMult;
+ }
}
data = new_data;