feat: build real2sim platform
This commit is contained in:
commit
a40cef7553
3
.env.example
Normal file
3
.env.example
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
DASHSCOPE_API_KEY=sk-your-beijing-region-api-key
|
||||||
|
DASHSCOPE_API_BASE=https://dashscope.aliyuncs.com/api/v1
|
||||||
|
PORT=8787
|
||||||
31
.gitignore
vendored
Normal file
31
.gitignore
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
.data
|
||||||
|
coverage
|
||||||
|
playwright-report
|
||||||
|
test-results
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
63
README.md
Normal file
63
README.md
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# real2sim 平台
|
||||||
|
|
||||||
|
基于阿里云百炼 DashScope `Tripo/Tripo-H3.1` 的 3D 资产生成与柔性物体仿真工作台。前端默认中文,并内置英文切换。
|
||||||
|
|
||||||
|
## 功能
|
||||||
|
|
||||||
|
- 模型生成:支持文生 3D、单图生 3D、多图生 3D。
|
||||||
|
- Tripo 参数:支持 `Tripo-H3.1` / `Tripo-P1.0`、贴图质量、几何精度、PBR、无贴图生成。
|
||||||
|
- 异步任务:后端创建 DashScope 任务,本地保存任务记录,前端支持轮询与手动刷新。
|
||||||
|
- 柔性物体:从资产库选择源 GLB,生成柔性版本 prompt,提交 H3.1 派生任务。
|
||||||
|
- 仿真配置:按材料、弹性、阻尼、厚度、最大形变、重力导出 `real2sim.flexProfile.v1` JSON。
|
||||||
|
- 资产库:展示历史任务、预览图、GLB 链接,并可一键作为柔性源。
|
||||||
|
|
||||||
|
## 技术栈
|
||||||
|
|
||||||
|
- 前端:React、Vite、TypeScript、Three.js、@react-three/fiber、lucide-react
|
||||||
|
- 后端:Express、Zod、DashScope HTTP API
|
||||||
|
- 测试:Vitest
|
||||||
|
|
||||||
|
## 本地运行
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
cp .env.example .env.local
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
`.env.local` 需要配置北京地域的 DashScope API Key:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
DASHSCOPE_API_KEY=sk-your-beijing-region-api-key
|
||||||
|
DASHSCOPE_API_BASE=https://dashscope.aliyuncs.com/api/v1
|
||||||
|
PORT=8787
|
||||||
|
```
|
||||||
|
|
||||||
|
前端地址:`http://localhost:5173`
|
||||||
|
|
||||||
|
后端地址:`http://localhost:8787`
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
- `GET /api/health`
|
||||||
|
- `GET /api/tripo/tasks`
|
||||||
|
- `POST /api/tripo/tasks`
|
||||||
|
- `GET /api/tripo/tasks/:taskId`
|
||||||
|
- `POST /api/flex/tasks`
|
||||||
|
|
||||||
|
## Tripo 接口说明
|
||||||
|
|
||||||
|
DashScope 3D 生成是异步流程:
|
||||||
|
|
||||||
|
1. `POST /api/v1/services/aigc/video-generation/3d-generation` 创建任务。
|
||||||
|
2. `GET /api/v1/tasks/{task_id}` 查询任务。
|
||||||
|
|
||||||
|
官方输入方式为 `prompt`、`image`、`images` 三选一,不直接接收 GLB 作为再生成输入。因此本平台的柔性流程会绑定源 GLB 作为仿真资产,并用源 prompt / 源名称派生柔性版本生成任务。
|
||||||
|
|
||||||
|
## 验证
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run test:run
|
||||||
|
npm run lint
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
25
eslint.config.js
Normal file
25
eslint.config.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import js from '@eslint/js'
|
||||||
|
import globals from 'globals'
|
||||||
|
import reactHooks from 'eslint-plugin-react-hooks'
|
||||||
|
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||||
|
import tseslint from 'typescript-eslint'
|
||||||
|
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||||
|
|
||||||
|
export default defineConfig([
|
||||||
|
globalIgnores(['dist']),
|
||||||
|
{
|
||||||
|
files: ['**/*.{ts,tsx}'],
|
||||||
|
extends: [
|
||||||
|
js.configs.recommended,
|
||||||
|
tseslint.configs.recommended,
|
||||||
|
reactHooks.configs.flat.recommended,
|
||||||
|
reactRefresh.configs.vite,
|
||||||
|
],
|
||||||
|
languageOptions: {
|
||||||
|
globals: globals.browser,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
'react-hooks/set-state-in-effect': 'off',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
13
index.html
Normal file
13
index.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>real2sim 平台</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
5478
package-lock.json
generated
Normal file
5478
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
49
package.json
Normal file
49
package.json
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"name": "real2sim-platform",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "concurrently -k \"npm:server\" \"npm:client\"",
|
||||||
|
"client": "vite",
|
||||||
|
"server": "tsx watch server/index.ts",
|
||||||
|
"start": "tsx server/index.ts",
|
||||||
|
"build": "tsc -b && vite build",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"test": "vitest",
|
||||||
|
"test:run": "vitest run"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@react-three/drei": "^10.7.7",
|
||||||
|
"@react-three/fiber": "^9.6.1",
|
||||||
|
"cors": "^2.8.6",
|
||||||
|
"dotenv": "^17.4.2",
|
||||||
|
"express": "^5.2.1",
|
||||||
|
"lucide-react": "^1.17.0",
|
||||||
|
"react": "^19.2.6",
|
||||||
|
"react-dom": "^19.2.6",
|
||||||
|
"three": "^0.184.0",
|
||||||
|
"zod": "^4.4.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^10.0.1",
|
||||||
|
"@types/cors": "^2.8.19",
|
||||||
|
"@types/express": "^5.0.6",
|
||||||
|
"@types/node": "^24.12.3",
|
||||||
|
"@types/react": "^19.2.14",
|
||||||
|
"@types/react-dom": "^19.2.3",
|
||||||
|
"@vitejs/plugin-react": "^6.0.1",
|
||||||
|
"concurrently": "^10.0.3",
|
||||||
|
"eslint": "^10.3.0",
|
||||||
|
"eslint-plugin-react-hooks": "^7.1.1",
|
||||||
|
"eslint-plugin-react-refresh": "^0.5.2",
|
||||||
|
"globals": "^17.6.0",
|
||||||
|
"playwright": "^1.60.0",
|
||||||
|
"tsx": "^4.22.4",
|
||||||
|
"typescript": "~6.0.2",
|
||||||
|
"typescript-eslint": "^8.59.2",
|
||||||
|
"vite": "^8.0.12",
|
||||||
|
"vitest": "^4.1.8"
|
||||||
|
}
|
||||||
|
}
|
||||||
1
public/favicon.svg
Normal file
1
public/favicon.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 9.3 KiB |
58
server/flex.test.ts
Normal file
58
server/flex.test.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import { buildFlexiblePrompt, createSimulationExport } from './flex.js'
|
||||||
|
|
||||||
|
describe('flex profile helpers', () => {
|
||||||
|
it('builds a material-aware prompt for Tripo generation', () => {
|
||||||
|
const prompt = buildFlexiblePrompt({
|
||||||
|
sourceName: '工业夹爪',
|
||||||
|
sourcePrompt: '一个双指机器人夹爪',
|
||||||
|
behaviorPrompt: '转化为柔性末端执行器',
|
||||||
|
model: 'Tripo/Tripo-H3.1',
|
||||||
|
parameters: {
|
||||||
|
texture_quality: 'detailed',
|
||||||
|
geometry_quality: 'standard',
|
||||||
|
pbr: true,
|
||||||
|
texture: true,
|
||||||
|
},
|
||||||
|
simulation: {
|
||||||
|
material: 'softRobot',
|
||||||
|
elasticity: 82,
|
||||||
|
damping: 48,
|
||||||
|
thickness: 4,
|
||||||
|
deformation: 70,
|
||||||
|
gravity: 9.8,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(prompt).toContain('一个双指机器人夹爪')
|
||||||
|
expect(prompt).toContain('软体机器人结构')
|
||||||
|
expect(prompt).toContain('弹性强度 82/100')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('exports normalized simulation parameters', () => {
|
||||||
|
const profile = createSimulationExport({
|
||||||
|
sourceTaskId: 'task-1',
|
||||||
|
sourceName: '软袋',
|
||||||
|
sourceModelUrl: 'https://example.com/model.glb',
|
||||||
|
model: 'Tripo/Tripo-H3.1',
|
||||||
|
parameters: {
|
||||||
|
texture_quality: 'detailed',
|
||||||
|
geometry_quality: 'ultra',
|
||||||
|
pbr: true,
|
||||||
|
texture: true,
|
||||||
|
},
|
||||||
|
simulation: {
|
||||||
|
material: 'cloth',
|
||||||
|
elasticity: 50,
|
||||||
|
damping: 25,
|
||||||
|
thickness: 1.5,
|
||||||
|
deformation: 88,
|
||||||
|
gravity: 9.8,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(profile.schema).toBe('real2sim.flexProfile.v1')
|
||||||
|
expect(profile.physics.elasticity).toBe(0.5)
|
||||||
|
expect(profile.solver.preserveVolume).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
54
server/flex.ts
Normal file
54
server/flex.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import type { CreateFlexTaskInput, SimulationProfile } from './schemas.js'
|
||||||
|
|
||||||
|
const materialCopy: Record<SimulationProfile['material'], string> = {
|
||||||
|
silicone: '半透明软硅胶材质,边缘圆润,受力后可压缩回弹',
|
||||||
|
cloth: '轻薄织物材质,表面有细密纤维纹理和自然褶皱',
|
||||||
|
inflatable: '充气膜结构,内部有气压支撑,表面柔和鼓起',
|
||||||
|
softRobot: '软体机器人结构,带有分段腔体、柔性关节和可驱动褶皱',
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildFlexiblePrompt(input: CreateFlexTaskInput): string {
|
||||||
|
const source =
|
||||||
|
input.sourcePrompt ||
|
||||||
|
input.sourceName ||
|
||||||
|
'一个适合仿真验证的真实物体'
|
||||||
|
const behavior = input.behaviorPrompt || '保持原始轮廓特征,同时变成可弯曲、可压缩的柔性物体'
|
||||||
|
const material = materialCopy[input.simulation.material]
|
||||||
|
const elasticity = Math.round(input.simulation.elasticity)
|
||||||
|
const deformation = Math.round(input.simulation.deformation)
|
||||||
|
|
||||||
|
return [
|
||||||
|
source,
|
||||||
|
behavior,
|
||||||
|
material,
|
||||||
|
`弹性强度 ${elasticity}/100,形变幅度 ${deformation}/100。`,
|
||||||
|
'生成高精度、可用于 real-to-sim 工作流的 3D 资产,保留清晰几何结构和物理仿真可读的材质细节。',
|
||||||
|
].join(' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createSimulationExport(input: CreateFlexTaskInput) {
|
||||||
|
return {
|
||||||
|
schema: 'real2sim.flexProfile.v1',
|
||||||
|
source: {
|
||||||
|
taskId: input.sourceTaskId,
|
||||||
|
modelUrl: input.sourceModelUrl || undefined,
|
||||||
|
prompt: input.sourcePrompt || undefined,
|
||||||
|
name: input.sourceName || undefined,
|
||||||
|
},
|
||||||
|
material: input.simulation.material,
|
||||||
|
physics: {
|
||||||
|
elasticity: input.simulation.elasticity / 100,
|
||||||
|
damping: input.simulation.damping / 100,
|
||||||
|
thicknessMm: input.simulation.thickness,
|
||||||
|
maxDeformation: input.simulation.deformation / 100,
|
||||||
|
gravity: input.simulation.gravity,
|
||||||
|
},
|
||||||
|
solver: {
|
||||||
|
type: 'position-based-dynamics',
|
||||||
|
substeps: 8,
|
||||||
|
selfCollision: true,
|
||||||
|
preserveVolume: input.simulation.material !== 'cloth',
|
||||||
|
},
|
||||||
|
generatedAt: new Date().toISOString(),
|
||||||
|
}
|
||||||
|
}
|
||||||
162
server/index.ts
Normal file
162
server/index.ts
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
import cors from 'cors'
|
||||||
|
import dotenv from 'dotenv'
|
||||||
|
import express from 'express'
|
||||||
|
import { ZodError } from 'zod'
|
||||||
|
import { buildFlexiblePrompt, createSimulationExport } from './flex.js'
|
||||||
|
import { createFlexTaskSchema, createTripoTaskSchema } from './schemas.js'
|
||||||
|
import { getTask, mergeTaskOutput, readTasks, upsertTask, type StoredTask } from './taskStore.js'
|
||||||
|
import { createTripoTask, queryTripoTask } from './tripoClient.js'
|
||||||
|
|
||||||
|
dotenv.config({ path: '.env.local' })
|
||||||
|
dotenv.config()
|
||||||
|
|
||||||
|
const app = express()
|
||||||
|
const port = Number(process.env.PORT || 8787)
|
||||||
|
|
||||||
|
app.use(cors())
|
||||||
|
app.use(express.json({ limit: '1mb' }))
|
||||||
|
|
||||||
|
app.get('/api/health', (_req, res) => {
|
||||||
|
res.json({
|
||||||
|
ok: true,
|
||||||
|
service: 'real2sim-platform',
|
||||||
|
apiConfigured: Boolean(process.env.DASHSCOPE_API_KEY),
|
||||||
|
defaultModel: 'Tripo/Tripo-H3.1',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get('/api/tripo/tasks', async (_req, res, next) => {
|
||||||
|
try {
|
||||||
|
res.json({ tasks: await readTasks() })
|
||||||
|
} catch (error) {
|
||||||
|
next(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.post('/api/tripo/tasks', async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const input = createTripoTaskSchema.parse(req.body)
|
||||||
|
const response = await createTripoTask(input)
|
||||||
|
const taskId = response.output?.task_id
|
||||||
|
|
||||||
|
if (!taskId || !response.output) {
|
||||||
|
throw new Error('DashScope did not return a task_id.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = input.mode === 'text' ? input.prompt || taskId : input.mode === 'image' ? '单图生成' : '多图生成'
|
||||||
|
const now = new Date().toISOString()
|
||||||
|
const task: StoredTask = {
|
||||||
|
taskId,
|
||||||
|
kind: 'generation',
|
||||||
|
title,
|
||||||
|
status: response.output.task_status,
|
||||||
|
requestId: response.request_id,
|
||||||
|
request: input,
|
||||||
|
output: response.output,
|
||||||
|
usage: response.usage,
|
||||||
|
createdAt: now,
|
||||||
|
updatedAt: now,
|
||||||
|
}
|
||||||
|
|
||||||
|
await upsertTask(task)
|
||||||
|
res.status(201).json({ task })
|
||||||
|
} catch (error) {
|
||||||
|
next(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get('/api/tripo/tasks/:taskId', async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const response = await queryTripoTask(req.params.taskId)
|
||||||
|
if (!response.output) {
|
||||||
|
throw new Error('DashScope did not return task output.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await getTask(req.params.taskId)
|
||||||
|
const updated = existing
|
||||||
|
? mergeTaskOutput(existing, response.output, response.usage)
|
||||||
|
: ({
|
||||||
|
taskId: response.output.task_id,
|
||||||
|
kind: 'generation',
|
||||||
|
title: response.output.task_id,
|
||||||
|
status: response.output.task_status,
|
||||||
|
requestId: response.request_id,
|
||||||
|
request: {
|
||||||
|
mode: 'text',
|
||||||
|
model: 'Tripo/Tripo-H3.1',
|
||||||
|
prompt: '',
|
||||||
|
parameters: {
|
||||||
|
texture_quality: 'standard',
|
||||||
|
geometry_quality: 'standard',
|
||||||
|
pbr: true,
|
||||||
|
texture: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
output: response.output,
|
||||||
|
usage: response.usage,
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
updatedAt: new Date().toISOString(),
|
||||||
|
} satisfies StoredTask)
|
||||||
|
|
||||||
|
await upsertTask(updated)
|
||||||
|
res.json({ task: updated })
|
||||||
|
} catch (error) {
|
||||||
|
next(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.post('/api/flex/tasks', async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const input = createFlexTaskSchema.parse(req.body)
|
||||||
|
const prompt = buildFlexiblePrompt(input)
|
||||||
|
const response = await createTripoTask({
|
||||||
|
mode: 'text',
|
||||||
|
model: input.model,
|
||||||
|
prompt,
|
||||||
|
parameters: input.parameters,
|
||||||
|
})
|
||||||
|
|
||||||
|
const taskId = response.output?.task_id
|
||||||
|
if (!taskId || !response.output) {
|
||||||
|
throw new Error('DashScope did not return a task_id.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const now = new Date().toISOString()
|
||||||
|
const task: StoredTask = {
|
||||||
|
taskId,
|
||||||
|
kind: 'flex',
|
||||||
|
title: input.sourceName ? `${input.sourceName} · 柔性版本` : '柔性物体生成',
|
||||||
|
status: response.output.task_status,
|
||||||
|
requestId: response.request_id,
|
||||||
|
request: input,
|
||||||
|
output: response.output,
|
||||||
|
usage: response.usage,
|
||||||
|
createdAt: now,
|
||||||
|
updatedAt: now,
|
||||||
|
}
|
||||||
|
|
||||||
|
await upsertTask(task)
|
||||||
|
res.status(201).json({
|
||||||
|
task,
|
||||||
|
prompt,
|
||||||
|
simulationExport: createSimulationExport(input),
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
next(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.use((error: unknown, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
|
||||||
|
void _next
|
||||||
|
if (error instanceof ZodError) {
|
||||||
|
res.status(400).json({ error: 'Validation failed', issues: error.issues })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = error instanceof Error ? error.message : 'Unknown server error.'
|
||||||
|
res.status(500).json({ error: message })
|
||||||
|
})
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`real2sim API listening on http://localhost:${port}`)
|
||||||
|
})
|
||||||
84
server/schemas.ts
Normal file
84
server/schemas.ts
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
export const tripoModelSchema = z.enum(['Tripo/Tripo-H3.1', 'Tripo/Tripo-P1.0'])
|
||||||
|
|
||||||
|
export const generationModeSchema = z.enum(['text', 'image', 'multiImage'])
|
||||||
|
|
||||||
|
export const tripoParametersSchema = z.object({
|
||||||
|
texture_quality: z.enum(['standard', 'detailed']).default('standard'),
|
||||||
|
geometry_quality: z.enum(['standard', 'ultra']).default('standard'),
|
||||||
|
pbr: z.boolean().default(true),
|
||||||
|
texture: z.boolean().default(true),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const multiImageSlotSchema = z.object({
|
||||||
|
type: z.enum(['jpeg', 'png']).default('png'),
|
||||||
|
file_token: z.string().url().or(z.literal('')).default(''),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const createTripoTaskSchema = z
|
||||||
|
.object({
|
||||||
|
mode: generationModeSchema,
|
||||||
|
model: tripoModelSchema.default('Tripo/Tripo-H3.1'),
|
||||||
|
prompt: z.string().trim().max(1024).optional(),
|
||||||
|
image: z.string().trim().url().optional().or(z.literal('')),
|
||||||
|
images: z.array(multiImageSlotSchema).length(4).optional(),
|
||||||
|
parameters: tripoParametersSchema.default({}),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (data.mode === 'text' && !data.prompt) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
path: ['prompt'],
|
||||||
|
message: 'Prompt is required for text-to-3D.',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.mode === 'image' && !data.image) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
path: ['image'],
|
||||||
|
message: 'Image URL is required for image-to-3D.',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.mode === 'multiImage') {
|
||||||
|
const validImages = data.images?.filter((item) => item.file_token).length ?? 0
|
||||||
|
if (validImages < 2) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
path: ['images'],
|
||||||
|
message: 'At least two image URLs are required for multi-image generation.',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const simulationProfileSchema = z.object({
|
||||||
|
material: z.enum(['silicone', 'cloth', 'inflatable', 'softRobot']),
|
||||||
|
elasticity: z.number().min(0).max(100),
|
||||||
|
damping: z.number().min(0).max(100),
|
||||||
|
thickness: z.number().min(0.1).max(20),
|
||||||
|
deformation: z.number().min(0).max(100),
|
||||||
|
gravity: z.number().min(0).max(30),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const createFlexTaskSchema = z.object({
|
||||||
|
sourceTaskId: z.string().trim().optional(),
|
||||||
|
sourceName: z.string().trim().max(160).optional(),
|
||||||
|
sourcePrompt: z.string().trim().max(1024).optional(),
|
||||||
|
sourceModelUrl: z.string().trim().url().optional().or(z.literal('')),
|
||||||
|
behaviorPrompt: z.string().trim().max(1024).optional(),
|
||||||
|
model: tripoModelSchema.default('Tripo/Tripo-H3.1'),
|
||||||
|
parameters: tripoParametersSchema.default({
|
||||||
|
texture_quality: 'detailed',
|
||||||
|
geometry_quality: 'standard',
|
||||||
|
pbr: true,
|
||||||
|
texture: true,
|
||||||
|
}),
|
||||||
|
simulation: simulationProfileSchema,
|
||||||
|
})
|
||||||
|
|
||||||
|
export type CreateTripoTaskInput = z.infer<typeof createTripoTaskSchema>
|
||||||
|
export type CreateFlexTaskInput = z.infer<typeof createFlexTaskSchema>
|
||||||
|
export type SimulationProfile = z.infer<typeof simulationProfileSchema>
|
||||||
68
server/taskStore.ts
Normal file
68
server/taskStore.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
||||||
|
import path from 'node:path'
|
||||||
|
import type { CreateFlexTaskInput, CreateTripoTaskInput } from './schemas.js'
|
||||||
|
import type { DashScopeTaskOutput, TaskStatus } from './tripoClient.js'
|
||||||
|
|
||||||
|
const dataDir = path.join(process.cwd(), '.data')
|
||||||
|
const storePath = path.join(dataDir, 'tasks.json')
|
||||||
|
|
||||||
|
export type StoredTask = {
|
||||||
|
taskId: string
|
||||||
|
kind: 'generation' | 'flex'
|
||||||
|
title: string
|
||||||
|
status: TaskStatus
|
||||||
|
requestId?: string
|
||||||
|
request: CreateTripoTaskInput | CreateFlexTaskInput
|
||||||
|
output?: DashScopeTaskOutput
|
||||||
|
usage?: Record<string, unknown>
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureStore() {
|
||||||
|
await mkdir(dataDir, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function readTasks(): Promise<StoredTask[]> {
|
||||||
|
try {
|
||||||
|
const body = await readFile(storePath, 'utf8')
|
||||||
|
return JSON.parse(body) as StoredTask[]
|
||||||
|
} catch (error) {
|
||||||
|
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function writeTasks(tasks: StoredTask[]) {
|
||||||
|
await ensureStore()
|
||||||
|
await writeFile(storePath, JSON.stringify(tasks, null, 2))
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function upsertTask(task: StoredTask) {
|
||||||
|
const tasks = await readTasks()
|
||||||
|
const index = tasks.findIndex((item) => item.taskId === task.taskId)
|
||||||
|
if (index >= 0) {
|
||||||
|
tasks[index] = task
|
||||||
|
} else {
|
||||||
|
tasks.unshift(task)
|
||||||
|
}
|
||||||
|
await writeTasks(tasks.slice(0, 80))
|
||||||
|
return task
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getTask(taskId: string) {
|
||||||
|
const tasks = await readTasks()
|
||||||
|
return tasks.find((task) => task.taskId === taskId)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function mergeTaskOutput(task: StoredTask, output: DashScopeTaskOutput, usage?: Record<string, unknown>) {
|
||||||
|
return {
|
||||||
|
...task,
|
||||||
|
status: output.task_status,
|
||||||
|
output,
|
||||||
|
usage,
|
||||||
|
updatedAt: new Date().toISOString(),
|
||||||
|
} satisfies StoredTask
|
||||||
|
}
|
||||||
107
server/tripoClient.ts
Normal file
107
server/tripoClient.ts
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
import type { CreateTripoTaskInput } from './schemas.js'
|
||||||
|
|
||||||
|
export type TaskStatus = 'PENDING' | 'RUNNING' | 'SUCCEEDED' | 'FAILED' | 'CANCELED' | 'UNKNOWN'
|
||||||
|
|
||||||
|
export type TripoTaskResult = {
|
||||||
|
pbr_model_url?: string
|
||||||
|
base_model_url?: string
|
||||||
|
rendered_image_url?: string
|
||||||
|
orig_prompt?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DashScopeTaskOutput = {
|
||||||
|
task_id: string
|
||||||
|
task_status: TaskStatus
|
||||||
|
submit_time?: string
|
||||||
|
scheduled_time?: string
|
||||||
|
end_time?: string
|
||||||
|
results?: TripoTaskResult[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DashScopeTaskResponse = {
|
||||||
|
request_id?: string
|
||||||
|
output?: DashScopeTaskOutput
|
||||||
|
usage?: Record<string, unknown>
|
||||||
|
code?: string
|
||||||
|
message?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TripoPayload = {
|
||||||
|
model: CreateTripoTaskInput['model']
|
||||||
|
input: {
|
||||||
|
prompt?: string
|
||||||
|
image?: string
|
||||||
|
images?: Array<Record<string, string>>
|
||||||
|
}
|
||||||
|
parameters: CreateTripoTaskInput['parameters']
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiBase = process.env.DASHSCOPE_API_BASE || 'https://dashscope.aliyuncs.com/api/v1'
|
||||||
|
|
||||||
|
function apiKey() {
|
||||||
|
const key = process.env.DASHSCOPE_API_KEY
|
||||||
|
if (!key) {
|
||||||
|
throw new Error('DASHSCOPE_API_KEY is not configured.')
|
||||||
|
}
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readDashScopeResponse(response: Response): Promise<DashScopeTaskResponse> {
|
||||||
|
const text = await response.text()
|
||||||
|
const json = text ? (JSON.parse(text) as DashScopeTaskResponse) : {}
|
||||||
|
|
||||||
|
if (!response.ok || json.code) {
|
||||||
|
const message = json.message || `DashScope request failed with HTTP ${response.status}.`
|
||||||
|
throw new Error(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toTripoPayload(input: CreateTripoTaskInput): TripoPayload {
|
||||||
|
const payload: TripoPayload = {
|
||||||
|
model: input.model,
|
||||||
|
input: {},
|
||||||
|
parameters: input.parameters,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.mode === 'text') {
|
||||||
|
payload.input.prompt = input.prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.mode === 'image') {
|
||||||
|
payload.input.image = input.image || undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.mode === 'multiImage') {
|
||||||
|
payload.input.images = input.images?.map((item) =>
|
||||||
|
item.file_token ? { type: item.type, file_token: item.file_token } : {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createTripoTask(input: CreateTripoTaskInput) {
|
||||||
|
const response = await fetch(`${apiBase}/services/aigc/video-generation/3d-generation`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${apiKey()}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-DashScope-Async': 'enable',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(toTripoPayload(input)),
|
||||||
|
})
|
||||||
|
|
||||||
|
return readDashScopeResponse(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function queryTripoTask(taskId: string) {
|
||||||
|
const response = await fetch(`${apiBase}/tasks/${encodeURIComponent(taskId)}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${apiKey()}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return readDashScopeResponse(response)
|
||||||
|
}
|
||||||
713
src/App.css
Normal file
713
src/App.css
Normal file
@ -0,0 +1,713 @@
|
|||||||
|
.app-shell {
|
||||||
|
min-height: 100vh;
|
||||||
|
color: #18211f;
|
||||||
|
background:
|
||||||
|
linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(247, 250, 248, 0.96)),
|
||||||
|
radial-gradient(circle at 18% 0%, rgba(94, 234, 212, 0.14), transparent 31%),
|
||||||
|
radial-gradient(circle at 100% 4%, rgba(249, 115, 115, 0.12), transparent 28%),
|
||||||
|
#f5f8f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 10;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(260px, 1fr) auto minmax(230px, 1fr);
|
||||||
|
gap: 22px;
|
||||||
|
align-items: center;
|
||||||
|
padding: 18px 28px;
|
||||||
|
border-bottom: 1px solid rgba(31, 41, 38, 0.12);
|
||||||
|
background: rgba(248, 251, 249, 0.86);
|
||||||
|
backdrop-filter: blur(18px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-mark {
|
||||||
|
display: grid;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: 38px;
|
||||||
|
height: 38px;
|
||||||
|
place-items: center;
|
||||||
|
color: #052e2b;
|
||||||
|
border: 1px solid rgba(4, 120, 87, 0.24);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: linear-gradient(145deg, #b7f6e9, #f5fffb);
|
||||||
|
box-shadow: 0 14px 30px rgba(20, 83, 45, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 1.1;
|
||||||
|
font-weight: 720;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand p {
|
||||||
|
margin: 3px 0 0;
|
||||||
|
color: #5a6864;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 4px;
|
||||||
|
padding: 4px;
|
||||||
|
border: 1px solid rgba(31, 41, 38, 0.12);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgba(255, 255, 255, 0.66);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button,
|
||||||
|
.language-button,
|
||||||
|
.secondary-button,
|
||||||
|
.submit-button,
|
||||||
|
.asset-actions button,
|
||||||
|
.toggle,
|
||||||
|
.segmented button,
|
||||||
|
.timeline-item {
|
||||||
|
font: inherit;
|
||||||
|
letter-spacing: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button {
|
||||||
|
display: inline-flex;
|
||||||
|
min-height: 34px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 7px;
|
||||||
|
padding: 0 12px;
|
||||||
|
color: #52625d;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button.active {
|
||||||
|
color: #10201c;
|
||||||
|
background: #ffffff;
|
||||||
|
box-shadow: 0 5px 16px rgba(15, 23, 42, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.api-status,
|
||||||
|
.language-button {
|
||||||
|
display: inline-flex;
|
||||||
|
min-height: 34px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 7px;
|
||||||
|
padding: 0 11px;
|
||||||
|
border-radius: 7px;
|
||||||
|
border: 1px solid rgba(31, 41, 38, 0.13);
|
||||||
|
background: rgba(255, 255, 255, 0.72);
|
||||||
|
color: #42514d;
|
||||||
|
font-size: 13px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.api-status.ready {
|
||||||
|
color: #047857;
|
||||||
|
}
|
||||||
|
|
||||||
|
.api-status.missing {
|
||||||
|
color: #b45309;
|
||||||
|
}
|
||||||
|
|
||||||
|
.language-button {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-banner {
|
||||||
|
margin: 16px 28px 0;
|
||||||
|
padding: 11px 14px;
|
||||||
|
color: #7f1d1d;
|
||||||
|
border: 1px solid rgba(248, 113, 113, 0.35);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #fff7f7;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workbench {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(284px, 330px) minmax(420px, 1fr) minmax(284px, 336px);
|
||||||
|
gap: 18px;
|
||||||
|
padding: 18px 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-panel,
|
||||||
|
.result-panel,
|
||||||
|
.viewport-panel,
|
||||||
|
.timeline {
|
||||||
|
border: 1px solid rgba(31, 41, 38, 0.12);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: rgba(255, 255, 255, 0.78);
|
||||||
|
box-shadow: 0 18px 42px rgba(15, 23, 42, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-form,
|
||||||
|
.result-panel {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 15px;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-heading {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-heading h2 {
|
||||||
|
margin: 2px 0 0;
|
||||||
|
color: #15211e;
|
||||||
|
font-size: 19px;
|
||||||
|
line-height: 1.22;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-label {
|
||||||
|
display: block;
|
||||||
|
color: #60706b;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 7px;
|
||||||
|
min-width: 0;
|
||||||
|
color: #52625d;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-inline {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 92px minmax(0, 1fr) 44px;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input,
|
||||||
|
textarea,
|
||||||
|
select {
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #16231f;
|
||||||
|
border: 1px solid rgba(31, 41, 38, 0.14);
|
||||||
|
border-radius: 7px;
|
||||||
|
background: rgba(255, 255, 255, 0.9);
|
||||||
|
outline: none;
|
||||||
|
font: 14px/1.35 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||||
|
letter-spacing: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
input,
|
||||||
|
select {
|
||||||
|
height: 38px;
|
||||||
|
padding: 0 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
min-height: 88px;
|
||||||
|
resize: vertical;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus,
|
||||||
|
textarea:focus,
|
||||||
|
select:focus {
|
||||||
|
border-color: rgba(20, 184, 166, 0.72);
|
||||||
|
box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.14);
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmented {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 5px;
|
||||||
|
padding: 4px;
|
||||||
|
border: 1px solid rgba(31, 41, 38, 0.12);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #eef4f1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmented button {
|
||||||
|
display: inline-flex;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-height: 30px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 0 8px;
|
||||||
|
color: #566662;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmented button.selected {
|
||||||
|
color: #0f211d;
|
||||||
|
background: #ffffff;
|
||||||
|
box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-row,
|
||||||
|
.button-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle {
|
||||||
|
display: inline-flex;
|
||||||
|
min-height: 38px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: #4d5d58;
|
||||||
|
border: 1px solid rgba(31, 41, 38, 0.13);
|
||||||
|
border-radius: 7px;
|
||||||
|
background: #ffffff;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
width: 28px;
|
||||||
|
height: 16px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: #cfd9d4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch::after {
|
||||||
|
position: absolute;
|
||||||
|
top: 3px;
|
||||||
|
left: 3px;
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
content: '';
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #ffffff;
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle.checked .switch {
|
||||||
|
background: #14b8a6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle.checked .switch::after {
|
||||||
|
transform: translateX(12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.submit-button,
|
||||||
|
.primary-link,
|
||||||
|
.secondary-button,
|
||||||
|
.secondary-link {
|
||||||
|
display: inline-flex;
|
||||||
|
min-height: 40px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 0 12px;
|
||||||
|
border-radius: 7px;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submit-button,
|
||||||
|
.primary-link {
|
||||||
|
color: #06201c;
|
||||||
|
border: 1px solid rgba(20, 184, 166, 0.42);
|
||||||
|
background: linear-gradient(135deg, #67f2dc, #d9f99d);
|
||||||
|
box-shadow: 0 12px 22px rgba(20, 184, 166, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.submit-button:disabled {
|
||||||
|
cursor: wait;
|
||||||
|
opacity: 0.72;
|
||||||
|
}
|
||||||
|
|
||||||
|
.secondary-button,
|
||||||
|
.secondary-link {
|
||||||
|
color: #25312e;
|
||||||
|
border: 1px solid rgba(31, 41, 38, 0.14);
|
||||||
|
background: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-stack {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='range'] {
|
||||||
|
height: 22px;
|
||||||
|
padding: 0;
|
||||||
|
accent-color: #14b8a6;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
output {
|
||||||
|
color: #1c2925;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 700;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.viewport-panel {
|
||||||
|
display: flex;
|
||||||
|
min-height: 640px;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.viewport-toolbar {
|
||||||
|
display: flex;
|
||||||
|
min-height: 58px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 14px;
|
||||||
|
padding: 12px 15px;
|
||||||
|
border-bottom: 1px solid rgba(31, 41, 38, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.viewport-toolbar strong {
|
||||||
|
display: block;
|
||||||
|
margin-top: 2px;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mini-link {
|
||||||
|
display: inline-flex;
|
||||||
|
min-width: 44px;
|
||||||
|
min-height: 30px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: #06322c;
|
||||||
|
border: 1px solid rgba(20, 184, 166, 0.34);
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #ecfffb;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 800;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvas-wrap {
|
||||||
|
min-height: 0;
|
||||||
|
flex: 1;
|
||||||
|
background:
|
||||||
|
linear-gradient(90deg, rgba(15, 23, 42, 0.05) 1px, transparent 1px),
|
||||||
|
linear-gradient(0deg, rgba(15, 23, 42, 0.05) 1px, transparent 1px),
|
||||||
|
radial-gradient(circle at center, rgba(94, 234, 212, 0.16), transparent 42%),
|
||||||
|
#f7faf8;
|
||||||
|
background-size: 34px 34px, 34px 34px, auto, auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-panel {
|
||||||
|
min-height: 640px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.render-preview,
|
||||||
|
.render-empty,
|
||||||
|
.empty-panel {
|
||||||
|
display: grid;
|
||||||
|
min-height: 174px;
|
||||||
|
place-items: center;
|
||||||
|
overflow: hidden;
|
||||||
|
color: #60706b;
|
||||||
|
border: 1px solid rgba(31, 41, 38, 0.1);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #f5faf7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.render-preview img {
|
||||||
|
width: 100%;
|
||||||
|
height: 214px;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-meta {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-meta div {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 86px minmax(0, 1fr);
|
||||||
|
gap: 8px;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-meta dt {
|
||||||
|
color: #60706b;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-meta dd {
|
||||||
|
min-width: 0;
|
||||||
|
margin: 0;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
color: #16231f;
|
||||||
|
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-stack {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 9px;
|
||||||
|
margin-top: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-pill {
|
||||||
|
display: inline-flex;
|
||||||
|
min-height: 24px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 0 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 750;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-pending,
|
||||||
|
.status-running {
|
||||||
|
color: #075985;
|
||||||
|
background: #e0f2fe;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-succeeded {
|
||||||
|
color: #047857;
|
||||||
|
background: #dffbed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-failed,
|
||||||
|
.status-canceled,
|
||||||
|
.status-unknown {
|
||||||
|
color: #9f1239;
|
||||||
|
background: #ffe4e6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.asset-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.asset-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 54px minmax(0, 1fr) auto;
|
||||||
|
gap: 11px;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid rgba(31, 41, 38, 0.1);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.asset-row img,
|
||||||
|
.asset-thumb {
|
||||||
|
width: 54px;
|
||||||
|
height: 54px;
|
||||||
|
border-radius: 7px;
|
||||||
|
object-fit: cover;
|
||||||
|
background: #eef4f1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.asset-thumb {
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
color: #60706b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.asset-row strong,
|
||||||
|
.asset-row span {
|
||||||
|
display: block;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.asset-row strong {
|
||||||
|
color: #16231f;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.asset-row span {
|
||||||
|
margin: 2px 0 6px;
|
||||||
|
color: #60706b;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.asset-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.asset-actions button {
|
||||||
|
display: grid;
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
place-items: center;
|
||||||
|
color: #243430;
|
||||||
|
border: 1px solid rgba(31, 41, 38, 0.12);
|
||||||
|
border-radius: 7px;
|
||||||
|
background: #f8fbf9;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline {
|
||||||
|
margin: 0 28px 24px;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 7px;
|
||||||
|
color: #52625d;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 760;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-strip {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
overflow-x: auto;
|
||||||
|
padding: 10px 0 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-strip p {
|
||||||
|
margin: 0;
|
||||||
|
color: #60706b;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-item {
|
||||||
|
display: grid;
|
||||||
|
flex: 0 0 210px;
|
||||||
|
grid-template-columns: minmax(0, 1fr) auto;
|
||||||
|
gap: 4px 8px;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10px;
|
||||||
|
text-align: left;
|
||||||
|
border: 1px solid rgba(31, 41, 38, 0.11);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #ffffff;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-item.selected {
|
||||||
|
border-color: rgba(20, 184, 166, 0.48);
|
||||||
|
box-shadow: inset 0 0 0 1px rgba(20, 184, 166, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-item span:first-child {
|
||||||
|
color: #60706b;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-item strong {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
overflow: hidden;
|
||||||
|
color: #17231f;
|
||||||
|
font-size: 13px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1180px) {
|
||||||
|
.topbar {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs {
|
||||||
|
justify-content: flex-start;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-actions {
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workbench {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.viewport-panel,
|
||||||
|
.result-panel {
|
||||||
|
min-height: 500px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 680px) {
|
||||||
|
.topbar,
|
||||||
|
.workbench {
|
||||||
|
padding-right: 14px;
|
||||||
|
padding-left: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button {
|
||||||
|
min-width: max-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-row,
|
||||||
|
.toggle-row,
|
||||||
|
.button-grid,
|
||||||
|
.image-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-inline {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline {
|
||||||
|
margin-right: 14px;
|
||||||
|
margin-left: 14px;
|
||||||
|
}
|
||||||
|
}
|
||||||
756
src/App.tsx
Normal file
756
src/App.tsx
Normal file
@ -0,0 +1,756 @@
|
|||||||
|
import {
|
||||||
|
AlertTriangle,
|
||||||
|
Box,
|
||||||
|
BrainCircuit,
|
||||||
|
CheckCircle2,
|
||||||
|
Database,
|
||||||
|
Download,
|
||||||
|
ExternalLink,
|
||||||
|
Image,
|
||||||
|
Languages,
|
||||||
|
Layers,
|
||||||
|
RefreshCw,
|
||||||
|
SlidersHorizontal,
|
||||||
|
Sparkles,
|
||||||
|
Waves,
|
||||||
|
} from 'lucide-react'
|
||||||
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
|
import { Viewport3D } from './components/Viewport3D'
|
||||||
|
import {
|
||||||
|
createFlexTask,
|
||||||
|
createGenerationTask,
|
||||||
|
getModelUrl,
|
||||||
|
getPrimaryResult,
|
||||||
|
getSourcePrompt,
|
||||||
|
health,
|
||||||
|
isLiveStatus,
|
||||||
|
listTasks,
|
||||||
|
refreshTask,
|
||||||
|
type FlexRequest,
|
||||||
|
type GenerationRequest,
|
||||||
|
type SimulationProfile,
|
||||||
|
type StoredTask,
|
||||||
|
type TaskStatus,
|
||||||
|
} from './lib/api'
|
||||||
|
import { downloadJson } from './lib/download'
|
||||||
|
import { getInitialLocale, messages, type Locale, type Messages } from './lib/i18n'
|
||||||
|
import './App.css'
|
||||||
|
|
||||||
|
type TabId = 'generation' | 'flex' | 'library'
|
||||||
|
type GenerationMode = GenerationRequest['mode']
|
||||||
|
type TripoModel = GenerationRequest['model']
|
||||||
|
|
||||||
|
const defaultParameters: GenerationRequest['parameters'] = {
|
||||||
|
texture_quality: 'detailed',
|
||||||
|
geometry_quality: 'standard',
|
||||||
|
pbr: true,
|
||||||
|
texture: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultSimulation: SimulationProfile = {
|
||||||
|
material: 'silicone',
|
||||||
|
elasticity: 72,
|
||||||
|
damping: 42,
|
||||||
|
thickness: 3.2,
|
||||||
|
deformation: 64,
|
||||||
|
gravity: 9.8,
|
||||||
|
}
|
||||||
|
|
||||||
|
const imageLabels = ['front', 'left', 'back', 'right'] as const
|
||||||
|
|
||||||
|
function statusText(status: TaskStatus | undefined, t: Messages) {
|
||||||
|
const key = (status || 'UNKNOWN').toLowerCase() as 'pending' | 'running' | 'succeeded' | 'failed' | 'canceled' | 'unknown'
|
||||||
|
return t.task[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTime(value?: string) {
|
||||||
|
if (!value) return '-'
|
||||||
|
return new Intl.DateTimeFormat('zh-CN', {
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
}).format(new Date(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
function Field({
|
||||||
|
label,
|
||||||
|
children,
|
||||||
|
inline = false,
|
||||||
|
}: {
|
||||||
|
label: string
|
||||||
|
children: React.ReactNode
|
||||||
|
inline?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<label className={inline ? 'field field-inline' : 'field'}>
|
||||||
|
<span>{label}</span>
|
||||||
|
{children}
|
||||||
|
</label>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Segmented<T extends string>({
|
||||||
|
value,
|
||||||
|
options,
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
value: T
|
||||||
|
options: Array<{ value: T; label: string; icon?: React.ReactNode }>
|
||||||
|
onChange: (value: T) => void
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="segmented">
|
||||||
|
{options.map((option) => (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
key={option.value}
|
||||||
|
className={value === option.value ? 'selected' : ''}
|
||||||
|
onClick={() => onChange(option.value)}
|
||||||
|
>
|
||||||
|
{option.icon}
|
||||||
|
<span>{option.label}</span>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Toggle({
|
||||||
|
checked,
|
||||||
|
label,
|
||||||
|
disabled,
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
checked: boolean
|
||||||
|
label: string
|
||||||
|
disabled?: boolean
|
||||||
|
onChange: (value: boolean) => void
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`toggle ${checked ? 'checked' : ''}`}
|
||||||
|
disabled={disabled}
|
||||||
|
onClick={() => onChange(!checked)}
|
||||||
|
aria-pressed={checked}
|
||||||
|
>
|
||||||
|
<span className="switch" />
|
||||||
|
{label}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function StatusPill({ status, t }: { status?: TaskStatus; t: Messages }) {
|
||||||
|
const normalized = (status || 'UNKNOWN').toLowerCase()
|
||||||
|
return <span className={`status-pill status-${normalized}`}>{statusText(status, t)}</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
function TaskPanel({
|
||||||
|
task,
|
||||||
|
busy,
|
||||||
|
onRefresh,
|
||||||
|
onUseForFlex,
|
||||||
|
t,
|
||||||
|
}: {
|
||||||
|
task?: StoredTask | null
|
||||||
|
busy: boolean
|
||||||
|
onRefresh: (taskId: string) => void
|
||||||
|
onUseForFlex: (task: StoredTask) => void
|
||||||
|
t: Messages
|
||||||
|
}) {
|
||||||
|
const result = getPrimaryResult(task)
|
||||||
|
const modelUrl = getModelUrl(task)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<aside className="result-panel">
|
||||||
|
<div className="panel-heading">
|
||||||
|
<div>
|
||||||
|
<span className="panel-label">{t.task.title}</span>
|
||||||
|
<h2>{task ? t.task.current : t.task.noTask}</h2>
|
||||||
|
</div>
|
||||||
|
{task ? <StatusPill status={task.status} t={t} /> : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{task ? (
|
||||||
|
<>
|
||||||
|
{result?.rendered_image_url ? (
|
||||||
|
<a href={result.rendered_image_url} target="_blank" rel="noreferrer" className="render-preview">
|
||||||
|
<img src={result.rendered_image_url} alt={t.task.rendered} />
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<div className="render-empty">
|
||||||
|
<Box size={28} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<dl className="task-meta">
|
||||||
|
<div>
|
||||||
|
<dt>{t.task.taskId}</dt>
|
||||||
|
<dd>{task.taskId}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>{t.task.status}</dt>
|
||||||
|
<dd>{statusText(task.status, t)}</dd>
|
||||||
|
</div>
|
||||||
|
{task.requestId ? (
|
||||||
|
<div>
|
||||||
|
<dt>{t.task.requestId}</dt>
|
||||||
|
<dd>{task.requestId}</dd>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<div className="button-stack">
|
||||||
|
<button type="button" className="secondary-button" onClick={() => onRefresh(task.taskId)} disabled={busy}>
|
||||||
|
<RefreshCw size={16} />
|
||||||
|
{t.task.poll}
|
||||||
|
</button>
|
||||||
|
{result?.pbr_model_url ? (
|
||||||
|
<a href={result.pbr_model_url} className="primary-link" target="_blank" rel="noreferrer">
|
||||||
|
<Download size={16} />
|
||||||
|
{t.task.downloadPbr}
|
||||||
|
</a>
|
||||||
|
) : null}
|
||||||
|
{result?.base_model_url ? (
|
||||||
|
<a href={result.base_model_url} className="secondary-link" target="_blank" rel="noreferrer">
|
||||||
|
<Download size={16} />
|
||||||
|
{t.task.downloadBase}
|
||||||
|
</a>
|
||||||
|
) : null}
|
||||||
|
{modelUrl ? (
|
||||||
|
<button type="button" className="secondary-button" onClick={() => onUseForFlex(task)}>
|
||||||
|
<Waves size={16} />
|
||||||
|
{t.library.useForFlex}
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<div className="empty-panel">
|
||||||
|
<Sparkles size={28} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</aside>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Timeline({
|
||||||
|
tasks,
|
||||||
|
currentTaskId,
|
||||||
|
onSelect,
|
||||||
|
t,
|
||||||
|
}: {
|
||||||
|
tasks: StoredTask[]
|
||||||
|
currentTaskId?: string
|
||||||
|
onSelect: (task: StoredTask) => void
|
||||||
|
t: Messages
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<section className="timeline">
|
||||||
|
<div className="timeline-title">
|
||||||
|
<Database size={16} />
|
||||||
|
<span>{t.timeline.title}</span>
|
||||||
|
</div>
|
||||||
|
<div className="timeline-strip">
|
||||||
|
{tasks.length ? (
|
||||||
|
tasks.slice(0, 10).map((task) => (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
key={task.taskId}
|
||||||
|
className={task.taskId === currentTaskId ? 'timeline-item selected' : 'timeline-item'}
|
||||||
|
onClick={() => onSelect(task)}
|
||||||
|
>
|
||||||
|
<span>{task.kind === 'flex' ? t.tabs.flex : t.tabs.generation}</span>
|
||||||
|
<strong>{task.title}</strong>
|
||||||
|
<StatusPill status={task.status} t={t} />
|
||||||
|
</button>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<p>{t.timeline.empty}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
const [locale, setLocale] = useState<Locale>(getInitialLocale)
|
||||||
|
const t = messages[locale]
|
||||||
|
const [activeTab, setActiveTab] = useState<TabId>('generation')
|
||||||
|
const [apiConfigured, setApiConfigured] = useState(false)
|
||||||
|
const [tasks, setTasks] = useState<StoredTask[]>([])
|
||||||
|
const [currentTask, setCurrentTask] = useState<StoredTask | null>(null)
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
|
||||||
|
const [mode, setMode] = useState<GenerationMode>('text')
|
||||||
|
const [model, setModel] = useState<TripoModel>('Tripo/Tripo-H3.1')
|
||||||
|
const [prompt, setPrompt] = useState('一只由柔性硅胶制成的机器人夹爪,带有清晰的传感器细节')
|
||||||
|
const [imageUrl, setImageUrl] = useState('')
|
||||||
|
const [imageSlots, setImageSlots] = useState([
|
||||||
|
{ type: 'png' as const, file_token: '' },
|
||||||
|
{ type: 'png' as const, file_token: '' },
|
||||||
|
{ type: 'png' as const, file_token: '' },
|
||||||
|
{ type: 'png' as const, file_token: '' },
|
||||||
|
])
|
||||||
|
const [parameters, setParameters] = useState<GenerationRequest['parameters']>(defaultParameters)
|
||||||
|
|
||||||
|
const [sourceTaskId, setSourceTaskId] = useState('')
|
||||||
|
const [sourceName, setSourceName] = useState('')
|
||||||
|
const [sourcePrompt, setSourcePrompt] = useState('')
|
||||||
|
const [sourceModelUrl, setSourceModelUrl] = useState('')
|
||||||
|
const [behaviorPrompt, setBehaviorPrompt] = useState('保持原始结构比例,转化为适合抓取、挤压和碰撞仿真的柔性版本')
|
||||||
|
const [simulation, setSimulation] = useState<SimulationProfile>(defaultSimulation)
|
||||||
|
const [lastSimulationExport, setLastSimulationExport] = useState<Record<string, unknown> | null>(null)
|
||||||
|
|
||||||
|
const successfulTasks = useMemo(() => tasks.filter((task) => getModelUrl(task)), [tasks])
|
||||||
|
|
||||||
|
const loadTasks = useCallback(async () => {
|
||||||
|
const response = await listTasks()
|
||||||
|
setTasks(response.tasks)
|
||||||
|
setCurrentTask((current) => {
|
||||||
|
if (!current) return response.tasks[0] ?? null
|
||||||
|
return response.tasks.find((task) => task.taskId === current.taskId) ?? current
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
health()
|
||||||
|
.then((response) => setApiConfigured(response.apiConfigured))
|
||||||
|
.catch(() => setApiConfigured(false))
|
||||||
|
loadTasks().catch((loadError) => setError(loadError instanceof Error ? loadError.message : t.errors.generic))
|
||||||
|
}, [loadTasks, t.errors.generic])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.localStorage.setItem('real2sim.locale', locale)
|
||||||
|
}, [locale])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!currentTask || !isLiveStatus(currentTask.status)) return
|
||||||
|
const timer = window.setInterval(() => {
|
||||||
|
refreshTask(currentTask.taskId)
|
||||||
|
.then((response) => {
|
||||||
|
setCurrentTask(response.task)
|
||||||
|
setTasks((items) => [response.task, ...items.filter((item) => item.taskId !== response.task.taskId)])
|
||||||
|
})
|
||||||
|
.catch((pollError) => setError(pollError instanceof Error ? pollError.message : t.errors.generic))
|
||||||
|
}, 15000)
|
||||||
|
return () => window.clearInterval(timer)
|
||||||
|
}, [currentTask, t.errors.generic])
|
||||||
|
|
||||||
|
function updateParameters(next: Partial<GenerationRequest['parameters']>) {
|
||||||
|
setParameters((current) => ({ ...current, ...next }))
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectTask(task: StoredTask) {
|
||||||
|
setCurrentTask(task)
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectTaskForFlex(task: StoredTask) {
|
||||||
|
setSourceTaskId(task.taskId)
|
||||||
|
setSourceName(task.title)
|
||||||
|
setSourcePrompt(getSourcePrompt(task))
|
||||||
|
setSourceModelUrl(getModelUrl(task))
|
||||||
|
setActiveTab('flex')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleGenerationSubmit(event: React.FormEvent) {
|
||||||
|
event.preventDefault()
|
||||||
|
setBusy(true)
|
||||||
|
setError('')
|
||||||
|
|
||||||
|
const payload: GenerationRequest = {
|
||||||
|
mode,
|
||||||
|
model,
|
||||||
|
prompt: mode === 'text' ? prompt.trim() : undefined,
|
||||||
|
image: mode === 'image' ? imageUrl.trim() : undefined,
|
||||||
|
images: mode === 'multiImage' ? imageSlots : undefined,
|
||||||
|
parameters,
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await createGenerationTask(payload)
|
||||||
|
setCurrentTask(response.task)
|
||||||
|
await loadTasks()
|
||||||
|
} catch (submitError) {
|
||||||
|
setError(submitError instanceof Error ? submitError.message : t.errors.generic)
|
||||||
|
} finally {
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleFlexSubmit(event: React.FormEvent) {
|
||||||
|
event.preventDefault()
|
||||||
|
setBusy(true)
|
||||||
|
setError('')
|
||||||
|
|
||||||
|
const payload: FlexRequest = {
|
||||||
|
sourceTaskId: sourceTaskId || undefined,
|
||||||
|
sourceName: sourceName || undefined,
|
||||||
|
sourcePrompt: sourcePrompt || undefined,
|
||||||
|
sourceModelUrl: sourceModelUrl || undefined,
|
||||||
|
behaviorPrompt,
|
||||||
|
model: 'Tripo/Tripo-H3.1',
|
||||||
|
parameters: {
|
||||||
|
texture_quality: 'detailed',
|
||||||
|
geometry_quality: 'standard',
|
||||||
|
pbr: true,
|
||||||
|
texture: true,
|
||||||
|
},
|
||||||
|
simulation,
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await createFlexTask(payload)
|
||||||
|
setCurrentTask(response.task)
|
||||||
|
setLastSimulationExport(response.simulationExport)
|
||||||
|
await loadTasks()
|
||||||
|
} catch (submitError) {
|
||||||
|
setError(submitError instanceof Error ? submitError.message : t.errors.generic)
|
||||||
|
} finally {
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleRefreshTask(taskId: string) {
|
||||||
|
setBusy(true)
|
||||||
|
setError('')
|
||||||
|
try {
|
||||||
|
const response = await refreshTask(taskId)
|
||||||
|
setCurrentTask(response.task)
|
||||||
|
await loadTasks()
|
||||||
|
} catch (refreshError) {
|
||||||
|
setError(refreshError instanceof Error ? refreshError.message : t.errors.generic)
|
||||||
|
} finally {
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportSimulation() {
|
||||||
|
const profile =
|
||||||
|
lastSimulationExport ||
|
||||||
|
({
|
||||||
|
schema: 'real2sim.flexProfile.v1',
|
||||||
|
source: {
|
||||||
|
taskId: sourceTaskId || undefined,
|
||||||
|
modelUrl: sourceModelUrl || undefined,
|
||||||
|
prompt: sourcePrompt || undefined,
|
||||||
|
name: sourceName || undefined,
|
||||||
|
},
|
||||||
|
material: simulation.material,
|
||||||
|
physics: {
|
||||||
|
elasticity: simulation.elasticity / 100,
|
||||||
|
damping: simulation.damping / 100,
|
||||||
|
thicknessMm: simulation.thickness,
|
||||||
|
maxDeformation: simulation.deformation / 100,
|
||||||
|
gravity: simulation.gravity,
|
||||||
|
},
|
||||||
|
} satisfies Record<string, unknown>)
|
||||||
|
downloadJson('real2sim-flex-profile.json', profile)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="app-shell">
|
||||||
|
<header className="topbar">
|
||||||
|
<div className="brand">
|
||||||
|
<div className="brand-mark">
|
||||||
|
<Box size={20} />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h1>{t.app.name}</h1>
|
||||||
|
<p>{t.app.subtitle}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<nav className="tabs" aria-label="primary">
|
||||||
|
<button type="button" className={activeTab === 'generation' ? 'active' : ''} onClick={() => setActiveTab('generation')}>
|
||||||
|
<Sparkles size={17} />
|
||||||
|
{t.tabs.generation}
|
||||||
|
</button>
|
||||||
|
<button type="button" className={activeTab === 'flex' ? 'active' : ''} onClick={() => setActiveTab('flex')}>
|
||||||
|
<Waves size={17} />
|
||||||
|
{t.tabs.flex}
|
||||||
|
</button>
|
||||||
|
<button type="button" className={activeTab === 'library' ? 'active' : ''} onClick={() => setActiveTab('library')}>
|
||||||
|
<Database size={17} />
|
||||||
|
{t.tabs.library}
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
<div className="top-actions">
|
||||||
|
<span className={apiConfigured ? 'api-status ready' : 'api-status missing'}>
|
||||||
|
{apiConfigured ? <CheckCircle2 size={15} /> : <AlertTriangle size={15} />}
|
||||||
|
{apiConfigured ? t.app.apiReady : t.app.apiMissing}
|
||||||
|
</span>
|
||||||
|
<button type="button" className="language-button" onClick={() => setLocale(locale === 'zh' ? 'en' : 'zh')}>
|
||||||
|
<Languages size={16} />
|
||||||
|
{locale === 'zh' ? '中文' : 'EN'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
{error ? <div className="error-banner">{error}</div> : null}
|
||||||
|
|
||||||
|
<main className="workbench">
|
||||||
|
<section className="control-panel">
|
||||||
|
{activeTab === 'generation' ? (
|
||||||
|
<form onSubmit={handleGenerationSubmit} className="panel-form">
|
||||||
|
<div className="panel-heading">
|
||||||
|
<div>
|
||||||
|
<span className="panel-label">{t.tabs.generation}</span>
|
||||||
|
<h2>{t.generation.title}</h2>
|
||||||
|
</div>
|
||||||
|
<Sparkles size={22} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Field label={t.generation.mode}>
|
||||||
|
<Segmented<GenerationMode>
|
||||||
|
value={mode}
|
||||||
|
onChange={setMode}
|
||||||
|
options={[
|
||||||
|
{ value: 'text', label: t.generation.text, icon: <BrainCircuit size={15} /> },
|
||||||
|
{ value: 'image', label: t.generation.image, icon: <Image size={15} /> },
|
||||||
|
{ value: 'multiImage', label: t.generation.multiImage, icon: <Layers size={15} /> },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
{mode === 'text' ? (
|
||||||
|
<Field label={t.generation.prompt}>
|
||||||
|
<textarea value={prompt} onChange={(event) => setPrompt(event.target.value)} placeholder={t.generation.promptPlaceholder} />
|
||||||
|
</Field>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{mode === 'image' ? (
|
||||||
|
<Field label={t.generation.imageUrl}>
|
||||||
|
<input value={imageUrl} onChange={(event) => setImageUrl(event.target.value)} placeholder={t.generation.imagePlaceholder} />
|
||||||
|
</Field>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{mode === 'multiImage' ? (
|
||||||
|
<div className="image-grid">
|
||||||
|
{imageSlots.map((slot, index) => (
|
||||||
|
<Field label={t.generation[imageLabels[index]]} key={imageLabels[index]}>
|
||||||
|
<input
|
||||||
|
value={slot.file_token}
|
||||||
|
onChange={(event) =>
|
||||||
|
setImageSlots((items) =>
|
||||||
|
items.map((item, itemIndex) =>
|
||||||
|
itemIndex === index ? { ...item, file_token: event.target.value } : item,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder={t.generation.imagePlaceholder}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<div className="field-row">
|
||||||
|
<Field label={t.generation.model}>
|
||||||
|
<select value={model} onChange={(event) => setModel(event.target.value as TripoModel)}>
|
||||||
|
<option value="Tripo/Tripo-H3.1">Tripo-H3.1</option>
|
||||||
|
<option value="Tripo/Tripo-P1.0">Tripo-P1.0</option>
|
||||||
|
</select>
|
||||||
|
</Field>
|
||||||
|
<Field label={t.generation.geometryQuality}>
|
||||||
|
<select
|
||||||
|
value={parameters.geometry_quality}
|
||||||
|
disabled={model !== 'Tripo/Tripo-H3.1'}
|
||||||
|
onChange={(event) =>
|
||||||
|
updateParameters({ geometry_quality: event.target.value as GenerationRequest['parameters']['geometry_quality'] })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="standard">{t.generation.standard}</option>
|
||||||
|
<option value="ultra">{t.generation.ultra}</option>
|
||||||
|
</select>
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Field label={t.generation.textureQuality}>
|
||||||
|
<Segmented<GenerationRequest['parameters']['texture_quality']>
|
||||||
|
value={parameters.texture_quality}
|
||||||
|
onChange={(value) => updateParameters({ texture_quality: value })}
|
||||||
|
options={[
|
||||||
|
{ value: 'standard', label: t.generation.standard },
|
||||||
|
{ value: 'detailed', label: t.generation.detailed },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<div className="toggle-row">
|
||||||
|
<Toggle
|
||||||
|
checked={parameters.pbr}
|
||||||
|
label={t.generation.pbr}
|
||||||
|
onChange={(value) => updateParameters({ pbr: value, texture: value ? true : parameters.texture })}
|
||||||
|
/>
|
||||||
|
<Toggle
|
||||||
|
checked={parameters.texture}
|
||||||
|
label={t.generation.texture}
|
||||||
|
disabled={parameters.pbr}
|
||||||
|
onChange={(value) => updateParameters({ texture: value, pbr: value ? parameters.pbr : false })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" className="submit-button" disabled={busy}>
|
||||||
|
<Sparkles size={17} />
|
||||||
|
{busy ? t.generation.generating : t.generation.generate}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{activeTab === 'flex' ? (
|
||||||
|
<form onSubmit={handleFlexSubmit} className="panel-form">
|
||||||
|
<div className="panel-heading">
|
||||||
|
<div>
|
||||||
|
<span className="panel-label">{t.tabs.flex}</span>
|
||||||
|
<h2>{t.flex.title}</h2>
|
||||||
|
</div>
|
||||||
|
<Waves size={22} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Field label={t.flex.source}>
|
||||||
|
<select
|
||||||
|
value={sourceTaskId}
|
||||||
|
onChange={(event) => {
|
||||||
|
const selected = tasks.find((task) => task.taskId === event.target.value)
|
||||||
|
if (selected) selectTaskForFlex(selected)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="">{t.flex.chooseSource}</option>
|
||||||
|
{successfulTasks.map((task) => (
|
||||||
|
<option value={task.taskId} key={task.taskId}>
|
||||||
|
{task.title}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field label={t.flex.sourcePrompt}>
|
||||||
|
<textarea value={sourcePrompt} onChange={(event) => setSourcePrompt(event.target.value)} />
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field label={t.flex.sourceModelUrl}>
|
||||||
|
<input value={sourceModelUrl} onChange={(event) => setSourceModelUrl(event.target.value)} />
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field label={t.flex.behavior}>
|
||||||
|
<textarea value={behaviorPrompt} onChange={(event) => setBehaviorPrompt(event.target.value)} placeholder={t.flex.behaviorPlaceholder} />
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Field label={t.flex.material}>
|
||||||
|
<Segmented<SimulationProfile['material']>
|
||||||
|
value={simulation.material}
|
||||||
|
onChange={(material) => setSimulation((current) => ({ ...current, material }))}
|
||||||
|
options={[
|
||||||
|
{ value: 'silicone', label: t.flex.silicone },
|
||||||
|
{ value: 'cloth', label: t.flex.cloth },
|
||||||
|
{ value: 'inflatable', label: t.flex.inflatable },
|
||||||
|
{ value: 'softRobot', label: t.flex.softRobot },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<div className="slider-stack">
|
||||||
|
{[
|
||||||
|
['elasticity', t.flex.elasticity, 0, 100, 1],
|
||||||
|
['damping', t.flex.damping, 0, 100, 1],
|
||||||
|
['thickness', t.flex.thickness, 0.1, 20, 0.1],
|
||||||
|
['deformation', t.flex.deformation, 0, 100, 1],
|
||||||
|
['gravity', t.flex.gravity, 0, 30, 0.1],
|
||||||
|
].map(([key, label, min, max, step]) => (
|
||||||
|
<Field label={label as string} inline key={key as string}>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min={min as number}
|
||||||
|
max={max as number}
|
||||||
|
step={step as number}
|
||||||
|
value={simulation[key as keyof SimulationProfile] as number}
|
||||||
|
onChange={(event) =>
|
||||||
|
setSimulation((current) => ({
|
||||||
|
...current,
|
||||||
|
[key as keyof SimulationProfile]: Number(event.target.value),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<output>{simulation[key as keyof SimulationProfile]}</output>
|
||||||
|
</Field>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="button-grid">
|
||||||
|
<button type="submit" className="submit-button" disabled={busy}>
|
||||||
|
<Waves size={17} />
|
||||||
|
{busy ? t.generation.generating : t.flex.generate}
|
||||||
|
</button>
|
||||||
|
<button type="button" className="secondary-button" onClick={exportSimulation}>
|
||||||
|
<SlidersHorizontal size={17} />
|
||||||
|
{t.flex.export}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{activeTab === 'library' ? (
|
||||||
|
<section className="panel-form">
|
||||||
|
<div className="panel-heading">
|
||||||
|
<div>
|
||||||
|
<span className="panel-label">{t.tabs.library}</span>
|
||||||
|
<h2>{t.library.title}</h2>
|
||||||
|
</div>
|
||||||
|
<Database size={22} />
|
||||||
|
</div>
|
||||||
|
<div className="asset-list">
|
||||||
|
{tasks.length ? (
|
||||||
|
tasks.map((task) => {
|
||||||
|
const result = getPrimaryResult(task)
|
||||||
|
const modelUrl = getModelUrl(task)
|
||||||
|
return (
|
||||||
|
<article className="asset-row" key={task.taskId}>
|
||||||
|
{result?.rendered_image_url ? (
|
||||||
|
<img src={result.rendered_image_url} alt="" />
|
||||||
|
) : (
|
||||||
|
<div className="asset-thumb">
|
||||||
|
<Box size={18} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div>
|
||||||
|
<strong>{task.title}</strong>
|
||||||
|
<span>{formatTime(task.createdAt)}</span>
|
||||||
|
<StatusPill status={task.status} t={t} />
|
||||||
|
</div>
|
||||||
|
<div className="asset-actions">
|
||||||
|
<button type="button" onClick={() => selectTask(task)}>
|
||||||
|
<ExternalLink size={15} />
|
||||||
|
</button>
|
||||||
|
{modelUrl ? (
|
||||||
|
<button type="button" onClick={() => selectTaskForFlex(task)}>
|
||||||
|
<Waves size={15} />
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<div className="empty-panel">
|
||||||
|
<Database size={28} />
|
||||||
|
<span>{t.library.empty}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
) : null}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<Viewport3D task={currentTask} simulation={simulation} labels={t.viewport} />
|
||||||
|
|
||||||
|
<TaskPanel task={currentTask} busy={busy} onRefresh={handleRefreshTask} onUseForFlex={selectTaskForFlex} t={t} />
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<Timeline tasks={tasks} currentTaskId={currentTask?.taskId} onSelect={selectTask} t={t} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App
|
||||||
95
src/components/Viewport3D.tsx
Normal file
95
src/components/Viewport3D.tsx
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
import { Environment, Float, MeshDistortMaterial, OrbitControls, ContactShadows } from '@react-three/drei'
|
||||||
|
import { Canvas, useFrame } from '@react-three/fiber'
|
||||||
|
import { useRef } from 'react'
|
||||||
|
import type { Mesh } from 'three'
|
||||||
|
import type { SimulationProfile, StoredTask } from '../lib/api'
|
||||||
|
import { getModelUrl } from '../lib/api'
|
||||||
|
import type { Messages } from '../lib/i18n'
|
||||||
|
|
||||||
|
type Viewport3DProps = {
|
||||||
|
task?: StoredTask | null
|
||||||
|
simulation: SimulationProfile
|
||||||
|
labels: Messages['viewport']
|
||||||
|
}
|
||||||
|
|
||||||
|
function SoftBody({ simulation }: { simulation: SimulationProfile }) {
|
||||||
|
const meshRef = useRef<Mesh>(null)
|
||||||
|
const distort = 0.14 + simulation.deformation / 220
|
||||||
|
const speed = 0.75 + simulation.elasticity / 80
|
||||||
|
|
||||||
|
useFrame(({ clock }) => {
|
||||||
|
const mesh = meshRef.current
|
||||||
|
if (!mesh) return
|
||||||
|
mesh.rotation.y = clock.elapsedTime * 0.28
|
||||||
|
mesh.rotation.x = Math.sin(clock.elapsedTime * 0.45) * 0.08
|
||||||
|
const squeeze = 1 + Math.sin(clock.elapsedTime * speed) * (simulation.elasticity / 900)
|
||||||
|
mesh.scale.set(1.25 / squeeze, 0.92 * squeeze, 1.05)
|
||||||
|
})
|
||||||
|
|
||||||
|
const colorByMaterial = {
|
||||||
|
silicone: '#5eead4',
|
||||||
|
cloth: '#f97373',
|
||||||
|
inflatable: '#a3e635',
|
||||||
|
softRobot: '#7dd3fc',
|
||||||
|
}[simulation.material]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Float speed={1.15} rotationIntensity={0.35} floatIntensity={0.32}>
|
||||||
|
<mesh ref={meshRef} castShadow receiveShadow position={[0, 0.25, 0]}>
|
||||||
|
<icosahedronGeometry args={[1.45, 18]} />
|
||||||
|
<MeshDistortMaterial
|
||||||
|
color={colorByMaterial}
|
||||||
|
distort={distort}
|
||||||
|
speed={speed}
|
||||||
|
roughness={0.46}
|
||||||
|
metalness={0.03}
|
||||||
|
clearcoat={0.36}
|
||||||
|
/>
|
||||||
|
</mesh>
|
||||||
|
</Float>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function StageGrid() {
|
||||||
|
return (
|
||||||
|
<group>
|
||||||
|
<mesh rotation={[-Math.PI / 2, 0, 0]} position={[0, -1.12, 0]} receiveShadow>
|
||||||
|
<planeGeometry args={[7.2, 7.2, 18, 18]} />
|
||||||
|
<meshStandardMaterial color="#eef2ef" roughness={0.9} />
|
||||||
|
</mesh>
|
||||||
|
<gridHelper args={[7.2, 18, '#a7b0aa', '#dde4df']} position={[0, -1.1, 0]} />
|
||||||
|
</group>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Viewport3D({ task, simulation, labels }: Viewport3DProps) {
|
||||||
|
const modelUrl = getModelUrl(task)
|
||||||
|
const status = modelUrl ? labels.modelReady : task ? labels.preview : labels.idle
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className="viewport-panel" aria-label={labels.label}>
|
||||||
|
<div className="viewport-toolbar">
|
||||||
|
<div>
|
||||||
|
<span className="panel-label">{labels.label}</span>
|
||||||
|
<strong>{status}</strong>
|
||||||
|
</div>
|
||||||
|
{modelUrl ? (
|
||||||
|
<a href={modelUrl} target="_blank" rel="noreferrer" className="mini-link">
|
||||||
|
GLB
|
||||||
|
</a>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
<div className="canvas-wrap">
|
||||||
|
<Canvas camera={{ position: [3.7, 2.5, 4.2], fov: 42 }} gl={{ preserveDrawingBuffer: true, antialias: true }} shadows>
|
||||||
|
<ambientLight intensity={0.72} />
|
||||||
|
<directionalLight position={[4, 5, 3]} intensity={2.1} castShadow />
|
||||||
|
<SoftBody simulation={simulation} />
|
||||||
|
<StageGrid />
|
||||||
|
<ContactShadows position={[0, -1.08, 0]} opacity={0.28} scale={5} blur={2.4} far={3} />
|
||||||
|
<Environment preset="studio" />
|
||||||
|
<OrbitControls enablePan={false} minDistance={3.4} maxDistance={8} />
|
||||||
|
</Canvas>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
42
src/index.css
Normal file
42
src/index.css
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
:root {
|
||||||
|
font-family:
|
||||||
|
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
|
||||||
|
"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
|
||||||
|
color: #18211f;
|
||||||
|
background: #f5f8f6;
|
||||||
|
font-synthesis: none;
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
min-width: 320px;
|
||||||
|
background: #f5f8f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
min-width: 320px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
button,
|
||||||
|
a,
|
||||||
|
input,
|
||||||
|
textarea,
|
||||||
|
select {
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:focus-visible,
|
||||||
|
a:focus-visible,
|
||||||
|
input:focus-visible,
|
||||||
|
textarea:focus-visible,
|
||||||
|
select:focus-visible {
|
||||||
|
outline: 2px solid rgba(20, 184, 166, 0.75);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
125
src/lib/api.ts
Normal file
125
src/lib/api.ts
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
export type TaskStatus = 'PENDING' | 'RUNNING' | 'SUCCEEDED' | 'FAILED' | 'CANCELED' | 'UNKNOWN'
|
||||||
|
|
||||||
|
export type TripoTaskResult = {
|
||||||
|
pbr_model_url?: string
|
||||||
|
base_model_url?: string
|
||||||
|
rendered_image_url?: string
|
||||||
|
orig_prompt?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TripoTaskOutput = {
|
||||||
|
task_id: string
|
||||||
|
task_status: TaskStatus
|
||||||
|
submit_time?: string
|
||||||
|
scheduled_time?: string
|
||||||
|
end_time?: string
|
||||||
|
results?: TripoTaskResult[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StoredTask = {
|
||||||
|
taskId: string
|
||||||
|
kind: 'generation' | 'flex'
|
||||||
|
title: string
|
||||||
|
status: TaskStatus
|
||||||
|
requestId?: string
|
||||||
|
request: Record<string, unknown>
|
||||||
|
output?: TripoTaskOutput
|
||||||
|
usage?: Record<string, unknown>
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SimulationProfile = {
|
||||||
|
material: 'silicone' | 'cloth' | 'inflatable' | 'softRobot'
|
||||||
|
elasticity: number
|
||||||
|
damping: number
|
||||||
|
thickness: number
|
||||||
|
deformation: number
|
||||||
|
gravity: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GenerationRequest = {
|
||||||
|
mode: 'text' | 'image' | 'multiImage'
|
||||||
|
model: 'Tripo/Tripo-H3.1' | 'Tripo/Tripo-P1.0'
|
||||||
|
prompt?: string
|
||||||
|
image?: string
|
||||||
|
images?: Array<{ type: 'jpeg' | 'png'; file_token: string }>
|
||||||
|
parameters: {
|
||||||
|
texture_quality: 'standard' | 'detailed'
|
||||||
|
geometry_quality: 'standard' | 'ultra'
|
||||||
|
pbr: boolean
|
||||||
|
texture: boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FlexRequest = {
|
||||||
|
sourceTaskId?: string
|
||||||
|
sourceName?: string
|
||||||
|
sourcePrompt?: string
|
||||||
|
sourceModelUrl?: string
|
||||||
|
behaviorPrompt?: string
|
||||||
|
model: GenerationRequest['model']
|
||||||
|
parameters: GenerationRequest['parameters']
|
||||||
|
simulation: SimulationProfile
|
||||||
|
}
|
||||||
|
|
||||||
|
async function requestJson<T>(url: string, options?: RequestInit): Promise<T> {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
...options,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...options?.headers,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const body = await response.json().catch(() => ({}))
|
||||||
|
if (!response.ok) {
|
||||||
|
const message = body?.error || body?.message || `HTTP ${response.status}`
|
||||||
|
throw new Error(message)
|
||||||
|
}
|
||||||
|
return body as T
|
||||||
|
}
|
||||||
|
|
||||||
|
export function health() {
|
||||||
|
return requestJson<{ ok: boolean; apiConfigured: boolean; defaultModel: string }>('/api/health')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listTasks() {
|
||||||
|
return requestJson<{ tasks: StoredTask[] }>('/api/tripo/tasks')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createGenerationTask(payload: GenerationRequest) {
|
||||||
|
return requestJson<{ task: StoredTask }>('/api/tripo/tasks', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function refreshTask(taskId: string) {
|
||||||
|
return requestJson<{ task: StoredTask }>(`/api/tripo/tasks/${encodeURIComponent(taskId)}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createFlexTask(payload: FlexRequest) {
|
||||||
|
return requestJson<{ task: StoredTask; prompt: string; simulationExport: Record<string, unknown> }>('/api/flex/tasks', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPrimaryResult(task?: StoredTask | null) {
|
||||||
|
return task?.output?.results?.[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getModelUrl(task?: StoredTask | null) {
|
||||||
|
const result = getPrimaryResult(task)
|
||||||
|
return result?.pbr_model_url || result?.base_model_url || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSourcePrompt(task?: StoredTask | null) {
|
||||||
|
const resultPrompt = getPrimaryResult(task)?.orig_prompt
|
||||||
|
const requestPrompt = typeof task?.request?.prompt === 'string' ? task.request.prompt : ''
|
||||||
|
return resultPrompt || requestPrompt || task?.title || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isLiveStatus(status?: TaskStatus) {
|
||||||
|
return status === 'PENDING' || status === 'RUNNING'
|
||||||
|
}
|
||||||
9
src/lib/download.ts
Normal file
9
src/lib/download.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export function downloadJson(filename: string, data: unknown) {
|
||||||
|
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' })
|
||||||
|
const url = URL.createObjectURL(blob)
|
||||||
|
const anchor = document.createElement('a')
|
||||||
|
anchor.href = url
|
||||||
|
anchor.download = filename
|
||||||
|
anchor.click()
|
||||||
|
URL.revokeObjectURL(url)
|
||||||
|
}
|
||||||
224
src/lib/i18n.ts
Normal file
224
src/lib/i18n.ts
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
export type Locale = 'zh' | 'en'
|
||||||
|
|
||||||
|
const dictionaries = {
|
||||||
|
zh: {
|
||||||
|
app: {
|
||||||
|
name: 'real2sim 平台',
|
||||||
|
subtitle: 'Tripo H3.1 资产生成与柔性仿真工作台',
|
||||||
|
apiReady: 'API 已配置',
|
||||||
|
apiMissing: 'API 未配置',
|
||||||
|
language: '语言',
|
||||||
|
refresh: '刷新',
|
||||||
|
},
|
||||||
|
tabs: {
|
||||||
|
generation: '模型生成',
|
||||||
|
flex: '柔性物体',
|
||||||
|
library: '资产库',
|
||||||
|
},
|
||||||
|
generation: {
|
||||||
|
title: 'Tripo 3D 生成',
|
||||||
|
mode: '输入方式',
|
||||||
|
text: '文本',
|
||||||
|
image: '单图',
|
||||||
|
multiImage: '多图',
|
||||||
|
prompt: '提示词',
|
||||||
|
promptPlaceholder: '例如:一只带有工业传感器的柔性机器人夹爪',
|
||||||
|
imageUrl: '公网图片 URL',
|
||||||
|
imagePlaceholder: 'https://example.com/object.png',
|
||||||
|
front: '前视图',
|
||||||
|
left: '左视图',
|
||||||
|
back: '后视图',
|
||||||
|
right: '右视图',
|
||||||
|
model: '模型',
|
||||||
|
textureQuality: '贴图质量',
|
||||||
|
geometryQuality: '几何精度',
|
||||||
|
standard: '标准',
|
||||||
|
detailed: '高清',
|
||||||
|
ultra: '超清',
|
||||||
|
pbr: 'PBR 材质',
|
||||||
|
texture: '生成贴图',
|
||||||
|
generate: '创建任务',
|
||||||
|
generating: '提交中',
|
||||||
|
noTexture: '无贴图',
|
||||||
|
},
|
||||||
|
flex: {
|
||||||
|
title: '柔性物体生成',
|
||||||
|
source: '源资产',
|
||||||
|
sourceModelUrl: '源 GLB',
|
||||||
|
sourcePrompt: '源描述',
|
||||||
|
behavior: '柔性目标',
|
||||||
|
behaviorPlaceholder: '保持原始轮廓,变成可压缩、可弯曲、适合仿真的柔性版本',
|
||||||
|
material: '材料类型',
|
||||||
|
silicone: '软硅胶',
|
||||||
|
cloth: '织物',
|
||||||
|
inflatable: '充气膜',
|
||||||
|
softRobot: '软体机器人',
|
||||||
|
elasticity: '弹性',
|
||||||
|
damping: '阻尼',
|
||||||
|
thickness: '厚度 mm',
|
||||||
|
deformation: '最大形变',
|
||||||
|
gravity: '重力',
|
||||||
|
generate: '生成柔性版本',
|
||||||
|
export: '导出仿真配置',
|
||||||
|
chooseSource: '从资产库选择',
|
||||||
|
},
|
||||||
|
library: {
|
||||||
|
title: '资产库',
|
||||||
|
empty: '暂无任务',
|
||||||
|
useForFlex: '作为柔性源',
|
||||||
|
openModel: '打开 GLB',
|
||||||
|
openImage: '打开预览',
|
||||||
|
createdAt: '创建时间',
|
||||||
|
},
|
||||||
|
task: {
|
||||||
|
title: '任务结果',
|
||||||
|
current: '当前任务',
|
||||||
|
taskId: '任务 ID',
|
||||||
|
requestId: '请求 ID',
|
||||||
|
status: '状态',
|
||||||
|
noTask: '尚未创建任务',
|
||||||
|
poll: '查询状态',
|
||||||
|
downloadPbr: '下载 PBR GLB',
|
||||||
|
downloadBase: '下载基础 GLB',
|
||||||
|
rendered: '渲染预览',
|
||||||
|
pending: '排队中',
|
||||||
|
running: '处理中',
|
||||||
|
succeeded: '成功',
|
||||||
|
failed: '失败',
|
||||||
|
canceled: '已取消',
|
||||||
|
unknown: '未知',
|
||||||
|
},
|
||||||
|
viewport: {
|
||||||
|
label: '3D 预览',
|
||||||
|
modelReady: '模型链接已生成',
|
||||||
|
preview: '软体预览',
|
||||||
|
idle: '等待生成',
|
||||||
|
},
|
||||||
|
timeline: {
|
||||||
|
title: '任务时间线',
|
||||||
|
empty: '暂无历史任务',
|
||||||
|
},
|
||||||
|
errors: {
|
||||||
|
generic: '请求失败',
|
||||||
|
validation: '请检查输入',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
en: {
|
||||||
|
app: {
|
||||||
|
name: 'real2sim Platform',
|
||||||
|
subtitle: 'Tripo H3.1 asset generation and soft simulation workbench',
|
||||||
|
apiReady: 'API configured',
|
||||||
|
apiMissing: 'API missing',
|
||||||
|
language: 'Language',
|
||||||
|
refresh: 'Refresh',
|
||||||
|
},
|
||||||
|
tabs: {
|
||||||
|
generation: 'Model Generation',
|
||||||
|
flex: 'Flexible Object',
|
||||||
|
library: 'Asset Library',
|
||||||
|
},
|
||||||
|
generation: {
|
||||||
|
title: 'Tripo 3D Generation',
|
||||||
|
mode: 'Input Mode',
|
||||||
|
text: 'Text',
|
||||||
|
image: 'Single Image',
|
||||||
|
multiImage: 'Multi Image',
|
||||||
|
prompt: 'Prompt',
|
||||||
|
promptPlaceholder: 'Example: a flexible robot gripper with industrial sensors',
|
||||||
|
imageUrl: 'Public Image URL',
|
||||||
|
imagePlaceholder: 'https://example.com/object.png',
|
||||||
|
front: 'Front',
|
||||||
|
left: 'Left',
|
||||||
|
back: 'Back',
|
||||||
|
right: 'Right',
|
||||||
|
model: 'Model',
|
||||||
|
textureQuality: 'Texture Quality',
|
||||||
|
geometryQuality: 'Geometry Quality',
|
||||||
|
standard: 'Standard',
|
||||||
|
detailed: 'Detailed',
|
||||||
|
ultra: 'Ultra',
|
||||||
|
pbr: 'PBR material',
|
||||||
|
texture: 'Texture',
|
||||||
|
generate: 'Create Task',
|
||||||
|
generating: 'Submitting',
|
||||||
|
noTexture: 'Untextured',
|
||||||
|
},
|
||||||
|
flex: {
|
||||||
|
title: 'Flexible Object Generation',
|
||||||
|
source: 'Source Asset',
|
||||||
|
sourceModelUrl: 'Source GLB',
|
||||||
|
sourcePrompt: 'Source Description',
|
||||||
|
behavior: 'Soft Target',
|
||||||
|
behaviorPlaceholder: 'Preserve the original silhouette as a compressible, bendable simulation-ready variant',
|
||||||
|
material: 'Material',
|
||||||
|
silicone: 'Silicone',
|
||||||
|
cloth: 'Cloth',
|
||||||
|
inflatable: 'Inflatable',
|
||||||
|
softRobot: 'Soft Robot',
|
||||||
|
elasticity: 'Elasticity',
|
||||||
|
damping: 'Damping',
|
||||||
|
thickness: 'Thickness mm',
|
||||||
|
deformation: 'Max Deformation',
|
||||||
|
gravity: 'Gravity',
|
||||||
|
generate: 'Generate Soft Variant',
|
||||||
|
export: 'Export Simulation Profile',
|
||||||
|
chooseSource: 'Choose from Library',
|
||||||
|
},
|
||||||
|
library: {
|
||||||
|
title: 'Asset Library',
|
||||||
|
empty: 'No tasks yet',
|
||||||
|
useForFlex: 'Use as Flex Source',
|
||||||
|
openModel: 'Open GLB',
|
||||||
|
openImage: 'Open Preview',
|
||||||
|
createdAt: 'Created',
|
||||||
|
},
|
||||||
|
task: {
|
||||||
|
title: 'Task Result',
|
||||||
|
current: 'Current Task',
|
||||||
|
taskId: 'Task ID',
|
||||||
|
requestId: 'Request ID',
|
||||||
|
status: 'Status',
|
||||||
|
noTask: 'No task yet',
|
||||||
|
poll: 'Query Status',
|
||||||
|
downloadPbr: 'Download PBR GLB',
|
||||||
|
downloadBase: 'Download Base GLB',
|
||||||
|
rendered: 'Rendered Preview',
|
||||||
|
pending: 'Pending',
|
||||||
|
running: 'Running',
|
||||||
|
succeeded: 'Succeeded',
|
||||||
|
failed: 'Failed',
|
||||||
|
canceled: 'Canceled',
|
||||||
|
unknown: 'Unknown',
|
||||||
|
},
|
||||||
|
viewport: {
|
||||||
|
label: '3D Preview',
|
||||||
|
modelReady: 'Model link generated',
|
||||||
|
preview: 'Soft preview',
|
||||||
|
idle: 'Waiting',
|
||||||
|
},
|
||||||
|
timeline: {
|
||||||
|
title: 'Task Timeline',
|
||||||
|
empty: 'No history yet',
|
||||||
|
},
|
||||||
|
errors: {
|
||||||
|
generic: 'Request failed',
|
||||||
|
validation: 'Check the input',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as const
|
||||||
|
|
||||||
|
type WidenMessages<T> = {
|
||||||
|
readonly [K in keyof T]: T[K] extends string ? string : WidenMessages<T[K]>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Messages = WidenMessages<typeof dictionaries.zh>
|
||||||
|
|
||||||
|
export const messages: Record<Locale, Messages> = dictionaries
|
||||||
|
|
||||||
|
export function getInitialLocale(): Locale {
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
return 'zh'
|
||||||
|
}
|
||||||
|
const saved = window.localStorage.getItem('real2sim.locale')
|
||||||
|
return saved === 'en' ? 'en' : 'zh'
|
||||||
|
}
|
||||||
10
src/main.tsx
Normal file
10
src/main.tsx
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { StrictMode } from 'react'
|
||||||
|
import { createRoot } from 'react-dom/client'
|
||||||
|
import './index.css'
|
||||||
|
import App from './App.tsx'
|
||||||
|
|
||||||
|
createRoot(document.getElementById('root')!).render(
|
||||||
|
<StrictMode>
|
||||||
|
<App />
|
||||||
|
</StrictMode>,
|
||||||
|
)
|
||||||
25
tsconfig.app.json
Normal file
25
tsconfig.app.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||||
|
"target": "es2023",
|
||||||
|
"lib": ["ES2023", "DOM"],
|
||||||
|
"module": "esnext",
|
||||||
|
"types": ["vite/client"],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"erasableSyntaxOnly": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
||||||
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
24
tsconfig.node.json
Normal file
24
tsconfig.node.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||||
|
"target": "es2023",
|
||||||
|
"lib": ["ES2023"],
|
||||||
|
"module": "esnext",
|
||||||
|
"types": ["node"],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"erasableSyntaxOnly": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
},
|
||||||
|
"include": ["vite.config.ts"]
|
||||||
|
}
|
||||||
12
vite.config.ts
Normal file
12
vite.config.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import react from '@vitejs/plugin-react'
|
||||||
|
|
||||||
|
// https://vite.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react()],
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
'/api': 'http://localhost:8787',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user