136 lines
2.8 KiB
Go
136 lines
2.8 KiB
Go
package sceneview
|
|
|
|
import (
|
|
"aego/core/mathx"
|
|
"aego/editor/core/gizmo"
|
|
"aego/editor/core/shape"
|
|
"aego/engine"
|
|
"aego/render/debug"
|
|
"aego/scene"
|
|
"aego/ui/core"
|
|
)
|
|
|
|
func (p *Panel) render() {
|
|
if p.viewMode == Mode3D {
|
|
p.render3D()
|
|
return
|
|
}
|
|
wd, t := p.cur, p.target
|
|
if p.pool == nil || wd == nil || wd.scene == nil || t == nil {
|
|
return
|
|
}
|
|
th := &p.ui().Theme
|
|
r := p.d.Viewport.Renderer
|
|
|
|
grid := p.view
|
|
grid.Label = "sceneview.grid"
|
|
f := r.View(grid)
|
|
if p.d.Tools.Grid {
|
|
dbg := f.Debug()
|
|
dbg.Space(debug.World)
|
|
step := p.d.Tools.SnapMove
|
|
if step <= 0 {
|
|
step = 1
|
|
}
|
|
drawGrid(dbg, f.View(), p.space, step, th)
|
|
}
|
|
f.End()
|
|
|
|
sv := p.view
|
|
sv.DoClear = false
|
|
sv.Label = "sceneview.scene"
|
|
wd.runner.SetTarget(t.Texture, t.BucketW, t.BucketH)
|
|
wd.runner.SetViewportSize(t.W, t.H)
|
|
wd.runner.SetFixedView(sv)
|
|
wd.runner.SetHidden(p.runnerHide())
|
|
p.d.Viewport.RenderWorld(wd.w)
|
|
p.flushCapture()
|
|
|
|
ov := p.view
|
|
ov.DoClear = false
|
|
ov.Label = "sceneview.overlay"
|
|
f = r.View(ov)
|
|
dbg := f.Debug()
|
|
dbg.Space(debug.Overlay)
|
|
p.drawOverlays(wd.scene, dbg, th)
|
|
p.drawSelection(wd.scene, dbg, th)
|
|
p.drawGizmos(wd.scene, dbg, th)
|
|
p.drawBox(dbg, th)
|
|
f.End()
|
|
}
|
|
|
|
func (p *Panel) drawOverlays(s *scene.Scene, dbg *debug.Draw, th *core.Theme) {
|
|
win := p.d.Project.Window
|
|
col := th.TextDim
|
|
col.A = 0.7
|
|
p.shapes().Overlays(&shape.OverlayCtx{
|
|
Scene: s,
|
|
World: p.worldOf(s),
|
|
Debug: dbg,
|
|
View: p.view,
|
|
Window: mathx.Vec2{X: float32(win.Width), Y: float32(win.Height)},
|
|
Px: p.space.PxToWorld(1),
|
|
Color: col,
|
|
})
|
|
}
|
|
|
|
func (p *Panel) worldOf(s *scene.Scene) *engine.World {
|
|
if p.docs().ActiveScene() == s {
|
|
return p.docs().ActiveWorld()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *Panel) drawGizmos(s *scene.Scene, dbg *debug.Draw, th *core.Theme) {
|
|
if !p.hasPivot {
|
|
return
|
|
}
|
|
dc := &gizmo.DrawCtx{
|
|
Debug: dbg,
|
|
Space: p.space,
|
|
Scene: s,
|
|
Node: p.activeNode,
|
|
Pivot: p.pivot,
|
|
Rotation: p.rotation,
|
|
Colors: gizmo.Colors{
|
|
X: th.AxisX,
|
|
Y: th.AxisY,
|
|
Center: th.Text,
|
|
Rotate: th.Accent,
|
|
Hot: th.AxisHot,
|
|
},
|
|
}
|
|
parts := func(g gizmo.Gizmo) (gizmo.Part, gizmo.Part) {
|
|
hot, active := gizmo.PartNone, gizmo.PartNone
|
|
if p.hotGizmo == g {
|
|
hot = p.hot
|
|
}
|
|
if p.active == g && p.edit != nil {
|
|
active = p.edit.Part
|
|
}
|
|
return hot, active
|
|
}
|
|
if p.gizmos != nil {
|
|
p.gizmos.Each(s, s.Handle(p.activeNode), func(g gizmo.Gizmo) {
|
|
dc.Hot, dc.Active = parts(g)
|
|
g.Draw(dc)
|
|
})
|
|
}
|
|
if p.gizmoActive() {
|
|
dc.Hot, dc.Active = parts(&p.gizmo)
|
|
p.gizmo.Draw(dc)
|
|
}
|
|
}
|
|
|
|
func (p *Panel) drawBox(dbg *debug.Draw, th *core.Theme) {
|
|
if p.mode != modeBox {
|
|
return
|
|
}
|
|
a, b := p.worldAt(p.boxStart), p.worldAt(p.boxEnd)
|
|
box := mathx.AABB2{
|
|
Min: mathx.Vec2{X: min(a.X, b.X), Y: min(a.Y, b.Y)},
|
|
Max: mathx.Vec2{X: max(a.X, b.X), Y: max(a.Y, b.Y)},
|
|
}
|
|
dbg.AABB(box, th.Accent)
|
|
}
|