新增画布3D部分模型

This commit is contained in:
zcr
2026-03-17 16:02:04 +08:00
parent 91688b1686
commit 4728a44ca5
6 changed files with 190 additions and 0 deletions

151
src/routers/generate_3D.py Normal file
View File

@@ -0,0 +1,151 @@
import json
import logging
import httpx
import requests
from fastapi import APIRouter
from src.core.config import settings
from src.schemas.generate_3D import ImageTo3DRequest, ToSVGRequest
from src.schemas.response_template import ResponseModel
router = APIRouter(prefix="/canvas", tags=["Furniture Canvas"])
logger = logging.getLogger(__name__)
@router.post("/img_to_3D")
async def img_to_3D(request_data: ImageTo3DRequest):
"""
### 参数说明:
- **input_images**:输入图片list,单张或多张
- **model**: 推理模式,单张或多张
### 请求体示例:
```json
单张
{
"input_images": ["test/img_to_3d_data/example_multi_image/character_1.png"],
"model": "single"
}
多张
{
"input_imaes": [
"test/img_to_3d_data/example_multi_image/character_1.png",
"test/img_to_3d_data/example_multi_image/character_2.png",
"test/img_to_3d_data/example_multi_image/character_3.png"
],
"model": "multi"
}
```
### 输出示例:
```json
{
"glb_path": "test/3d_result/glb/5ebe2fe118c94946bdc379e4d44799d2.glb",
"glb_static_img_path": "test/3d_result/png/19c4b60ab7594e3f84e58d0169739bd1.png",
"glb_info": {
"file_format": ".glb",
"vertex_count": 7312,
"centroid": [
0.0010040254158151611,
-0.10831894948487081,
0.07473365460649548
],
"bounding_box_min": [
-0.23948338627815247,
-0.38543057441711426,
-0.5015472769737244
],
"bounding_box_max": [
0.228701651096344,
0.37523990869522095,
0.49702101945877075
],
"size": [
0.46818503737449646,
0.7606704831123352,
0.9985682964324951
],
"size_ratio": [
0.21019126841430072,
0.34150235681882596,
0.4483063747668733
],
"size_ratio_percentage": [
21.019126841430072,
34.1502356818826,
44.83063747668733
]
}
}
```
"""
try:
logger.info(
f"img_to_3D request: {json.dumps(request_data.dict(), indent=4)}"
)
input_data = {
"image_paths": request_data.input_images,
"model": request_data.model,
}
async with httpx.AsyncClient(timeout=120) as client:
resp = await client.post(
f"http://{settings.IMAGE_TO_3D_MODEL_URL}/canvas/img_to_3D",
json=input_data
)
result = resp.json()
logger.info(f"img_to_3D response: {json.dumps(result, indent=4)}")
return ResponseModel(data=result)
except Exception as e:
logger.warning(f"img_to_3D Run Exception: {e}")
@router.post("/3d_to_3views")
async def to_3views(request_data: ToSVGRequest):
"""
### 参数说明:
- **minio_glb_path**:glb文件路径
### 请求体示例:
```json
{
"minio_glb_path": "test/3d_result/glb/543570111d344552b080ff6f875e4e83.glb"
}
```
### 输出示例:
```json
{
"minio_svg_path": "test/3d_result/svg/bbcd534cffa143bba418148a0db80ad0.svg"
}
```
"""
try:
logger.info(
f"img_to_3D request: {json.dumps(request_data.dict(), indent=4)}"
)
input_data = {
"minio_glb_path": request_data.minio_glb_path,
}
async with httpx.AsyncClient(timeout=120) as client:
resp = await client.post(
f"http://{settings.IMAGE_TO_3D_MODEL_URL}/canvas/3d_to_3views",
json=input_data
)
result = resp.json()
logger.info(f"img_to_3D response: {json.dumps(result, indent=4)}")
return ResponseModel(data=result)
except Exception as e:
logger.warning(f"img_to_3D Run Exception: {e}")