service-database-upload-env3d.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package api
  2. import (
  3. "assetcenter/conf"
  4. "assetcenter/db/model"
  5. "assetcenter/db/repo"
  6. "time"
  7. "go.mongodb.org/mongo-driver/bson/primitive"
  8. "infish.cn/comm"
  9. )
  10. func UploadEnv3d(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetEnv3dHdr) (interface{}, error) {
  11. asset := body
  12. source := asset.Source
  13. asset.Enable = BoolValue(false)
  14. if source == nil || source.File.Size < 1 || len(source.File.Url) < 1 {
  15. asset.AssetState = model.AssetState_Empty
  16. } else {
  17. // !hdr 无效,直接成功
  18. // asset.AssetState = model.AssetState_Waiting
  19. asset.AssetState = model.AssetState_Succ
  20. // asset.Source.ToneMap = &model.ToneMap{
  21. // Method: Int32Value(1),
  22. // Exposure: Float64Value(1),
  23. // Brightness: Float64Value(0.1),
  24. // Contrast: Float64Value(0.06),
  25. // Saturation: Float64Value(1),
  26. // }
  27. // asset.Source.Options = &model.Env3dOption{
  28. // Rotation: 0,
  29. // Exposure: 1,
  30. // }
  31. }
  32. asset.CreateTime = time.Now()
  33. asset.UpdateTime = time.Now()
  34. if conf.AppConfig.IsSaveLocal() {
  35. asset.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  36. }
  37. // assetSource := asset.Source
  38. collectionName := dbConf.AssetConf.Collection
  39. assetId, err := repo.RepoDbAddDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, asset)
  40. if err != nil {
  41. return nil, err
  42. }
  43. // !hdr 没用上
  44. // if asset.AssetState == model.AssetState_Waiting { //模型转换请求
  45. // url, err := bus.NatsCenter.RequestConfig("bus-network")
  46. // if err != nil {
  47. // return nil, err
  48. // }
  49. // err = funcgraph.CreateHdr(assetSource.File.Url, assetId, dbConf.Db.Name, dbConf.AssetConf.Collection, url)
  50. // if err != nil {
  51. // update := bson.M{"$set": bson.M{"assetState": model.AssetState_Failed}}
  52. // repo.RepoUpdateSetDbDocProps(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, assetId, update)
  53. // }
  54. // }
  55. return assetId, err
  56. }
  57. func UpdateHdrComm(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetEnv3dHdr) (interface{}, error) {
  58. asset := body
  59. asset.UpdateTime = time.Now()
  60. id := asset.Id.Hex()
  61. asset.Id = primitive.NilObjectID
  62. if conf.AppConfig.IsSaveLocal() {
  63. asset.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  64. }
  65. collectionName := dbConf.AssetConf.Collection
  66. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  67. }
  68. func UpdateHdrSource(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetEnv3dHdr) (interface{}, error) {
  69. asset := body
  70. asset.UpdateTime = time.Now()
  71. id := asset.Id.Hex()
  72. asset.Id = primitive.NilObjectID
  73. if conf.AppConfig.IsSaveLocal() {
  74. asset.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  75. }
  76. collectionName := dbConf.AssetConf.Collection
  77. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  78. }