|
@@ -414,7 +414,6 @@ static Vector<real_t> _xform_to_array(const Transform3D p_transform) {
|
|
|
|
|
|
Error GLTFDocument::_serialize_nodes(Ref<GLTFState> p_state) {
|
|
|
Array nodes;
|
|
|
- const int scene_node_count = p_state->scene_nodes.size();
|
|
|
for (int i = 0; i < p_state->nodes.size(); i++) {
|
|
|
Dictionary node;
|
|
|
Ref<GLTFNode> gltf_node = p_state->nodes[i];
|
|
@@ -465,7 +464,7 @@ Error GLTFDocument::_serialize_nodes(Ref<GLTFState> p_state) {
|
|
|
}
|
|
|
|
|
|
Node *scene_node = nullptr;
|
|
|
- if (i < scene_node_count) {
|
|
|
+ if (i < (int)p_state->scene_nodes.size()) {
|
|
|
scene_node = p_state->scene_nodes[i];
|
|
|
}
|
|
|
for (Ref<GLTFDocumentExtension> ext : document_extensions) {
|
|
@@ -5264,6 +5263,7 @@ void GLTFDocument::_convert_scene_node(Ref<GLTFState> p_state, Node *p_current,
|
|
|
gltf_node.instantiate();
|
|
|
gltf_node->set_original_name(p_current->get_name());
|
|
|
gltf_node->set_name(_gen_unique_name(p_state, p_current->get_name()));
|
|
|
+ gltf_node->merge_meta_from(p_current);
|
|
|
if (cast_to<Node3D>(p_current)) {
|
|
|
Node3D *spatial = cast_to<Node3D>(p_current);
|
|
|
_convert_spatial(p_state, spatial, gltf_node);
|
|
@@ -5309,14 +5309,18 @@ void GLTFDocument::_convert_scene_node(Ref<GLTFState> p_state, Node *p_current,
|
|
|
ERR_CONTINUE(ext.is_null());
|
|
|
ext->convert_scene_node(p_state, gltf_node, p_current);
|
|
|
}
|
|
|
- GLTFNodeIndex current_node_i = p_state->nodes.size();
|
|
|
- GLTFNodeIndex gltf_root = p_gltf_root;
|
|
|
- if (gltf_root == -1) {
|
|
|
- gltf_root = current_node_i;
|
|
|
- p_state->root_nodes.push_back(gltf_root);
|
|
|
+ GLTFNodeIndex current_node_i;
|
|
|
+ if (gltf_node->get_parent() == -1) {
|
|
|
+ current_node_i = p_state->append_gltf_node(gltf_node, p_current, p_gltf_parent);
|
|
|
+ } else if (gltf_node->get_parent() < -1) {
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ current_node_i = p_state->nodes.size() - 1;
|
|
|
+ while (gltf_node != p_state->nodes[current_node_i]) {
|
|
|
+ current_node_i--;
|
|
|
+ }
|
|
|
}
|
|
|
- gltf_node->merge_meta_from(p_current);
|
|
|
- _create_gltf_node(p_state, p_current, current_node_i, p_gltf_parent, gltf_root, gltf_node);
|
|
|
+ const GLTFNodeIndex gltf_root = (p_gltf_root == -1) ? current_node_i : p_gltf_root;
|
|
|
for (int node_i = 0; node_i < p_current->get_child_count(); node_i++) {
|
|
|
_convert_scene_node(p_state, p_current->get_child(node_i), current_node_i, gltf_root);
|
|
|
}
|
|
@@ -5377,18 +5381,6 @@ void GLTFDocument::_convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeInd
|
|
|
}
|
|
|
#endif // MODULE_CSG_ENABLED
|
|
|
|
|
|
-void GLTFDocument::_create_gltf_node(Ref<GLTFState> p_state, Node *p_scene_parent, GLTFNodeIndex p_current_node_i,
|
|
|
- GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_gltf_node, Ref<GLTFNode> p_gltf_node) {
|
|
|
- p_state->scene_nodes.insert(p_current_node_i, p_scene_parent);
|
|
|
- p_state->nodes.push_back(p_gltf_node);
|
|
|
- ERR_FAIL_COND(p_current_node_i == p_parent_node_index);
|
|
|
- p_state->nodes.write[p_current_node_i]->parent = p_parent_node_index;
|
|
|
- if (p_parent_node_index == -1) {
|
|
|
- return;
|
|
|
- }
|
|
|
- p_state->nodes.write[p_parent_node_index]->children.push_back(p_current_node_i);
|
|
|
-}
|
|
|
-
|
|
|
void GLTFDocument::_convert_animation_player_to_gltf(AnimationPlayer *p_animation_player, Ref<GLTFState> p_state, GLTFNodeIndex p_gltf_current, GLTFNodeIndex p_gltf_root_index, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent) {
|
|
|
ERR_FAIL_NULL(p_animation_player);
|
|
|
p_state->animation_players.push_back(p_animation_player);
|