fabric.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package comm
  2. import (
  3. "time"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. )
  6. type Fabric struct {
  7. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
  8. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId,omitempty"`
  9. TeamId string `bson:"teamId,omitempty" json:"teamId,omitempty"` //所属团队Id
  10. CompanyId string `bson:"companyId,omitempty" json:"companyId,omitempty"` //所属团队Id
  11. Name string `bson:"name,omitempty" json:"name,omitempty"`
  12. CusNum string `bson:"cusNum,omitempty" json:"cusNum,omitempty"`
  13. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail,omitempty"`
  14. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime,omitempty"`
  15. Price float32 `bson:"price,omitempty" json:"price,omitempty"`
  16. ColorCards []*MaterialConf `bson:"colorCards,omitempty" json:"colorCards,omitempty"`
  17. Categories []string `bson:"categories,omitempty" json:"categories,omitempty"`
  18. State int32 `bson:"state,omitempty" json:"state,omitempty"`
  19. }
  20. func (s *AssetMatGroup) CopyFromFabric(fab *Fabric) {
  21. s.Id = fab.Id
  22. s.AssetState = AssetState_Succ
  23. s.Categories = fab.Categories
  24. s.CreateTime = fab.CreateTime
  25. s.UpdateTime = fab.CreateTime
  26. s.UserId = fab.UserId
  27. s.OwnerId = fab.UserId
  28. s.OwnerType = "user"
  29. s.CusCategories = fab.Categories
  30. s.CusNum = fab.CusNum
  31. s.Name = fab.Name
  32. enable := true
  33. s.Enable = &enable
  34. s.Thumbnail = fab.Thumbnail
  35. s.Source = &AssetMatGroupSource{
  36. Version: "1.0",
  37. ColorCards: []*MatConfigSource{},
  38. }
  39. var toFloat32 = func(f *float64) *float32 {
  40. var out float32 = 0
  41. if f != nil {
  42. out = float32(*f)
  43. }
  44. return &out
  45. }
  46. for _, c := range fab.ColorCards {
  47. conf := &MatConfigSource{
  48. Version: 1,
  49. Type: c.Type,
  50. Name: c.Name,
  51. CusNum: c.CusNum,
  52. Thumbnail: c.Thumbnail,
  53. UvTransform: c.Uvtransform,
  54. CusUvTransform: c.CusUvTransform,
  55. Albedo: &MatTextureColor{
  56. Color: c.BaseColor,
  57. Texture: c.BaseMap,
  58. },
  59. Roughness: &MatTextureFactor{
  60. Texture: c.RoughMap,
  61. Factor: toFloat32(c.RoughFactor),
  62. },
  63. Metalness: &MatTextureFactor{
  64. Factor: toFloat32(c.MetalFactor),
  65. Texture: c.MetalMap,
  66. },
  67. Normal: &MatNormal{
  68. UseTexture: &enable,
  69. Texture: c.NormalMap,
  70. },
  71. Opacity: &MatTextureFactorWithEnable{
  72. Texture: c.OpacMap,
  73. Factor: toFloat32(c.OpacFactor),
  74. },
  75. Displace: &MatTextureFactorWithEnable{
  76. Texture: c.DisplaceMap,
  77. Factor: toFloat32(c.DisplaceFactor),
  78. },
  79. Diffuse: &MatTextureColor{
  80. Color: c.DiffuseColor,
  81. Texture: c.DiffuseMap,
  82. },
  83. Gloss: &MatTextureFactor{
  84. Factor: toFloat32(c.GlossFactor),
  85. Texture: c.GlossMap,
  86. },
  87. Specular: &MatTextureColor{
  88. Color: c.SpecColor,
  89. Texture: c.SpecMap,
  90. },
  91. UvMap: "box",
  92. }
  93. if c.BaseMap != nil && len(c.BaseMap.Url) > 0 {
  94. conf.Albedo.UseTexture = &enable
  95. }
  96. if c.RoughMap != nil && len(c.RoughMap.Url) > 0 {
  97. conf.Roughness.UseTexture = &enable
  98. }
  99. if c.MetalMap != nil && len(c.MetalMap.Url) > 0 {
  100. conf.Metalness.UseTexture = &enable
  101. }
  102. if c.OpacFactor != nil && *c.OpacFactor < 0.99 {
  103. conf.Opacity.Enable = true
  104. }
  105. if c.OpacMap != nil && len(c.OpacMap.Url) > 0 {
  106. conf.Opacity.Enable = true
  107. conf.Opacity.UseTexture = &enable
  108. }
  109. if c.DisplaceMap != nil && len(c.DisplaceMap.Url) > 0 {
  110. conf.Displace.Enable = true
  111. conf.Displace.UseTexture = &enable
  112. }
  113. if c.DiffuseMap != nil && len(c.DiffuseMap.Url) > 0 {
  114. conf.Diffuse.UseTexture = &enable
  115. }
  116. if c.GlossMap != nil && len(c.GlossMap.Url) > 0 {
  117. conf.Gloss.UseTexture = &enable
  118. }
  119. if c.SpecMap != nil && len(c.SpecMap.Url) > 0 {
  120. conf.Specular.UseTexture = &enable
  121. }
  122. s.Source.ColorCards = append(s.Source.ColorCards, conf)
  123. }
  124. }