Initial commit: Material Texture API service
- Go + Gin + GORM + PostgreSQL backend - RESTful API for material management - Docker deployment support - Database partitioning for billion-scale data - API documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
54
internal/models/binding.go
Normal file
54
internal/models/binding.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type MaterialBinding struct {
|
||||
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
MaterialID int64 `json:"material_id" gorm:"not null;index:idx_bindings_material_id"`
|
||||
GroupID string `json:"group_id" gorm:"size:255;not null;index:idx_bindings_group_id"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||||
|
||||
// 关联的材质(用于预加载)
|
||||
Material *Material `json:"material,omitempty" gorm:"foreignKey:MaterialID;constraint:OnDelete:CASCADE"`
|
||||
}
|
||||
|
||||
func (MaterialBinding) TableName() string {
|
||||
return "material_bindings"
|
||||
}
|
||||
|
||||
// 绑定请求 - 一个材质绑定到多个group_id
|
||||
type BindingRequest struct {
|
||||
GroupIDs []string `json:"group_ids" binding:"required,min=1,max=10000"`
|
||||
}
|
||||
|
||||
// 解绑请求
|
||||
type UnbindRequest struct {
|
||||
GroupIDs []string `json:"group_ids" binding:"required,min=1,max=10000"`
|
||||
}
|
||||
|
||||
// 批量查询group_id关联材质的请求
|
||||
type GroupMaterialsRequest struct {
|
||||
GroupIDs []string `json:"group_ids" binding:"required,min=1,max=10000"`
|
||||
}
|
||||
|
||||
// 批量查询结果 - 包含材质详情
|
||||
type GroupMaterialResult struct {
|
||||
GroupID string `json:"group_id"`
|
||||
Material *Material `json:"material"`
|
||||
}
|
||||
|
||||
// GetGroups 分页查询参数
|
||||
type GroupListQuery struct {
|
||||
Page int `form:"page"`
|
||||
PageSize int `form:"page_size"`
|
||||
}
|
||||
|
||||
// GetGroups 分页响应
|
||||
type GroupListResponse struct {
|
||||
Items []string `json:"items"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
68
internal/models/material.go
Normal file
68
internal/models/material.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Material struct {
|
||||
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
Name string `json:"name" gorm:"size:255;not null"`
|
||||
|
||||
// 漫反射颜色 (Diffuse)
|
||||
DiffuseR float64 `json:"diffuse_r" gorm:"not null;default:0"`
|
||||
DiffuseG float64 `json:"diffuse_g" gorm:"not null;default:0"`
|
||||
DiffuseB float64 `json:"diffuse_b" gorm:"not null;default:0"`
|
||||
Alpha float64 `json:"alpha" gorm:"not null;default:1"`
|
||||
|
||||
// 高光 (Specular)
|
||||
Shininess float64 `json:"shininess" gorm:"not null;default:0"`
|
||||
SpecularR float64 `json:"specular_r" gorm:"not null;default:0"`
|
||||
SpecularG float64 `json:"specular_g" gorm:"not null;default:0"`
|
||||
SpecularB float64 `json:"specular_b" gorm:"not null;default:0"`
|
||||
|
||||
// 环境光 (Ambient)
|
||||
AmbientR float64 `json:"ambient_r" gorm:"not null;default:0"`
|
||||
AmbientG float64 `json:"ambient_g" gorm:"not null;default:0"`
|
||||
AmbientB float64 `json:"ambient_b" gorm:"not null;default:0"`
|
||||
|
||||
// PBR属性
|
||||
Metallic float64 `json:"metallic" gorm:"not null;default:0"`
|
||||
Roughness float64 `json:"roughness" gorm:"not null;default:0.5"`
|
||||
Reflectance float64 `json:"reflectance" gorm:"not null;default:0.5"`
|
||||
|
||||
// 乐观锁版本号 (用于防止并发覆盖)
|
||||
Version int64 `json:"version" gorm:"not null;default:0"`
|
||||
|
||||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
||||
}
|
||||
|
||||
func (Material) TableName() string {
|
||||
return "materials"
|
||||
}
|
||||
|
||||
// 创建/更新材质的请求结构
|
||||
type MaterialRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
DiffuseR float64 `json:"diffuse_r"`
|
||||
DiffuseG float64 `json:"diffuse_g"`
|
||||
DiffuseB float64 `json:"diffuse_b"`
|
||||
Alpha float64 `json:"alpha"`
|
||||
Shininess float64 `json:"shininess"`
|
||||
SpecularR float64 `json:"specular_r"`
|
||||
SpecularG float64 `json:"specular_g"`
|
||||
SpecularB float64 `json:"specular_b"`
|
||||
AmbientR float64 `json:"ambient_r"`
|
||||
AmbientG float64 `json:"ambient_g"`
|
||||
AmbientB float64 `json:"ambient_b"`
|
||||
Metallic float64 `json:"metallic"`
|
||||
Roughness float64 `json:"roughness"`
|
||||
Reflectance float64 `json:"reflectance"`
|
||||
}
|
||||
|
||||
// 列表查询参数
|
||||
type MaterialListQuery struct {
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"page_size,default=20"`
|
||||
Name string `form:"name"`
|
||||
}
|
||||
Reference in New Issue
Block a user