Commit recent project changes

This commit is contained in:
balaji
2026-06-16 16:19:50 +05:30
parent 5b8b90c2fb
commit 972b38057a
4 changed files with 661 additions and 139 deletions
+109 -2
View File
@@ -40,15 +40,19 @@ import {
Clipboard, Clipboard,
RotateCw, RotateCw,
Save, Save,
FolderOpen FolderOpen,
Sparkles
} from "lucide-react"; } from "lucide-react";
import { motion, AnimatePresence } from "framer-motion"; import { motion, AnimatePresence } from "framer-motion";
import { ErrorBoundary } from "./components/ErrorBoundary"; import { ErrorBoundary } from "./components/ErrorBoundary";
import { ModelViewer } from "./components/ModelViewer"; import { ModelViewer } from "./components/ModelViewer";
import { JuiceBox } from "./components/JuiceBox"; import { JuiceBox } from "./components/JuiceBox";
import { RenderModal, RenderSettings } from "./components/RenderModal"; import { RenderModal, RenderSettings } from "./components/RenderModal";
import { UnifiedMappingMaterial } from './components/UnifiedMappingMaterial';
import { ImageTo3DModal } from "./components/ImageTo3DModal"; import { ImageTo3DModal } from "./components/ImageTo3DModal";
import { UVEditor } from "./components/UVEditor"; import { UVEditor } from "./components/UVEditor";
import { VizAiModal } from "./components/VizAiModal";
import { ApiSettingsModal } from "./components/ApiSettingsModal";
import { EffectComposer, DepthOfField, Bloom, Vignette, BrightnessContrast, HueSaturation } from "@react-three/postprocessing"; import { EffectComposer, DepthOfField, Bloom, Vignette, BrightnessContrast, HueSaturation } from "@react-three/postprocessing";
import { cn } from "./lib/utils"; import { cn } from "./lib/utils";
import * as THREE from "three"; import * as THREE from "three";
@@ -412,6 +416,9 @@ export default function App() {
const [backgroundType, setBackgroundType] = useState<"color" | "hdri" | "image">("color"); const [backgroundType, setBackgroundType] = useState<"color" | "hdri" | "image">("color");
const [showGrid, setShowGrid] = useState(true); const [showGrid, setShowGrid] = useState(true);
const [showRenderModal, setShowRenderModal] = useState(false); const [showRenderModal, setShowRenderModal] = useState(false);
const [showVizAi, setShowVizAi] = useState(false);
const [showApiSettings, setShowApiSettings] = useState(false);
const [vizAiBaseImage, setVizAiBaseImage] = useState<string | null>(null);
const [renderRequest, setRenderRequest] = useState<RenderSettings | null>(null); const [renderRequest, setRenderRequest] = useState<RenderSettings | null>(null);
const [exportRequest, setExportRequest] = useState(false); const [exportRequest, setExportRequest] = useState(false);
const [exportFormat, setExportFormat] = useState<'glb' | 'usdz'>('glb'); const [exportFormat, setExportFormat] = useState<'glb' | 'usdz'>('glb');
@@ -1716,7 +1723,28 @@ export default function App() {
<span className="hover:text-white cursor-pointer">Camera</span> <span className="hover:text-white cursor-pointer">Camera</span>
<span className="hover:text-white cursor-pointer">Image</span> <span className="hover:text-white cursor-pointer">Image</span>
<span className="hover:text-white cursor-pointer">Render</span> <span className="hover:text-white cursor-pointer">Render</span>
<span className="hover:text-white cursor-pointer">Tools</span> <div className="relative">
<span
className="hover:text-primary cursor-pointer px-1 py-0.5 rounded hover:bg-white/40 dark:hover:bg-white/5 transition-colors"
onClick={() => setOpenMenu(openMenu === 'tools' ? null : 'tools')}
>
Tools
</span>
{openMenu === 'tools' && (
<div className="absolute top-full left-0 mt-1 w-48 bg-zinc-900 border border-zinc-800 rounded-lg shadow-xl py-1 z-50">
<button
className="w-full flex items-center gap-2 px-4 py-2 text-xs text-zinc-300 hover:bg-zinc-800 hover:text-white"
onClick={() => {
setShowApiSettings(true);
setOpenMenu(null);
}}
>
<Settings size={14} />
<span>API Settings</span>
</button>
</div>
)}
</div>
<div className="relative"> <div className="relative">
<span <span
className="hover:text-primary cursor-pointer px-1 py-0.5 rounded hover:bg-white/40 dark:hover:bg-white/5 transition-colors" className="hover:text-primary cursor-pointer px-1 py-0.5 rounded hover:bg-white/40 dark:hover:bg-white/5 transition-colors"
@@ -2372,6 +2400,17 @@ export default function App() {
onRender={(settings) => setRenderRequest(settings)} onRender={(settings) => setRenderRequest(settings)}
/> />
<VizAiModal
isOpen={showVizAi}
onClose={() => setShowVizAi(false)}
baseImage={vizAiBaseImage}
/>
<ApiSettingsModal
isOpen={showApiSettings}
onClose={() => setShowApiSettings(false)}
/>
{/* Export / Save Dialog */} {/* Export / Save Dialog */}
{exportDialog && ( {exportDialog && (
<div className="fixed inset-0 z-[200] flex items-center justify-center bg-black/60 backdrop-blur-sm" <div className="fixed inset-0 z-[200] flex items-center justify-center bg-black/60 backdrop-blur-sm"
@@ -4560,6 +4599,19 @@ export default function App() {
<ImageIcon size={18} /> <ImageIcon size={18} />
<span className="text-[9px]">Render</span> <span className="text-[9px]">Render</span>
</button> </button>
<button
onClick={() => {
const canvas = document.querySelector('canvas');
if (canvas) {
setVizAiBaseImage(canvas.toDataURL("image/png"));
setShowVizAi(true);
}
}}
className="flex flex-col items-center gap-0.5 text-blue-500 hover:text-blue-400 transition-colors"
>
<Sparkles size={18} />
<span className="text-[9px]">Viz AI</span>
</button>
</div> </div>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<div className="text-[10px] text-zinc-500 mr-4"> <div className="text-[10px] text-zinc-500 mr-4">
@@ -4749,6 +4801,61 @@ export default function App() {
} }
}); });
// Save model data for scene persistence
const modelBlob = await fetch(modelUrl).then(r => r.blob());
const modelBase64 = await new Promise<string>((resolve) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result as string);
reader.readAsDataURL(modelBlob);
});
setModelData({ name: "Generated_Model.glb", data: modelBase64, extension: 'glb' });
const boundingBox = new THREE.Box3().setFromObject(object);
const center = new THREE.Vector3();
boundingBox.getCenter(center);
const size = new THREE.Vector3();
boundingBox.getSize(size);
const maxDim = Math.max(size.x || 0, size.y || 0, size.z || 0) || 1;
const radius = maxDim / 2;
const minY = boundingBox.min.y;
setModelBounds({ center, size, maxDim, minY, radius });
if (directionalLightRef.current) {
const light = directionalLightRef.current;
light.shadow.camera.left = -maxDim;
light.shadow.camera.right = maxDim;
light.shadow.camera.top = maxDim;
light.shadow.camera.bottom = -maxDim;
light.shadow.camera.near = 0.1;
light.shadow.camera.far = maxDim * 5;
light.shadow.camera.updateProjectionMatrix();
light.shadow.mapSize.width = 2048;
light.shadow.mapSize.height = 2048;
}
let cameraZDistance = 0;
if (cameraRef.current) {
const camera = cameraRef.current;
const fovRadians = camera.fov * (Math.PI / 180);
cameraZDistance = radius / Math.sin(fovRadians / 2);
cameraZDistance *= 1.5;
camera.position.set(center.x, center.y + (maxDim / 4), center.z + cameraZDistance);
camera.near = radius / 100;
camera.far = radius * 100;
camera.updateProjectionMatrix();
camera.lookAt(center);
}
if (orbitControlsRef.current) {
const controls = orbitControlsRef.current;
if (center) controls.target.copy(center);
controls.minDistance = radius / 2;
controls.maxDistance = (cameraZDistance || radius * 10) * 5;
controls.update();
}
setLoadedModel(object); setLoadedModel(object);
setBlobURLs(prev => [...prev, modelUrl]); setBlobURLs(prev => [...prev, modelUrl]);
setSceneObjects(prev => [ setSceneObjects(prev => [
+173
View File
@@ -0,0 +1,173 @@
import React, { useState, useEffect } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { X, Settings, Key, Sparkles, Image as ImageIcon, Lightbulb, Box } from 'lucide-react';
import { cn } from '../lib/utils';
interface ApiSettingsModalProps {
isOpen: boolean;
onClose: () => void;
}
export const ApiSettingsModal: React.FC<ApiSettingsModalProps> = ({ isOpen, onClose }) => {
const [falApiKey, setFalApiKey] = useState('');
const [tripoApiKey, setTripoApiKey] = useState('');
const [meshyApiKey, setMeshyApiKey] = useState('');
const [stabilityApiKey, setStabilityApiKey] = useState('');
const [openAiKey, setOpenAiKey] = useState('');
useEffect(() => {
if (isOpen) {
setFalApiKey(localStorage.getItem('FAL_API_KEY') || '');
setTripoApiKey(localStorage.getItem('TRIPO_API_KEY') || '');
setMeshyApiKey(localStorage.getItem('MESHY_API_KEY') || '');
setStabilityApiKey(localStorage.getItem('stability_api_key') || '');
setOpenAiKey(localStorage.getItem('openai_api_key') || '');
}
}, [isOpen]);
const saveKeys = () => {
localStorage.setItem('FAL_API_KEY', falApiKey);
localStorage.setItem('TRIPO_API_KEY', tripoApiKey);
localStorage.setItem('MESHY_API_KEY', meshyApiKey);
localStorage.setItem('stability_api_key', stabilityApiKey);
localStorage.setItem('openai_api_key', openAiKey);
onClose();
};
if (!isOpen) return null;
return (
<AnimatePresence>
<div className="fixed inset-0 z-[150] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm">
<motion.div
initial={{ opacity: 0, scale: 0.95, y: 20 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
exit={{ opacity: 0, scale: 0.95, y: 20 }}
className="w-full max-w-2xl bg-zinc-900 border border-zinc-800 rounded-xl shadow-2xl overflow-hidden flex flex-col h-[80vh]"
>
{/* Header */}
<div className="h-14 bg-zinc-950 flex items-center justify-between px-6 border-b border-zinc-800 shrink-0">
<div className="flex items-center gap-3">
<div className="w-8 h-8 rounded-lg bg-gradient-to-tr from-zinc-700 to-zinc-600 flex items-center justify-center">
<Settings size={16} className="text-white" />
</div>
<div>
<h2 className="text-sm font-bold text-zinc-100">Global API Settings</h2>
<p className="text-[10px] text-zinc-400">Configure your API keys for AI generation features</p>
</div>
</div>
<button onClick={onClose} className="p-2 hover:bg-zinc-800 rounded-lg transition-colors">
<X size={18} className="text-zinc-400" />
</button>
</div>
{/* Content */}
<div className="flex-1 overflow-y-auto p-6 bg-zinc-900/50 flex flex-col gap-6 custom-scrollbar">
{/* 3D Generation */}
<div className="flex flex-col gap-4">
<h3 className="text-xs font-bold text-zinc-500 uppercase tracking-widest flex items-center gap-2">
<Box size={14} /> Image-to-3D Providers
</h3>
<div className="grid grid-cols-1 gap-4 pl-2 border-l-2 border-zinc-800">
<div className="flex flex-col gap-2">
<div className="flex items-center justify-between">
<label className="text-sm font-bold text-zinc-300">Fal.ai Key</label>
<span className="text-[10px] text-zinc-500">For Hunyuan3D</span>
</div>
<input
type="password"
placeholder="Enter Fal.ai API Key..."
value={falApiKey}
onChange={(e) => setFalApiKey(e.target.value)}
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-zinc-500"
/>
</div>
<div className="flex flex-col gap-2">
<div className="flex items-center justify-between">
<label className="text-sm font-bold text-zinc-300">Tripo3D Key</label>
<span className="text-[10px] text-zinc-500">For Native Tripo3D</span>
</div>
<input
type="password"
placeholder="Enter Tripo3D API Key..."
value={tripoApiKey}
onChange={(e) => setTripoApiKey(e.target.value)}
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-zinc-500"
/>
</div>
<div className="flex flex-col gap-2">
<div className="flex items-center justify-between">
<label className="text-sm font-bold text-zinc-300">Meshy.ai Key</label>
<span className="text-[10px] text-zinc-500">For Native Meshy</span>
</div>
<input
type="password"
placeholder="Enter Meshy API Key..."
value={meshyApiKey}
onChange={(e) => setMeshyApiKey(e.target.value)}
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-zinc-500"
/>
</div>
</div>
</div>
<div className="h-px bg-zinc-800/50 w-full" />
{/* Viz AI (Image-to-Image & LLM) */}
<div className="flex flex-col gap-4">
<h3 className="text-xs font-bold text-zinc-500 uppercase tracking-widest flex items-center gap-2">
<Sparkles size={14} /> Viz AI & Mockup Generation
</h3>
<div className="grid grid-cols-1 gap-4 pl-2 border-l-2 border-zinc-800">
<div className="flex flex-col gap-2">
<div className="flex items-center justify-between">
<label className="text-sm font-bold text-blue-400">Stability AI Key</label>
<span className="text-[10px] text-zinc-500">For Scene rendering (Image-to-Image)</span>
</div>
<input
type="password"
placeholder="sk-..."
value={stabilityApiKey}
onChange={(e) => setStabilityApiKey(e.target.value)}
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-blue-500/50"
/>
</div>
<div className="flex flex-col gap-2">
<div className="flex items-center justify-between">
<label className="text-sm font-bold text-green-400">OpenAI Key</label>
<span className="text-[10px] text-zinc-500">For AI Idea Prompt Generation</span>
</div>
<input
type="password"
placeholder="sk-..."
value={openAiKey}
onChange={(e) => setOpenAiKey(e.target.value)}
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-green-500/50"
/>
</div>
</div>
</div>
</div>
<div className="p-6 bg-zinc-950 border-t border-zinc-800 shrink-0">
<button
onClick={saveKeys}
className="w-full py-3 bg-white hover:bg-zinc-200 text-black font-bold rounded-xl transition-colors flex items-center justify-center gap-2"
>
<Key size={16} />
Save Keys
</button>
</div>
</motion.div>
</div>
</AnimatePresence>
);
};
+45 -137
View File
@@ -44,7 +44,6 @@ const ModelPreview = ({ url }: { url: string }) => {
}; };
export const ImageTo3DModal: React.FC<ImageTo3DModalProps> = ({ isOpen, onClose, onPushToApp }) => { export const ImageTo3DModal: React.FC<ImageTo3DModalProps> = ({ isOpen, onClose, onPushToApp }) => {
const [activeTab, setActiveTab] = useState<'generator' | 'settings'>('generator');
const [apiProvider, setApiProvider] = useState<'fal' | 'tripo' | 'meshy'>('fal'); const [apiProvider, setApiProvider] = useState<'fal' | 'tripo' | 'meshy'>('fal');
const [apiKey, setApiKey] = useState(''); const [apiKey, setApiKey] = useState('');
const [tripoApiKey, setTripoApiKey] = useState(''); const [tripoApiKey, setTripoApiKey] = useState('');
@@ -59,8 +58,9 @@ export const ImageTo3DModal: React.FC<ImageTo3DModalProps> = ({ isOpen, onClose,
const [meshyShouldTexture, setMeshyShouldTexture] = useState(true); const [meshyShouldTexture, setMeshyShouldTexture] = useState(true);
const [meshyEnablePbr, setMeshyEnablePbr] = useState(false); const [meshyEnablePbr, setMeshyEnablePbr] = useState(false);
const [meshyHdTexture, setMeshyHdTexture] = useState(false); const [meshyHdTexture, setMeshyHdTexture] = useState(false);
const [meshyTexturePrompt, setMeshyTexturePrompt] = useState(''); const [meshyTexturePrompt, setMeshyTexturePrompt] = useState('clear text');
const [meshyTextureImageUrl, setMeshyTextureImageUrl] = useState(''); const [meshyTextureImageUrl, setMeshyTextureImageUrl] = useState('');
const [meshyEnhanceImage, setMeshyEnhanceImage] = useState(true);
const [meshyShouldRemesh, setMeshyShouldRemesh] = useState(false); const [meshyShouldRemesh, setMeshyShouldRemesh] = useState(false);
const [meshyTopology, setMeshyTopology] = useState('triangle'); const [meshyTopology, setMeshyTopology] = useState('triangle');
const [meshyTargetPolycount, setMeshyTargetPolycount] = useState(30000); const [meshyTargetPolycount, setMeshyTargetPolycount] = useState(30000);
@@ -120,16 +120,6 @@ export const ImageTo3DModal: React.FC<ImageTo3DModalProps> = ({ isOpen, onClose,
if (savedModel) setSelectedModel(savedModel); if (savedModel) setSelectedModel(savedModel);
}, []); }, []);
const handleSaveSettings = () => {
localStorage.setItem('API_PROVIDER', apiProvider);
localStorage.setItem('FAL_API_KEY', apiKey);
localStorage.setItem('TRIPO_API_KEY', tripoApiKey);
localStorage.setItem('MESHY_API_KEY', meshyApiKey);
localStorage.setItem('FAL_MODEL', selectedModel);
if (apiProvider === 'fal') fal.config({ credentials: apiKey });
setActiveTab('generator');
};
const handleImageUpload = (e: React.ChangeEvent<HTMLInputElement>) => { const handleImageUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0]; const file = e.target.files?.[0];
if (file) { if (file) {
@@ -157,18 +147,15 @@ export const ImageTo3DModal: React.FC<ImageTo3DModalProps> = ({ isOpen, onClose,
return; return;
} }
if (apiProvider === 'fal' && !apiKey) { if (apiProvider === 'fal' && !apiKey) {
setError("Fal API Key is required. Please check settings."); setError("Fal API Key is required. Please set it in Tools > API Settings.");
setActiveTab('settings');
return; return;
} }
if (apiProvider === 'tripo' && !tripoApiKey) { if (apiProvider === 'tripo' && !tripoApiKey) {
setError("Tripo API Key is required. Please check settings."); setError("Tripo API Key is required. Please set it in Tools > API Settings.");
setActiveTab('settings');
return; return;
} }
if (apiProvider === 'meshy' && !meshyApiKey) { if (apiProvider === 'meshy' && !meshyApiKey) {
setError("Meshy API Key is required. Please check settings."); setError("Meshy API Key is required. Please set it in Tools > API Settings.");
setActiveTab('settings');
return; return;
} }
@@ -293,7 +280,8 @@ export const ImageTo3DModal: React.FC<ImageTo3DModalProps> = ({ isOpen, onClose,
let payload: any = { let payload: any = {
image_url: dataUrl, image_url: dataUrl,
model_type: meshyModelType, model_type: meshyModelType,
should_texture: meshyShouldTexture should_texture: meshyShouldTexture,
should_enhance_image: meshyEnhanceImage
}; };
if (meshyModelType !== 'lowpoly') { if (meshyModelType !== 'lowpoly') {
@@ -387,127 +375,44 @@ export const ImageTo3DModal: React.FC<ImageTo3DModalProps> = ({ isOpen, onClose,
</div> </div>
<div className="flex flex-1 overflow-hidden"> <div className="flex flex-1 overflow-hidden">
{/* Sidebar Tabs */}
<div className="w-48 bg-zinc-950 border-r border-zinc-800 flex flex-col p-2 gap-1">
<button
onClick={() => setActiveTab('generator')}
className={cn(
"flex items-center gap-2 px-4 py-2.5 rounded-lg text-xs font-medium transition-colors",
activeTab === 'generator' ? "bg-zinc-800 text-blue-400" : "text-zinc-500 hover:bg-zinc-800/50 hover:text-zinc-300"
)}
>
<ImageIcon size={16} />
Generator
</button>
<button
onClick={() => setActiveTab('settings')}
className={cn(
"flex items-center gap-2 px-4 py-2.5 rounded-lg text-xs font-medium transition-colors",
activeTab === 'settings' ? "bg-zinc-800 text-blue-400" : "text-zinc-500 hover:bg-zinc-800/50 hover:text-zinc-300"
)}
>
<SettingsIcon size={16} />
API Settings
</button>
</div>
{/* Content Area */} {/* Content Area */}
<div className="flex-1 overflow-y-auto bg-zinc-900/50 p-6"> <div className="flex-1 overflow-y-auto bg-zinc-900/50 p-6">
{activeTab === 'settings' ? (
<div className="flex flex-col gap-6 max-w-lg">
<div>
<h3 className="text-sm font-bold text-zinc-200 mb-1">API Configuration</h3>
<p className="text-xs text-zinc-500">Configure your API credentials to access AI models.</p>
</div>
<div className="flex flex-col gap-2">
<label className="text-[10px] font-bold text-zinc-500 uppercase tracking-widest">API Provider</label>
<select
value={apiProvider}
onChange={(e) => setApiProvider(e.target.value as 'fal' | 'tripo' | 'meshy')}
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2.5 text-sm text-zinc-300 focus:outline-none focus:border-blue-500/50"
>
<option value="fal">Fal.ai</option>
<option value="tripo">Tripo3D (Native)</option>
<option value="meshy">Meshy (Native)</option>
</select>
</div>
{apiProvider === 'fal' ? (
<>
<div className="flex flex-col gap-2">
<label className="text-[10px] font-bold text-zinc-500 uppercase tracking-widest">FAL_KEY (API Key)</label>
<input
type="password"
value={apiKey}
onChange={(e) => setApiKey(e.target.value)}
placeholder="Enter your fal.ai API key"
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2.5 text-sm text-zinc-300 focus:outline-none focus:border-blue-500/50"
/>
</div>
<div className="flex flex-col gap-2">
<label className="text-[10px] font-bold text-zinc-500 uppercase tracking-widest">AI Model</label>
<select
value={selectedModel}
onChange={(e) => setSelectedModel(e.target.value)}
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2.5 text-sm text-zinc-300 focus:outline-none focus:border-blue-500/50"
>
{MODELS.map(m => (
<option key={m.id} value={m.id}>{m.name} ({m.id})</option>
))}
</select>
</div>
</>
) : apiProvider === 'tripo' ? (
<div className="flex flex-col gap-2">
<label className="text-[10px] font-bold text-zinc-500 uppercase tracking-widest">TRIPO API KEY</label>
<input
type="password"
value={tripoApiKey}
onChange={(e) => setTripoApiKey(e.target.value)}
placeholder="Enter your Tripo3D API key (starts with tsk_...)"
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2.5 text-sm text-zinc-300 focus:outline-none focus:border-blue-500/50"
/>
</div>
) : (
<div className="flex flex-col gap-2">
<label className="text-[10px] font-bold text-zinc-500 uppercase tracking-widest">MESHY API KEY</label>
<input
type="password"
value={meshyApiKey}
onChange={(e) => setMeshyApiKey(e.target.value)}
placeholder="Enter your Meshy API key (starts with msy_...)"
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2.5 text-sm text-zinc-300 focus:outline-none focus:border-blue-500/50"
/>
</div>
)}
<div className="flex items-center gap-3 mt-2">
<button
onClick={validateKey}
disabled={isValidatingKey || (apiProvider === 'fal' && !apiKey) || (apiProvider === 'tripo' && !tripoApiKey) || (apiProvider === 'meshy' && !meshyApiKey)}
className="px-4 py-2 bg-zinc-800 hover:bg-zinc-700 disabled:opacity-50 text-zinc-300 text-xs font-bold rounded-lg flex items-center gap-2 transition-colors"
>
{isValidatingKey && <Loader2 size={14} className="animate-spin" />}
Test Connection
</button>
{keyValidationStatus === 'valid' && <span className="text-xs text-green-500 font-bold flex items-center gap-1"><Check size={14} /> Valid Key</span>}
{keyValidationStatus === 'invalid' && <span className="text-xs text-red-500 font-bold flex items-center gap-1"><X size={14} /> Invalid Key</span>}
{keyValidationStatus === 'error' && <span className="text-xs text-orange-500 font-bold flex items-center gap-1"><AlertCircle size={14} /> Network Error</span>}
</div>
<button
onClick={handleSaveSettings}
className="mt-4 px-6 py-2.5 bg-blue-600 hover:bg-blue-500 text-white rounded-lg text-sm font-bold shadow-lg shadow-blue-900/20 transition-all w-fit"
>
Save Settings
</button>
</div>
) : (
<div className="grid grid-cols-2 gap-6 h-full"> <div className="grid grid-cols-2 gap-6 h-full">
{/* Left Column: Upload */} {/* Left Column: Upload */}
<div className="flex flex-col gap-4"> <div className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
<label className="text-[10px] font-bold text-zinc-500 uppercase tracking-widest">Provider & Model</label>
<div className="flex gap-2">
<select
value={apiProvider}
onChange={(e) => {
const val = e.target.value as 'fal' | 'tripo' | 'meshy';
setApiProvider(val);
localStorage.setItem('API_PROVIDER', val);
}}
className="flex-1 bg-zinc-950 border border-zinc-800 rounded-lg px-3 py-2 text-xs text-zinc-300 focus:outline-none focus:border-blue-500/50"
>
<option value="fal">Fal.ai</option>
<option value="tripo">Tripo3D</option>
<option value="meshy">Meshy</option>
</select>
{apiProvider === 'fal' && (
<select
value={selectedModel}
onChange={(e) => {
setSelectedModel(e.target.value);
localStorage.setItem('FAL_MODEL', e.target.value);
}}
className="flex-1 bg-zinc-950 border border-zinc-800 rounded-lg px-3 py-2 text-xs text-zinc-300 focus:outline-none focus:border-blue-500/50"
>
{MODELS.map(m => (
<option key={m.id} value={m.id}>{m.name}</option>
))}
</select>
)}
</div>
</div>
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<h3 className="text-sm font-bold text-zinc-200">Input Image</h3> <h3 className="text-sm font-bold text-zinc-200">Input Image</h3>
<span className="text-[10px] text-zinc-500 bg-zinc-800 px-2 py-0.5 rounded-full">Front View</span> <span className="text-[10px] text-zinc-500 bg-zinc-800 px-2 py-0.5 rounded-full">Front View</span>
@@ -600,6 +505,10 @@ export const ImageTo3DModal: React.FC<ImageTo3DModalProps> = ({ isOpen, onClose,
<input type="checkbox" checked={meshyShouldRemesh} onChange={e => setMeshyShouldRemesh(e.target.checked)} disabled={meshyModelType === 'lowpoly'} className="rounded border-zinc-700 bg-zinc-900 text-blue-500 cursor-pointer" /> <input type="checkbox" checked={meshyShouldRemesh} onChange={e => setMeshyShouldRemesh(e.target.checked)} disabled={meshyModelType === 'lowpoly'} className="rounded border-zinc-700 bg-zinc-900 text-blue-500 cursor-pointer" />
Remesh Remesh
</label> </label>
<label className="flex items-center gap-1.5 text-xs text-zinc-300 cursor-pointer" title="Keep enabled to prevent flat text/logos from becoming embossed geometry">
<input type="checkbox" checked={meshyEnhanceImage} onChange={e => setMeshyEnhanceImage(e.target.checked)} className="rounded border-zinc-700 bg-zinc-900 text-blue-500 cursor-pointer" />
Enhance Image
</label>
</div> </div>
{meshyShouldRemesh && meshyModelType !== 'lowpoly' && ( {meshyShouldRemesh && meshyModelType !== 'lowpoly' && (
@@ -678,8 +587,7 @@ export const ImageTo3DModal: React.FC<ImageTo3DModalProps> = ({ isOpen, onClose,
)} )}
</div> </div>
</div> </div>
)} </div>
</div>
</div> </div>
</motion.div> </motion.div>
</div> </div>
+334
View File
@@ -0,0 +1,334 @@
import React, { useState, useEffect } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { X, Sparkles, Image as ImageIcon, Loader2, Download, Settings, Wand2, Lightbulb } from 'lucide-react';
import { cn } from '../lib/utils';
interface VizAiModalProps {
isOpen: boolean;
onClose: () => void;
baseImage: string | null;
}
const dataURLtoBlob = (dataurl: string) => {
const arr = dataurl.split(',');
const mime = arr[0].match(/:(.*?);/)?.[1];
const bstr = atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
while(n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], {type:mime});
};
export const VizAiModal: React.FC<VizAiModalProps> = ({ isOpen, onClose, baseImage }) => {
// API Keys
const [stabilityApiKey, setStabilityApiKey] = useState('');
const [openAiKey, setOpenAiKey] = useState('');
// Prompt Generation State (AI Idea)
const [productName, setProductName] = useState('');
const [ingredients, setIngredients] = useState('');
const [imageTone, setImageTone] = useState('');
const [packDesign, setPackDesign] = useState('');
const [isGeneratingPrompt, setIsGeneratingPrompt] = useState(false);
// Image Generation State
const [prompt, setPrompt] = useState('');
const [strength, setStrength] = useState(0.85);
const [isGeneratingImage, setIsGeneratingImage] = useState(false);
const [generatedImage, setGeneratedImage] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (isOpen) {
setStabilityApiKey(localStorage.getItem('stability_api_key') || '');
setOpenAiKey(localStorage.getItem('openai_api_key') || '');
}
}, [isOpen]);
const generateAiIdea = async () => {
if (!openAiKey) {
setError("Please set your OpenAI API key in Tools > API Settings first.");
return;
}
setIsGeneratingPrompt(true);
setError(null);
try {
const response = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${openAiKey}`
},
body: JSON.stringify({
model: 'gpt-4o-mini',
messages: [{
role: 'system',
content: 'You are an expert prompt engineer for Stable Diffusion. Your goal is to take product specifications and write a single, highly descriptive prompt for generating a beautiful, professional product mockup scene. Describe the lighting, the background, and the aesthetic vividly.'
}, {
role: 'user',
content: `Create a single, highly descriptive image generation prompt based on these details:
Product Name: ${productName || 'Unspecified Product'}
Ingredients/Elements: ${ingredients || 'None specified'}
Image Tone/Mood: ${imageTone || 'Professional, studio lighting'}
Pack Design/Shape: ${packDesign || 'Standard'}
Return ONLY the prompt string (under 100 words) without any conversational text or quotes.`
}]
})
});
const data = await response.json();
if (data.error) throw new Error(data.error.message);
const generated = data.choices?.[0]?.message?.content?.trim() || "";
// Strip quotes if they were included
setPrompt(generated.replace(/^"|"$/g, ''));
} catch (err: any) {
console.error(err);
setError(err.message || "Failed to generate AI Idea.");
} finally {
setIsGeneratingPrompt(false);
}
};
const generateImage = async () => {
if (!stabilityApiKey) {
setError("Please set your Stability AI API key in Tools > API Settings first.");
return;
}
if (!baseImage) {
setError("No base image captured from the scene.");
return;
}
if (!prompt) {
setError("Please enter a prompt or use AI Idea.");
return;
}
setIsGeneratingImage(true);
setError(null);
try {
const formData = new FormData();
formData.append('image', dataURLtoBlob(baseImage), 'base.png');
formData.append('prompt', prompt);
formData.append('strength', strength.toString());
formData.append('mode', 'image-to-image');
formData.append('model', 'sd3.5-large');
formData.append('output_format', 'png');
const response = await fetch('https://api.stability.ai/v2beta/stable-image/generate/sd3', {
method: 'POST',
headers: {
'Authorization': `Bearer ${stabilityApiKey}`,
'Accept': 'image/*'
},
body: formData
});
if (!response.ok) {
const errData = await response.json().catch(() => ({}));
throw new Error(errData.message || `Stability API error: ${response.status}`);
}
const blob = await response.blob();
const imageUrl = URL.createObjectURL(blob);
setGeneratedImage(imageUrl);
} catch (err: any) {
console.error(err);
setError(err.message || "Failed to generate image.");
} finally {
setIsGeneratingImage(false);
}
};
if (!isOpen) return null;
return (
<AnimatePresence>
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm">
<motion.div
initial={{ opacity: 0, scale: 0.95, y: 20 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
exit={{ opacity: 0, scale: 0.95, y: 20 }}
className="w-full max-w-5xl bg-zinc-900 border border-zinc-800 rounded-xl shadow-2xl overflow-hidden flex flex-col h-[80vh]"
>
{/* Header */}
<div className="h-14 bg-zinc-950 flex items-center justify-between px-6 border-b border-zinc-800 shrink-0">
<div className="flex items-center gap-3">
<div className="w-8 h-8 rounded-lg bg-gradient-to-tr from-purple-600 to-blue-500 flex items-center justify-center">
<Sparkles size={16} className="text-white" />
</div>
<div>
<h2 className="text-sm font-bold text-zinc-100">VIZ AI Generator</h2>
<p className="text-[10px] text-zinc-400">Generate stunning product mockups directly from your 3D scene</p>
</div>
</div>
<div className="flex items-center gap-2">
<button onClick={onClose} className="p-2 hover:bg-zinc-800 rounded-lg transition-colors">
<X size={18} className="text-zinc-400" />
</button>
</div>
</div>
<div className="flex-1 overflow-hidden flex bg-zinc-900/50">
<div className="flex w-full h-full">
{/* Left Panel: Inputs */}
<div className="w-[400px] border-r border-zinc-800 flex flex-col overflow-y-auto custom-scrollbar">
{/* AI Idea Box */}
<div className="p-5 border-b border-zinc-800 bg-zinc-950/30">
<div className="flex items-center gap-2 mb-4">
<Lightbulb size={16} className="text-yellow-500" />
<h3 className="text-xs font-bold text-zinc-300 uppercase tracking-wider">AI Idea Generator</h3>
</div>
<div className="flex flex-col gap-3">
<input
type="text"
placeholder="Product Name (e.g. Tetra Juice)"
value={productName}
onChange={(e) => setProductName(e.target.value)}
className="w-full bg-zinc-900 border border-zinc-800 rounded px-3 py-2 text-xs text-white placeholder-zinc-600 focus:border-yellow-500/50 outline-none"
/>
<input
type="text"
placeholder="Ingredients (e.g. Oranges, Mint)"
value={ingredients}
onChange={(e) => setIngredients(e.target.value)}
className="w-full bg-zinc-900 border border-zinc-800 rounded px-3 py-2 text-xs text-white placeholder-zinc-600 focus:border-yellow-500/50 outline-none"
/>
<input
type="text"
placeholder="Image Tone (e.g. Fresh, Bright, Morning)"
value={imageTone}
onChange={(e) => setImageTone(e.target.value)}
className="w-full bg-zinc-900 border border-zinc-800 rounded px-3 py-2 text-xs text-white placeholder-zinc-600 focus:border-yellow-500/50 outline-none"
/>
<input
type="text"
placeholder="Pack Design (e.g. Sleek, Modern)"
value={packDesign}
onChange={(e) => setPackDesign(e.target.value)}
className="w-full bg-zinc-900 border border-zinc-800 rounded px-3 py-2 text-xs text-white placeholder-zinc-600 focus:border-yellow-500/50 outline-none"
/>
<button
onClick={generateAiIdea}
disabled={isGeneratingPrompt}
className="w-full mt-2 py-2 bg-yellow-500/10 hover:bg-yellow-500/20 text-yellow-500 border border-yellow-500/30 rounded-lg text-xs font-bold transition-all flex items-center justify-center gap-2"
>
{isGeneratingPrompt ? <Loader2 size={14} className="animate-spin" /> : <Wand2 size={14} />}
{isGeneratingPrompt ? 'Generating Idea...' : 'Suggest Prompt'}
</button>
</div>
</div>
{/* Main Generation Settings */}
<div className="p-5 flex flex-col gap-6">
<div className="flex flex-col gap-2">
<label className="text-xs font-bold text-zinc-300">Prompt</label>
<textarea
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
placeholder="Describe the background and lighting..."
className="w-full h-32 bg-zinc-900 border border-zinc-800 rounded-lg p-3 text-sm text-white placeholder-zinc-600 focus:border-blue-500/50 outline-none resize-none"
/>
</div>
<div className="flex flex-col gap-2">
<div className="flex justify-between">
<label className="text-xs font-bold text-zinc-400">Creative Strength</label>
<span className="text-xs text-blue-400 font-mono">{strength.toFixed(2)}</span>
</div>
<input
type="range"
min="0" max="1" step="0.05"
value={strength}
onChange={(e) => setStrength(parseFloat(e.target.value))}
className="w-full accent-blue-500"
/>
<div className="flex justify-between text-[10px] text-zinc-600">
<span>Similar to Base</span>
<span>Highly Creative</span>
</div>
</div>
{error && (
<div className="p-3 bg-red-500/10 border border-red-500/20 rounded-lg text-xs text-red-400">
{error}
</div>
)}
<button
onClick={generateImage}
disabled={isGeneratingImage}
className="w-full py-4 mt-auto bg-gradient-to-r from-purple-600 to-blue-600 hover:from-purple-500 hover:to-blue-500 text-white font-bold rounded-xl shadow-lg transition-all flex items-center justify-center gap-2"
>
{isGeneratingImage ? <Loader2 size={18} className="animate-spin" /> : <Sparkles size={18} />}
{isGeneratingImage ? 'Generating Scene...' : 'Generate Image'}
</button>
</div>
</div>
{/* Right Panel: Previews */}
<div className="flex-1 p-6 bg-zinc-950 flex flex-col gap-4 relative overflow-y-auto">
<div className="grid grid-cols-2 gap-6 h-full">
{/* Base Image */}
<div className="flex flex-col gap-2">
<div className="flex items-center justify-between">
<span className="text-xs font-bold text-zinc-500 uppercase tracking-widest">Base Render</span>
</div>
<div className="flex-1 bg-zinc-900 border border-zinc-800 rounded-xl overflow-hidden flex items-center justify-center relative shadow-inner">
{baseImage ? (
<img src={baseImage} alt="Base Render" className="w-full h-full object-contain" />
) : (
<div className="text-zinc-600 flex flex-col items-center gap-2">
<ImageIcon size={32} />
<span className="text-xs">No scene captured</span>
</div>
)}
</div>
</div>
{/* Generated Image */}
<div className="flex flex-col gap-2">
<div className="flex items-center justify-between">
<span className="text-xs font-bold text-blue-500 uppercase tracking-widest">AI Result</span>
{generatedImage && (
<a
href={generatedImage}
download="viz_ai_mockup.png"
className="text-xs text-zinc-400 hover:text-white flex items-center gap-1"
>
<Download size={14} /> Download
</a>
)}
</div>
<div className="flex-1 bg-zinc-900 border border-blue-500/20 rounded-xl overflow-hidden flex items-center justify-center relative shadow-lg">
{isGeneratingImage ? (
<div className="flex flex-col items-center gap-4 text-blue-500">
<Loader2 size={32} className="animate-spin" />
<span className="text-sm font-medium animate-pulse">Rendering via Stability AI...</span>
</div>
) : generatedImage ? (
<img src={generatedImage} alt="AI Result" className="w-full h-full object-contain" />
) : (
<div className="text-zinc-600 flex flex-col items-center gap-2">
<Sparkles size={32} className="opacity-50" />
<span className="text-xs">Result will appear here</span>
</div>
)}
</div>
</div>
</div>
</div>
</div>
</div>
</motion.div>
</div>
</AnimatePresence>
);
};