database.go 47 KB

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