mirror of
https://github.com/status-im/whispervis.git
synced 2025-02-01 07:55:29 +00:00
Fix WebGL initialization order issue
This commit is contained in:
parent
c3acd329c7
commit
1d2651c4ef
3
graph.go
3
graph.go
@ -29,6 +29,9 @@ func (p *Page) UpdateGraph() {
|
||||
// and creates all new objects based on current data and positions.
|
||||
// It doesn't do any calculations of changes to the layout or graph data.
|
||||
func (p *Page) RecreateObjects() {
|
||||
p.loaded = true
|
||||
p.loader.Reset()
|
||||
|
||||
p.webgl.RemoveObjects()
|
||||
p.webgl.CreateObjects(p.layout.Positions(), p.layout.Links())
|
||||
|
||||
|
8
page.go
8
page.go
@ -39,7 +39,7 @@ func NewPage() *Page {
|
||||
}
|
||||
page.forceEditor = widgets.NewForceEditor(page.onForcesApply)
|
||||
page.network = widgets.NewNetworkSelector(page.onNetworkChange)
|
||||
page.webgl = NewWebGLScene()
|
||||
page.webgl = NewWebGLScene(page.onWebGLReady)
|
||||
page.simulationWidget = widgets.NewSimulation("http://localhost:8084", page.startSimulation, page.replaySimulation)
|
||||
page.statsWidget = widgets.NewStats()
|
||||
return page
|
||||
@ -128,6 +128,7 @@ func (p *Page) onNetworkChange(network *network.Network) {
|
||||
|
||||
// set forced positions if found in network
|
||||
if network.Positions != nil {
|
||||
fmt.Println("Using precalculated positions")
|
||||
p.layout.SetPositions(network.Positions)
|
||||
go p.RecreateObjects()
|
||||
return
|
||||
@ -194,3 +195,8 @@ func (p *Page) header() *vecty.HTML {
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// onWebGLReady is executed when WebGL context is up and ready to render scene.
|
||||
func (p *Page) onWebGLReady() {
|
||||
p.onNetworkChange(p.network.Current())
|
||||
}
|
||||
|
10
scene.go
10
scene.go
@ -33,12 +33,15 @@ type WebGLScene struct {
|
||||
lines []*Line
|
||||
|
||||
rt *RenderThrottler // used as a helper to reduce rendering calls when animation is not needed (experimental)
|
||||
|
||||
initFn func() // function to run on initialization
|
||||
}
|
||||
|
||||
// NewWebGLScene inits and returns new WebGL scene and canvas.
|
||||
func NewWebGLScene() *WebGLScene {
|
||||
func NewWebGLScene(initFn func()) *WebGLScene {
|
||||
w := &WebGLScene{
|
||||
rt: NewRenderThrottler(),
|
||||
rt: NewRenderThrottler(),
|
||||
initFn: initFn,
|
||||
}
|
||||
w.WebGLRenderer = vthree.NewWebGLRenderer(vthree.WebGLOptions{
|
||||
Init: w.init,
|
||||
@ -61,6 +64,9 @@ func (w *WebGLScene) init(renderer *three.WebGLRenderer) {
|
||||
|
||||
w.InitScene(windowWidth, windowHeight)
|
||||
|
||||
if w.initFn != nil {
|
||||
w.initFn()
|
||||
}
|
||||
w.animate()
|
||||
}
|
||||
|
||||
|
@ -139,6 +139,10 @@ func (n *NetworkSelector) onUpload(json []byte) {
|
||||
n.networks[net.Name] = net
|
||||
n.setCurrentNetwork(net)
|
||||
|
||||
if n.handler != nil {
|
||||
go n.handler(n.current)
|
||||
}
|
||||
|
||||
vecty.Rerender(n)
|
||||
}
|
||||
|
||||
@ -150,8 +154,4 @@ func (n *NetworkSelector) Current() *network.Network {
|
||||
// setCurrentNetwork changes current network and runs needed update handlers.
|
||||
func (n *NetworkSelector) setCurrentNetwork(net *network.Network) {
|
||||
n.current = net
|
||||
|
||||
if n.handler != nil {
|
||||
go n.handler(n.current)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user