@ -45,7 +45,7 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
//logx.Info("收到渲染任务消息")
var renderImageData websocket_data . RenderImageReqMsg
if err := json . Unmarshal ( data , & renderImageData ) ; err != nil {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "数据格式错误" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "数据格式错误" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
logx . Error ( "invalid format of websocket render image message" , err )
return
}
@ -76,7 +76,7 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
case w . extendRenderProperty . renderChan <- renderImageData : //发入到缓冲队列
return
case <- time . After ( time . Millisecond * 50 ) : //超过50毫秒丢弃
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "渲染队列溢出,请稍后再发" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "渲染队列溢出,请稍后再发" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
return
}
}
@ -145,47 +145,47 @@ func (w *wsConnectItem) consumeRenderImageData() {
// 执行渲染任务
func ( w * wsConnectItem ) renderImage ( renderImageData websocket_data . RenderImageReqMsg ) {
if ! strings . Contains ( renderImageData . RenderData . Logo , "fusen" ) {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "非法的logo" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "非法的logo" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
return
}
//没传分辨率
if renderImageData . RenderData . Resolution == "" {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "请传入合图分辨率" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "请传入合图分辨率" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
return
}
//分辨率校验
resolution , err := strconv . Atoi ( renderImageData . RenderData . Resolution )
if err != nil {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "请传入正确的合图分辨率格式" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "请传入正确的合图分辨率格式" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
return
}
if resolution < 512 || resolution > 2048 {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "请传入正确的合图分辨率范围值(512~2048)" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "请传入正确的合图分辨率范围值(512~2048)" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
return
}
lenColor := len ( renderImageData . RenderData . TemplateTagColor . Colors )
if lenColor == 0 {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "请传入模板标签选择的颜色" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "请传入模板标签选择的颜色" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
return
}
if renderImageData . RenderData . TemplateTagColor . SelectedColorIndex >= lenColor || renderImageData . RenderData . TemplateTagColor . SelectedColorIndex < 0 {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "选择的模板标签颜色索引越界" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "选择的模板标签颜色索引越界" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
return
}
//获取产品信息(部分字段)
productInfo , err := w . logic . svcCtx . AllModels . FsProduct . FindOne ( w . logic . ctx , renderImageData . RenderData . ProductId , "id,is_customization" )
if err != nil {
if errors . Is ( err , gorm . ErrRecordNotFound ) {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "该产品不存在" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "该产品不存在" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
return
}
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "获取产品失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "获取产品失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
logx . Error ( err )
return
}
//不可定制
if * productInfo . IsCustomization == 0 {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "该产品不可定制" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "该产品不可定制" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
return
}
//用户id赋值
@ -201,11 +201,11 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
element , err := w . logic . svcCtx . AllModels . FsProductTemplateElement . FindOneByModelId ( w . logic . ctx , * productTemplate . ElementModelId )
if err != nil {
if errors . Is ( err , gorm . ErrRecordNotFound ) {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "云渲染设置不存在" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "云渲染设置不存在" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
logx . Error ( "element info is not found,element_model_id = " , * productTemplate . ElementModelId )
return
}
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "获取云渲染设置失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "获取云渲染设置失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
logx . Error ( "failed to get element ," , err )
return
}
@ -235,7 +235,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
}
res , err := w . logic . svcCtx . Repositories . ImageHandle . LogoCombine ( w . logic . ctx , & combineReq )
if err != nil {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "合成刀版图失败:" + err . Error ( ) , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "合成刀版图失败:" + err . Error ( ) , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
logx . Error ( "合成刀版图失败,合成请求数据:" , combineReq , "错误信息:" , err )
return
}
@ -243,19 +243,19 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
if res != nil && res . ResourceUrl != nil {
combineImage = * res . ResourceUrl
} else {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "合成的刀版图是空的地址" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "合成的刀版图是空的地址" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
logx . Error ( "合成刀版图失败,合成的刀版图是空指针:" , err )
return
}
//发送合图完毕阶段消息
w . sendCombineImageStepResponseMessage ( renderImageData . Re nderId, renderImageData . Re questId, combineImage , productSize . Id , model3dInfo . Id , productTemplate . Id , res . DebugData )
w . sendCombineImageStepResponseMessage ( renderImageData . Re questId, combineImage , productSize . Id , model3dInfo . Id , productTemplate . Id , res . DebugData )
//获取唯一id
taskId := w . genRenderTaskId ( combineImage , renderImageData , model3dInfo , productTemplate , element )
//查询有没有缓存的资源,有就返回
resource , err := w . logic . svcCtx . AllModels . FsResource . FindOneById ( w . logic . ctx , taskId )
if err != nil {
if ! errors . Is ( err , gorm . ErrRecordNotFound ) {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , taskId , "获取unity云渲染缓存失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , taskId , "获取unity云渲染缓存失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
logx . Error ( "failed to find render resource:" , err )
return
}
@ -266,7 +266,6 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
if w . debug == nil || w . debug . IsCache == 1 {
//返回给客户端
w . sendRenderResultData ( websocket_data . RenderImageRspMsg {
RenderId : renderImageData . RenderId ,
RequestId : renderImageData . RequestId ,
Image : * resource . ResourceUrl ,
RenderProcessTime : websocket_data . RenderProcessTime {
@ -291,43 +290,43 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData *websocket_data.
productTemplate , err = w . logic . svcCtx . AllModels . FsProductTemplateV2 . FindOneCloudRenderByProductIdTemplateTag ( w . logic . ctx , renderImageData . RenderData . ProductId , renderImageData . RenderData . TemplateTag , "sort ASC" )
if err != nil {
if errors . Is ( err , gorm . ErrRecordNotFound ) {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "找不到对应开启云渲染模板" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "找不到对应开启云渲染模板" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
return nil , nil , nil , errors . New ( "找不到对应开启云渲染模板" )
}
logx . Error ( err )
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "获取对应开启云渲染模板失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "获取对应开启云渲染模板失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , 0 , 0 , 0 , 0 )
return nil , nil , nil , errors . New ( "获取对应开启云渲染模板失败" )
}
//判断设计信息是否为空
if productTemplate . TemplateInfo == nil || * productTemplate . TemplateInfo == "" {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "模板设计信息是空的" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "模板设计信息是空的" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , 0 , 0 , 0 )
return nil , nil , nil , errors . New ( "模板设计信息是空的" )
}
//根据模板找到模型
model3d , err = w . logic . svcCtx . AllModels . FsProductModel3d . FindOne ( w . logic . ctx , * productTemplate . ModelId )
if err != nil {
if errors . Is ( err , gorm . ErrRecordNotFound ) {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "找不到对应模型" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "找不到对应模型" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , 0 , 0 , 0 )
return nil , nil , nil , errors . New ( "找不到对应模型" )
}
logx . Error ( err )
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "获取对应模型失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , 0 , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "获取对应模型失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , 0 , 0 , 0 )
return nil , nil , nil , errors . New ( "获取对应模型失败" )
}
//判断设计信息是否为空
if model3d . ModelInfo == nil || * model3d . ModelInfo == "" {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "模型设计信息是空的" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3d . Id , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "模型设计信息是空的" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3d . Id , 0 , 0 )
return nil , nil , nil , errors . New ( "模型设计信息是空的" )
}
//根据模型id获取尺寸信息
productSize , err = w . logic . svcCtx . AllModels . FsProductSize . FindOne ( w . logic . ctx , * model3d . SizeId )
if err != nil {
if errors . Is ( err , gorm . ErrRecordNotFound ) {
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "找不到对应尺寸" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3d . Id , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "找不到对应尺寸" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3d . Id , 0 , 0 )
return nil , nil , nil , errors . New ( "找不到对应尺寸" )
}
logx . Error ( err )
w . renderErrResponse ( renderImageData . Re nderId, renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "获取对应尺寸失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3d . Id , 0 , 0 )
w . renderErrResponse ( renderImageData . Re questId, renderImageData . RenderData . TemplateTag , "" , "获取对应尺寸失败" , renderImageData . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3d . Id , 0 , 0 )
return nil , nil , nil , errors . New ( "获取对应尺寸失败" )
}
return
@ -341,7 +340,7 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
refletion , err = strconv . Atoi ( * element . Refletion )
if err != nil {
logx . Error ( "err refletion" )
w . renderErrResponse ( info . Re nderId, info . Re questId, info . RenderData . TemplateTag , taskId , "解析云渲染设置, 把Refletion字段值从字符串转数字失败" , info . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
w . renderErrResponse ( info . Re questId, info . RenderData . TemplateTag , taskId , "解析云渲染设置, 把Refletion字段值从字符串转数字失败" , info . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
return err
}
}
@ -350,7 +349,7 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
if element . Mode != nil && * element . Mode != "" {
if err = json . Unmarshal ( [ ] byte ( * element . Mode ) , & mode ) ; err != nil {
logx . Error ( "faile to parse element mode json:" , err )
w . renderErrResponse ( info . Re nderId, info . Re questId, info . RenderData . TemplateTag , taskId , "解析云渲染设置字段 mode 为map对象失败" , info . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
w . renderErrResponse ( info . Re questId, info . RenderData . TemplateTag , taskId , "解析云渲染设置字段 mode 为map对象失败" , info . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
return err
}
}
@ -398,11 +397,10 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
} ,
}
//发送运行阶段消息(组装数据)
w . sendAssembleRenderDataStepResponseMessage ( info . Re nderId, info . Re questId)
w . sendAssembleRenderDataStepResponseMessage ( info . Re questId)
temId := websocket_data . ToUnityIdStruct {
TaskId : taskId ,
Wid : w . uniqueId ,
RenderId : info . RenderId ,
RequestId : info . RequestId ,
RenderBeginTime : time . Now ( ) . UTC ( ) . UnixMilli ( ) ,
TemplateTag : info . RenderData . TemplateTag ,
@ -434,13 +432,13 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
beginPostTime := time . Now ( ) . UTC ( ) . UnixMilli ( )
_ , err = curl . ApiCall ( url , "POST" , header , bytes . NewReader ( postDataBytes ) , time . Second * 10 )
if err != nil {
w . renderErrResponse ( info . Re nderId, info . Re questId, info . RenderData . TemplateTag , taskId , "请求unity接口失败" , info . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
w . renderErrResponse ( info . Re questId, info . RenderData . TemplateTag , taskId , "请求unity接口失败" , info . RenderData . ProductId , w . userId , w . guestId , productTemplate . Id , model3dInfo . Id , productSize . Id , * productTemplate . ElementModelId )
logx . Error ( "failed to send data to unity" )
return err
}
logx . Info ( fmt . Sprintf ( "发送unity post数据耗时:%dms" , time . Now ( ) . UTC ( ) . UnixMilli ( ) - beginPostTime ) )
//发送运行阶段消息
w . sendRenderDataToUnityStepResponseMessage ( info . Re nderId, info . Re questId)
w . sendRenderDataToUnityStepResponseMessage ( info . Re questId)
logx . Info ( "发送到unity成功,刀版图:" , combineImage /*, " 请求unity的数据:", string(postDataBytes)*/ )
return nil
}