database.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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 DbAsset struct {
  21. Id string `bson:"id,omitempty" json:"id"` //资产id
  22. Label string `bson:"label,omitempty" json:"label"`
  23. Type int `bson:"type,omitempty" json:"type"` //AssetTypeMesh AssetTypeImage ...
  24. Collection string `bson:"collection,omitempty" json:"collection"` //数据库存储集合
  25. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  26. CategoryIds []string `bson:"categoryIds,omitempty" json:"categoryIds"`
  27. }
  28. type AssetDbConf struct {
  29. Db *Database
  30. AssetConf *DbAsset
  31. }
  32. type Database struct {
  33. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"` //数据库Id
  34. UserId string `bson:"userId,omitempty" json:"userId"` //数据库Id
  35. Name string `bson:"name,omitempty" json:"name"` //数据库名字
  36. Label string `bson:"label,omitempty" json:"label"` //前端展示标签
  37. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  38. Categories *comm.DbCategory `bson:"categories,omitempty" json:"categories"` //数据的分类
  39. Assets []*DbAsset `bson:"assets,omitempty" json:"assets"` //资产定义
  40. }
  41. func CreateDefaultDbAssets() []*DbAsset {
  42. return []*DbAsset{
  43. &DbAsset{
  44. Id: "1",
  45. Label: "模型",
  46. Type: AssetTypeMesh,
  47. Collection: "mesh",
  48. CreateTime: time.Now(),
  49. },
  50. &DbAsset{
  51. Id: "2",
  52. Label: "图片",
  53. Type: AssetTypeImage,
  54. Collection: "image",
  55. CreateTime: time.Now(),
  56. },
  57. &DbAsset{
  58. Id: "3",
  59. Label: "材质球",
  60. Type: AssetTypeMaterial,
  61. Collection: "material",
  62. CreateTime: time.Now(),
  63. }, &DbAsset{
  64. Id: "4",
  65. Label: "环境球",
  66. Type: AssetTypeEnv3d,
  67. Collection: "env3d",
  68. CreateTime: time.Now(),
  69. },
  70. }
  71. }
  72. func CreateDefaultDatabase() *Database {
  73. return &Database{
  74. Name: "qdb-default",
  75. Label: "默认资产库",
  76. CreateTime: time.Now(),
  77. Assets: CreateDefaultDbAssets(),
  78. Categories: &comm.DbCategory{},
  79. }
  80. }
  81. type Obb struct {
  82. Min Vec3Obj `bson:"min,omitempty" json:"min"`
  83. Max Vec3Obj `bson:"max,omitempty" json:"max"`
  84. }
  85. type StaticMesh struct {
  86. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  87. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  88. Name string `bson:"name,omitempty" json:"name"`
  89. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  90. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  91. State int `bson:"state,omitempty" json:"state"` //created completed published
  92. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  93. Categories []string `bson:"categories,omitempty" json:"categories,omitempty"` //所属分类Id
  94. Components []*MeshMatConf `bson:"components,omitempty" json:"components"`
  95. Osgjs *OssType `bson:"osgjs,omitempty" json:"osgjs"`
  96. File *OssType `bson:"file,omitempty" json:"file"` //hdr or fbx
  97. Shadow *OssType `bson:"shadow,omitempty" json:"shadow,omitempty"`
  98. Obb *Obb `bson:"obb,omitempty" json:"obb,omitempty"`
  99. }
  100. type AssetBase struct {
  101. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  102. Name string `bson:"name,omitempty" json:"name"`
  103. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  104. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  105. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  106. Categories []string `bson:"categories,omitempty" json:"categories"` //所属分类Id
  107. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  108. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  109. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  110. }
  111. type StaticMeshSource struct {
  112. Components []*MeshMatConf `bson:"components,omitempty" json:"components"`
  113. Osgjs *OssType `bson:"osgjs,omitempty" json:"osgjs"`
  114. File *OssType `bson:"file,omitempty" json:"file"` //hdr or fbx
  115. Glb *OssType `bson:"glb,omitempty" json:"glb"` //hdr or fbx
  116. Shadow *OssType `bson:"shadow,omitempty" json:"shadow,omitempty"`
  117. BoundingBox *Obb `bson:"boundingBox,omitempty" json:"boundingBox,omitempty"`
  118. }
  119. type HdrSource struct {
  120. Config *Evn3dHdrConf `bson:"config,omitempty" json:"config"`
  121. File *OssType `bson:"file,omitempty" json:"file"` //hdr or fbx
  122. Options *Env3dOption `bson:"options,omitempty" json:"options"`
  123. ToneMap *ToneMap `bson:"toneMap,omitempty" json:"toneMap"`
  124. }
  125. type ImageSource struct {
  126. File *OssType `bson:"file,omitempty" json:"file"` //hdr or fbx
  127. }
  128. type AssetUserInfo struct {
  129. Name string `bson:"name,omitempty" json:"name"`
  130. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  131. }
  132. type IAsset interface {
  133. SetIdEmpty()
  134. ResetCreateTime()
  135. SetOwner(id string, otype string)
  136. SetAssetType(atype string)
  137. SetUserInfo(id string, info *comm.AssetUserInfo)
  138. }
  139. type AssetStaticMesh struct {
  140. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  141. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"` //用户Id
  142. UserInfo *comm.AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty"` //用户Id
  143. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"` //userId teamId companyId
  144. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"` //user team company
  145. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"` //user team company
  146. Name string `bson:"name,omitempty" json:"name"`
  147. CusNum string `bson:"cusNum,omitempty" json:"cusNum,omitempty"` //型号
  148. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  149. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  150. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  151. Categories []string `bson:"categories,omitempty" json:"categories"` //所属分类Id
  152. CusCategories []string `bson:"cusCategories,omitempty" json:"cusCategories"` //用户自定义分类
  153. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  154. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  155. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  156. Source *StaticMeshSource `bson:"source,omitempty" json:"source,omitempty"`
  157. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty"` //用户数据
  158. }
  159. func (s *AssetStaticMesh) SetIdEmpty() {
  160. s.Id = primitive.NilObjectID
  161. }
  162. func (s *AssetStaticMesh) ResetCreateTime() {
  163. s.CreateTime = time.Now()
  164. s.UpdateTime = time.Now()
  165. }
  166. func (s *AssetStaticMesh) SetOwner(id string, otype string) {
  167. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  168. s.OwnerType = otype
  169. }
  170. func (s *AssetStaticMesh) SetUserInfo(id string, info *comm.AssetUserInfo) {
  171. s.UserId, _ = primitive.ObjectIDFromHex(id)
  172. s.UserInfo = info
  173. }
  174. func (s *AssetStaticMesh) SetAssetType(otype string) {
  175. s.AssetType = otype
  176. }
  177. type AssetEnv3dHdr struct {
  178. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  179. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"` //用户Id
  180. UserInfo *comm.AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty"` //用户Id
  181. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  182. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"`
  183. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"`
  184. Name string `bson:"name,omitempty" json:"name"`
  185. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  186. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  187. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  188. Categories []string `bson:"categories,omitempty" json:"categories"` //所属分类Id
  189. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  190. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  191. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  192. Source *HdrSource `bson:"source,omitempty" json:"source,omitempty"`
  193. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty"` //用户数据
  194. }
  195. func (s *AssetEnv3dHdr) SetIdEmpty() {
  196. s.Id = primitive.NilObjectID
  197. }
  198. func (s *AssetEnv3dHdr) ResetCreateTime() {
  199. s.CreateTime = time.Now()
  200. s.UpdateTime = time.Now()
  201. }
  202. func (s *AssetEnv3dHdr) SetOwner(id string, otype string) {
  203. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  204. s.OwnerType = otype
  205. }
  206. func (s *AssetEnv3dHdr) SetAssetType(otype string) {
  207. s.AssetType = otype
  208. }
  209. func (s *AssetEnv3dHdr) SetUserInfo(id string, info *comm.AssetUserInfo) {
  210. s.UserId, _ = primitive.ObjectIDFromHex(id)
  211. s.UserInfo = info
  212. }
  213. type AssetMat struct {
  214. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  215. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"` //用户Id
  216. UserInfo *comm.AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty"` //用户Id
  217. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  218. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"` //user team company
  219. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"` //user team company
  220. CusNum string `bson:"cusNum,omitempty" json:"cusNum,omitempty"` //型号
  221. Name string `bson:"name,omitempty" json:"name"`
  222. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  223. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  224. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  225. Categories []string `bson:"categories,omitempty" json:"categories"` //所属分类Id
  226. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  227. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  228. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  229. Source *MatConfig `bson:"source,omitempty" json:"source,omitempty"`
  230. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty"` //用户数据
  231. }
  232. func (s *AssetMat) SetIdEmpty() {
  233. s.Id = primitive.NilObjectID
  234. }
  235. func (s *AssetMat) ResetCreateTime() {
  236. s.CreateTime = time.Now()
  237. s.UpdateTime = time.Now()
  238. }
  239. func (s *AssetMat) SetOwner(id string, otype string) {
  240. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  241. s.OwnerType = otype
  242. }
  243. func (s *AssetMat) SetAssetType(otype string) {
  244. s.AssetType = otype
  245. }
  246. func (s *AssetMat) SetUserInfo(id string, info *comm.AssetUserInfo) {
  247. s.UserId, _ = primitive.ObjectIDFromHex(id)
  248. s.UserInfo = info
  249. }
  250. type AssetImage struct {
  251. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  252. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"` //用户Id
  253. UserInfo *comm.AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty"` //用户Id
  254. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  255. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"` //user team company
  256. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"` //user team company
  257. Name string `bson:"name,omitempty" json:"name"`
  258. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  259. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  260. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  261. Categories []string `bson:"categories,omitempty" json:"categories"` //所属分类Id
  262. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  263. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  264. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  265. Source *ImageSource `bson:"source,omitempty" json:"source,omitempty"`
  266. }
  267. func (s *AssetImage) SetIdEmpty() {
  268. s.Id = primitive.NilObjectID
  269. }
  270. func (s *AssetImage) ResetCreateTime() {
  271. s.CreateTime = time.Now()
  272. s.UpdateTime = time.Now()
  273. }
  274. func (s *AssetImage) SetOwner(id string, otype string) {
  275. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  276. s.OwnerType = otype
  277. }
  278. func (s *AssetImage) SetAssetType(otype string) {
  279. s.AssetType = otype
  280. }
  281. func (s *AssetImage) SetUserInfo(id string, info *comm.AssetUserInfo) {
  282. s.UserId, _ = primitive.ObjectIDFromHex(id)
  283. s.UserInfo = info
  284. }
  285. type AssetPackage struct {
  286. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  287. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"` //userId teamId companyId
  288. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"` //user team company
  289. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"` //用户Id
  290. UserInfo *comm.AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty"` //用户Id
  291. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"` //业务类型 shoe sole heel decorate
  292. Name string `bson:"name,omitempty" json:"name"`
  293. CusNum string `bson:"cusNum,omitempty" json:"cusNum,omitempty"` //型号
  294. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  295. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  296. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  297. Categories []string `bson:"categories,omitempty" json:"categories"` //所属分类Id
  298. CusCategories []string `bson:"cusCategories,omitempty" json:"cusCategories"` //所属分类Id
  299. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  300. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  301. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  302. Source *comm.Queen3dPackageSource `bson:"source,omitempty" json:"source,omitempty"`
  303. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty"` //用户数据
  304. }
  305. func (s *AssetPackage) SetIdEmpty() {
  306. s.Id = primitive.NilObjectID
  307. }
  308. func (s *AssetPackage) ResetCreateTime() {
  309. s.CreateTime = time.Now()
  310. s.UpdateTime = time.Now()
  311. }
  312. func (s *AssetPackage) SetOwner(id string, otype string) {
  313. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  314. s.OwnerType = otype
  315. }
  316. func (s *AssetPackage) SetAssetType(otype string) {
  317. s.AssetType = otype
  318. }
  319. func (s *AssetPackage) SetUserInfo(id string, info *comm.AssetUserInfo) {
  320. s.UserId, _ = primitive.ObjectIDFromHex(id)
  321. s.UserInfo = info
  322. }