Skip to content

Commit

Permalink
Block preview generation in the game.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Nov 23, 2024
1 parent 4838f25 commit 5efd7b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 11 additions & 5 deletions editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ void EditorInterface::make_scene_preview(const String &p_path, Node *p_scene, in
ERR_FAIL_COND(!p_scene);
ERR_FAIL_COND(p_scene->is_inside_tree());

World3D *world = memnew(World3D);
SubViewport *sub_viewport_node = memnew(SubViewport);
if (!sub_viewport_node) {
return;
Expand All @@ -245,14 +244,18 @@ void EditorInterface::make_scene_preview(const String &p_path, Node *p_scene, in
sub_viewport_node->set_update_mode(SubViewport::UPDATE_ALWAYS);
sub_viewport_node->set_size(Vector2i(p_preview_size, p_preview_size));
sub_viewport_node->set_transparent_background(false);
Ref<World3D> world;
world.instantiate();
sub_viewport_node->set_world_3d(world);

EditorNode::get_singleton()->add_child(sub_viewport_node);

Ref<Environment> env = memnew(Environment);
Ref<Environment> env;
env.instantiate();
env->set_background(Environment::BG_CLEAR_COLOR);

Ref<CameraAttributesPractical> camera_attributes = memnew(CameraAttributesPractical);
Ref<CameraAttributesPractical> camera_attributes;
camera_attributes.instantiate();

Node3D *root = memnew(Node3D);
root->set_name("Root");
Expand Down Expand Up @@ -306,16 +309,19 @@ void EditorInterface::make_scene_preview(const String &p_path, Node *p_scene, in
Main::iteration();
Main::iteration();

// Get the exture.
// Get the texture.
Ref<Texture2D> texture = sub_viewport_node->get_texture();
ERR_FAIL_COND_MSG(texture.is_null(), "Failed to get texture from sub_viewport_node.");

// Remove the initial scene node.
sub_viewport_node->remove_child(p_scene);

// Cleanup the viewport.
if (sub_viewport_node) {
sub_viewport_node->queue_free();
sub_viewport_node->get_parent()->remove_child(sub_viewport_node);
if (sub_viewport_node->get_parent()) {
sub_viewport_node->get_parent()->remove_child(sub_viewport_node);
}
}

// Now generate the cache image.
Expand Down
4 changes: 3 additions & 1 deletion editor/import/3d/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3169,7 +3169,9 @@ Error ResourceImporterScene::import(ResourceUID::ID p_source_id, const String &p
print_verbose("Saving scene to: " + p_save_path + ".scn");
err = ResourceSaver::save(packer, p_save_path + ".scn", flags); //do not take over, let the changed files reload themselves
ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save scene to file '" + p_save_path + ".scn'.");
_generate_preview_for_scene(p_source_file, scene);
if (Engine::get_singleton()->is_editor_hint()) {
_generate_preview_for_scene(p_source_file, scene);
}
} else {
ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown scene import type: " + _scene_import_type);
}
Expand Down

0 comments on commit 5efd7b6

Please sign in to comment.