database.go 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. package comm
  2. import (
  3. "math"
  4. "time"
  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. AssetTypeScene = 50 //"scene " //场景
  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. UserId string `bson:"userId,omitempty" json:"userId"`
  23. Label string `bson:"label,omitempty" json:"label"`
  24. Type int `bson:"type,omitempty" json:"type"` //AssetTypeMesh AssetTypeImage ...
  25. Collection string `bson:"collection,omitempty" json:"collection"` //数据库存储集合
  26. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  27. CategoryIds []string `bson:"categoryIds,omitempty" json:"categoryIds"`
  28. }
  29. type AssetDbConf struct {
  30. Db *Database
  31. AssetConf *DbAsset
  32. }
  33. type DbCategoryOld struct {
  34. Id string `bson:"id,omitempty" json:"id"`
  35. Type string `bson:"type,omitempty" json:"type"`
  36. Parent string `bson:"parent,omitempty" json:"parent"`
  37. Name string `bson:"name,omitempty" json:"name"`
  38. Value string `bson:"value,omitempty" json:"value"`
  39. Level *int32 `bson:"level,omitempty" json:"level"`
  40. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  41. OrderId int64 `bson:"orderId,omitempty" json:"orderId"`
  42. }
  43. type DatabaseOld struct {
  44. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"` //数据库Id
  45. UserId string `bson:"userId,omitempty" json:"userId"` //数据库Id
  46. Name string `bson:"name,omitempty" json:"name"` //数据库名字
  47. Label string `bson:"label,omitempty" json:"label"` //前端展示标签
  48. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  49. Categories []*DbCategoryOld `bson:"categories,omitempty" json:"categories"` //数据的分类
  50. Assets []*DbAsset `bson:"assets,omitempty" json:"assets"` //资产定义
  51. }
  52. type Database struct {
  53. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"` //数据库Id
  54. UserId string `bson:"userId,omitempty" json:"userId"` //数据库Id
  55. Name string `bson:"name,omitempty" json:"name"` //数据库名字
  56. Label string `bson:"label,omitempty" json:"label"` //前端展示标签
  57. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  58. Categories *DbCategory `bson:"categories,omitempty" json:"categories" complex:"true"` //数据的分类
  59. Assets []*DbAsset `bson:"assets,omitempty" json:"assets" complex:"true"` //资产定义
  60. }
  61. type UserDatabase struct {
  62. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"` //userId
  63. UserName string `bson:"userName,omitempty" json:"userName"` //用户名字
  64. Limits int `bson:"limits,omitempty" json:"limits"` //数据库限制数据
  65. }
  66. func CreateDefaultDbAssets() []*DbAsset {
  67. return []*DbAsset{
  68. {
  69. Id: primitive.NewObjectID().Hex(),
  70. Label: "模型",
  71. Type: AssetTypeMesh,
  72. Collection: "mesh",
  73. CreateTime: time.Now(),
  74. },
  75. {
  76. Id: primitive.NewObjectID().Hex(),
  77. Label: "图片",
  78. Type: AssetTypeImage,
  79. Collection: "image",
  80. CreateTime: time.Now(),
  81. },
  82. {
  83. Id: primitive.NewObjectID().Hex(),
  84. Label: "材质球",
  85. Type: AssetTypeMaterial,
  86. Collection: "material",
  87. CreateTime: time.Now(),
  88. },
  89. {
  90. Id: primitive.NewObjectID().Hex(),
  91. Label: "环境球",
  92. Type: AssetTypeEnv3d,
  93. Collection: "env3d",
  94. CreateTime: time.Now(),
  95. },
  96. }
  97. }
  98. func CreateDefaultDatabase() *Database {
  99. return &Database{
  100. Name: "qdb-default",
  101. Label: "默认资产库",
  102. CreateTime: time.Now(),
  103. Assets: CreateDefaultDbAssets(),
  104. Categories: &DbCategory{},
  105. }
  106. }
  107. type Obb struct {
  108. Min Vec3Obj `bson:"min,omitempty" json:"min"`
  109. Max Vec3Obj `bson:"max,omitempty" json:"max"`
  110. }
  111. type AssetBase struct {
  112. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  113. Name string `bson:"name,omitempty" json:"name"`
  114. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  115. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  116. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  117. Categories []string `bson:"categories,omitempty" json:"categories"` //所属分类Id
  118. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  119. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  120. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  121. }
  122. type UvSize struct {
  123. Width int `bson:"width,omitempty" json:"width,omitempty"`
  124. Height int `bson:"height,omitempty" json:"height,omitempty"`
  125. }
  126. type MatTextureColor struct {
  127. UseTexture *bool `bson:"useTexture" json:"useTexture"`
  128. Texture *OssType `bson:"texture" json:"texture"`
  129. Color *Vect3 `bson:"color" json:"color"`
  130. }
  131. func (m *MatTextureColor) UpdateSourceUrl(handler UpdateUrlHandler) {
  132. if m.Texture != nil {
  133. m.Texture.UpdateSourceUrl(handler)
  134. }
  135. }
  136. type MatDiamond struct {
  137. ScaleY *float32 `bson:"scaleY" json:"scaleY"`
  138. ScaleX *float32 `bson:"scaleX" json:"scaleX"`
  139. Brightness *float32 `bson:"brightness" json:"brightness"`
  140. Color *Vect3 `bson:"color" json:"color"`
  141. }
  142. type MatTextureFactor struct {
  143. UseTexture *bool `bson:"useTexture" json:"useTexture"`
  144. Texture *OssType `bson:"texture" json:"texture"`
  145. Factor *float32 `bson:"factor" json:"factor"`
  146. }
  147. func (m *MatTextureFactor) UpdateSourceUrl(handler UpdateUrlHandler) {
  148. if m.Texture != nil {
  149. m.Texture.UpdateSourceUrl(handler)
  150. }
  151. }
  152. type MatNormal struct {
  153. UseTexture *bool `bson:"useTexture" json:"useTexture"`
  154. Texture *OssType `bson:"texture" json:"texture"`
  155. Factor *float32 `bson:"factor" json:"factor"`
  156. FlipY *bool `bson:"flipY" json:"flipY"`
  157. }
  158. func (n *MatNormal) UpdateSourceUrl(handler UpdateUrlHandler) {
  159. if n.Texture != nil {
  160. n.Texture.UpdateSourceUrl(handler)
  161. }
  162. }
  163. type MatTextureFactorWithEnable struct {
  164. UseTexture *bool `bson:"useTexture" json:"useTexture"`
  165. Texture *OssType `bson:"texture" json:"texture"`
  166. Factor *float32 `bson:"factor" json:"factor"`
  167. Enable bool `bson:"enable" json:"enable"`
  168. }
  169. func (n *MatTextureFactorWithEnable) UpdateSourceUrl(handler UpdateUrlHandler) {
  170. if n.Texture != nil {
  171. n.Texture.UpdateSourceUrl(handler)
  172. }
  173. }
  174. type MatAlbedo struct {
  175. Color *Vect3 `bson:"color" json:"color"`
  176. Texture *OssType `bson:"texture" json:"texture"`
  177. UseTexture *bool `bson:"useTexture" json:"useTexture"`
  178. }
  179. func (n *MatAlbedo) UpdateSourceUrl(handler UpdateUrlHandler) {
  180. if n.Texture != nil {
  181. n.Texture.UpdateSourceUrl(handler)
  182. }
  183. }
  184. type MatRoughness struct {
  185. UseTexture *bool `bson:"useTexture" json:"useTexture"`
  186. Texture *OssType `bson:"texture" json:"texture"`
  187. Factor *float32 `bson:"factor" json:"factor"`
  188. }
  189. func (n *MatRoughness) UpdateSourceUrl(handler UpdateUrlHandler) {
  190. if n.Texture != nil {
  191. n.Texture.UpdateSourceUrl(handler)
  192. }
  193. }
  194. type MatMetalness struct {
  195. UseTexture *bool `bson:"useTexture" json:"useTexture"`
  196. Texture *OssType `bson:"texture" json:"texture"`
  197. Factor *float32 `bson:"factor" json:"factor"`
  198. }
  199. func (n *MatMetalness) UpdateSourceUrl(handler UpdateUrlHandler) {
  200. if n.Texture != nil {
  201. n.Texture.UpdateSourceUrl(handler)
  202. }
  203. }
  204. type MatDisplace struct {
  205. UseTexture *bool `bson:"useTexture" json:"useTexture"`
  206. Texture *OssType `bson:"texture" json:"texture"`
  207. Factor *float32 `bson:"factor" json:"factor"`
  208. }
  209. type MatDiffuse struct {
  210. UseTexture *bool `bson:"useTexture" json:"useTexture"`
  211. Texture *OssType `bson:"texture" json:"texture"`
  212. Factor *float32 `bson:"factor" json:"factor"`
  213. }
  214. type MatOpacity struct {
  215. Enable bool `bson:"enable" json:"enable"`
  216. Factor *float32 `bson:"factor" json:"factor"`
  217. Texture *OssType `bson:"texture" json:"texture"`
  218. UseTexture *bool `bson:"useTexture" json:"useTexture"`
  219. }
  220. func (n *MatOpacity) UpdateSourceUrl(handler UpdateUrlHandler) {
  221. if n.Texture != nil {
  222. n.Texture.UpdateSourceUrl(handler)
  223. }
  224. }
  225. type TechMatConfig struct {
  226. Version int `bson:"version,omitempty" json:"version"`
  227. Type string `bson:"type,omitempty" json:"type"`
  228. Uvtransform *MaterailUv `bson:"uvtransform,omitempty" json:"uvtransform"`
  229. CullFace string `bson:"cullFace" json:"cullFace"`
  230. Albedo *MatAlbedo `bson:"albedo" json:"albedo"`
  231. Roughness *MatRoughness `bson:"roughness" json:"roughness"`
  232. Metalness *MatMetalness `bson:"metalness" json:"metalness"`
  233. Specular *MatAlbedo `bson:"specular" json:"specular"`
  234. Normal *MatNormal `bson:"normal" json:"normal"`
  235. Opacity *MatOpacity `bson:"opacity" json:"opacity"`
  236. }
  237. func (n *TechMatConfig) UpdateSourceUrl(handler UpdateUrlHandler) {
  238. if n.Albedo != nil {
  239. n.Albedo.UpdateSourceUrl(handler)
  240. }
  241. if n.Roughness != nil {
  242. n.Roughness.UpdateSourceUrl(handler)
  243. }
  244. if n.Metalness != nil {
  245. n.Metalness.UpdateSourceUrl(handler)
  246. }
  247. if n.Specular != nil {
  248. n.Specular.UpdateSourceUrl(handler)
  249. }
  250. if n.Normal != nil {
  251. n.Normal.UpdateSourceUrl(handler)
  252. }
  253. if n.Opacity != nil {
  254. n.Opacity.UpdateSourceUrl(handler)
  255. }
  256. }
  257. type ComponentImage struct {
  258. Id string `bson:"id" json:"id"`
  259. Image *OssType `bson:"image" json:"image"`
  260. Width int `bson:"width" json:"width"`
  261. Height int `bson:"height" json:"height"`
  262. Position Vect2 `bson:"position" json:"position"`
  263. Scale Vect2 `bson:"scale" json:"scale"`
  264. Rotation float64 `bson:"rotation" json:"rotation"`
  265. FillType string `bson:"fillType" json:"fillType"`
  266. Technology string `bson:"technology" json:"technology"`
  267. BasicColor Vect3 `bson:"basicColor" json:"basicColor"`
  268. AotuFactor float32 `bson:"aotuFactor" json:"aotuFactor"`
  269. RoughFactor float32 `bson:"roughFactor" json:"roughFactor"`
  270. ReflectionFactor float32 `bson:"reflectionFactor" json:"reflectionFactor"`
  271. MetalFactor float32 `bson:"metalFactor" json:"metalFactor"`
  272. IsAotu *bool `bson:"isAotu" json:"isAotu"`
  273. TjColor Vect3 `bson:"tjColor" json:"tjColor"` //烫金颜色
  274. }
  275. type MeshMatConf struct {
  276. UvMap *OssType `bson:"uvmap" json:"uvmap"`
  277. UvSize *UvSize `bson:"uvsize" json:"uvsize"`
  278. Name string `bson:"name" json:"name"`
  279. Material *MaterialConf `bson:"material" json:"material"`
  280. TechMaterial *TechMatConfig `bson:"techMaterial" json:"techMaterial"`
  281. Images []*ComponentImage `bson:"images" json:"images"`
  282. Index int `bson:"index" json:"index"`
  283. Visible *bool `bson:"visible" json:"visible"`
  284. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty"` //自定义数据
  285. }
  286. type StaticMeshSource struct {
  287. Components []*MeshMatConf `bson:"components,omitempty" json:"components"`
  288. Osgjs *OssType `bson:"osgjs,omitempty" json:"osgjs"`
  289. File *OssType `bson:"file,omitempty" json:"file"` //hdr or fbx
  290. Glb *OssType `bson:"glb,omitempty" json:"glb"` //hdr or fbx
  291. Shadow *OssType `bson:"shadow,omitempty" json:"shadow,omitempty"`
  292. BoundingBox *Obb `bson:"boundingBox,omitempty" json:"boundingBox,omitempty"`
  293. }
  294. type HdrSource struct {
  295. Config *Evn3dHdrConf `bson:"config,omitempty" json:"config"`
  296. File *OssType `bson:"file,omitempty" json:"file"` //hdr or fbx
  297. Options *Env3dOption `bson:"options,omitempty" json:"options"`
  298. ToneMap *ToneMap `bson:"toneMap,omitempty" json:"toneMap"`
  299. }
  300. type ImageSource struct {
  301. File *OssType `bson:"file,omitempty" json:"file"` //hdr or fbx
  302. }
  303. type AssetStaticMesh struct {
  304. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  305. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"`
  306. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"` //userId teamId companyId
  307. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"` //user team company
  308. Name string `bson:"name,omitempty" json:"name"`
  309. CusNum string `bson:"cusNum,omitempty" json:"cusNum,omitempty"` //型号
  310. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  311. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  312. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  313. Categories []string `bson:"categories,omitempty" json:"categories"` //所属分类Id
  314. CusCategories []string `bson:"cusCategories,omitempty" json:"cusCategories"` //所属分类Id
  315. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  316. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  317. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  318. Source *StaticMeshSource `bson:"source,omitempty" json:"source,omitempty"`
  319. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty"` //自定义数据
  320. }
  321. type AssetEnv3dHdr struct {
  322. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  323. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"` //用户Id
  324. UserInfo *AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty" complex:"true"` //用户Id
  325. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  326. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"`
  327. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"`
  328. Name string `bson:"name,omitempty" json:"name"`
  329. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  330. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  331. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail" complex:"true"`
  332. Categories []string `bson:"categories,omitempty" json:"categories" complex:"true"` //所属分类Id
  333. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  334. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  335. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  336. Source *HdrSource `bson:"source,omitempty" json:"source,omitempty" complex:"true"`
  337. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty" complex:"true"` //用户数据
  338. }
  339. func (s *AssetEnv3dHdr) UpdateSourceUrl(handler UpdateUrlHandler) {
  340. if s.Thumbnail != nil {
  341. s.Thumbnail.UpdateSourceUrl(handler)
  342. }
  343. if s.UserInfo != nil && s.UserInfo.Thumbnail != nil {
  344. s.UserInfo.Thumbnail.UpdateSourceUrl(handler)
  345. }
  346. if s.Source == nil {
  347. return
  348. }
  349. if s.Source.Config != nil {
  350. s.Source.Config.UpdateSourceUrl(handler)
  351. }
  352. if s.Source.File != nil {
  353. s.Source.File.UpdateSourceUrl(handler)
  354. }
  355. }
  356. func (s *AssetEnv3dHdr) SetIdEmpty() {
  357. s.Id = primitive.NilObjectID
  358. }
  359. func (s *AssetEnv3dHdr) ResetCreateTime() {
  360. s.CreateTime = time.Now()
  361. s.UpdateTime = time.Now()
  362. }
  363. func (s *AssetEnv3dHdr) SetOwner(id string, otype string) {
  364. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  365. s.OwnerType = otype
  366. }
  367. func (s *AssetEnv3dHdr) SetAssetType(otype string) {
  368. s.AssetType = otype
  369. }
  370. func (s *AssetEnv3dHdr) SetUserInfo(id string, info *AssetUserInfo) {
  371. s.UserId, _ = primitive.ObjectIDFromHex(id)
  372. s.UserInfo = info
  373. }
  374. type CusColorParams struct {
  375. BaseAlbedoId string `bson:"baseAlbedoId,omitempty" json:"baseAlbedoId,omitempty"` //基础图片
  376. BaseAlbedo *OssType `bson:"baseAlbedo,omitempty" json:"baseAlbedo,omitempty"` //基础图片
  377. SourceMode *int `bson:"sourceMode,omitempty" json:"sourceMode,omitempty"`
  378. SourceColor *Vect3 `bson:"sourceColor,omitempty" json:"sourceColor,omitempty"`
  379. TargetColor *Vect3 `bson:"targetColor,omitempty" json:"targetColor,omitempty"`
  380. ColorVariationHue *int `bson:"color_variation_hue,omitempty" json:"color_variation_hue,omitempty"`
  381. ColorVariationChroma *float32 `bson:"color_variation_chroma,omitempty" json:"color_variation_chroma,omitempty"`
  382. ColorVariationLuma *float32 `bson:"color_variation_luma,omitempty" json:"color_variation_luma,omitempty"`
  383. UseMask bool `bson:"useMask,omitempty" json:"useMask,omitempty"`
  384. MaskHue *int `bson:"mask_hue,omitempty" json:"mask_hue,omitempty"`
  385. MaskChroma *float32 `bson:"mask_chroma,omitempty" json:"mask_chroma,omitempty"`
  386. MaskLuma *float32 `bson:"mask_luma,omitempty" json:"mask_luma,omitempty"`
  387. MaskBlur *float32 `bson:"mask_blur,omitempty" json:"mask_blur,omitempty"`
  388. MaskSmoothness *float32 `bson:"mask_smoothness,omitempty" json:"mask_smoothness,omitempty"`
  389. }
  390. const (
  391. MatGenerateCusColor = "cuscolor" //色卡换色 算法生成
  392. MatGenerateTech = "tech" //按工艺生成
  393. CusColorSourceModeAverage = 0
  394. CusColorSourceModeColor = 1
  395. CusColorSourceModeTexure = 2
  396. )
  397. type MatConfigSource struct {
  398. Id string `bson:"id,omitempty" json:"id,omitempty"`
  399. Name string `bson:"name,omitempty" json:"name,omitempty"`
  400. CusNum string `bson:"cusNum,omitempty" json:"cusNum,omitempty"`
  401. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail,omitempty"`
  402. UvTransform *MaterailUv `bson:"uv,omitempty" json:"uv,omitempty"`
  403. CusUvTransform *MaterailUv `bson:"cusUv,omitempty" json:"cusUv,omitempty"`
  404. CullFace string `bson:"cullFace" json:"cullFace,omitempty"`
  405. Diamond *MatDiamond `bson:"diamond" json:"diamond,omitempty"`
  406. Albedo *MatTextureColor `bson:"albedo" json:"albedo,omitempty"`
  407. Roughness *MatTextureFactor `bson:"roughness" json:"roughness,omitempty"`
  408. Metalness *MatTextureFactor `bson:"metalness" json:"metalness,omitempty"`
  409. Normal *MatNormal `bson:"normal" json:"normal,omitempty"`
  410. Opacity *MatTextureFactorWithEnable `bson:"opacity" json:"opacity,omitempty"`
  411. Displace *MatTextureFactorWithEnable `bson:"displace,omitempty" json:"displace,omitempty"` //置换
  412. Diffuse *MatTextureColor `bson:"diffuse,omitempty" json:"diffuse,omitempty"`
  413. Specular *MatTextureColor `bson:"specular" json:"specular,omitempty"`
  414. Gloss *MatTextureFactor `bson:"gloss,omitempty" json:"gloss,omitempty"` //光泽贴图
  415. Version int `bson:"version,omitempty" json:"version,omitempty"`
  416. Type string `bson:"type,omitempty" json:"type,omitempty"` //高光流 金属流(默认) meta spec
  417. UvMap string `bson:"uvMap,omitempty" json:"uvMap,omitempty"` //uv包裹 box、uv
  418. ClassType string `bson:"classType,omitempty" json:"classType,omitempty"` //pbr(默认) / diamond
  419. //工艺相关材质球
  420. TechMaterial *TechMatConfig `bson:"techMaterial" json:"techMaterial,omitempty"`
  421. Images []*ComponentImage `bson:"images" json:"images,omitempty"`
  422. //自定义换色材质
  423. ColorMatch *CusColorParams `bson:"colorMatch" json:"colorMatch,omitempty"` //自定义颜色参数
  424. GenerateType string `bson:"generateType" json:"generateType,omitempty"` //面临生成类型 cuscolor(换色) / tech(工艺)
  425. //其他数据
  426. Anisotropic float32 `bson:"anisotropic" json:"anisotropic"`
  427. AnisotropicRotation float32 `bson:"anisotropicRotation" json:"anisotropicRotation"`
  428. Clearcoat float32 `bson:"clearcoat" json:"clearcoat"`
  429. ClearcoatRoughness float32 `bson:"clearcoatRoughness" json:"clearcoatRoughness"`
  430. Emission Vect3 `bson:"emission" json:"emission"`
  431. EmissionStrength float32 `bson:"emissionStrength" json:"emissionStrength"`
  432. Ior float32 `bson:"ior" json:"ior"`
  433. Sheen float32 `bson:"sheen" json:"sheen"`
  434. SheenTint float32 `bson:"sheenTint" json:"sheenTint"`
  435. SpecularTint float32 `bson:"specularTint" json:"specularTint"`
  436. Subsurface float32 `bson:"subsurface" json:"subsurface"`
  437. SubsurfaceColor Vect3 `bson:"subsurfaceColor" json:"subsurfaceColor"`
  438. SubsurfaceRadius Vect3 `bson:"subsurfaceRadius" json:"subsurfaceRadius"`
  439. Transmission float32 `bson:"transmission" json:"transmission"`
  440. TransmissionRoughness float32 `bson:"transmissionRoughness" json:"transmissionRoughness"`
  441. Reflectivity float32 `bson:"reflectivity" json:"reflectivity"`
  442. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty"` //指定要数据放置的字段
  443. }
  444. func (m *MatConfigSource) UpdateSourceUrl(handler UpdateUrlHandler) {
  445. if m.Thumbnail != nil {
  446. m.Thumbnail.UpdateSourceUrl(handler)
  447. }
  448. if m.Albedo != nil {
  449. m.Albedo.UpdateSourceUrl(handler)
  450. }
  451. if m.Roughness != nil {
  452. m.Roughness.UpdateSourceUrl(handler)
  453. }
  454. if m.Metalness != nil {
  455. m.Metalness.UpdateSourceUrl(handler)
  456. }
  457. if m.Normal != nil {
  458. m.Normal.UpdateSourceUrl(handler)
  459. }
  460. if m.Opacity != nil {
  461. m.Opacity.UpdateSourceUrl(handler)
  462. }
  463. if m.Displace != nil {
  464. m.Displace.UpdateSourceUrl(handler)
  465. }
  466. if m.Diffuse != nil {
  467. m.Diffuse.UpdateSourceUrl(handler)
  468. }
  469. if m.Specular != nil {
  470. m.Specular.UpdateSourceUrl(handler)
  471. }
  472. if m.Gloss != nil {
  473. m.Gloss.UpdateSourceUrl(handler)
  474. }
  475. if m.TechMaterial != nil {
  476. m.TechMaterial.UpdateSourceUrl(handler)
  477. }
  478. for _, im := range m.Images {
  479. if im.Image != nil {
  480. im.Image.UpdateSourceUrl(handler)
  481. }
  482. }
  483. if m.ColorMatch != nil && m.ColorMatch.BaseAlbedo != nil {
  484. m.ColorMatch.BaseAlbedo.UpdateSourceUrl(handler)
  485. }
  486. }
  487. type AssetMatGroupSource struct {
  488. Version string `bson:"version,omitempty" json:"version"`
  489. ColorCards []*MatConfigSource `bson:"colorCards,omitempty" json:"colorCards"`
  490. }
  491. type AssetMatGroup struct {
  492. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  493. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"`
  494. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  495. UserInfo *AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty" complex:"true"` //用户信息
  496. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"`
  497. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"`
  498. Name string `bson:"name,omitempty" json:"name"` //名字
  499. CusNum string `bson:"cusNum,omitempty" json:"cusNum"` //编号
  500. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  501. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  502. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail" complex:"true"`
  503. Categories []string `bson:"categories,omitempty" json:"categories" complex:"true"` //所属分类Id
  504. CusCategories []string `bson:"cusCategories,omitempty" json:"cusCategories" complex:"true"` //所属分类Id
  505. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  506. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  507. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  508. Source *AssetMatGroupSource `bson:"source,omitempty" json:"source,omitempty" complex:"true"`
  509. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty" complex:"true"` //自定义数据
  510. }
  511. func (s *AssetMatGroup) UpdateSourceUrl(handler UpdateUrlHandler) {
  512. if s.UserInfo != nil && s.UserInfo.Thumbnail != nil {
  513. s.UserInfo.Thumbnail.UpdateSourceUrl(handler)
  514. }
  515. if s.Thumbnail != nil {
  516. s.Thumbnail.UpdateSourceUrl(handler)
  517. }
  518. if s.Source != nil && s.Source.ColorCards != nil {
  519. for _, c := range s.Source.ColorCards {
  520. c.UpdateSourceUrl(handler)
  521. }
  522. }
  523. }
  524. func (s *AssetMatGroup) SetIdEmpty() {
  525. s.Id = primitive.NilObjectID
  526. }
  527. func (s *AssetMatGroup) ResetCreateTime() {
  528. s.CreateTime = time.Now()
  529. s.UpdateTime = time.Now()
  530. }
  531. func (s *AssetMatGroup) SetOwner(id string, otype string) {
  532. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  533. s.OwnerType = otype
  534. }
  535. func (s *AssetMatGroup) SetAssetType(otype string) {
  536. s.AssetType = otype
  537. }
  538. func (s *AssetMatGroup) SetUserInfo(id string, info *AssetUserInfo) {
  539. s.UserId, _ = primitive.ObjectIDFromHex(id)
  540. s.UserInfo = info
  541. }
  542. type AssetMat struct {
  543. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  544. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"`
  545. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  546. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"`
  547. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"`
  548. UserInfo *AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty" complex:"true"` //用户信息
  549. Name string `bson:"name,omitempty" json:"name"` //名字
  550. CusNum string `bson:"cusNum,omitempty" json:"cusNum"` //编号
  551. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  552. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  553. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail" complex:"true"`
  554. Categories []string `bson:"categories,omitempty" json:"categories" complex:"true"` //所属分类Id
  555. CusCategories []string `bson:"cusCategories,omitempty" json:"cusCategories" complex:"true"` //所属分类Id
  556. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  557. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  558. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  559. Source *MatConfigSource `bson:"source,omitempty" json:"source,omitempty" complex:"true"`
  560. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty" complex:"true"` //自定义数据
  561. }
  562. func (s *AssetMat) UpdateSourceUrl(handler UpdateUrlHandler) {
  563. if s.UserInfo != nil && s.UserInfo.Thumbnail != nil {
  564. s.UserInfo.Thumbnail.UpdateSourceUrl(handler)
  565. }
  566. if s.Thumbnail != nil {
  567. s.Thumbnail.UpdateSourceUrl(handler)
  568. }
  569. if s.Source != nil {
  570. s.Source.UpdateSourceUrl(handler)
  571. }
  572. }
  573. func (s *AssetMat) SetIdEmpty() {
  574. s.Id = primitive.NilObjectID
  575. }
  576. func (s *AssetMat) ResetCreateTime() {
  577. s.CreateTime = time.Now()
  578. s.UpdateTime = time.Now()
  579. }
  580. func (s *AssetMat) SetOwner(id string, otype string) {
  581. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  582. s.OwnerType = otype
  583. }
  584. func (s *AssetMat) SetAssetType(otype string) {
  585. s.AssetType = otype
  586. }
  587. func (s *AssetMat) SetUserInfo(id string, info *AssetUserInfo) {
  588. s.UserId, _ = primitive.ObjectIDFromHex(id)
  589. s.UserInfo = info
  590. }
  591. func (m *AssetMat) CopyFromSpecMat(sm *SpecialMat) {
  592. m.Name = sm.Name
  593. m.CreateTime = sm.CreateTime
  594. m.UpdateTime = sm.CreateTime
  595. m.Thumbnail = sm.Thumbnail
  596. m.UserData = map[string]string{"category": sm.Category}
  597. m.AssetState = AssetState_Succ
  598. trueV := true
  599. m.Enable = &trueV
  600. m.Source = &MatConfigSource{
  601. Version: 1,
  602. Id: sm.Id.Hex(),
  603. Name: sm.Name,
  604. Thumbnail: sm.Thumbnail,
  605. Type: sm.Type,
  606. UvTransform: sm.Uvtransform,
  607. Albedo: &MatTextureColor{},
  608. Roughness: &MatTextureFactor{},
  609. Metalness: &MatTextureFactor{},
  610. Opacity: &MatTextureFactorWithEnable{Enable: false},
  611. Displace: &MatTextureFactorWithEnable{Enable: false},
  612. Diffuse: &MatTextureColor{},
  613. Specular: &MatTextureColor{},
  614. Gloss: &MatTextureFactor{},
  615. }
  616. if len(m.Source.Type) < 1 {
  617. m.Source.Type = "meta"
  618. }
  619. falseV := false
  620. if sm.BaseMap != nil {
  621. if len(sm.BaseMap.Url) > 0 {
  622. m.Source.Albedo.UseTexture = &trueV
  623. m.Source.Albedo.Texture = sm.BaseMap
  624. } else {
  625. m.Source.Albedo.UseTexture = &falseV
  626. m.Source.Albedo.Color = sm.BaseColor
  627. }
  628. }
  629. if sm.NormalMap != nil {
  630. m.Source.Normal = &MatNormal{
  631. UseTexture: &trueV,
  632. Texture: sm.NormalMap,
  633. FlipY: &falseV,
  634. }
  635. }
  636. if sm.RoughMap != nil {
  637. if len(sm.BaseMap.Url) > 0 {
  638. m.Source.Roughness.UseTexture = &trueV
  639. m.Source.Roughness.Texture = sm.RoughMap
  640. } else {
  641. m.Source.Roughness.UseTexture = &falseV
  642. if sm.RoughFactor != nil {
  643. v := float32(*sm.RoughFactor)
  644. m.Source.Roughness.Factor = &v
  645. } else {
  646. v := float32(0.5)
  647. m.Source.Roughness.Factor = &v
  648. }
  649. }
  650. }
  651. if sm.MetalMap != nil {
  652. if len(sm.MetalMap.Url) > 0 {
  653. m.Source.Metalness.UseTexture = &trueV
  654. m.Source.Metalness.Texture = sm.MetalMap
  655. } else {
  656. m.Source.Metalness.UseTexture = &falseV
  657. if sm.MetalFactor != nil {
  658. v := float32(*sm.MetalFactor)
  659. m.Source.Metalness.Factor = &v
  660. } else {
  661. v := float32(0.5)
  662. m.Source.Metalness.Factor = &v
  663. }
  664. }
  665. }
  666. if sm.OpacMap != nil {
  667. if len(sm.OpacMap.Url) > 0 {
  668. m.Source.Opacity.UseTexture = &trueV
  669. m.Source.Opacity.Texture = sm.OpacMap
  670. m.Source.Opacity.Enable = true
  671. if sm.OpacFactor != nil {
  672. v := float32(*sm.OpacFactor)
  673. m.Source.Opacity.Factor = &v
  674. } else {
  675. v := float32(1.0)
  676. m.Source.Opacity.Factor = &v
  677. }
  678. } else if sm.OpacFactor != nil {
  679. if math.Abs(*sm.OpacFactor-1.0) < 0.001 {
  680. m.Source.Opacity.UseTexture = &falseV
  681. m.Source.Opacity.Enable = true
  682. v := float32(*sm.OpacFactor)
  683. m.Source.Opacity.Factor = &v
  684. }
  685. }
  686. }
  687. if sm.DisplaceMap != nil {
  688. if len(sm.DisplaceMap.Url) > 0 {
  689. m.Source.Displace.UseTexture = &trueV
  690. m.Source.Displace.Texture = sm.DisplaceMap
  691. m.Source.Displace.Enable = true
  692. } else if sm.DisplaceFactor != nil {
  693. v := float32(*sm.DisplaceFactor)
  694. m.Source.Displace.Factor = &v
  695. }
  696. }
  697. if sm.DiffuseMap != nil {
  698. if len(sm.DiffuseMap.Url) > 0 {
  699. m.Source.Diffuse.UseTexture = &trueV
  700. m.Source.Diffuse.Texture = sm.DiffuseMap
  701. } else {
  702. m.Source.Diffuse.UseTexture = &falseV
  703. m.Source.Diffuse.Color = sm.DiffuseColor
  704. }
  705. }
  706. if sm.SpecMap != nil {
  707. if len(sm.SpecMap.Url) > 0 {
  708. m.Source.Specular.UseTexture = &trueV
  709. m.Source.Specular.Texture = sm.SpecMap
  710. } else {
  711. m.Source.Specular.UseTexture = &falseV
  712. m.Source.Specular.Color = sm.SpecColor
  713. }
  714. }
  715. if sm.GlossMap != nil {
  716. if len(sm.GlossMap.Url) > 0 {
  717. m.Source.Gloss.UseTexture = &trueV
  718. m.Source.Gloss.Texture = sm.GlossMap
  719. } else {
  720. m.Source.Gloss.UseTexture = &falseV
  721. if sm.GlossFactor != nil {
  722. v := float32(*sm.GlossFactor)
  723. m.Source.Gloss.Factor = &v
  724. }
  725. }
  726. }
  727. m.Source.UvMap = "box"
  728. }
  729. func (m *AssetMat) CopyFromLineMat(sm *LineMat) {
  730. m.Name = sm.Name
  731. m.CreateTime = sm.CreateTime
  732. m.UpdateTime = sm.CreateTime
  733. m.Thumbnail = sm.Thumbnail
  734. m.UserData = map[string]string{"category": sm.Category}
  735. m.AssetState = AssetState_Succ
  736. trueV := true
  737. m.Enable = &trueV
  738. m.Source = &MatConfigSource{
  739. Version: 1,
  740. Id: sm.Id.Hex(),
  741. Name: sm.Name,
  742. Thumbnail: sm.Thumbnail,
  743. Type: sm.Type,
  744. UvTransform: sm.Uvtransform,
  745. Albedo: &MatTextureColor{},
  746. Roughness: &MatTextureFactor{},
  747. Metalness: &MatTextureFactor{},
  748. Opacity: &MatTextureFactorWithEnable{Enable: false},
  749. Displace: &MatTextureFactorWithEnable{Enable: false},
  750. Diffuse: &MatTextureColor{},
  751. Specular: &MatTextureColor{},
  752. Gloss: &MatTextureFactor{},
  753. }
  754. if len(m.Source.Type) < 1 {
  755. m.Source.Type = "meta"
  756. }
  757. falseV := false
  758. if sm.BaseMap != nil {
  759. if len(sm.BaseMap.Url) > 0 {
  760. m.Source.Albedo.UseTexture = &trueV
  761. m.Source.Albedo.Texture = sm.BaseMap
  762. } else {
  763. m.Source.Albedo.UseTexture = &falseV
  764. m.Source.Albedo.Color = sm.BaseColor
  765. }
  766. }
  767. if sm.NormalMap != nil {
  768. m.Source.Normal = &MatNormal{
  769. UseTexture: &trueV,
  770. Texture: sm.NormalMap,
  771. FlipY: &falseV,
  772. }
  773. }
  774. if sm.RoughMap != nil {
  775. if len(sm.BaseMap.Url) > 0 {
  776. m.Source.Roughness.UseTexture = &trueV
  777. m.Source.Roughness.Texture = sm.RoughMap
  778. } else {
  779. m.Source.Roughness.UseTexture = &falseV
  780. if sm.RoughFactor != nil {
  781. v := float32(*sm.RoughFactor)
  782. m.Source.Roughness.Factor = &v
  783. } else {
  784. v := float32(0.5)
  785. m.Source.Roughness.Factor = &v
  786. }
  787. }
  788. }
  789. if sm.MetalMap != nil {
  790. if len(sm.MetalMap.Url) > 0 {
  791. m.Source.Metalness.UseTexture = &trueV
  792. m.Source.Metalness.Texture = sm.MetalMap
  793. } else {
  794. m.Source.Metalness.UseTexture = &falseV
  795. if sm.MetalFactor != nil {
  796. v := float32(*sm.MetalFactor)
  797. m.Source.Metalness.Factor = &v
  798. } else {
  799. v := float32(0.5)
  800. m.Source.Metalness.Factor = &v
  801. }
  802. }
  803. }
  804. if sm.OpacMap != nil {
  805. if len(sm.OpacMap.Url) > 0 {
  806. m.Source.Opacity.UseTexture = &trueV
  807. m.Source.Opacity.Texture = sm.OpacMap
  808. m.Source.Opacity.Enable = true
  809. if sm.OpacFactor != nil {
  810. v := float32(*sm.OpacFactor)
  811. m.Source.Opacity.Factor = &v
  812. } else {
  813. v := float32(1.0)
  814. m.Source.Opacity.Factor = &v
  815. }
  816. } else if sm.OpacFactor != nil {
  817. if math.Abs(*sm.OpacFactor-1.0) < 0.001 {
  818. m.Source.Opacity.UseTexture = &falseV
  819. m.Source.Opacity.Enable = true
  820. v := float32(*sm.OpacFactor)
  821. m.Source.Opacity.Factor = &v
  822. }
  823. }
  824. }
  825. if sm.DisplaceMap != nil {
  826. if len(sm.DisplaceMap.Url) > 0 {
  827. m.Source.Displace.UseTexture = &trueV
  828. m.Source.Displace.Texture = sm.DisplaceMap
  829. m.Source.Displace.Enable = true
  830. } else if sm.DisplaceFactor != nil {
  831. v := float32(*sm.DisplaceFactor)
  832. m.Source.Displace.Factor = &v
  833. }
  834. }
  835. if sm.DiffuseMap != nil {
  836. if len(sm.DiffuseMap.Url) > 0 {
  837. m.Source.Diffuse.UseTexture = &trueV
  838. m.Source.Diffuse.Texture = sm.DiffuseMap
  839. } else {
  840. m.Source.Diffuse.UseTexture = &falseV
  841. m.Source.Diffuse.Color = sm.DiffuseColor
  842. }
  843. }
  844. if sm.SpecMap != nil {
  845. if len(sm.SpecMap.Url) > 0 {
  846. m.Source.Specular.UseTexture = &trueV
  847. m.Source.Specular.Texture = sm.SpecMap
  848. } else {
  849. m.Source.Specular.UseTexture = &falseV
  850. m.Source.Specular.Color = sm.SpecColor
  851. }
  852. }
  853. if sm.GlossMap != nil {
  854. if len(sm.GlossMap.Url) > 0 {
  855. m.Source.Gloss.UseTexture = &trueV
  856. m.Source.Gloss.Texture = sm.GlossMap
  857. } else {
  858. m.Source.Gloss.UseTexture = &falseV
  859. if sm.GlossFactor != nil {
  860. v := float32(*sm.GlossFactor)
  861. m.Source.Gloss.Factor = &v
  862. }
  863. }
  864. }
  865. m.Source.UvMap = "box"
  866. }
  867. func (m *AssetMat) CopyFromMatConf(sm *MaterialConf) {
  868. m.Name = sm.Name
  869. m.CreateTime = time.Now()
  870. m.UpdateTime = time.Now()
  871. m.Thumbnail = sm.Thumbnail
  872. m.CusNum = sm.CusNum
  873. m.AssetState = AssetState_Succ
  874. trueV := true
  875. m.Enable = &trueV
  876. m.Source = &MatConfigSource{
  877. Version: 1,
  878. Id: sm.MatId.Hex(),
  879. CusNum: sm.CusNum,
  880. Name: sm.Name,
  881. Thumbnail: sm.Thumbnail,
  882. UserData: sm.UserData,
  883. Type: sm.Type,
  884. UvTransform: sm.Uvtransform,
  885. CusUvTransform: sm.CusUvTransform,
  886. Albedo: &MatTextureColor{},
  887. Roughness: &MatTextureFactor{},
  888. Metalness: &MatTextureFactor{},
  889. Opacity: &MatTextureFactorWithEnable{Enable: false},
  890. Displace: &MatTextureFactorWithEnable{Enable: false},
  891. Diffuse: &MatTextureColor{},
  892. Specular: &MatTextureColor{},
  893. Gloss: &MatTextureFactor{},
  894. }
  895. if len(m.Source.Type) < 1 {
  896. m.Source.Type = "meta"
  897. }
  898. falseV := false
  899. if sm.BaseMap != nil {
  900. if len(sm.BaseMap.Url) > 0 {
  901. m.Source.Albedo.UseTexture = &trueV
  902. m.Source.Albedo.Texture = sm.BaseMap
  903. } else {
  904. m.Source.Albedo.UseTexture = &falseV
  905. m.Source.Albedo.Color = sm.BaseColor
  906. }
  907. }
  908. if sm.NormalMap != nil {
  909. m.Source.Normal = &MatNormal{
  910. UseTexture: &trueV,
  911. Texture: sm.NormalMap,
  912. FlipY: &falseV,
  913. }
  914. }
  915. if sm.RoughMap != nil {
  916. if len(sm.BaseMap.Url) > 0 {
  917. m.Source.Roughness.UseTexture = &trueV
  918. m.Source.Roughness.Texture = sm.RoughMap
  919. } else {
  920. m.Source.Roughness.UseTexture = &falseV
  921. if sm.RoughFactor != nil {
  922. v := float32(*sm.RoughFactor)
  923. m.Source.Roughness.Factor = &v
  924. } else {
  925. v := float32(0.5)
  926. m.Source.Roughness.Factor = &v
  927. }
  928. }
  929. }
  930. if sm.MetalMap != nil {
  931. if len(sm.MetalMap.Url) > 0 {
  932. m.Source.Metalness.UseTexture = &trueV
  933. m.Source.Metalness.Texture = sm.MetalMap
  934. } else {
  935. m.Source.Metalness.UseTexture = &falseV
  936. if sm.MetalFactor != nil {
  937. v := float32(*sm.MetalFactor)
  938. m.Source.Metalness.Factor = &v
  939. } else {
  940. v := float32(0.5)
  941. m.Source.Metalness.Factor = &v
  942. }
  943. }
  944. }
  945. if sm.OpacMap != nil {
  946. if len(sm.OpacMap.Url) > 0 {
  947. m.Source.Opacity.UseTexture = &trueV
  948. m.Source.Opacity.Texture = sm.OpacMap
  949. m.Source.Opacity.Enable = true
  950. if sm.OpacFactor != nil {
  951. v := float32(*sm.OpacFactor)
  952. m.Source.Opacity.Factor = &v
  953. } else {
  954. v := float32(1.0)
  955. m.Source.Opacity.Factor = &v
  956. }
  957. } else if sm.OpacFactor != nil {
  958. if math.Abs(*sm.OpacFactor-1.0) < 0.001 {
  959. m.Source.Opacity.UseTexture = &falseV
  960. m.Source.Opacity.Enable = true
  961. v := float32(*sm.OpacFactor)
  962. m.Source.Opacity.Factor = &v
  963. }
  964. }
  965. }
  966. if sm.DisplaceMap != nil {
  967. if len(sm.DisplaceMap.Url) > 0 {
  968. m.Source.Displace.UseTexture = &trueV
  969. m.Source.Displace.Texture = sm.DisplaceMap
  970. m.Source.Displace.Enable = true
  971. } else if sm.DisplaceFactor != nil {
  972. v := float32(*sm.DisplaceFactor)
  973. m.Source.Displace.Factor = &v
  974. }
  975. }
  976. if sm.DiffuseMap != nil {
  977. if len(sm.DiffuseMap.Url) > 0 {
  978. m.Source.Diffuse.UseTexture = &trueV
  979. m.Source.Diffuse.Texture = sm.DiffuseMap
  980. } else {
  981. m.Source.Diffuse.UseTexture = &falseV
  982. m.Source.Diffuse.Color = sm.DiffuseColor
  983. }
  984. }
  985. if sm.SpecMap != nil {
  986. if len(sm.SpecMap.Url) > 0 {
  987. m.Source.Specular.UseTexture = &trueV
  988. m.Source.Specular.Texture = sm.SpecMap
  989. } else {
  990. m.Source.Specular.UseTexture = &falseV
  991. m.Source.Specular.Color = sm.SpecColor
  992. }
  993. }
  994. if sm.GlossMap != nil {
  995. if len(sm.GlossMap.Url) > 0 {
  996. m.Source.Gloss.UseTexture = &trueV
  997. m.Source.Gloss.Texture = sm.GlossMap
  998. } else {
  999. m.Source.Gloss.UseTexture = &falseV
  1000. if sm.GlossFactor != nil {
  1001. v := float32(*sm.GlossFactor)
  1002. m.Source.Gloss.Factor = &v
  1003. }
  1004. }
  1005. }
  1006. m.Source.UvMap = "box"
  1007. }
  1008. type AssetImage struct {
  1009. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  1010. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"` //用户Id
  1011. UserInfo *AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty" complex:"true"` //用户Id
  1012. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"`
  1013. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"` //user team company
  1014. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"` //user team company
  1015. Name string `bson:"name,omitempty" json:"name"`
  1016. CusNum string `bson:"cusNum,omitempty" json:"cusNum,omitempty"` //型号
  1017. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  1018. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  1019. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail" complex:"true"`
  1020. Categories []string `bson:"categories,omitempty" json:"categories" complex:"true"` //所属分类Id
  1021. CusCategories []string `bson:"cusCategories,omitempty" json:"cusCategories" complex:"true"` //所属分类Id
  1022. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  1023. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  1024. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  1025. Source *ImageSource `bson:"source,omitempty" json:"source,omitempty" complex:"true"`
  1026. }
  1027. func (s *AssetImage) UpdateSourceUrl(handler UpdateUrlHandler) {
  1028. if s.Thumbnail != nil {
  1029. s.Thumbnail.UpdateSourceUrl(handler)
  1030. }
  1031. if s.Source != nil && s.Source.File != nil {
  1032. s.Source.File.UpdateSourceUrl(handler)
  1033. }
  1034. }
  1035. func (s *AssetImage) SetIdEmpty() {
  1036. s.Id = primitive.NilObjectID
  1037. }
  1038. func (s *AssetImage) ResetCreateTime() {
  1039. s.CreateTime = time.Now()
  1040. s.UpdateTime = time.Now()
  1041. }
  1042. func (s *AssetImage) SetOwner(id string, otype string) {
  1043. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  1044. s.OwnerType = otype
  1045. }
  1046. func (s *AssetImage) SetAssetType(otype string) {
  1047. s.AssetType = otype
  1048. }
  1049. func (s *AssetImage) SetUserInfo(id string, info *AssetUserInfo) {
  1050. s.UserId, _ = primitive.ObjectIDFromHex(id)
  1051. s.UserInfo = info
  1052. }
  1053. type AssetUserInfo struct {
  1054. Name string `bson:"name,omitempty" json:"name"`
  1055. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  1056. }
  1057. type AssetPackage struct {
  1058. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  1059. OwnerId primitive.ObjectID `bson:"ownerId,omitempty" json:"ownerId,omitempty"` //userId teamId companyId
  1060. OwnerType string `bson:"ownerType,omitempty" json:"ownerType,omitempty"` //user team company
  1061. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"` //用户Id
  1062. UserInfo *AssetUserInfo `bson:"userInfo,omitempty" json:"userInfo,omitempty" complex:"true"` //用户Id
  1063. AssetType string `bson:"assetType,omitempty" json:"assetType,omitempty"` //业务类型 shoe sole heel decorate
  1064. Name string `bson:"name,omitempty" json:"name"`
  1065. CusNum string `bson:"cusNum,omitempty" json:"cusNum,omitempty"` //型号
  1066. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  1067. UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
  1068. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail" complex:"true"`
  1069. Categories []string `bson:"categories,omitempty" json:"categories" complex:"true"` //所属分类Id
  1070. CusCategories []string `bson:"cusCategories,omitempty" json:"cusCategories" complex:"true"` //所属分类Id
  1071. TaskId string `bson:"taskId,omitempty" json:"taskId"` //资产处理id
  1072. AssetState int `bson:"assetState,omitempty" json:"assetState"`
  1073. Enable *bool `bson:"enable,omitempty" json:"enable"` //是否有效!
  1074. Source *Queen3dPackageSource `bson:"source,omitempty" json:"source,omitempty" complex:"true"`
  1075. UserData interface{} `bson:"userData,omitempty" json:"userData,omitempty" complex:"true"` //用户数据
  1076. }
  1077. func (s *AssetPackage) SetIdEmpty() {
  1078. s.Id = primitive.NilObjectID
  1079. }
  1080. func (s *AssetPackage) ResetCreateTime() {
  1081. s.CreateTime = time.Now()
  1082. s.UpdateTime = time.Now()
  1083. }
  1084. func (s *AssetPackage) SetOwner(id string, otype string) {
  1085. s.OwnerId, _ = primitive.ObjectIDFromHex(id)
  1086. s.OwnerType = otype
  1087. }
  1088. func (s *AssetPackage) SetAssetType(otype string) {
  1089. s.AssetType = otype
  1090. }
  1091. func (s *AssetPackage) SetUserInfo(id string, info *AssetUserInfo) {
  1092. s.UserId, _ = primitive.ObjectIDFromHex(id)
  1093. s.UserInfo = info
  1094. }
  1095. type UpdateUrlHandler func(string) string
  1096. func (s *AssetPackage) UpdateSourceUrl(handler UpdateUrlHandler) {
  1097. if s.Thumbnail != nil {
  1098. s.Thumbnail.Url = handler(s.Thumbnail.Url)
  1099. }
  1100. if s.Source == nil {
  1101. return
  1102. }
  1103. source := s.Source
  1104. for _, g := range source.Geoms {
  1105. g.UpdateSourceUrl(handler)
  1106. }
  1107. for _, e := range source.Env3ds {
  1108. e.UpdateSourceUrl(handler)
  1109. }
  1110. for _, p := range source.Products {
  1111. p.UpdateSourceUrl(handler)
  1112. }
  1113. for _, s := range source.Scenes {
  1114. s.UpdateSourceUrl(handler)
  1115. }
  1116. for _, m := range source.Mats {
  1117. m.UpdateSourceUrl(handler)
  1118. }
  1119. }