Restore Continuum image reference inputs

This commit is contained in:
2026-10-30 11:06:44 +00:00
parent d1e97eecc7
commit e6116df914
5 changed files with 43 additions and 226 deletions
+9 -93
View File
@@ -12,15 +12,6 @@ import sys
REFERENCE_IMAGES_V39_TYPE = "H3_CONTINUUM_REFERENCE_IMAGES_V39"
class DumasH3RefModBundle(list):
"""H3_REF_MODS list with optional per-chunk routing metadata."""
def __init__(self, values=(), *, chunk_refs=None):
super().__init__(values)
self.chunk_refs = tuple(tuple(int(index) for index in refs)
for refs in (chunk_refs or ()))
def _continuum_reference_bundle_type():
"""Find the upstream H3 bundle class without copying its implementation."""
candidates = [
@@ -42,34 +33,6 @@ def _continuum_reference_bundle_type():
)
def _visual_refmods(mods):
"""Return positive-weight visual RefMods in stable picker order."""
result = []
seen = set()
for mod, strength in (mods or []):
if getattr(mod, "kind", None) == "audio" or float(strength) <= 0:
continue
key = str(getattr(mod, "path", "") or "") or (getattr(mod, "name", "refmod"), id(mod))
if key in seen:
continue
seen.add(key)
result.append((mod, float(strength)))
return result
def _refmod_directive(refmods, start_slot, slots=None):
"""Build conservative default definitions for RefMods in the prompt."""
lines = []
for offset, (mod, _strength) in enumerate(refmods):
slot = slots[offset] if slots is not None else start_slot + offset
name = str(getattr(mod, "name", "visual reference") or "visual reference").strip()
lines.append(
f"@R{slot} is the {name} visual reference; preserve its identity, "
"appearance, and important physical details when it is used."
)
return "\n".join(lines)
MAX_CLIPS = 16
DEFAULT_CLIP_SECONDS = 4.0
@@ -200,8 +163,8 @@ class DumasH3SequencePromptBuilder:
"the node emits one absolute Timeline prompt for Sequence Prompt."
)
CATEGORY = "Dumas/MiniMax H3/Prompt"
RETURN_TYPES = ("STRING", "INT", "FLOAT", REFERENCE_IMAGES_V39_TYPE, "H3_REF_MODS", "INT")
RETURN_NAMES = ("sequence_prompt", "chunk_count", "chunk_duration", "reference_images", "ref_mods", "refmod_offset")
RETURN_TYPES = ("STRING", "INT", "FLOAT", REFERENCE_IMAGES_V39_TYPE)
RETURN_NAMES = ("sequence_prompt", "chunk_count", "chunk_duration", "reference_images")
FUNCTION = "build"
@classmethod
@@ -218,9 +181,9 @@ class DumasH3SequencePromptBuilder:
},
"optional": {
**{
f"ref_mod_{index}": ("H3_REF_MODS", {
"display_name": f"RefMod {index} (@R{index})",
"tooltip": f"RefMod socket {index}; use @R{index} in a clip prompt.",
f"reference_image_{index}": ("IMAGE", {
"display_name": f"Reference Image {index} (@R{index})",
"tooltip": f"Fixed Reference Image {index}; use @R{index} in a clip prompt.",
}) for index in range(1, 10)
},
},
@@ -249,73 +212,28 @@ class DumasH3SequencePromptBuilder:
"clips": [clip for clip in sequence["clips"] if clip.get("enabled", True)],
}
selectors = []
routing_directive = str(shared_directive or "").strip()
directive = routing_directive
directive = str(shared_directive or "").strip()
sound = str(soundscape or "").strip() or "N/A"
music_text = str(music or "").strip() or "N/A"
# Each socket is one deterministic @R slot. This avoids trying to
# inspect the contents of a chained bundle in the browser and makes
# the socket order match the prompt chips exactly.
refmods = []
for index in range(1, 10):
refmods.extend(_visual_refmods(kwargs.get(f"ref_mod_{index}")))
if len(refmods) > 9:
raise ValueError("The prompt builder supports at most nine RefMod slots.")
authored_text_by_chunk = []
for clip in active_sequence["clips"]:
authored_text_by_chunk.append("\n".join([
routing_directive,
*(str(slot.get("text", "")) for slot in clip["slots"]),
f"overall_soundscape: {sound}",
f"non_diegetic_music: {music_text}",
]))
# RefMod slots are defined by socket order, but only referenced slots
# should be passed to the sampler. Keep the original @R number in the
# generated definition so a sparse use such as @R2 remains accurate.
referenced_slots = {
index for index in range(1, len(refmods) + 1)
if any(re.search(rf"@R{index}(?![A-Za-z0-9_])", text, re.IGNORECASE)
for text in authored_text_by_chunk)
}
selected_refmods = [
refmod for index, refmod in enumerate(refmods, start=1)
if index in referenced_slots
]
selected_slots = [index for index in range(1, len(refmods) + 1) if index in referenced_slots]
selected_position = {slot: position for position, slot in enumerate(selected_slots)}
chunk_refs = []
for text in authored_text_by_chunk:
chunk_refs.append(tuple(
selected_position[index]
for index in selected_slots
if re.search(rf"@R{index}(?![A-Za-z0-9_])", text, re.IGNORECASE)
))
generated = _refmod_directive(selected_refmods, 1, selected_slots)
if generated:
directive = "\n\n".join(part for part in (directive, generated) if part)
for reference_index in range(1, 10):
chunks = []
for chunk_index, clip in enumerate(active_sequence["clips"], start=1):
# Match against the same per-chunk content emitted by
# format_sequence_prompt, not only the editable shot lines.
text = "\n".join([
routing_directive,
directive,
*(str(slot.get("text", "")) for slot in clip["slots"]),
f"overall_soundscape: {sound}",
f"non_diegetic_music: {music_text}",
])
available = reference_index <= len(refmods)
if available and re.search(
if kwargs.get(f"reference_image_{reference_index}") is not None and re.search(
rf"@(R{reference_index}|image{reference_index})(?![A-Za-z0-9_])",
text,
re.IGNORECASE,
):
chunks.append(chunk_index)
selectors.append(",".join(map(str, chunks)) or "off")
# Keep the typed reference-images output for compatibility with the
# Continuum bridge, but it is intentionally empty: this builder now
# owns RefMod sockets rather than image sockets.
images = (None,) * 9
images = tuple(kwargs.get(f"reference_image_{index}") for index in range(1, 10))
reference_bundle = _continuum_reference_bundle_type()(
images=images,
reference_use="Per chunk",
@@ -331,8 +249,6 @@ class DumasH3SequencePromptBuilder:
len(active_sequence["clips"]),
float(default_chunk_seconds),
reference_bundle,
DumasH3RefModBundle(selected_refmods, chunk_refs=chunk_refs),
0,
)