feat(web): add texture paint with persistent packed images
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled

- Add TexturePaintView with brush, stroke, undo/redo and OPFS persistence.
- Import/pack local images with a valid ImageTile and replace stale packed files.
- Sync the engine packed asset cache after Main refresh and pack operations.
- Add pixel-level texture paint E2E for draw/undo and OPFS reopen.
- Document linked-image limits and the local RE-derived practice texture.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
mes123456
2026-11-13 05:02:21 +08:00
parent 7267db7cb4
commit d959f66839
14 changed files with 420 additions and 18 deletions

View File

@@ -1048,6 +1048,7 @@ bool refresh_scene_from_main(EngineState &engine,
error = parsed.error;
return false;
}
engine.packed_assets = parsed.packed_assets;
snapshot = json::parse(parsed.scene_ir);
std::string merged_media_snapshot = snapshot.dump();
if (!web_engine_blend_main_merge_media_snapshot(
@@ -2490,6 +2491,7 @@ std::string refresh_error;
return last_error_code;
}
bool applied = false;
std::vector<uint8_t> packed_image_update;
std::string main_error;
std::string command_feedback;
std::string active_object_id = snapshot_active_object_id(snapshot);
@@ -2682,7 +2684,7 @@ std::string refresh_error;
applied = web_engine_blend_main_pack_image(
engine->authoritative_main, command.value("imageId", "").c_str(),
command.value("mimeType", "").c_str(), command.value("width", 0), command.value("height", 0),
command.value("base64", "").c_str(), main_error);
command.value("base64", "").c_str(), packed_image_update, main_error);
}
else if (type == "setMaterialImageNode") {
applied = web_engine_blend_main_set_material_image(
@@ -4046,6 +4048,9 @@ else if (type == "setMetaballElements") {
set_error(WEB_ENGINE_INVALID_ARGUMENT, main_error.c_str());
return last_error_code;
}
if (applied && type == "packImage" && !packed_image_update.empty()) {
engine->packed_assets[command.value("imageId", "")] = std::move(packed_image_update);
}
if (applied && type == "setObjectSelection" && command.value("active", false)) {
snapshot["activeObjectId"] = active_object_id;
if (snapshot.contains("editorWorkflow")) {

View File

@@ -15097,7 +15097,7 @@ bool web_engine_blend_main_import_image(WebBlendMainState *state,
}
image->source = IMA_SRC_FILE;
image->type = IMA_TYPE_IMAGE;
if (ImageTile *tile = static_cast<ImageTile *>(image->tiles.first)) {
if (ImageTile *tile = BKE_image_get_tile(image, 0)) {
tile->gen_x = width;
tile->gen_y = height;
tile->gen_depth = 32;
@@ -15119,6 +15119,7 @@ bool web_engine_blend_main_pack_image(WebBlendMainState *state,
const int width,
const int height,
const char *base64,
std::vector<uint8_t> &packed_bytes,
std::string &error)
{
if (state == nullptr || state->main == nullptr || image_id == nullptr || mime_type == nullptr ||
@@ -15145,13 +15146,15 @@ bool web_engine_blend_main_pack_image(WebBlendMainState *state,
error = "packImage base64 payload is empty or exceeds 256 MiB";
return false;
}
packed_bytes = decoded;
if (width > 0 && height > 0) {
if (ImageTile *tile = static_cast<ImageTile *>(image->tiles.first)) {
if (ImageTile *tile = BKE_image_get_tile(image, 0)) {
tile->gen_x = width;
tile->gen_y = height;
tile->gen_depth = 32;
}
}
BKE_image_free_packedfiles(image);
char *owned = MEM_new_array_uninitialized<char>(decoded.size(), "WebEngine packed external image");
memcpy(owned, decoded.data(), decoded.size());
BKE_image_packfiles_from_mem(nullptr, image, owned, decoded.size());

View File

@@ -442,6 +442,7 @@ bool web_engine_blend_main_pack_image(WebBlendMainState *state,
int width,
int height,
const char *base64,
std::vector<uint8_t> &packed_bytes,
std::string &error);
bool web_engine_blend_main_set_material_image(WebBlendMainState *state,
const char *material_id,