database.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package model
  2. import (
  3. "time"
  4. "infish.cn/comm"
  5. "go.mongodb.org/mongo-driver/bson/primitive"
  6. )
  7. const (
  8. AssetTypeMesh = 10 //"mesh" //模型
  9. AssetTypeImage = 20 //"image" //图片
  10. AssetTypeMaterial = 30 //"material" //材质球
  11. AssetTypeMaterialGroup = 31 //"material" //材质球组
  12. AssetTypeEnv3d = 40 //"hdr " //环境球
  13. AssetTypePackage = 50 //"package " //3d资产包
  14. AssetState_Empty = 0
  15. AssetState_Waiting = 100 //等待处理
  16. AssetState_Proccing = 101 //正在处理
  17. AssetState_Failed = 102 //处理失败!
  18. AssetState_Succ = 200 //处理成功
  19. )
  20. type DatabaseAssetV0 struct {
  21. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"` //数据库Id
  22. UserId string `bson:"userId,omitempty" json:"userId"` //数据库Id
  23. Name string `bson:"name,omitempty" json:"name"` //数据库名字
  24. Label string `bson:"label,omitempty" json:"label"` //前端展示标签
  25. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  26. Categories *comm.DbCategory `bson:"categories,omitempty" json:"categories"` //数据的分类
  27. Assets *comm.DbAsset `bson:"assets,omitempty" json:"assets"` //资产定义
  28. }
  29. type Obb struct {
  30. Min Vec3Obj `bson:"min,omitempty" json:"min"`
  31. Max Vec3Obj `bson:"max,omitempty" json:"max"`
  32. }
  33. type StaticMesh struct {
  34. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  35. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  36. Name string `bson:"name,omitempty" json:"name"`
  37. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  38. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  39. State int `bson:"state,omitempty" json:"state"` //created completed published
  40. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  41. Categories []string `bson:"categories,omitempty" json:"categories,omitempty"` //所属分类Id
  42. Components []*MeshMatConf `bson:"components,omitempty" json:"components"`
  43. Osgjs *OssType `bson:"osgjs,omitempty" json:"osgjs"`
  44. File *OssType `bson:"file,omitempty" json:"file"` //hdr or fbx
  45. Shadow *OssType `bson:"shadow,omitempty" json:"shadow,omitempty"`
  46. Obb *Obb `bson:"obb,omitempty" json:"obb,omitempty"`
  47. }
  48. type AssetBase struct {
  49. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  50. Name string `bson:"name,omitempty" json:"name"`
  51. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  52. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  53. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  54. Categories []string `bson:"categories,omitempty" json:"categories"` //所属分类Id
  55. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  56. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  57. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  58. }
  59. type StaticMeshSource struct {
  60. Components []*MeshMatConf `bson:"components,omitempty" json:"components"`
  61. Osgjs *OssType `bson:"osgjs,omitempty" json:"osgjs"`
  62. File *OssType `bson:"file,omitempty" json:"file"` //hdr or fbx
  63. Glb *OssType `bson:"glb,omitempty" json:"glb"` //hdr or fbx
  64. Shadow *OssType `bson:"shadow,omitempty" json:"shadow,omitempty"`
  65. BoundingBox *Obb `bson:"boundingBox,omitempty" json:"boundingBox,omitempty"`
  66. }
  67. type HdrSource struct {
  68. Config *Evn3dHdrConf `bson:"config,omitempty" json:"config"`
  69. File *OssType `bson:"file,omitempty" json:"file"` //hdr or fbx
  70. Options *Env3dOption `bson:"options,omitempty" json:"options"`
  71. ToneMap *ToneMap `bson:"toneMap,omitempty" json:"toneMap"`
  72. }
  73. type ImageSource struct {
  74. File *OssType `bson:"file,omitempty" json:"file"` //hdr or fbx
  75. }
  76. type AssetUserInfo struct {
  77. Name string `bson:"name,omitempty" json:"name"`
  78. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  79. }
  80. type IAsset interface {
  81. SetIdEmpty()
  82. ResetCreateTime()
  83. SetOwner(id string, otype string)
  84. SetAssetType(atype string)
  85. SetUserInfo(id string, info *comm.AssetUserInfo)
  86. }
  87. type AssetStaticMesh struct {
  88. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  89. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"` //用户Id
  90. UserInfo *comm.AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty"` //用户Id
  91. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"` //userId teamId companyId
  92. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"` //user team company
  93. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"` //user team company
  94. Name string `bson:"name,omitempty" json:"name"`
  95. CusNum string `bson:"cusNum,omitempty" json:"cusNum,omitempty"` //型号
  96. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  97. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  98. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  99. Categories []string `bson:"categories,omitempty" json:"categories"` //所属分类Id
  100. CusCategories []string `bson:"cusCategories,omitempty" json:"cusCategories"` //用户自定义分类
  101. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  102. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  103. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  104. Source *StaticMeshSource `bson:"source,omitempty" json:"source,omitempty"`
  105. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty"` //用户数据
  106. }
  107. func (s *AssetStaticMesh) SetIdEmpty() {
  108. s.Id = primitive.NilObjectID
  109. }
  110. func (s *AssetStaticMesh) ResetCreateTime() {
  111. s.CreateTime = time.Now()
  112. s.UpdateTime = time.Now()
  113. }
  114. func (s *AssetStaticMesh) SetOwner(id string, otype string) {
  115. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  116. s.OwnerType = otype
  117. }
  118. func (s *AssetStaticMesh) SetUserInfo(id string, info *comm.AssetUserInfo) {
  119. s.UserId, _ = primitive.ObjectIDFromHex(id)
  120. s.UserInfo = info
  121. }
  122. func (s *AssetStaticMesh) SetAssetType(otype string) {
  123. s.AssetType = otype
  124. }
  125. type AssetMat struct {
  126. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  127. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"` //用户Id
  128. UserInfo *comm.AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty"` //用户Id
  129. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  130. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"` //user team company
  131. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"` //user team company
  132. CusNum string `bson:"cusNum,omitempty" json:"cusNum,omitempty"` //型号
  133. Name string `bson:"name,omitempty" json:"name"`
  134. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  135. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  136. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  137. Categories []string `bson:"categories,omitempty" json:"categories"` //所属分类Id
  138. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  139. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  140. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  141. Source *MatConfig `bson:"source,omitempty" json:"source,omitempty"`
  142. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty"` //用户数据
  143. }
  144. func (s *AssetMat) SetIdEmpty() {
  145. s.Id = primitive.NilObjectID
  146. }
  147. func (s *AssetMat) ResetCreateTime() {
  148. s.CreateTime = time.Now()
  149. s.UpdateTime = time.Now()
  150. }
  151. func (s *AssetMat) SetOwner(id string, otype string) {
  152. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  153. s.OwnerType = otype
  154. }
  155. func (s *AssetMat) SetAssetType(otype string) {
  156. s.AssetType = otype
  157. }
  158. func (s *AssetMat) SetUserInfo(id string, info *comm.AssetUserInfo) {
  159. s.UserId, _ = primitive.ObjectIDFromHex(id)
  160. s.UserInfo = info
  161. }