Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Scale H3 Image character sheets

Bitti73101be153fc
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 65b8b9a..051acde 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -10,6 +10,7 @@ Changes since 0.4.0.
## Fixes and improvements
+- MiniMax H3 Image character sheet presets scale by 1.675 with 32-pixel alignment, up to 3424 pixels high. Each view stays below 20 MP; all four views combine into a 9184 × 3424 sheet that can be saved and reopened.
- MiniMax H3 Image Zoom width and height fields now snap typed sizes to multiples of 32, keeping the displayed values in sync with the box.
- Fixed Zoom rejecting MiniMax H3 Image outputs above the older canvas limit; aligned outputs up to 20 MP are now supported.
- MiniMax H3 Image now supports character sheets, using its image prompts, reference limits and six-step generation recipe.
diff --git a/src-tauri/src/commands/artifacts.rs b/src-tauri/src/commands/artifacts.rs
index db6a915..9ee3555 100644
--- a/src-tauri/src/commands/artifacts.rs
+++ b/src-tauri/src/commands/artifacts.rs
@@ -226,7 +226,10 @@ pub(crate) fn save_generated_image(
pub(crate) fn write_generated_png_frame(folder: &str, id: &str, width: u32, height: u32, rgba: &[u8]) -> Result<GeneratedImageFile, String> {
use image::ImageEncoder;
- if width == 0 || height == 0 || width > 8192 || height > 8192 || rgba.len() != width as usize * height as usize * 4 {
+ // A character sheet combines up to four individually limited 20 MP views.
+ if width == 0 || height == 0 || width > 16_384 || height > 16_384
+ || u64::from(width) * u64::from(height) > 80 * 1024 * 1024
+ || rgba.len() != width as usize * height as usize * 4 {
return Err("Invalid PNG image dimensions or pixels.".into());
}
let root = ProjectRoot::open(folder)?;
diff --git a/src-tauri/src/commands/character_sheet.rs b/src-tauri/src/commands/character_sheet.rs
index 1aca97b..fe69fbe 100644
--- a/src-tauri/src/commands/character_sheet.rs
+++ b/src-tauri/src/commands/character_sheet.rs
@@ -3,6 +3,14 @@ use crate::project::paths::ProjectRoot;
use crate::rendered;
use image::{ImageEncoder, RgbaImage};
+const MAX_VIEW_EDGE: u32 = 8192;
+const MAX_VIEW_PIXELS: u64 = 20 * 1024 * 1024;
+
+fn valid_view_size(width: u32, height: u32) -> bool {
+ width > 0 && height > 0 && width <= MAX_VIEW_EDGE && height <= MAX_VIEW_EDGE
+ && u64::from(width) * u64::from(height) <= MAX_VIEW_PIXELS
+}
+
fn cache_directory(sheet_id: &str) -> Result<String, String> {
Ok(format!(
"cache/character-sheets/{}",
@@ -37,10 +45,7 @@ fn write_view(
pixels: &[u8],
) -> Result<(), String> {
if index >= 4
- || width == 0
- || width > 2048
- || height == 0
- || height > 8192
+ || !valid_view_size(width, height)
|| pixels.len() != width as usize * height as usize * 4
{
return Err("Invalid character sheet view dimensions or pixels.".into());
@@ -74,7 +79,7 @@ pub(crate) fn combine_character_sheet(
for index in indices {
let path = root.existing(&format!("{directory}/{index}.png"))?;
let (width, height) = image::image_dimensions(&path).map_err(|error| error.to_string())?;
- if width == 0 || width > 2048 || height == 0 || height > 8192 {
+ if !valid_view_size(width, height) {
return Err("Invalid character sheet view dimensions.".into());
}
if !views.is_empty() && common_height != height {
@@ -82,6 +87,9 @@ pub(crate) fn combine_character_sheet(
}
common_height = height;
total_width += width;
+ if total_width > 16_384 || u64::from(total_width) * u64::from(common_height) > 4 * MAX_VIEW_PIXELS {
+ return Err("Combined character sheet exceeds the supported image size.".into());
+ }
views.push((path, width));
}
let mut sheet = RgbaImage::new(total_width, common_height);
@@ -200,12 +208,29 @@ mod tests {
}
}
+ #[test]
+ fn character_sheet_saves_scaled_h3_views_above_20_mp_combined() {
+ let folder = project_folder();
+ let path = folder.path().to_string_lossy().into_owned();
+ for (index, width) in [3424, 1920, 1920, 1920].into_iter().enumerate() {
+ assert!(valid_view_size(width, 3424));
+ write_view(&path, "h3-sheet", index, width, 3424,
+ &[index as u8, 80, 120, 255].repeat(width as usize * 3424)).unwrap();
+ }
+ let saved = combine_character_sheet(path.clone(), "h3-sheet".into(), None).unwrap();
+ assert_eq!((saved.width, saved.height), (9184, 3424));
+ assert_eq!(image::image_dimensions(folder.path().join(saved.relative_path)).unwrap(), (9184, 3424));
+ assert!(!valid_view_size(4608, 4608));
+ assert!(!valid_view_size(8193, 32));
+ discard_character_sheet_views(path, "h3-sheet".into()).unwrap();
+ }
+
#[test]
fn character_sheet_rejects_missing_mismatched_and_oversized_views() {
let folder = project_folder();
let path = folder.path().to_string_lossy().into_owned();
assert!(write_view(&path, "sheet", 4, 1, 1, &[0; 4]).is_err());
- assert!(write_view(&path, "sheet", 0, 2049, 1, &[0; 4]).is_err());
+ assert!(write_view(&path, "sheet", 0, 8193, 1, &[0; 4]).is_err());
write_view(&path, "sheet", 0, 1, 1, &[0; 4]).unwrap();
assert!(combine_character_sheet(path.clone(), "sheet".into(), None).is_err());
for index in 1..4 {
diff --git a/src-tauri/src/project/image.rs b/src-tauri/src/project/image.rs
index 16be8c5..d9c6bac 100644
--- a/src-tauri/src/project/image.rs
+++ b/src-tauri/src/project/image.rs
@@ -50,7 +50,7 @@ impl ImageTemplateSnapshot {
let valid_options = match self.kind.as_str() {
"extend" => self.views.is_none() && self.height.is_none() && self.bounds.as_ref().is_some_and(|b|
[b.x, b.y, b.width, b.height].iter().all(|v| v.is_finite()) && b.width > 0.0 && b.height > 0.0),
- "character-sheet" => self.bounds.is_none() && matches!(self.height, Some(512 | 1024 | 1536 | 2048))
+ "character-sheet" => self.bounds.is_none() && self.height.is_some_and(|height| (512..=3424).contains(&height) && height % 32 == 0)
&& self.views.as_ref().is_none_or(|views| views.close_up || views.front || views.side || views.back),
_ => false,
};
@@ -167,8 +167,8 @@ impl ImageScene {
}
if let Some(source) = &self.source_image {
crate::project::paths::normalize_project_path(&source.relative_path)?;
- if source.name.is_empty() || !(1..=8192).contains(&source.width) || !(1..=8192).contains(&source.height) {
- return Err("Source image dimensions must be between 1 and 8192 pixels.".into());
+ if source.name.is_empty() || !(1..=16_384).contains(&source.width) || !(1..=16_384).contains(&source.height) {
+ return Err("Source image dimensions must be between 1 and 16384 pixels.".into());
}
}
if self.nodes.is_empty()
diff --git a/src-tauri/src/tests/images.rs b/src-tauri/src/tests/images.rs
index 46f9725..947fbbf 100644
--- a/src-tauri/src/tests/images.rs
+++ b/src-tauri/src/tests/images.rs
@@ -243,12 +243,17 @@ fn image_template_settings_survive_save_and_reopen() {
serde_json::json!({"kind":"extend", "sourceId":"source", "sourceName":"Original", "generatorName":"Default generator", "prompt":"Continue the forest", "steps":28, "seed":-1, "bounds":{"x":-64,"y":-32,"width":768,"height":640}}),
serde_json::json!({"kind":"character-sheet", "sourceId":"source", "sourceName":"Original", "generatorName":"Default generator", "prompt":"Red coat", "steps":28, "seed":0, "height":1024}),
serde_json::json!({"kind":"character-sheet", "sourceId":"source", "sourceName":"Original", "generatorName":"Default generator", "prompt":"Red coat", "steps":28, "seed":0, "height":1024, "views":{"closeUp":false,"front":false,"side":true,"back":true}}),
+ serde_json::json!({"kind":"character-sheet", "sourceId":"source", "sourceName":"Original", "generatorName":"MiniMax H3 Image", "prompt":"Red coat", "steps":6, "seed":0, "height":3424, "views":{"closeUp":true,"front":true,"side":true,"back":true}}),
] {
for pending in [true, false] {
let mut config = image_fixture();
let mut snapshot: serde_json::Value = serde_json::from_str(include_str!("../../../fixtures/image-generation-snapshot.json")).unwrap();
snapshot["template"] = template.clone();
snapshot["usedSeed"] = serde_json::json!(1234);
+ if template["height"] == 3424 {
+ snapshot["scene"]["rootType"] = serde_json::json!("image");
+ snapshot["scene"]["sourceImage"] = serde_json::json!({"relativePath":"media/result.png", "name":"Character sheet", "width":9184, "height":3424});
+ }
config.assets.push(serde_json::from_value(serde_json::json!({
"id":"template-result", "kind":"image", "name":"Template result", "mimeType":"image/png",
"width":512, "height":512, "createdAt":config.created_at, "imageDraft":pending,
diff --git a/src/components/ImageProject.integration.test.tsx b/src/components/ImageProject.integration.test.tsx
index 98786c6..e87c3a4 100644
--- a/src/components/ImageProject.integration.test.tsx
+++ b/src/components/ImageProject.integration.test.tsx
@@ -49,16 +49,16 @@ it.each(["minimax-h3", "h3_image"])("opens %s template settings and executes onl
expect(screen.queryByRole("complementary", { name: "Image node inspector" })).not.toBeInTheDocument();
const panel = within(screen.getByRole("complementary", { name: "Character sheet settings" }));
const before = structuredClone(queue.project(project).getSnapshot().config);
- choose("Character sheet resolution", "2048 px high");
+ choose("Character sheet resolution", modelType === "h3_image" ? "3424 px high" : "2048 px high");
expect(panel.getByRole("switch", { name: "Side view" })).not.toBeChecked();
for (const name of ["Close up", "Front view", "Back view"]) expect(panel.getByRole("switch", { name })).toBeChecked();
- expect(panel.getByText(/Sheet size:/)).toHaveTextContent("4352 × 2048 px");
+ expect(panel.getByText(/Sheet size:/)).toHaveTextContent(modelType === "h3_image" ? "7264 × 3424 px" : "4352 × 2048 px");
fireEvent.click(panel.getByRole("switch", { name: "Side view" }));
- expect(panel.getByText(/Sheet size:/)).toHaveTextContent("5504 × 2048 px");
+ expect(panel.getByText(/Sheet size:/)).toHaveTextContent(modelType === "h3_image" ? "9184 × 3424 px" : "5504 × 2048 px");
for (const name of ["Close up", "Front view", "Side view", "Back view"]) fireEvent.click(panel.getByRole("switch", { name }));
expect(panel.getByRole("button", { name: "Execute" })).toBeDisabled();
fireEvent.click(panel.getByRole("switch", { name: "Back view" }));
- expect(panel.getByText(/Sheet size:/)).toHaveTextContent("1152 × 2048 px");
+ expect(panel.getByText(/Sheet size:/)).toHaveTextContent(modelType === "h3_image" ? "1920 × 3424 px" : "1152 × 2048 px");
if (modelType === "h3_image") {
expect(panel.getByRole("spinbutton", { name: "Steps" })).toBeDisabled();
expect(panel.getByRole("spinbutton", { name: "Steps" })).toHaveValue(6);
diff --git a/src/components/workspace/CharacterSheetSettings.tsx b/src/components/workspace/CharacterSheetSettings.tsx
index e5b80a9..8c40290 100644
--- a/src/components/workspace/CharacterSheetSettings.tsx
+++ b/src/components/workspace/CharacterSheetSettings.tsx
@@ -1,7 +1,7 @@
import { SliderNumberInput, GENERATION_STEPS_RANGE } from "./SliderNumberInput";
import { imageSettings } from "../../lib/imageSettings";
import { useMemo, useState } from "react";
-import { CHARACTER_SHEET_HEIGHTS, CHARACTER_SHEET_ORDER, CHARACTER_SHEET_VIEWS, characterSheetDimensions, characterSheetViewIndices, characterSheetViews, compileCharacterSheet, emptyCharacterSheetOptions, type CharacterSheetOptions } from "../../lib/characterSheet";
+import { CHARACTER_SHEET_HEIGHTS, CHARACTER_SHEET_ORDER, CHARACTER_SHEET_VIEWS, characterSheetDimensions, characterSheetViewDimensions, characterSheetViewIndices, characterSheetViews, compileCharacterSheet, emptyCharacterSheetOptions, type CharacterSheetOptions } from "../../lib/characterSheet";
import type { ProjectAsset, ProjectConfig } from "../../lib/project";
import { ComboBox, InfoBar, ItemHeader, PropRow, ToggleSwitch } from "../ui";
import { Dismiss16, Sparkle16 } from "../ui/icons";
@@ -20,7 +20,11 @@ export function CharacterSheetSettings({ config, source, references, missingLabe
steps: config.imageScene?.steps ?? defaultSteps, seed: config.imageScene?.seed ?? -1, ...initialOptions,
// Older submitted sheets always generated all four views.
...(initialOptions && !initialOptions.views ? { views: { closeUp: true, front: true, side: true, back: true } } : {}) }));
- const dimensions = characterSheetDimensions(imageSettings(config).resolution, options.height);
+ // Submitted snapshots store actual pixels; editable settings store preset heights.
+ const dimensions = initialOptions?.height !== undefined ? characterSheetViewDimensions(initialOptions.height)
+ : characterSheetDimensions(imageSettings(config).resolution, options.height, modelType);
+ const resolutionOptions = initialOptions?.height !== undefined ? [{ value: initialOptions.height, label: `${initialOptions.height} px high` }]
+ : CHARACTER_SHEET_HEIGHTS.map((height) => ({ value: height, label: `${characterSheetDimensions(imageSettings(config).resolution, height, modelType)[0].height} px high` }));
const selectedViews = characterSheetViews(options);
const indices = characterSheetViewIndices(options);
const [error, setError] = useState<string | null>(null);
@@ -49,7 +53,7 @@ export function CharacterSheetSettings({ config, source, references, missingLabe
onChange={(checked) => update("views", { ...selectedViews, [view.id]: checked })} />
</PropRow>)}
<PropRow label="Resolution" htmlFor="character-sheet-resolution" tooltip="Width follows the selected view proportions."><ComboBox id="character-sheet-resolution" aria-label="Character sheet resolution" value={options.height} disabled={busy}
- options={CHARACTER_SHEET_HEIGHTS.map((height) => ({ value: height, label: `${height} px high` }))} onChange={(height) => update("height", height)} /></PropRow>
+ options={resolutionOptions} onChange={(height) => update("height", height)} /></PropRow>
<p className="image-inspector__caption">Sheet size: {indices.reduce((width, index) => width + dimensions[index].width, 0)} × {dimensions[0].height} px.</p>
<PropRow label="Steps" htmlFor="character-sheet-steps" tooltip="All selected views use the same step count."><SliderNumberInput id="character-sheet-steps" aria-label="Steps" {...GENERATION_STEPS_RANGE} required disabled={busy || modelType === "h3_image"}
value={steps} onCommit={(steps) => update("steps", steps)} /></PropRow>
diff --git a/src/components/workspace/ImageEditor.test.tsx b/src/components/workspace/ImageEditor.test.tsx
index 5eab6e6..f644c96 100644
--- a/src/components/workspace/ImageEditor.test.tsx
+++ b/src/components/workspace/ImageEditor.test.tsx
@@ -162,15 +162,16 @@ it.each([mossImageTemplate(), ...kreaImageTemplates()])("offers $name for new im
});
it.each([
- ["extend", true], ["extend", false], ["character-sheet", true], ["character-sheet", false],
-] as const)("shows the existing %s panel only while the selected entry is generating (pending: %s)", (kind, pending) => {
+ ["extend", true, 1024], ["extend", false, 1024], ["character-sheet", true, 1024], ["character-sheet", false, 1024],
+ ["character-sheet", true, 3424], ["character-sheet", false, 3424],
+] as const)("shows the existing %s panel only while the selected entry is generating (pending: %s, height: %s)", (kind, pending, height) => {
const initial = parseProjectConfig(fixture);
const source = { id: "source", kind: "image" as const, name: "Original", relativePath: "media/source.png", width: 512, height: 512, mimeType: "image/png", createdAt: initial.createdAt };
initial.assets = [source];
const name = kind === "extend" ? "Zoom" : "Character sheet";
const generation = { ...imageGenerationSnapshot({ ...initial, imageScene: { ...createImageScene("Snowy forest"), steps: 28, seed: -1 } }, "Compiled prompt", "removed-generator"), usedSeed: 1234,
template: { sourceId: source.id, sourceName: source.name, generatorName: "Recorded generator", prompt: "Snowy forest", steps: 28, seed: -1,
- ...(kind === "extend" ? { kind, bounds: { x: -64, y: -32, width: 768, height: 640 } } : { kind, height: 1024 }) } };
+ ...(kind === "extend" ? { kind, bounds: { x: -64, y: -32, width: 768, height: 640 } } : { kind, height }) } };
let saved = createTemplateImageDraft(initial, "template-result", `${name} result`, generation, { width: 512, height: 512 });
if (!pending) {
const result = { ...source, id: "template-result", name: `${name} result`, relativePath: "media/result.png" };
@@ -192,7 +193,10 @@ it.each([
expect(panel.getByLabelText("Zoom y")).toHaveValue(-32);
expect(panel.getByLabelText("Zoom width")).toHaveValue(768);
expect(panel.getByLabelText("Zoom height")).toHaveValue(640);
- } else expect(comboValue(panel.getByLabelText("Character sheet resolution"))).toBe("1024");
+ } else {
+ expect(comboValue(panel.getByLabelText("Character sheet resolution"))).toBe(String(height));
+ expect(panel.getByText(/Sheet size:/)).toHaveTextContent(height === 3424 ? "9184 × 3424 px" : "2752 × 1024 px");
+ }
expect(screen.getByRole("button", { name: "Cancel" })).toBeEnabled();
expect(screen.getByRole("progressbar", { name: "Image generation progress" })).toBeInTheDocument();
fireEvent.contextMenu(screen.getByRole("button", { name: `View ${name} result` }));
diff --git a/src/lib/characterSheet.test.ts b/src/lib/characterSheet.test.ts
index c7c530c..0848ef9 100644
--- a/src/lib/characterSheet.test.ts
+++ b/src/lib/characterSheet.test.ts
@@ -50,14 +50,18 @@ it.each(["minimax-h3", "h3_image"].flatMap((modelType) => [false, true].map((cha
const { queue, session } = setup();
const original = structuredClone(session.getSnapshot().config);
const selected = { ...template, modelType };
+ const height = modelType === "h3_image" ? 1696 : 1024;
+ const bodyWidth = modelType === "h3_image" ? 960 : 576;
+ const saved = { ...result, width: height + 2 * bodyWidth, height };
+ vi.mocked(invoke).mockImplementation(async (command) => command === "combine_character_sheet" ? saved : undefined);
queue.enqueueCharacterSheet(session, selected, "source");
queue.enqueueCharacterSheet(session, selected, "source");
expect(queue.getSnapshot()).toHaveLength(1);
const id = queue.getSnapshot()[0].id;
const pending = parseProjectConfig(JSON.parse(JSON.stringify(session.getSnapshot().config)));
expect(pending.assets).toHaveLength(2);
- expect(pending.assets[1]).toMatchObject({ id, imageDraft: true, parentAssetId: "source", width: 2176, height: 1024,
- imageGeneration: { template: { kind: "character-sheet", sourceId: "source", sourceName: "Hero", generatorName: template.name, prompt: "", height: 1024 } } });
+ expect(pending.assets[1]).toMatchObject({ id, imageDraft: true, parentAssetId: "source", width: saved.width, height,
+ imageGeneration: { template: { kind: "character-sheet", sourceId: "source", sourceName: "Hero", generatorName: template.name, prompt: "", height } } });
expect(pending.assets[1].relativePath).toBeUndefined();
expect(pending.imageScene!.outputAssetId).toBe(id);
expect(queue.getSnapshot()[0].imageDraftId).toBe(id);
@@ -73,8 +77,8 @@ it.each(["minimax-h3", "h3_image"].flatMap((modelType) => [false, true].map((cha
expect(request).toMatchObject({ stillImage: true, frames: 1, referencePaths, seed });
expect(request.steps).toBe(modelType === "h3_image" ? 6 : original.imageScene!.steps);
expect(vi.mocked(enqueueSlopfabGeneration).mock.calls[index][1].providerSettings.slopfab?.options.modelType).toBe(modelType);
- expect(request.canvasWidth / request.canvasHeight).toBe(viewIndex === 0 ? 1 : 9 / 16);
- expect(request.canvasHeight).toBe(1024);
+ expect(request.canvasWidth).toBe(viewIndex === 0 ? height : bodyWidth);
+ expect(request.canvasHeight).toBe(height);
if (index > 0) {
expect(invoke).toHaveBeenCalledWith("save_character_sheet_view", { folderPath: "C:/Character", sheetId: id, jobId: `${id}-view-2`, index: 1 });
expect(request.prompt).toContain("match the outfit in <Picture 2> from the requested angle");
@@ -106,7 +110,7 @@ it.each(["minimax-h3", "h3_image"].flatMap((modelType) => [false, true].map((cha
const reopened = parseProjectConfig(JSON.parse(JSON.stringify(session.getSnapshot().config)));
expect(reopened.assets).toHaveLength(2);
expect(reopened.assets[0]).toEqual(original.assets[0]);
- expect(reopened.assets[1]).toMatchObject({ id, name: "Character sheet - Hero", mimeType: "image/png", ...result, imageGeneration: { usedSeed: seed } });
+ expect(reopened.assets[1]).toMatchObject({ id, name: "Character sheet - Hero", mimeType: "image/png", ...saved, imageGeneration: { usedSeed: seed } });
expect(reopened.assets[1].parentAssetId).toBe("source");
expect(reopened.assets[1].imageDraft).toBe(false);
expect(reopened.assets[1].imageGeneration!.template).toEqual(pending.assets[1].imageGeneration!.template);
@@ -155,23 +159,30 @@ it("rejects a sheet with every view disabled before queueing", () => {
expect(queue.getSnapshot()).toHaveLength(0);
});
-it.each(CHARACTER_SHEET_HEIGHTS)("generates all four views at the selected %s px height", async (height) => {
+it.each(CHARACTER_SHEET_HEIGHTS.flatMap((height, index) => [
+ { modelType: "minimax-h3", height, outputHeight: height, bodyWidth: height * 9 / 16 },
+ { modelType: "h3_image", height, outputHeight: [832, 1696, 2560, 3424][index], bodyWidth: [480, 960, 1440, 1920][index] },
+]))("generates and reopens all four $modelType views at preset $height", async ({ modelType, height, outputHeight, bodyWidth }) => {
const { queue, session } = setup();
- const saved = { ...result, width: height * 43 / 16, height };
+ const saved = { ...result, width: outputHeight + 3 * bodyWidth, height: outputHeight };
vi.mocked(invoke).mockImplementation(async (command) => command === "combine_character_sheet" ? saved : undefined);
const options = { prompt: "", height, views: { closeUp: true, front: true, side: true, back: true } };
- queue.enqueueCharacterSheet(session, template, "source", options);
- expect(queue.getSnapshot()[0].settings.canvasHeight).toBe(height);
+ queue.enqueueCharacterSheet(session, { ...template, modelType }, "source", options);
+ expect(queue.getSnapshot()[0].settings.canvasHeight).toBe(outputHeight);
options.height = 512; // Queued dimensions must not follow later settings edits.
for (let index = 0; index < 4; index++) {
const request = await requestAt(index);
- expect(request.canvasHeight).toBe(height);
- expect(request.canvasWidth).toBe(index === 1 ? height : height * 9 / 16);
+ expect(request.canvasHeight).toBe(outputHeight);
+ expect(request.canvasWidth).toBe(index === 1 ? outputHeight : bodyWidth);
expect(request.canvasWidth % 32).toBe(0);
+ expect(request.canvasHeight % 32).toBe(0);
+ expect(request.canvasWidth * request.canvasHeight).toBeLessThanOrEqual(20 * 1024 * 1024);
emit("framesReady", request.jobId);
}
await waitFor(() => expect(queue.getSnapshot()[0].status).toBe("completed"));
- expect(session.getSnapshot().config.assets.at(-1)).toMatchObject(saved);
+ const reopened = parseProjectConfig(JSON.parse(JSON.stringify(session.getSnapshot().config)));
+ expect(reopened.assets.at(-1)).toMatchObject({ ...saved, imageGeneration: { template: { height: outputHeight }, scene: { sourceImage: saved } } });
+ expect(reopened.imageScene?.sourceImage).toMatchObject(saved);
expect(session.getSnapshot().config.settings.resolution).toBe("768p");
});
diff --git a/src/lib/characterSheet.ts b/src/lib/characterSheet.ts
index dcfb9be..682adc6 100644
--- a/src/lib/characterSheet.ts
+++ b/src/lib/characterSheet.ts
@@ -1,6 +1,7 @@
import { createImageScene } from "./imageScene";
import { compileImagePrompt } from "./imagePrompt";
import { outputDimensions } from "./export";
+import { imageGenerationSizeError, imageResolutionScale } from "./imageSettings";
import type { ProjectAsset, ProjectConfig, ProjectReference } from "./project";
export const CHARACTER_SHEET_VIEWS = [
@@ -20,12 +21,19 @@ export const characterSheetViews = (options?: CharacterSheetOptions): CharacterS
export const characterSheetViewIndices = (options?: CharacterSheetOptions) => CHARACTER_SHEET_VIEWS.flatMap((view, index) => characterSheetViews(options)[view.id] ? [index] : []);
export const emptyCharacterSheetOptions = (): CharacterSheetOptions => ({ prompt: "", views: characterSheetViews() });
-export function characterSheetDimensions(resolution: ProjectConfig["settings"]["resolution"], requestedHeight?: number) {
- // A shared height divisible by 512 makes both 1:1 and 9:16 exact on H3's
- // 32px grid, and keeps the combined image below the editor's 8192px limit.
+/** Dimensions from a saved output height; never apply the model scale twice. */
+export function characterSheetViewDimensions(height: number) {
+ return CHARACTER_SHEET_VIEWS.map((_, index) => ({ width: index === 0 ? height : Math.round(height * 9 / 16 / 32) * 32, height }));
+}
+
+export function characterSheetDimensions(resolution: ProjectConfig["settings"]["resolution"], requestedHeight?: number, modelType?: string) {
if (requestedHeight !== undefined && !CHARACTER_SHEET_HEIGHTS.some((height) => height === requestedHeight)) throw new Error("Choose a supported character sheet height.");
- const height = requestedHeight ?? Math.max(512, Math.min(2048, Math.round(outputDimensions(resolution, "1:1").height / 512) * 512));
- return CHARACTER_SHEET_VIEWS.map((_, index) => ({ width: index === 0 ? height : height * 9 / 16, height }));
+ const preset = requestedHeight ?? Math.max(512, Math.min(2048, Math.round(outputDimensions(resolution, "1:1").height / 512) * 512));
+ const height = Math.floor(preset * imageResolutionScale(modelType) / 32) * 32;
+ const dimensions = characterSheetViewDimensions(height);
+ const error = dimensions.map((size) => imageGenerationSizeError(size, modelType)).find(Boolean);
+ if (error) throw new Error(error);
+ return dimensions;
}
export function compileCharacterSheet(config: ProjectConfig, source: ProjectAsset, frontRelativePath: string, options: CharacterSheetOptions = emptyCharacterSheetOptions(), modelType?: string) {
diff --git a/src/lib/imageScene.ts b/src/lib/imageScene.ts
index 2be19e1..0f3175a 100644
--- a/src/lib/imageScene.ts
+++ b/src/lib/imageScene.ts
@@ -21,7 +21,7 @@ export const imageNodeSchema = z.object({
});
export const imageSourceSchema = z.object({
relativePath: z.string().min(1).refine((path) => !path.startsWith("/") && !path.includes("\\") && !path.includes(":") && !path.split("/").includes(".."), "Image source must be a project-relative path."),
- name: z.string().min(1), width: z.number().int().min(1).max(8192), height: z.number().int().min(1).max(8192),
+ name: z.string().min(1), width: z.number().int().min(1).max(16384), height: z.number().int().min(1).max(16384),
});
export type ImageSource = z.infer<typeof imageSourceSchema>;
export const imageSceneSchema = z.object({
diff --git a/src/lib/project.ts b/src/lib/project.ts
index 441519d..ff65217 100644
--- a/src/lib/project.ts
+++ b/src/lib/project.ts
@@ -153,7 +153,7 @@ const imageTemplateSnapshotSchema = z.discriminatedUnion("kind", [
z.object({ ...imageTemplateFields, kind: z.literal("extend"), bounds: z.object({
x: z.number().finite(), y: z.number().finite(), width: z.number().positive().finite(), height: z.number().positive().finite(),
}) }),
- z.object({ ...imageTemplateFields, kind: z.literal("character-sheet"), height: z.number().int().refine((height) => [512, 1024, 1536, 2048].includes(height), "Unsupported character sheet height."),
+ z.object({ ...imageTemplateFields, kind: z.literal("character-sheet"), height: z.number().int().min(512).max(3424).multipleOf(32),
views: z.object({ closeUp: z.boolean(), front: z.boolean(), side: z.boolean(), back: z.boolean() })
.refine((views) => Object.values(views).some(Boolean), "Enable at least one character sheet view.").optional() }),
]);
diff --git a/src/lib/workQueue.ts b/src/lib/workQueue.ts
index 5fd9a3c..9237086 100644
--- a/src/lib/workQueue.ts
+++ b/src/lib/workQueue.ts
@@ -517,7 +517,7 @@ export class WorkQueue {
config.imageScene = { ...(config.imageScene ?? createImageScene()),
steps: generationStepsWithLoras(options?.steps ?? current.imageScene?.steps ?? template.defaultSteps, config),
seed: options?.seed ?? current.imageScene?.seed ?? -1 };
- const dimensions = characterSheetDimensions(imageSettings(config).resolution, options?.height);
+ const dimensions = characterSheetDimensions(imageSettings(config).resolution, options?.height, template.modelType);
const indices = characterSheetViewIndices(options);
const order = CHARACTER_SHEET_ORDER.filter((index) => indices.includes(index));
const firstView = order[0];