mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 06:42:14 +00:00
desktop app: unblock object generations, styling cleanup, model selector (#1478)
This commit is contained in:
1 parent
a484b1d1a9
commit
9b6b0175ea
9 files changed
+189
-100
No files matched your search
@@ -32,6 +32,7 @@ import type { MediaItem } from "../../pages/PageEnigma/models";
|
||||
import { SPLAT_MODELS } from "@storyteller/model-list";
|
||||
import {
|
||||
ClassyModelSelector,
|
||||
IMAGE_TO_3D_OBJECT_PAGE_MODEL_LIST,
|
||||
IMAGE_TO_3D_WORLD_PAGE_MODEL_LIST,
|
||||
ModelPage,
|
||||
useSelectedModel,
|
||||
@@ -78,12 +79,9 @@ const generateId = () =>
|
||||
? crypto.randomUUID()
|
||||
: Math.random().toString(36).slice(2, 10);
|
||||
|
||||
const MODEL_OPTIONS = [
|
||||
{ id: EnqueueImageTo3dObjectModel.Hunyuan3d3, label: "Hunyuan 3.0" },
|
||||
{ id: EnqueueImageTo3dObjectModel.Hunyuan3d2_0, label: "Hunyuan 2.0" },
|
||||
];
|
||||
|
||||
const WORLD_MODEL_PAGE = ModelPage.ImageTo3DWorld;
|
||||
const OBJECT_MODEL_PAGE = ModelPage.ImageTo3DObject;
|
||||
const DEFAULT_OBJECT_MODEL_ID = EnqueueImageTo3dObjectModel.Hunyuan3d3;
|
||||
|
||||
export const ImageTo3DExperience = ({
|
||||
title,
|
||||
@@ -92,18 +90,21 @@ export const ImageTo3DExperience = ({
|
||||
backgroundImage,
|
||||
}: ImageTo3DExperienceProps) => {
|
||||
const [activeMode, setActiveMode] = useState<Mode>("image");
|
||||
const [selectedModel, setSelectedModel] =
|
||||
useState<EnqueueImageTo3dObjectModel>(
|
||||
EnqueueImageTo3dObjectModel.Hunyuan3d3,
|
||||
);
|
||||
const selectedWorldModel = useSelectedModel(WORLD_MODEL_PAGE);
|
||||
const selectedWorldProvider = useSelectedProviderForModel(
|
||||
WORLD_MODEL_PAGE,
|
||||
selectedWorldModel?.id,
|
||||
);
|
||||
const selectedObjectModel = useSelectedModel(OBJECT_MODEL_PAGE);
|
||||
const selectedObjectModelId =
|
||||
(selectedObjectModel?.id as EnqueueImageTo3dObjectModel | undefined) ??
|
||||
DEFAULT_OBJECT_MODEL_ID;
|
||||
const worldCredits = useCostBreakdownModalStore(
|
||||
(s) => s.estimatedCreditsByPage[WORLD_MODEL_PAGE],
|
||||
);
|
||||
const objectCredits = useCostBreakdownModalStore(
|
||||
(s) => s.estimatedCreditsByPage[OBJECT_MODEL_PAGE],
|
||||
);
|
||||
const [uploadedPreview, setUploadedPreview] = useState<string | null>(null);
|
||||
const [uploadedName, setUploadedName] = useState<string | null>(null);
|
||||
const [prompt, setPrompt] = useState("");
|
||||
@@ -140,9 +141,7 @@ export const ImageTo3DExperience = ({
|
||||
const clearPendingExternalImage = useImageTo3DWorldStore(
|
||||
(s) => s.clearPendingExternalImage,
|
||||
);
|
||||
const pendingObjectImage = useImageTo3DStore(
|
||||
(s) => s.pendingExternalImage,
|
||||
);
|
||||
const pendingObjectImage = useImageTo3DStore((s) => s.pendingExternalImage);
|
||||
const clearPendingObjectImage = useImageTo3DStore(
|
||||
(s) => s.clearPendingExternalImage,
|
||||
);
|
||||
@@ -186,7 +185,13 @@ export const ImageTo3DExperience = ({
|
||||
clearPendingObjectImage();
|
||||
}
|
||||
}
|
||||
}, [variant, pendingExternalImage, clearPendingExternalImage, pendingObjectImage, clearPendingObjectImage]);
|
||||
}, [
|
||||
variant,
|
||||
pendingExternalImage,
|
||||
clearPendingExternalImage,
|
||||
pendingObjectImage,
|
||||
clearPendingObjectImage,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
const onResize = () => setVh(window.innerHeight);
|
||||
@@ -451,14 +456,13 @@ export const ImageTo3DExperience = ({
|
||||
window.__storeTaskEnqueueMeta?.({
|
||||
prompt: snapshotPrompt || undefined,
|
||||
refImageUrls: snapshotPreview ? [snapshotPreview] : undefined,
|
||||
modelType:
|
||||
(selectedModel as any)?.tauriId || String(selectedModel),
|
||||
modelType: selectedObjectModel?.tauriId || selectedObjectModelId,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
|
||||
const result = await EnqueueImageTo3dObject({
|
||||
image_media_token: uploadedMediaToken || undefined,
|
||||
model: selectedModel,
|
||||
model: selectedObjectModelId,
|
||||
frontend_caller: "mini_app",
|
||||
frontend_subscriber_id: subscriberId,
|
||||
});
|
||||
@@ -469,10 +473,6 @@ export const ImageTo3DExperience = ({
|
||||
|
||||
if (activeMode === "text") {
|
||||
setPrompt("");
|
||||
} else {
|
||||
setUploadedPreview(null);
|
||||
setUploadedName(null);
|
||||
setUploadedMediaToken(null);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -922,10 +922,6 @@ export const ImageTo3DExperience = ({
|
||||
const activeResult =
|
||||
results.find((r) => r.id === selectedResultId) || results[0];
|
||||
|
||||
useEffect(() => {
|
||||
console.log("[ImageTo3D] Active result changed:", activeResult);
|
||||
}, [activeResult]);
|
||||
|
||||
return (
|
||||
<div className="bg-ui-panel-gradient flex h-[calc(100vh-56px)] w-full bg-ui-panel text-base-fg">
|
||||
{backgroundImage && !hasResults && (
|
||||
@@ -959,13 +955,14 @@ export const ImageTo3DExperience = ({
|
||||
<div
|
||||
className={twMerge(
|
||||
"mx-auto grid h-full w-full grid-cols-[1fr_300px] gap-4 overflow-hidden pb-10",
|
||||
variant === "world" ? "max-w-[1600px]" : "max-w-7xl",
|
||||
variant === "world" ? "max-w-[1600px]" : "max-w-[1600px]",
|
||||
)}
|
||||
style={{ height: `calc(100vh - ${bottomOffsetPx + 80}px)` }}
|
||||
>
|
||||
{/* Left: Viewer */}
|
||||
<div className="glass relative h-full overflow-hidden rounded-xl border border-ui-panel-border">
|
||||
<Viewer3D
|
||||
key={activeResult?.id}
|
||||
modelUrl={activeResult?.modelUrl}
|
||||
previewUrl={activeResult?.previewUrl}
|
||||
isActive={true}
|
||||
@@ -1018,7 +1015,7 @@ export const ImageTo3DExperience = ({
|
||||
|
||||
{/* Right: History List */}
|
||||
<div className="glass flex h-full flex-col overflow-hidden rounded-xl border border-ui-panel-border">
|
||||
<div className="flex items-center justify-between border-b border-ui-panel-border p-4">
|
||||
<div className="flex items-center justify-between p-4">
|
||||
<h3 className="font-semibold text-base-fg/80">History</h3>
|
||||
{results.length > 0 && (
|
||||
<button
|
||||
@@ -1031,47 +1028,63 @@ export const ImageTo3DExperience = ({
|
||||
</div>
|
||||
<div className="flex-1 overflow-y-auto p-3">
|
||||
<div className="space-y-3">
|
||||
{results.map((result) => (
|
||||
<button
|
||||
key={result.id}
|
||||
onClick={() => setSelectedResultId(result.id)}
|
||||
className={twMerge(
|
||||
"flex w-full gap-3 rounded-xl border p-2 text-left transition-all hover:bg-ui-controls/40",
|
||||
selectedResultId === result.id
|
||||
? "border-primary/50 bg-primary/10"
|
||||
: "border-transparent bg-ui-controls/20",
|
||||
)}
|
||||
>
|
||||
<div className="aspect-square h-16 w-16 shrink-0 overflow-hidden rounded-lg bg-black/20">
|
||||
{result.previewUrl ? (
|
||||
<img
|
||||
src={result.previewUrl}
|
||||
alt="thumb"
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-full w-full items-center justify-center text-base-fg/20">
|
||||
<FontAwesomeIcon icon={faCube} />
|
||||
</div>
|
||||
{results.map((result) => {
|
||||
const isPending = result.status === "pending";
|
||||
const isSelected = selectedResultId === result.id;
|
||||
return (
|
||||
<button
|
||||
key={result.id}
|
||||
onClick={() => setSelectedResultId(result.id)}
|
||||
className={twMerge(
|
||||
"group flex w-full items-center gap-3 rounded-xl border p-2 text-left transition-all hover:bg-ui-controls/40",
|
||||
isSelected
|
||||
? "border-primary/50 bg-primary/10"
|
||||
: "border-transparent bg-ui-controls/20",
|
||||
)}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1 py-1">
|
||||
<div className="truncate text-sm font-medium">
|
||||
{result.note || "Generated Model"}
|
||||
</div>
|
||||
<div className="mt-1 flex items-center gap-2 text-xs opacity-50">
|
||||
{result.status === "pending" ? (
|
||||
<span className="flex items-center gap-1.5 text-amber-400">
|
||||
<span className="block h-1.5 w-1.5 animate-pulse rounded-full bg-amber-400" />
|
||||
Generating...
|
||||
</span>
|
||||
>
|
||||
<div className="relative aspect-square h-14 w-14 shrink-0 overflow-hidden rounded-lg bg-black/30 ring-1 ring-white/5">
|
||||
{result.previewUrl ? (
|
||||
<img
|
||||
src={result.previewUrl}
|
||||
alt="thumb"
|
||||
className={twMerge(
|
||||
"h-full w-full object-cover transition-opacity",
|
||||
isPending && "opacity-40",
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
<span>{formatTime(result.timestamp)}</span>
|
||||
<div className="flex h-full w-full items-center justify-center text-base-fg/25">
|
||||
<FontAwesomeIcon
|
||||
icon={faCube}
|
||||
className="text-lg"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{isPending && (
|
||||
<div className="absolute inset-0 flex items-center justify-center bg-black/30">
|
||||
<div className="h-5 w-5 animate-spin rounded-full border-2 border-white/20 border-t-primary" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
<div className="min-w-0 flex-1 py-0.5">
|
||||
<div className="truncate text-sm font-medium text-base-fg/90">
|
||||
{result.note || "Generated Model"}
|
||||
</div>
|
||||
<div className="mt-1 flex items-center gap-1.5 text-xs">
|
||||
{isPending ? (
|
||||
<span className="text-base-fg/55">
|
||||
Generating…
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-base-fg/45">
|
||||
{formatTime(result.timestamp)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1107,27 +1120,13 @@ export const ImageTo3DExperience = ({
|
||||
hasResults ? "mt-3" : "mt-3",
|
||||
)}
|
||||
>
|
||||
{variant === "object" && (
|
||||
<div className="flex justify-center">
|
||||
<TabSelector
|
||||
tabs={MODEL_OPTIONS}
|
||||
activeTab={selectedModel}
|
||||
onTabChange={(id) =>
|
||||
setSelectedModel(id as EnqueueImageTo3dObjectModel)
|
||||
}
|
||||
className="w-fit"
|
||||
indicatorClassName="bg-primary/25"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<GenerateButton
|
||||
variant="primary"
|
||||
icon={undefined}
|
||||
disabled={!canGenerate}
|
||||
onClick={handleGenerate}
|
||||
loading={isGenerating}
|
||||
credits={variant === "world" ? worldCredits : undefined}
|
||||
credits={variant === "world" ? worldCredits : objectCredits}
|
||||
>
|
||||
{`Generate ${variant === "object" ? "Object" : "World"}`}
|
||||
</GenerateButton>
|
||||
@@ -1148,25 +1147,30 @@ export const ImageTo3DExperience = ({
|
||||
</div>
|
||||
</animated.div>
|
||||
|
||||
{variant === "world" && (
|
||||
<>
|
||||
<div className="absolute bottom-6 left-6 z-20 flex items-center gap-5">
|
||||
<ClassyModelSelector
|
||||
items={IMAGE_TO_3D_WORLD_PAGE_MODEL_LIST}
|
||||
page={WORLD_MODEL_PAGE}
|
||||
mode="hoverSelect"
|
||||
panelTitle="Select Model"
|
||||
panelClassName="min-w-[300px]"
|
||||
buttonClassName="bg-transparent p-0 text-lg hover:bg-transparent text-white/80 hover:text-white"
|
||||
showIconsInList
|
||||
/>
|
||||
</div>
|
||||
<div className="absolute bottom-6 right-6 z-20 flex items-center gap-2">
|
||||
<CostCalculatorButton modelPage={WORLD_MODEL_PAGE} />
|
||||
<HelpMenuButton />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div className="absolute bottom-6 left-6 z-20 flex items-center gap-5">
|
||||
<ClassyModelSelector
|
||||
items={
|
||||
variant === "world"
|
||||
? IMAGE_TO_3D_WORLD_PAGE_MODEL_LIST
|
||||
: IMAGE_TO_3D_OBJECT_PAGE_MODEL_LIST
|
||||
}
|
||||
page={variant === "world" ? WORLD_MODEL_PAGE : OBJECT_MODEL_PAGE}
|
||||
mode="hoverSelect"
|
||||
panelTitle="Select Model"
|
||||
panelClassName="min-w-[300px]"
|
||||
buttonClassName="bg-transparent p-0 text-lg hover:bg-transparent text-white/80 hover:text-white"
|
||||
showIconsInList
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="absolute bottom-6 right-6 z-20 flex items-center gap-2">
|
||||
<CostCalculatorButton
|
||||
modelPage={
|
||||
variant === "world" ? WORLD_MODEL_PAGE : OBJECT_MODEL_PAGE
|
||||
}
|
||||
/>
|
||||
<HelpMenuButton />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input
|
||||
|
||||
@@ -5,5 +5,6 @@ export enum ModelPage {
|
||||
Stage3D = "stage-3d",
|
||||
ImageEditor = "image-editor",
|
||||
ImageTo3DWorld = "image-to-3d-world",
|
||||
ImageTo3DObject = "image-to-3d-object",
|
||||
Angles = "angles",
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
IMAGE_MODELS,
|
||||
IMAGE_MODELS_BY_ID,
|
||||
SPLAT_MODELS,
|
||||
OBJECT_3D_MODELS,
|
||||
} from "@storyteller/model-list";
|
||||
import { ModelTag } from "@storyteller/model-list";
|
||||
|
||||
@@ -131,3 +132,9 @@ export const IMAGE_TO_3D_WORLD_PAGE_MODEL_LIST: ModelList =
|
||||
SPLAT_MODELS as Model[],
|
||||
<FontAwesomeIcon icon={faCube} className="h-4 w-4" />
|
||||
);
|
||||
|
||||
export const IMAGE_TO_3D_OBJECT_PAGE_MODEL_LIST: ModelList =
|
||||
buildItems(
|
||||
OBJECT_3D_MODELS as Model[],
|
||||
<FontAwesomeIcon icon={faCube} className="h-4 w-4" />
|
||||
);
|
||||
@@ -18,5 +18,7 @@ export * from "./lib/lists/ImageModels.js";
|
||||
export * from "./lib/lists/VideoModels.js";
|
||||
export * from "./lib/classes/SplatModel.js";
|
||||
export * from "./lib/lists/SplatModels.js";
|
||||
export * from "./lib/classes/Object3DModel.js";
|
||||
export * from "./lib/lists/Object3DModels.js";
|
||||
|
||||
|
||||
@@ -3,7 +3,12 @@ import { ModelCategory, ModelConfig } from "../legacy/ModelConfig.js";
|
||||
import { ModelTag } from "./metadata/ModelTag.js";
|
||||
import { GenerationProvider } from "@storyteller/api-enums";
|
||||
|
||||
export type ModelKind = "model" | "image_model" | "video_model" | "gaussian_model";
|
||||
export type ModelKind =
|
||||
| "model"
|
||||
| "image_model"
|
||||
| "video_model"
|
||||
| "gaussian_model"
|
||||
| "3d_object_model";
|
||||
|
||||
// NB: Do not create instances of this class directly, use subclasses.
|
||||
export class Model {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { ModelCreator } from "src/index.js";
|
||||
import { Model, ModelKind } from "./Model.js";
|
||||
import { ModelCategory } from "../legacy/ModelConfig.js";
|
||||
import { ModelTag } from "./metadata/ModelTag.js";
|
||||
import { GenerationProvider } from "@storyteller/api-enums";
|
||||
|
||||
export class Object3DModel extends Model {
|
||||
override readonly kind: ModelKind = "3d_object_model";
|
||||
|
||||
constructor(args: {
|
||||
id: string;
|
||||
tauriId: string;
|
||||
fullName: string;
|
||||
category: ModelCategory;
|
||||
creator: ModelCreator;
|
||||
selectorName: string;
|
||||
selectorDescription: string;
|
||||
selectorBadges: string[];
|
||||
tags?: ModelTag[];
|
||||
providers?: GenerationProvider[];
|
||||
progressBarTime?: number;
|
||||
maxPromptLength?: number;
|
||||
}) {
|
||||
super(args);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ModelInfo } from "./ModelInfo.js";
|
||||
import { ModelTag } from "../classes/metadata/ModelTag.js";
|
||||
|
||||
export type ModelCategory = "image" | "video" | "gaussian";
|
||||
export type ModelCategory = "image" | "video" | "gaussian" | "3d_object";
|
||||
|
||||
// Centralized model capability definition
|
||||
// For setting options for the model
|
||||
|
||||
@@ -2,5 +2,11 @@ import { IMAGE_MODELS } from "./ImageModels.js";
|
||||
import { VIDEO_MODELS } from "./VideoModels.js";
|
||||
import { Model } from "../classes/Model.js";
|
||||
import { SPLAT_MODELS } from "./SplatModels.js";
|
||||
import { OBJECT_3D_MODELS } from "./Object3DModels.js";
|
||||
|
||||
export const ALL_MODELS_LIST: Model[] = [...IMAGE_MODELS, ...VIDEO_MODELS, ...SPLAT_MODELS];
|
||||
export const ALL_MODELS_LIST: Model[] = [
|
||||
...IMAGE_MODELS,
|
||||
...VIDEO_MODELS,
|
||||
...SPLAT_MODELS,
|
||||
...OBJECT_3D_MODELS,
|
||||
];
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Object3DModel } from "../classes/Object3DModel.js";
|
||||
import { ModelCreator } from "../classes/metadata/ModelCreator.js";
|
||||
import { GenerationProvider } from "@storyteller/api-enums";
|
||||
|
||||
export const OBJECT_3D_MODELS: Object3DModel[] = [
|
||||
new Object3DModel({
|
||||
id: "hunyuan_3d_3",
|
||||
tauriId: "hunyuan_3d_3",
|
||||
fullName: "Hunyuan 3D 3.0",
|
||||
category: "3d_object",
|
||||
creator: ModelCreator.Tencent,
|
||||
selectorName: "Hunyuan 3.0",
|
||||
selectorDescription: "Highest quality 3D mesh generation",
|
||||
selectorBadges: ["~2 min."],
|
||||
providers: [GenerationProvider.Artcraft],
|
||||
progressBarTime: 120000,
|
||||
}),
|
||||
new Object3DModel({
|
||||
id: "hunyuan_3d_2_0",
|
||||
tauriId: "hunyuan_3d_2_0",
|
||||
fullName: "Hunyuan 3D 2.0",
|
||||
category: "3d_object",
|
||||
creator: ModelCreator.Tencent,
|
||||
selectorName: "Hunyuan 2.0",
|
||||
selectorDescription: "Faster, lower fidelity 3D mesh",
|
||||
selectorBadges: ["~45 sec."],
|
||||
providers: [GenerationProvider.Artcraft],
|
||||
progressBarTime: 60000,
|
||||
}),
|
||||
];
|
||||
|
||||
export const OBJECT_3D_MODELS_BY_ID: Map<string, Object3DModel> = new Map(
|
||||
OBJECT_3D_MODELS.map((model) => [model.id, model]),
|
||||
);
|
||||
|
||||
if (OBJECT_3D_MODELS_BY_ID.size !== OBJECT_3D_MODELS.length) {
|
||||
throw new Error("All 3D object models must have unique IDs");
|
||||
}
|
||||
Reference in new issue
Block a user