mat.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package model
  2. import (
  3. "math"
  4. "time"
  5. "go.mongodb.org/mongo-driver/bson/primitive"
  6. )
  7. const (
  8. MatType_2D = 3
  9. MatType_Color = 0
  10. MatType_Effect = 2
  11. MatType_Fabric = 1
  12. )
  13. //2D 面料
  14. type Mat2d struct {
  15. Image *OssType `bson:"image,omitempty" json:"image"`
  16. Name string `bson:"name,omitempty" json:"name"`
  17. // Uvtransform *Uvtransform `bson:"uv,omitempty" json:"uv"`
  18. }
  19. type ImageMat struct {
  20. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  21. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId"`
  22. Image *OssType `bson:"image,omitempty" json:"image"`
  23. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  24. Name string `bson:"name,omitempty" json:"name"`
  25. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  26. Category string `bson:"category,omitempty" json:"category"`
  27. Category2 string `bson:"category2,omitempty" json:"category2"`
  28. IsPublic *bool `bson:"isPublic,omitempty" json:"isPublic"`
  29. Platform *bool `bson:"platform,omitempty" json:"platform"` //是否属于平台
  30. ColorCards []*Mat2d `bson:"colorCards,omitempty" json:"colorCards"` //2D面料
  31. Categories []string `bson:"categories,omitempty" json:"categories"` //目录列表
  32. State int32 `bson:"state,omitempty" json:"state"`
  33. }
  34. type MaterialHeader struct {
  35. MatId primitive.ObjectID `bson:"matId,omitempty" json:"matId"` //材质球Id
  36. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  37. Name string `bson:"name,omitempty" json:"name"`
  38. BaseMap *OssType `bson:"baseMap,omitempty" json:"baseMap"`
  39. NormalMap *OssType `bson:"normalMap,omitempty" json:"normalMap"`
  40. RoughMap *OssType `bson:"roughMap,omitempty" json:"roughMap"`
  41. MetalMap *OssType `bson:"metalMap,omitempty" json:"metalMap"`
  42. Uvtransform *MaterailUv `bson:"uv,omitempty" json:"uv"`
  43. }
  44. const MIN = 0.0001
  45. // MIN 为用户自定义的比较精度
  46. func IsEqualFloat32(f1, f2 float32) bool {
  47. return math.Dim(float64(f1), float64(f2)) < MIN
  48. }
  49. func IsEqualFloat64(f1, f2 float64) bool {
  50. return math.Dim(f1, f2) < MIN
  51. }
  52. func (mat *MaterialHeader) IsEqual(mat2 *MaterialHeader) bool {
  53. changed := false
  54. if mat.BaseMap == nil || mat2.BaseMap == nil {
  55. changed = changed || mat.BaseMap != mat2.BaseMap
  56. } else {
  57. changed = changed || mat.BaseMap.Url != mat2.BaseMap.Url
  58. }
  59. if mat.NormalMap == nil || mat2.NormalMap == nil {
  60. changed = changed || mat.NormalMap != mat2.NormalMap
  61. } else {
  62. changed = changed || mat.NormalMap.Url != mat2.NormalMap.Url
  63. }
  64. if mat.RoughMap == nil || mat2.RoughMap == nil {
  65. changed = changed || mat.RoughMap != mat2.RoughMap
  66. } else {
  67. changed = changed || mat.RoughMap.Url != mat2.RoughMap.Url
  68. }
  69. if mat.MetalMap == nil || mat2.MetalMap == nil {
  70. changed = changed || mat.MetalMap != mat2.MetalMap
  71. } else {
  72. changed = changed || mat.MetalMap.Url != mat2.MetalMap.Url
  73. }
  74. if changed {
  75. return false
  76. }
  77. if mat.Uvtransform == nil || mat2.Uvtransform == nil {
  78. changed = mat2.Uvtransform == nil
  79. } else {
  80. changed = changed || !IsEqualFloat64(mat.Uvtransform.OffsetX, mat2.Uvtransform.OffsetX) ||
  81. !IsEqualFloat64(mat.Uvtransform.Scale, mat2.Uvtransform.Scale) ||
  82. !IsEqualFloat64(mat.Uvtransform.Rotate, mat2.Uvtransform.Rotate)
  83. }
  84. return !changed
  85. }
  86. type Fabric struct {
  87. Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
  88. UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId"`
  89. Name string `bson:"name,omitempty" json:"name"`
  90. Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"`
  91. CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
  92. Category string `bson:"category,omitempty" json:"category"`
  93. Category2 string `bson:"category2,omitempty" json:"category2"`
  94. IsPublic *bool `bson:"isPublic,omitempty" json:"isPublic"`
  95. Price float32 `bson:"price,omitempty" json:"price"`
  96. ColorCards []*MaterialHeader `bson:"colorCards,omitempty" json:"colorCards"`
  97. Platform *bool `bson:"platform,omitempty" json:"platform"`
  98. Categories []string `bson:"categories,omitempty" json:"categories"`
  99. State int32 `bson:"state,omitempty" json:"state"`
  100. }