From 983686d96c9049c076f451390a64437990a656a7 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 18:51:24 +0800 Subject: [PATCH] fix --- constants/websocket.go | 7 ++++--- server/websocket/internal/logic/ws_render_image.go | 7 +++++-- server/websocket/internal/logic/ws_reuse_last_connect.go | 1 + utils/websocket_data/render_data.go | 5 +++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/constants/websocket.go b/constants/websocket.go index e3cf11f9..f8305c28 100644 --- a/constants/websocket.go +++ b/constants/websocket.go @@ -24,7 +24,8 @@ const ( // websocket消息类型(云渲染类别) const ( - WEBSOCKET_RENDER_IMAGE Websocket = "WEBSOCKET_RENDER_IMAGE" //图片渲染消息(1级消息,双向通信) - WEBSOCKET_RENDER_IMAGE_ERR Websocket = "WEBSOCKET_RENDER_IMAGE_ERR" //图片渲染失败消息(1级消息,单向通信) - WEBSOCKET_COMBINE_IMAGE Websocket = "WEBSOCKET_COMBINE_IMAGE" //反回合成刀版图消息(2级消息,单向通信,属于 WEBSOCKET_RENDER_IMAGE 消息的子流程) + WEBSOCKET_RENDER_IMAGE Websocket = "WEBSOCKET_RENDER_IMAGE" //图片渲染消息(1级消息,双向通信) + WEBSOCKET_RENDER_IMAGE_ERR Websocket = "WEBSOCKET_RENDER_IMAGE_ERR" //图片渲染失败消息(1级消息,单向通信) + WEBSOCKET_COMBINE_IMAGE Websocket = "WEBSOCKET_COMBINE_IMAGE" //反回合成刀版图消息(2级消息,单向通信,属于 WEBSOCKET_RENDER_IMAGE 消息的子流程) + WEBSOCKET_SEND_DATA_TO_UNITY Websocket = "WEBSOCKET_SEND_DATA_TO_UNITY" //发送到unity进行渲染 ) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 00e7b773..f8e1fca1 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -48,6 +48,7 @@ type renderTask struct { uploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间 } +// 处理分发到这里的数据 func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { logx.Info("收到渲染任务消息:", string(data)) select { @@ -250,14 +251,14 @@ func (w *wsConnectItem) renderImage(data []byte) { }, }) //组装数据 - if err = w.assembleRenderData(taskId, combineImage, renderImageData, productTemplate, model3dInfo, element, productSize); err != nil { + if err = w.assembleRenderDataToUnity(taskId, combineImage, renderImageData, productTemplate, model3dInfo, element, productSize); err != nil { logx.Error("组装数据失败:", err) return } } // 组装数据发送给unity -func (w *wsConnectItem) assembleRenderData(taskId string, combineImage string, info websocket_data.RenderImageReqMsg, productTemplate *gmodel.FsProductTemplateV2, model3dInfo *gmodel.FsProductModel3d, element *gmodel.FsProductTemplateElement, productSize *gmodel.FsProductSize) (err error) { +func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage string, info websocket_data.RenderImageReqMsg, productTemplate *gmodel.FsProductTemplateV2, model3dInfo *gmodel.FsProductModel3d, element *gmodel.FsProductTemplateElement, productSize *gmodel.FsProductSize) (err error) { //组装数据 refletion := -1 if element.Refletion != nil && *element.Refletion != "" { @@ -358,6 +359,8 @@ func (w *wsConnectItem) assembleRenderData(taskId string, combineImage string, i unityRenderBeginTime: unityRenderBeginTime, }, }) + //发送send 到unity 运行阶段信息 + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_SEND_DATA_TO_UNITY, websocket_data.ToUnityRspMsg{RenderId: info.RenderId})) logx.Info("发送到unity成功,刀版图:", combineImage /*, " 请求unity的数据:", string(postDataBytes)*/) return nil } diff --git a/server/websocket/internal/logic/ws_reuse_last_connect.go b/server/websocket/internal/logic/ws_reuse_last_connect.go index 33fa2cd7..31475847 100644 --- a/server/websocket/internal/logic/ws_reuse_last_connect.go +++ b/server/websocket/internal/logic/ws_reuse_last_connect.go @@ -13,6 +13,7 @@ import ( type reuseConnProcessor struct { } +// 处理分发到这里的数据 func (r *reuseConnProcessor) allocationMessage(w *wsConnectItem, data []byte) { logx.Info("收到请求恢复上次连接标识数据:", string(data)) var wid string diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 013ee5b6..275eca06 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -51,3 +51,8 @@ type CombineProcessTime struct { CombineTakesTime string `json:"combine_takes_time"` //合图时间 UploadCombineImageTakesTime string `json:"upload_combine_image_takes_time"` //上传刀版图耗时 } + +// 发送到unity阶段信息返回数据 +type ToUnityRspMsg struct { + RenderId string `json:"render_id"` //渲染id +}