service-database-upload-env3d.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package api
  2. import (
  3. "mats/db/model"
  4. "mats/db/repo"
  5. funcgraph "mats/funcGraph"
  6. "time"
  7. "go.mongodb.org/mongo-driver/bson"
  8. "go.mongodb.org/mongo-driver/bson/primitive"
  9. )
  10. func UploadEnv3d(apictx *ApiSession, dbConf *model.AssetDbConf, body *model.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. asset.AssetState = model.AssetState_Waiting
  18. // asset.Source.ToneMap = &model.ToneMap{
  19. // Method: Int32Value(1),
  20. // Exposure: Float64Value(1),
  21. // Brightness: Float64Value(0.1),
  22. // Contrast: Float64Value(0.06),
  23. // Saturation: Float64Value(1),
  24. // }
  25. // asset.Source.Options = &model.Env3dOption{
  26. // Rotation: 0,
  27. // Exposure: 1,
  28. // }
  29. }
  30. asset.CreateTime = time.Now()
  31. asset.UpdateTime = time.Now()
  32. collectionName := dbConf.AssetConf.Collection
  33. assetId, err := repo.RepoDbAddDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, asset)
  34. if err != nil {
  35. return nil, err
  36. }
  37. if asset.AssetState == model.AssetState_Waiting { //模型转换请求
  38. err = funcgraph.CreateHdr(source.File.Url, assetId, dbConf.Db.Name, dbConf.AssetConf.Collection)
  39. if err != nil {
  40. update := bson.M{"$set": bson.M{"assetState": model.AssetState_Failed}}
  41. repo.RepoUpdateSetDbDocProps(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, assetId, update)
  42. }
  43. }
  44. return assetId, err
  45. }
  46. func UpdateHdrComm(apictx *ApiSession, dbConf *model.AssetDbConf, body *model.AssetEnv3dHdr) (interface{}, error) {
  47. asset := body
  48. asset.UpdateTime = time.Now()
  49. id := asset.Id.Hex()
  50. asset.Id = primitive.NilObjectID
  51. collectionName := dbConf.AssetConf.Collection
  52. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  53. }
  54. func UpdateHdrSource(apictx *ApiSession, dbConf *model.AssetDbConf, body *model.AssetEnv3dHdr) (interface{}, error) {
  55. asset := body
  56. asset.UpdateTime = time.Now()
  57. id := asset.Id.Hex()
  58. asset.Id = primitive.NilObjectID
  59. collectionName := dbConf.AssetConf.Collection
  60. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  61. }