zworld/engine/renderapi/vertex/format.go

64 lines
1.2 KiB
Go
Raw Normal View History

2024-01-14 22:56:06 +08:00
package vertex
import (
"zworld/engine/renderapi/color"
"zworld/plugins/math/vec2"
"zworld/plugins/math/vec3"
"zworld/plugins/math/vec4"
)
// P - Position only vertex
type P struct {
vec3.T `vtx:"position,float,3"`
}
func (v P) Position() vec3.T { return v.T }
// C - Colored Vertex
type C struct {
P vec3.T `vtx:"position,float,3"`
N vec3.T `vtx:"normal,float,3"`
C vec4.T `vtx:"color_0,float,4"`
}
func (v C) Position() vec3.T { return v.P }
// T - Textured Vertex
type T struct {
P vec3.T `vtx:"position,float,3"`
N vec3.T `vtx:"normal,float,3"`
T vec2.T `vtx:"texcoord_0,float,2"`
}
func (v T) Position() vec3.T { return v.P }
type UI struct {
P vec3.T `vtx:"position,float,3"`
C color.T `vtx:"color_0,float,4"`
T vec2.T `vtx:"texcoord_0,float,2"`
}
func (v UI) Position() vec3.T { return v.P }
func Min[V Vertex](vertices []V) vec3.T {
if len(vertices) == 0 {
return vec3.Zero
}
min := vec3.InfPos
for _, v := range vertices {
min = vec3.Min(min, v.Position())
}
return min
}
func Max[V Vertex](vertices []V) vec3.T {
if len(vertices) == 0 {
return vec3.Zero
}
max := vec3.InfNeg
for _, v := range vertices {
max = vec3.Max(max, v.Position())
}
return max
}