From c841c341fd1000357b926e889671544b0fb79867 Mon Sep 17 00:00:00 2001 From: XianglongZeng <1114802486@qq.com> Date: Tue, 17 Nov 2026 17:13:54 +0800 Subject: [PATCH] [feat] canvas: add a character four-view preset (#405) ## summary - Add a `four-view` image preset: one landscape sheet with front, right side and rear full-body views plus a frontal close-up. - Add an optional `faceEmphasis` field for `image-presets`. When the preset is `four-view` it swaps in a prompt that frames the front and side views from the chin down while keeping the full rear view and close-up. - Show the checkbox only for that preset and drop the parameter for other presets; translate the new labels to English. - Widen the image-preset dock a little and let the panel note wrap, so it stays readable beside the new checkbox without a wide empty gap. - Cover the preset list and output size, the prompt swap, the catalog field and the preset-scoped parameter in tests, and keep the existing preset names in both READMEs while documenting the new one. ## validation - `pytest tests/test_tool_tasks.py tests/test_tool_task_history.py`: 70 passed. - `node --test tests/toolCatalog.test.ts`: 11 passed. - `python scripts/generate_contracts.py --check`: verified. - `npm run check:i18n`: 0 problems. - `npx tsc --noEmit`: clean. - `npm test`: 929 of 930 passed; the remaining browser-host case fails in this environment while creating a temporary virtualenv (WinError 5) and does not touch this change. Fixes: #405 --- README.md | 2 +- README.zh-CN.md | 2 +- .../application/tool_image_edits.py | 21 +++++++++++++++- .../application/tool_operations.py | 3 ++- src/canvas/NodeTaskPanel.tsx | 15 +++++++++++ src/canvas/node-task-panel.css | 18 ++++++++++--- src/canvas/toolCatalog.ts | 2 ++ src/canvas/toolText.ts | 2 ++ src/canvas/workspace/WorkspaceView.tsx | 2 +- tests/test_tool_tasks.py | 25 ++++++++++++++++++- tests/toolCatalog.test.ts | 17 +++++++++++++ 11 files changed, 100 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d9c619258..ef4b3cbf9 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Use it to explore visual ideas, refine assets, and make short films. Projects st - **Work with AI**: Describe what you want to create, reference canvas assets, and ask the assistant to save text or generate content with your configured models. - **Canvas and reference assets**: Upload files, connect nodes, or use `@` to add references. Organize assets in one place and review generation history. - **Media editing**: Crop, adjust colors, and work with layers and clips. AI tools such as image extension, erasing, and background removal depend on the connected models' capabilities. -- **Image presets**: Select an image, choose Character three-view, Face three-view, Product three-view, Storyboard, or Multi-camera from **Presets**, then click **Generate** in the single-row panel. Three-view presets produce one reference sheet each; Storyboard and Multi-camera produce four separate images each, using landscape layouts and retaining a connection to the source. +- **Image presets**: Select an image, choose Character three-view, Character four-view, Face three-view, Product three-view, Storyboard, or Multi-camera from **Presets**, then click **Generate**. Character four-view adds a frontal close-up to the right of the full-body front, side, and rear views. Enable **Face emphasis** to ask the model to frame the front and side views from the chin down, keeping the full rear view and frontal close-up. The view presets each produce one reference sheet; Storyboard and Multi-camera each produce four separate images connected to the source. - **Timeline editing**: Arrange assets, adjust start and end points, speed, and volume, then preview and render an MP4. You can also export JSON, FCPXML, and asset bundles. - **Local projects, your choice of models**: The canvas saves automatically to your machine. Configure multiple models for a service and switch between them as needed. diff --git a/README.zh-CN.md b/README.zh-CN.md index d11cb383f..091a38d6c 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -30,7 +30,7 @@ OpenDirector 是一个在本地运行、通过浏览器使用的 AI 视频创作 - **与 AI 协作**:描述创作要求,引用画布素材,让助手保存文本并调用已配置的模型生成内容。 - **画布与参考素材**:上传文件、连接节点或用 `@` 添加参考,集中整理素材并查看生成历史。 - **媒体编辑**:裁剪、调色、处理图层和片段;扩图、消除、抠图等 AI 工具按已接入模型的能力提供。 -- **图像预设**:选中图片后,从「预设」直接选择人物三视图、面部三视图、产品三视图、分镜或多机位,在单行功能栏点击「生成」。三视图各输出一张参考板;分镜和多机位各输出四张独立图片,使用适合布局的横版画幅并关联原图。 +- **图像预设**:选中图片后,从「预设」选择人物三视图、人物四视图、面部三视图、产品三视图、连续分镜图或多机位,再点「生成」。人物四视图在正面、侧面和背面全身图的右侧加入正脸特写;勾选「脸部强调」后,会提示模型只拍摄正面和侧面从下巴到鞋底的部分,保留完整的背面全身和正脸特写。三视图和四视图各输出一张参考板;连续分镜图和多机位各输出四张独立图片,并关联原图。 - **时间线编排**:安排素材顺序、起止点、速度和音量,预览并合成 MP4,也可导出 JSON、FCPXML 和素材包。 - **本地项目,自选模型**:画布自动保存到本机,同一服务可配置多个模型,按用途切换。 diff --git a/packages/core/src/opendirector/application/tool_image_edits.py b/packages/core/src/opendirector/application/tool_image_edits.py index 17ab112c0..12cfb4cd5 100644 --- a/packages/core/src/opendirector/application/tool_image_edits.py +++ b/packages/core/src/opendirector/application/tool_image_edits.py @@ -183,6 +183,12 @@ class ImagePreset: '全部自然站立、双臂放松,同一高度与地面基线,完整呈现头顶到鞋底,不裁头、不切脚、不遮挡、不重叠。' '若原图仅有半身,依据可见服装合理补全下半身,补全部分在三个视角保持一致。' '保持参考图画风,纯净浅灰背景、均匀柔光、弱透视,无剧情场景、文字、标签、水印、分割线或额外视图。',)), + 'four-view': ImagePreset('人物四视图', ( + '根据参考图生成一张同一人物的横版四视图设定板。' + '从左到右依次为正面全身、右侧90度全身、背面全身、正脸特写,四个视图并排分开。' + '前三格自然站立,头顶到鞋底完整,同一比例与地面基线;最右格只展示正面头肩,清楚呈现正脸。' + '各视图保持同一人物、发型、服装和配饰。若参考图只展示半身,合理补全下半身并保持一致。' + '保持参考图画风、浅灰背景、均匀柔光,无文字、分割线、水印或额外视图。',), (3456, 1152)), 'face-three-view': ImagePreset('面部三视图', ( '以参考图人物的面部为唯一身份依据,生成同一人物的面部三视图参考板。' '3:1超宽横版画面均分为三个等宽区域,从左至右严格排列:正面、左侧90度、右侧90度。' @@ -210,10 +216,23 @@ class ImagePreset: '把机位升高到主体上方,高角度俯拍')), } +FOUR_VIEW_FACE_EMPHASIS = ( + '根据参考图生成同一人物的横版四格设定板,四张独立取景的照片从左到右并排。' + '第一格为正面、第二格为右侧90度。两格都降低取景范围,画框上缘正好切在下巴下沿,' + '脖子从顶边进入画面,从颈部一直拍到鞋底;下巴以上完全在画框外。' + '前两格顶边紧贴颈部,不在颈部上方留空;保持平直透视,不仰拍,不用面罩。' + '第三格拍完整的背面全身,从头顶到鞋底。第四格拍清晰的正脸头肩特写,保留参考人物的完整五官。' + '保持同一人物、体型、发型、服装、配饰和参考图画风。若参考图只展示半身,合理补全下半身并保持一致。' + '浅灰背景、均匀柔光,无文字、分割线、水印或额外视图。' +) + async def image_presets(ctx: ToolContext): image = _source_image(ctx) - preset = PRESETS[ctx.choice('preset', PRESETS)] + key = ctx.choice('preset', PRESETS) + preset = PRESETS[key] title, prompts = preset.title, preset.prompts + if key == 'four-view' and ctx.parameters.get('faceEmphasis') is True: + prompts = (FOUR_VIEW_FACE_EMPHASIS,) outputs = [] for index, instruction in enumerate(prompts, 1): await ctx.progress(f'正在生成{title}({index}/{len(prompts)})') diff --git a/packages/core/src/opendirector/application/tool_operations.py b/packages/core/src/opendirector/application/tool_operations.py index 755bc5ccf..9f2fb32f8 100644 --- a/packages/core/src/opendirector/application/tool_operations.py +++ b/packages/core/src/opendirector/application/tool_operations.py @@ -59,7 +59,8 @@ def _select(key, label, options, default=None, required=True): ToolSpec('panorama', ('image',), _needs('image.edit'), panorama, (_select('resolution', '清晰度', [('2K', '2K'), ('4K', '4K')], '2K'),)), ToolSpec('image-presets', ('image',), _needs('image.edit'), image_presets, - (_select('preset', '预设', [(key, value.title) for key, value in PRESETS.items()], 'three-view'),)), + (_select('preset', '预设', [(key, value.title) for key, value in PRESETS.items()], 'three-view'), + {'key': 'faceEmphasis', 'label': '脸部强调', 'type': 'boolean', 'required': False})), ToolSpec('multi-size', ('image',), _needs('image.edit'), multi_size), ToolSpec('product-replacement', ('image',), _needs('image.edit'), product_replacement), ToolSpec('dynamic-poster', ('image',), _needs('video.first_frame'), dynamic_poster), diff --git a/src/canvas/NodeTaskPanel.tsx b/src/canvas/NodeTaskPanel.tsx index ef7dd6377..e74eea3db 100644 --- a/src/canvas/NodeTaskPanel.tsx +++ b/src/canvas/NodeTaskPanel.tsx @@ -106,6 +106,9 @@ export function NodeTaskPanel({ ? t("tools.nodeTask.presetNote") : (toolReasonText(capability?.reason, t) ?? t("tools.nodeTask.notConnected"))); const models = capability?.models?.["image.edit"] ?? []; + const faceEmphasis = parameters.preset === "four-view" + ? capability?.fields?.find((field) => field.key === "faceEmphasis") + : undefined; return (
)} + {faceEmphasis && ( + + )} {note} diff --git a/src/canvas/node-task-panel.css b/src/canvas/node-task-panel.css index 7564a3799..a96f3d0bd 100644 --- a/src/canvas/node-task-panel.css +++ b/src/canvas/node-task-panel.css @@ -237,14 +237,26 @@ font-size: 11px; border-radius: 7px; } +.cw-preset-task-checkbox { + display: inline-flex; + flex-shrink: 0; + align-items: center; + gap: 4px; + white-space: nowrap; + font-size: 11px; + cursor: pointer; +} +.cw-preset-task-checkbox input { + margin: 0; + accent-color: #af93df; +} .cw-preset-task-note { flex: 1; min-width: 0; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; color: var(--cw-control-muted, #9299a9); font-size: 11px; + line-height: 15px; + white-space: normal; } .cw-preset-task-row > .cw-node-task-primary { flex-shrink: 0; diff --git a/src/canvas/toolCatalog.ts b/src/canvas/toolCatalog.ts index 891fb35b4..3b43b6583 100644 --- a/src/canvas/toolCatalog.ts +++ b/src/canvas/toolCatalog.ts @@ -617,6 +617,8 @@ export function createCanvasToolTask( selection?: ToolSelection, ): CanvasToolTask { let parameters = { ...values }; + if (tool === "image-presets" && values.preset !== "four-view") + delete parameters.faceEmphasis; if (tool === "multi-size") { const preset = multiSizePresets.find( (size) => size.ratio === values.aspectRatio, diff --git a/src/canvas/toolText.ts b/src/canvas/toolText.ts index 60f5704f5..280278fea 100644 --- a/src/canvas/toolText.ts +++ b/src/canvas/toolText.ts @@ -62,6 +62,8 @@ const EN: Record = { "背景声(近似)": "Background (approximate)", "三视图": "Three-view", "人物三视图": "Character three-view", + "人物四视图": "Character four-view", + "脸部强调": "Face emphasis", "面部三视图": "Face three-view", "产品三视图": "Product three-view", "连续分镜图": "Storyboard sequence", diff --git a/src/canvas/workspace/WorkspaceView.tsx b/src/canvas/workspace/WorkspaceView.tsx index 46e00f228..196dc0f8c 100644 --- a/src/canvas/workspace/WorkspaceView.tsx +++ b/src/canvas/workspace/WorkspaceView.tsx @@ -1487,7 +1487,7 @@ export function WorkspaceView({ rt }: { rt: WorkspaceRuntime }) { ...selectionPresentation.placement?.composer, width: activeAction.tool === "image-presets" - ? Math.min(440, selectionPresentation.composerWidth) + ? Math.min(470, selectionPresentation.composerWidth) : selectionPresentation.composerWidth, maxHeight: selectionPresentation.composerMaxHeight, transform: selectionPresentation.composerTransform, diff --git a/tests/test_tool_tasks.py b/tests/test_tool_tasks.py index df9afac3a..d2908feae 100644 --- a/tests/test_tool_tasks.py +++ b/tests/test_tool_tasks.py @@ -139,7 +139,9 @@ def test_catalog_reports_availability_by_capability(project): assert {'image.edit', 'video.first_frame', 'audio.speech', 'text.chat'} <= set(configured['capabilities']) assert any(field['key'] == 'preset' and field['options'] for field in tools['image-presets']['fields']) preset_field = next(field for field in tools['image-presets']['fields'] if field['key'] == 'preset') - assert [option['label'] for option in preset_field['options']] == ['人物三视图', '面部三视图', '产品三视图', '连续分镜图', '多机位'] + assert [option['label'] for option in preset_field['options']] == ['人物三视图', '人物四视图', '面部三视图', '产品三视图', '连续分镜图', '多机位'] + emphasis = next(field for field in tools['image-presets']['fields'] if field['key'] == 'faceEmphasis') + assert emphasis['type'] == 'boolean' and emphasis['required'] is False def test_outpaint_keeps_original_pixels_and_returns_requested_size(project): @@ -281,6 +283,7 @@ def test_presets_return_one_output_per_shot_and_local_hd_needs_no_model(project) @pytest.mark.parametrize('preset,count,size', [ ('three-view', 1, (2048, 1152)), + ('four-view', 1, (3456, 1152)), ('face-three-view', 1, (3456, 1152)), ('product-three-view', 1, (2048, 1152)), ('storyboard', 4, (2048, 1152)), @@ -311,6 +314,26 @@ def test_image_presets_reframe_portrait_reference_and_register_each_result(proje assert '朝向相反、左右镜像对称'.encode() in calls[0] elif preset == 'product-three-view': assert '近正交投影'.encode() in calls[0] + elif preset == 'four-view': + assert '正面全身、右侧90度全身、背面全身、正脸特写'.encode() in calls[0] + assert '下巴以上完全在画框外'.encode() not in calls[0] + + +@pytest.mark.parametrize('preset,crops_front_and_side', [('four-view', True), ('three-view', False)]) +def test_face_emphasis_only_affects_the_four_view_preset(project, preset, crops_front_and_side): + store, project_id, session = project + configs = configure(store, ZIMAGE) + source = upload(store, project_id, session, 'portrait.png', png((64, 96))) + calls = [] + task = run(store, configs, httpx.MockTransport(images_server(calls)), project_id, session, + {'tool': 'image-presets', 'sourceAssetIds': [source], + 'parameters': {'preset': preset, 'faceEmphasis': True}}) + assert task['status'] == 'succeeded', task.get('error') + assert len(task['outputs']) == len(calls) == 1 + assert ('下巴以上完全在画框外'.encode() in calls[0]) == crops_front_and_side + if crops_front_and_side: + assert '第三格拍完整的背面全身'.encode() in calls[0] + assert '第四格拍清晰的正脸头肩特写'.encode() in calls[0] def test_submission_rejects_tools_without_a_capable_model(project): diff --git a/tests/toolCatalog.test.ts b/tests/toolCatalog.test.ts index a6dfb2fb4..3e413a3c2 100644 --- a/tests/toolCatalog.test.ts +++ b/tests/toolCatalog.test.ts @@ -154,6 +154,23 @@ test("dynamic options and unknown task protocols cannot be guessed into a valid ); }); +test("face emphasis only accompanies the four-view preset", () => { + assert.deepEqual( + createCanvasToolTask("image-presets", [source.nodeId], { + preset: "four-view", + faceEmphasis: true, + }).parameters, + { preset: "four-view", faceEmphasis: true }, + ); + assert.deepEqual( + createCanvasToolTask("image-presets", [source.nodeId], { + preset: "three-view", + faceEmphasis: true, + }).parameters, + { preset: "three-view" }, + ); +}); + test("observed marketing presets derive exact pixels while custom dimensions remain explicit", () => { const confirmed = { available: true, parametersConfirmed: true }; for (const [aspectRatio, outputWidth, outputHeight] of [