三个提交入口的生成选项映射收敛为单一字段清单
- common::validation 用 tripo_generation_options_from! 由一份字段清单派生三个 From 实现 - multiview 手写的 TripoGenerationOptions 映射改为复用该 From 实现 - 新增共享字段时三条路径一起跟上,缺字段会在编译期报错
This commit is contained in:
@@ -3,6 +3,7 @@ use shared_contracts::model3d::common::{
|
||||
Model3dTextureVersion,
|
||||
};
|
||||
use shared_contracts::model3d::image_to_model::Model3dImageToModelParams;
|
||||
use shared_contracts::model3d::multiview_to_model::Model3dMultiviewToModelRequest;
|
||||
use shared_contracts::model3d::text_to_model::Model3dTextToModelParams;
|
||||
|
||||
use super::{TripoError, TripoField, TripoTaskHandle, TripoValidationReason};
|
||||
@@ -22,42 +23,46 @@ pub(crate) struct TripoGenerationOptions {
|
||||
pub compress: Option<Model3dCompression>,
|
||||
}
|
||||
|
||||
impl From<&Model3dTextToModelParams> for TripoGenerationOptions {
|
||||
fn from(params: &Model3dTextToModelParams) -> Self {
|
||||
Self {
|
||||
model: params.model,
|
||||
texture: params.texture,
|
||||
pbr: params.pbr,
|
||||
texture_quality: params.texture_quality,
|
||||
texture_version: params.texture_version,
|
||||
geometry_quality: params.geometry_quality,
|
||||
face_limit: params.face_limit,
|
||||
auto_size: params.auto_size,
|
||||
quad: params.quad,
|
||||
smart_low_poly: params.smart_low_poly,
|
||||
generate_parts: params.generate_parts,
|
||||
compress: params.compress,
|
||||
/// 三个提交入口共享的生成选项字段清单:文本 / 图片 / 多视图三种请求到
|
||||
/// [`TripoGenerationOptions`] 的映射全部由这一份清单派生。
|
||||
///
|
||||
/// 新增共享字段时只改这份清单,三条路径会一起跟上;若某个请求结构缺少该字段,
|
||||
/// 这里会直接编译失败,而不是在运行时静默漏校验。
|
||||
macro_rules! tripo_generation_options_from {
|
||||
($($field:ident),+ $(,)?) => {
|
||||
impl From<&Model3dTextToModelParams> for TripoGenerationOptions {
|
||||
fn from(params: &Model3dTextToModelParams) -> Self {
|
||||
Self { $($field: params.$field,)+ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Model3dImageToModelParams> for TripoGenerationOptions {
|
||||
fn from(params: &Model3dImageToModelParams) -> Self {
|
||||
Self { $($field: params.$field,)+ }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Model3dMultiviewToModelRequest> for TripoGenerationOptions {
|
||||
fn from(request: &Model3dMultiviewToModelRequest) -> Self {
|
||||
Self { $($field: request.$field,)+ }
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl From<&Model3dImageToModelParams> for TripoGenerationOptions {
|
||||
fn from(params: &Model3dImageToModelParams) -> Self {
|
||||
Self {
|
||||
model: params.model,
|
||||
texture: params.texture,
|
||||
pbr: params.pbr,
|
||||
texture_quality: params.texture_quality,
|
||||
texture_version: params.texture_version,
|
||||
geometry_quality: params.geometry_quality,
|
||||
face_limit: params.face_limit,
|
||||
auto_size: params.auto_size,
|
||||
quad: params.quad,
|
||||
smart_low_poly: params.smart_low_poly,
|
||||
generate_parts: params.generate_parts,
|
||||
compress: params.compress,
|
||||
}
|
||||
}
|
||||
tripo_generation_options_from! {
|
||||
model,
|
||||
texture,
|
||||
pbr,
|
||||
texture_quality,
|
||||
texture_version,
|
||||
geometry_quality,
|
||||
face_limit,
|
||||
auto_size,
|
||||
quad,
|
||||
smart_low_poly,
|
||||
generate_parts,
|
||||
compress,
|
||||
}
|
||||
|
||||
pub(crate) fn validate_generation_options(
|
||||
|
||||
@@ -43,20 +43,9 @@ impl TripoProviderClient {
|
||||
}
|
||||
Model3dMultiviewInputs::TaskId { task_id } => validate_task_id(task_id)?,
|
||||
}
|
||||
validate_generation_options(&TripoGenerationOptions {
|
||||
model: request.model,
|
||||
texture: request.texture,
|
||||
pbr: request.pbr,
|
||||
texture_quality: request.texture_quality,
|
||||
texture_version: request.texture_version,
|
||||
geometry_quality: request.geometry_quality,
|
||||
face_limit: request.face_limit,
|
||||
auto_size: request.auto_size,
|
||||
quad: request.quad,
|
||||
smart_low_poly: request.smart_low_poly,
|
||||
generate_parts: request.generate_parts,
|
||||
compress: request.compress,
|
||||
})?;
|
||||
// 与 text / image 路径共用同一份字段映射(见 common::validation 的宏),
|
||||
// 新增共享字段时三条路径一起跟上。
|
||||
validate_generation_options(&TripoGenerationOptions::from(request))?;
|
||||
let task_id = self
|
||||
.client
|
||||
.multiview_to_model(to_sdk_params(request)?)
|
||||
|
||||
Reference in New Issue
Block a user