package model import ( "math" "time" "go.mongodb.org/mongo-driver/bson/primitive" ) const ( MatType_2D = 3 MatType_Color = 0 MatType_Effect = 2 MatType_Fabric = 1 ) //2D 面料 type Mat2d struct { Image *OssType `bson:"image,omitempty" json:"image"` Name string `bson:"name,omitempty" json:"name"` // Uvtransform *Uvtransform `bson:"uv,omitempty" json:"uv"` } type ImageMat struct { Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"` UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId"` Image *OssType `bson:"image,omitempty" json:"image"` Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"` Name string `bson:"name,omitempty" json:"name"` CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"` Category string `bson:"category,omitempty" json:"category"` Category2 string `bson:"category2,omitempty" json:"category2"` IsPublic *bool `bson:"isPublic,omitempty" json:"isPublic"` Platform *bool `bson:"platform,omitempty" json:"platform"` //是否属于平台 ColorCards []*Mat2d `bson:"colorCards,omitempty" json:"colorCards"` //2D面料 Categories []string `bson:"categories,omitempty" json:"categories"` //目录列表 State int32 `bson:"state,omitempty" json:"state"` } type MaterialHeader struct { MatId primitive.ObjectID `bson:"matId,omitempty" json:"matId"` //材质球Id Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"` Name string `bson:"name,omitempty" json:"name"` BaseMap *OssType `bson:"baseMap,omitempty" json:"baseMap"` NormalMap *OssType `bson:"normalMap,omitempty" json:"normalMap"` RoughMap *OssType `bson:"roughMap,omitempty" json:"roughMap"` MetalMap *OssType `bson:"metalMap,omitempty" json:"metalMap"` Uvtransform *MaterailUv `bson:"uv,omitempty" json:"uv"` } const MIN = 0.0001 // MIN 为用户自定义的比较精度 func IsEqualFloat32(f1, f2 float32) bool { return math.Dim(float64(f1), float64(f2)) < MIN } func IsEqualFloat64(f1, f2 float64) bool { return math.Dim(f1, f2) < MIN } func (mat *MaterialHeader) IsEqual(mat2 *MaterialHeader) bool { changed := false if mat.BaseMap == nil || mat2.BaseMap == nil { changed = changed || mat.BaseMap != mat2.BaseMap } else { changed = changed || mat.BaseMap.Url != mat2.BaseMap.Url } if mat.NormalMap == nil || mat2.NormalMap == nil { changed = changed || mat.NormalMap != mat2.NormalMap } else { changed = changed || mat.NormalMap.Url != mat2.NormalMap.Url } if mat.RoughMap == nil || mat2.RoughMap == nil { changed = changed || mat.RoughMap != mat2.RoughMap } else { changed = changed || mat.RoughMap.Url != mat2.RoughMap.Url } if mat.MetalMap == nil || mat2.MetalMap == nil { changed = changed || mat.MetalMap != mat2.MetalMap } else { changed = changed || mat.MetalMap.Url != mat2.MetalMap.Url } if changed { return false } if mat.Uvtransform == nil || mat2.Uvtransform == nil { changed = mat2.Uvtransform == nil } else { changed = changed || !IsEqualFloat64(mat.Uvtransform.OffsetX, mat2.Uvtransform.OffsetX) || !IsEqualFloat64(mat.Uvtransform.Scale, mat2.Uvtransform.Scale) || !IsEqualFloat64(mat.Uvtransform.Rotate, mat2.Uvtransform.Rotate) } return !changed } type Fabric struct { Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"` UserId primitive.ObjectID `bson:"userId,omitempty" json:"userId"` Name string `bson:"name,omitempty" json:"name"` Thumbnail *OssType `bson:"thumbnail,omitempty" json:"thumbnail"` CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"` Category string `bson:"category,omitempty" json:"category"` Category2 string `bson:"category2,omitempty" json:"category2"` IsPublic *bool `bson:"isPublic,omitempty" json:"isPublic"` Price float32 `bson:"price,omitempty" json:"price"` ColorCards []*MaterialHeader `bson:"colorCards,omitempty" json:"colorCards"` Platform *bool `bson:"platform,omitempty" json:"platform"` Categories []string `bson:"categories,omitempty" json:"categories"` State int32 `bson:"state,omitempty" json:"state"` }