diff --git a/src/routers/generate_3D.py b/src/routers/generate_3D.py index f77302f..eb3448d 100755 --- a/src/routers/generate_3D.py +++ b/src/routers/generate_3D.py @@ -112,107 +112,6 @@ async def img_to_3D(request_data: ImageTo3DRequest): logger.warning(f"img_to_3D Run Exception: {e}") -@router.post("/img_to_3D_mq") -async def img_to_3d_endpoint(request_data: ImageTo3DRequest): - """ - ### 接口说明: - 将图片转换为3D模型(异步处理)。接口接收请求后立即返回任务ID,后台通过 Celery 处理,处理完成后结果会通过 RabbitMQ 发送。 - - ### 参数说明: - - **input_images**: 输入图片路径列表(支持单张或多张) - - **model**: 推理模式,`single` 表示单张图片,`multi` 表示多张图片融合 - - ### 请求体示例: - **单张图片模式:** - ```json - { - "input_images": ["test/img_to_3d_data/example/character_1.png"], - "model": "single" - } - **多张图片模式:** - ```json - { - "input_images": [ - "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 - { - "code": 200, - "message": "ok", - "data": { - "job_id": "b2c3d4e5-f6g7-8901-hijk-lm2345678901", - "status": "queued", - "message": "任务已进入后台处理" - } - } - ```json - { - "code": 429, - "message": "ok", - "data": { - "status": "queue_full", - "message": "当前 3D 生成请求较多,请稍后重试。", - "queue_length": 10, - "max_length": 10 - } - } - ```json - { - "code": 500, - "message": "ok", - "data": { - "status": "fail", - "message": "提交失败,请稍后重试。", - "error": str(e) - } - } - - - -------------------------------------------------------------------- - RabbitMQ 结果消息说明: - 处理完成后,结果会通过 RabbitMQ 发送到以下位置: - Queue: img_to_3d_results - - 消息格式: - ```json - { - "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", - "status": "completed", // 或 "failed" - "timestamp": "2026-04-01T14:35:22.456789", - "timestamp_unix": 1743510922, - "task_type": "img_to_3d_results", - "result": { - "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.001, -0.108, 0.075], - "size": [0.468, 0.761, 0.999] - } - } - } - status 说明: - completed: 处理成功,result 中包含 3D 模型相关路径和信息 - failed: 处理失败,result 中会包含 error 字段 - """ - result = submit_img_to_3d_task(input_images=request_data.input_images, model=request_data.model) - if result.get("state") == "success": - state_code = 200 - elif result.get("state") == "queue_full": - state_code = 429 - else: - state_code = 500 - - return ResponseModel(data=result, code=state_code) - - @router.post("/3d_to_3views") async def to_3views(request_data: ToSVGRequest): """ @@ -257,6 +156,139 @@ async def to_3views(request_data: ToSVGRequest): logger.warning(f"img_to_3D Run Exception: {e}") +@router.post("/img_to_3D_mq") +async def img_to_3d_endpoint(request_data: ImageTo3DRequest): + """ + ### 接口说明: + 将图片转换为3D模型(异步处理)。接口接收请求后立即返回任务ID,后台通过 Celery 处理,处理完成后结果会通过 RabbitMQ 发送。 + + ### 参数说明: + - **input_images**: 输入图片路径列表(支持单张或多张) + - **model**: 推理模式,`single` 表示单张图片,`multi` 表示多张图片融合 + + ### 请求体示例: + **单张图片模式:** + ```json + { + "input_images": ["test/img_to_3d_data/example/character_1.png"], + "model": "single" + } + ``` + **多张图片模式:** + ```json + { + "input_images": [ + "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 + { + "code": 200, + "message": "ok", + "data": { + "job_id": "b2c3d4e5-f6g7-8901-hijk-lm2345678901", + "status": "queued", + "message": "任务已进入后台处理" + } + } + ``` + ```json + { + "code": 429, + "message": "ok", + "data": { + "status": "queue_full", + "message": "当前 3D 生成请求较多,请稍后重试。", + "queue_length": 10, + "max_length": 10 + } + } + ``` + ```json + { + "code": 500, + "message": "ok", + "data": { + "status": "fail", + "message": "提交失败,请稍后重试。", + "error": str(e) + } + } + ``` + + -------------------------------------------------------------------- + RabbitMQ 结果消息说明: + 处理完成后,结果会通过 RabbitMQ 发送到以下位置: + Queue: img_to_3d_results + + 消息格式: + ```json + { + "job_id": "6d0492dd-f276-4512-913c-134de2ba4b84", + "status": "completed", + "timestamp": "2026-04-01T11:54:31.146435", + "task_type": "img_to_3d_results-prod", + "result": { + "glb_path": "test/3d_result/glb/3d2777e6ac4f48769e5bb4642807bfdb.glb", + "glb_static_img_path": "test/3d_result/png/d54f1fff6b0b48b5ba4604d334aed73b.png", + "glb_info": { + "file_format": ".glb", + "vertex_count": 5519, + "centroid": [ + -0.01005209478665426, + 0.10863836704985305, + -0.011404903160470693 + ], + "bounding_box_min": [ + -0.17623867094516754, + -0.499397873878479, + -0.16439560055732727 + ], + "bounding_box_max": [ + 0.18468153476715088, + 0.5002236366271973, + 0.1541675627231598 + ], + "size": [ + 0.3609202057123184, + 0.9996215105056763, + 0.31856316328048706 + ], + "size_ratio": [ + 0.21494798217733652, + 0.5953300015447786, + 0.189722016277885 + ], + "size_ratio_percentage": [ + 21.494798217733653, + 59.533000154477854, + 18.9722016277885 + ] + } + } + } + ``` + status 说明: + completed: 处理成功,result 中包含 3D 模型相关路径和信息 + failed: 处理失败,result 中会包含 error 字段 + """ + result = submit_img_to_3d_task(input_images=request_data.input_images, model=request_data.model) + if result.get("state") == "success": + state_code = 200 + elif result.get("state") == "queue_full": + state_code = 429 + else: + state_code = 500 + + return ResponseModel(data=result, code=state_code) + + @router.post("/3d_to_3views_mq") async def to_3views(request_data: ToSVGRequest): """ @@ -271,6 +303,7 @@ async def to_3views(request_data: ToSVGRequest): { "minio_glb_path": "test/3d_result/glb/543570111d344552b080ff6f875e4e83.glb" } + ``` ### 输出示例: ```json @@ -283,6 +316,7 @@ async def to_3views(request_data: ToSVGRequest): "message": "任务已进入后台处理" } } + ``` ### 输出示例: ```json @@ -295,6 +329,7 @@ async def to_3views(request_data: ToSVGRequest): "message": "任务已进入后台处理" } } + ``` ```json { "code": 429, @@ -306,6 +341,7 @@ async def to_3views(request_data: ToSVGRequest): "max_length": 10 } } + ``` ```json { "code": 500, @@ -316,23 +352,22 @@ async def to_3views(request_data: ToSVGRequest): "error": str(e) } } + ``` -------------------------------------------------------------------- RabbitMQ 结果消息说明: Queue: three_d_to_3views_results 消息格式: ```json { - "job_id": "b2c3d4e5-f6g7-8901-hijk-lm2345678901", - "status": "completed", // completed 或 failed - "timestamp": "2026-04-01T14:36:15.789012", - "timestamp_unix": 1743510975, + "job_id": "88047a47-6c16-4607-a548-00034b6d56cf", + "status": "completed", + "timestamp": "2026-04-01T12:28:41.026066", "task_type": "three_d_to_3views_results", "result": { - "minio_svg_path": "test/3d_result/svg/bbcd534cffa143bba418148a0db80ad0.svg", - "views": ["front", "side", "top"], - "status": "success" + "minio_svg_path": "test/3d_result/svg/dac119f93b3f46a3ad8a476b608feb71.svg" } } + ``` status 说明: completed: 处理成功,result 中包含转换后的视图图片路径 failed: 处理失败,result 中会包含 "error" 字段