improve generation placeholder placement

This commit is contained in:
134 2026-06-12 14:49:51 +08:00
parent 03aee55cb6
commit 88afa0551c
3 changed files with 47 additions and 20 deletions

View File

@ -1521,6 +1521,7 @@ export function CanvasChatPanel({
[nodes, selectedNodeIds]
);
const selectedImageNodesRef = useRef<CanvasNode[]>([]);
const generationAnchorNodesRef = useRef<CanvasNode[]>([]);
useEffect(() => {
selectedImageNodesRef.current = selectedImageNodes;
@ -3489,7 +3490,10 @@ export function CanvasChatPanel({
const currentNodes = useCanvasStore.getState().nodes;
const anchorNode = findCanvasImageAnchorNode(currentNodes, {
selectedNodes: selectedImageNodesRef.current,
selectedNodes:
generationAnchorNodesRef.current.length > 0
? generationAnchorNodesRef.current
: selectedImageNodesRef.current,
sourceImageUrls,
});
const size = { width: dimensions.width, height: dimensions.height };
@ -4687,7 +4691,10 @@ export function CanvasChatPanel({
const currentNodes = useCanvasStore.getState().nodes;
const anchorNode = findCanvasImageAnchorNode(currentNodes, {
selectedNodes: selectedImageNodesRef.current,
selectedNodes:
generationAnchorNodesRef.current.length > 0
? generationAnchorNodesRef.current
: selectedImageNodesRef.current,
sourceImageUrls: nearestUserImageUrls,
});
const size = { width: dimensions.width, height: dimensions.height };
@ -4918,7 +4925,10 @@ export function CanvasChatPanel({
isValidChatHttpUrl(String((node.data as any)?.src || "").trim()),
);
if (imageNodes.length === 0) return undefined;
if (imageNodes.length === 0) {
generationAnchorNodesRef.current = [];
return undefined;
}
const effectiveComposerMode = activeComposerModeRef.current || activeComposerMode;
const shouldIsolateDirectModeContext = effectiveComposerMode !== "agent";
@ -4927,11 +4937,13 @@ export function CanvasChatPanel({
);
if (shouldIsolateDirectModeContext && selectedImageNodesForContext.length === 0) {
generationAnchorNodesRef.current = [];
return undefined;
}
const MAX_CONTEXT_IMAGES = 12;
const selectedContextNodes = selectedImageNodesForContext.slice(0, 20);
generationAnchorNodesRef.current = selectedContextNodes.slice(0, 4);
const selectedIds = new Set(selectedContextNodes.map((node) => node.id));
const prioritizedNodes =
shouldIsolateDirectModeContext
@ -8101,6 +8113,13 @@ export function CanvasChatPanel({
? "生成失败"
: "正在创建图片";
const status = phase === "failed" ? "failed" : "generating";
const currentNodes = useCanvasStore.getState().nodes;
const anchorNode = findCanvasImageAnchorNode(currentNodes, {
selectedNodes:
generationAnchorNodesRef.current.length > 0
? generationAnchorNodesRef.current
: selectedImageNodesRef.current,
});
const imageParamSnapshot = imageParamsRef.current || imageParams;
const aspectRatio =
imageParamSnapshot.aspectRatio && imageParamSnapshot.aspectRatio !== "auto"
@ -8110,7 +8129,7 @@ export function CanvasChatPanel({
const ratioWidth = Number.isFinite(ratioWidthRaw) && ratioWidthRaw > 0 ? ratioWidthRaw : 1;
const ratioHeight = Number.isFinite(ratioHeightRaw) && ratioHeightRaw > 0 ? ratioHeightRaw : 1;
const baseSide = 340;
const placeholderSize =
const ratioPlaceholderSize =
ratioWidth >= ratioHeight
? {
width: baseSide,
@ -8120,6 +8139,18 @@ export function CanvasChatPanel({
width: Math.max(190, Math.round((baseSide * ratioWidth) / ratioHeight)),
height: baseSide,
};
const placeholderSize = anchorNode
? {
width: Math.max(180, Math.round(Number(anchorNode.size?.width || ratioPlaceholderSize.width))),
height: Math.max(180, Math.round(Number(anchorNode.size?.height || ratioPlaceholderSize.height))),
}
: ratioPlaceholderSize;
const position = getAnchoredGenerationPosition({
anchorNode,
fallbackNodeCount: currentNodes.length,
size: placeholderSize,
viewport: useCanvasStore.getState().viewport,
});
const metadata = {
canvasGenerationPlaceholder: true,
chatId: activeChatId,
@ -8149,23 +8180,15 @@ export function CanvasChatPanel({
...metadata,
},
},
position,
size: placeholderSize,
});
focusCanvasOnNode({ position, size: placeholderSize });
return;
}
delete canvasGenerationPlaceholderByChatIdRef.current[activeChatId];
}
const currentNodes = useCanvasStore.getState().nodes;
const anchorNode = findCanvasImageAnchorNode(currentNodes, {
selectedNodes: selectedImageNodesRef.current,
});
const position = getAnchoredGenerationPosition({
anchorNode,
fallbackNodeCount: currentNodes.length,
size: placeholderSize,
viewport: useCanvasStore.getState().viewport,
});
const nodeId = addNode({
type: "image",
position,

View File

@ -131,7 +131,7 @@ function ScatterParticleLayer({
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(34, 1, 0.1, 1000);
camera.position.set(0, 0, compact ? 46 : 42);
camera.position.set(0, 0, compact ? 48 : 44);
camera.lookAt(0, 0, 0);
const renderer = new THREE.WebGLRenderer({
@ -184,8 +184,8 @@ function ScatterParticleLayer({
const points = new THREE.Points(geometry, material);
points.rotation.x = -0.06;
const baseX = compact ? -5.2 : -5.8;
const baseY = compact ? 0.15 : -0.05;
const baseX = 0;
const baseY = 0;
points.position.set(baseX, baseY, 0);
scene.add(points);
@ -209,8 +209,8 @@ function ScatterParticleLayer({
points.rotation.y += 0.0048;
points.rotation.z += 0.0015;
points.rotation.x = -0.08 + Math.sin(time * 0.17) * 0.18;
points.position.x = baseX + Math.sin(time * 0.16) * 0.18;
points.position.y = baseY + Math.sin(time * 0.22) * 0.16;
points.position.x = baseX + Math.sin(time * 0.16) * 0.04;
points.position.y = baseY + Math.sin(time * 0.22) * 0.04;
material.uniforms.uTime.value = time;
renderer.render(scene, camera);
frameId = window.requestAnimationFrame(animate);

View File

@ -109,7 +109,11 @@ export const ImageGenerationLoading = memo(
</div>
<GenerationDotPlaceholder
className={count === 1 ? "h-[420px] w-full max-w-[420px]" : "h-[360px] w-full"}
className={
count === 1
? "h-[336px] min-h-[336px] w-full max-w-[336px]"
: "h-[288px] min-h-[288px] w-full"
}
compact={count > 1}
phase={phase}
/>