51 lines
856 B
Go
51 lines
856 B
Go
package lines
|
|
|
|
import (
|
|
"zworld/engine/object/mesh"
|
|
"zworld/engine/renderapi/color"
|
|
"zworld/plugins/math/vec3"
|
|
)
|
|
|
|
var Debug = &DebugLines{}
|
|
|
|
type DebugLines struct {
|
|
enabled bool
|
|
frame int
|
|
meshes []*Lines
|
|
}
|
|
|
|
func (li *DebugLines) Setup(frames int) {
|
|
li.meshes = make([]*Lines, frames)
|
|
for i := range li.meshes {
|
|
li.meshes[i] = New(Args{})
|
|
}
|
|
li.enabled = true
|
|
}
|
|
|
|
func (li *DebugLines) Add(from, to vec3.T, clr color.T) {
|
|
if !li.enabled {
|
|
return
|
|
}
|
|
mesh := li.meshes[li.frame]
|
|
mesh.Lines = append(mesh.Lines, Line{
|
|
Start: from,
|
|
End: to,
|
|
Color: clr,
|
|
})
|
|
}
|
|
|
|
func (li *DebugLines) Fetch() mesh.Mesh {
|
|
// build mesh for current frame
|
|
mesh := li.meshes[li.frame]
|
|
mesh.Refresh()
|
|
|
|
// set next frame
|
|
li.frame = (li.frame + 1) % len(li.meshes)
|
|
|
|
// prepare next mesh
|
|
nextMesh := li.meshes[li.frame]
|
|
nextMesh.Clear()
|
|
|
|
return mesh
|
|
}
|