Skip to content
Snippets Groups Projects
Commit 0081dcb4 authored by David Sehnal's avatar David Sehnal
Browse files

mol-canvas3d: fixed viewport freezing

parent a445e4c5
No related branches found
No related tags found
No related merge requests found
...@@ -248,7 +248,7 @@ namespace Canvas3D { ...@@ -248,7 +248,7 @@ namespace Canvas3D {
} }
async function identify(x: number, y: number): Promise<PickingId | undefined> { async function identify(x: number, y: number): Promise<PickingId | undefined> {
if (pickDirty || isPicking) return undefined if (pickDirty || isPicking) return;
isPicking = true isPicking = true
...@@ -265,19 +265,19 @@ namespace Canvas3D { ...@@ -265,19 +265,19 @@ namespace Canvas3D {
// await webgl.readPixelsAsync(xp, yp, 1, 1, buffer) // await webgl.readPixelsAsync(xp, yp, 1, 1, buffer)
webgl.readPixels(xp, yp, 1, 1, buffer) webgl.readPixels(xp, yp, 1, 1, buffer)
const objectId = decodeIdRGB(buffer[0], buffer[1], buffer[2]) const objectId = decodeIdRGB(buffer[0], buffer[1], buffer[2])
if (objectId === -1) return if (objectId === -1) { isPicking = false; return; }
instancePickTarget.bind() instancePickTarget.bind()
// await webgl.readPixelsAsync(xp, yp, 1, 1, buffer) // await webgl.readPixelsAsync(xp, yp, 1, 1, buffer)
webgl.readPixels(xp, yp, 1, 1, buffer) webgl.readPixels(xp, yp, 1, 1, buffer)
const instanceId = decodeIdRGB(buffer[0], buffer[1], buffer[2]) const instanceId = decodeIdRGB(buffer[0], buffer[1], buffer[2])
if (instanceId === -1) return if (instanceId === -1) { isPicking = false; return; }
groupPickTarget.bind() groupPickTarget.bind()
// await webgl.readPixelsAsync(xp, yp, 1, 1, buffer) // await webgl.readPixelsAsync(xp, yp, 1, 1, buffer)
webgl.readPixels(xp, yp, 1, 1, buffer) webgl.readPixels(xp, yp, 1, 1, buffer)
const groupId = decodeIdRGB(buffer[0], buffer[1], buffer[2]) const groupId = decodeIdRGB(buffer[0], buffer[1], buffer[2])
if (groupId === -1) return if (groupId === -1) { isPicking = false; return; }
isPicking = false isPicking = false
......
...@@ -67,8 +67,8 @@ export class ViewportControls extends PluginComponent { ...@@ -67,8 +67,8 @@ export class ViewportControls extends PluginComponent {
} }
export class Viewport extends PluginComponent<{ }, ViewportState> { export class Viewport extends PluginComponent<{ }, ViewportState> {
private container: HTMLDivElement | null = null; private container = React.createRef<HTMLDivElement>();
private canvas: HTMLCanvasElement | null = null; private canvas = React.createRef<HTMLCanvasElement>();
state: ViewportState = { state: ViewportState = {
noWebGl: false noWebGl: false
...@@ -79,7 +79,7 @@ export class Viewport extends PluginComponent<{ }, ViewportState> { ...@@ -79,7 +79,7 @@ export class Viewport extends PluginComponent<{ }, ViewportState> {
} }
componentDidMount() { componentDidMount() {
if (!this.canvas || !this.container || !this.plugin.initViewer(this.canvas, this.container)) { if (!this.canvas.current || !this.container.current || !this.plugin.initViewer(this.canvas.current!, this.container.current!)) {
this.setState({ noWebGl: true }); this.setState({ noWebGl: true });
} }
this.handleResize(); this.handleResize();
...@@ -123,11 +123,8 @@ export class Viewport extends PluginComponent<{ }, ViewportState> { ...@@ -123,11 +123,8 @@ export class Viewport extends PluginComponent<{ }, ViewportState> {
if (this.state.noWebGl) return this.renderMissing(); if (this.state.noWebGl) return this.renderMissing();
return <div className='msp-viewport'> return <div className='msp-viewport'>
<div className='msp-viewport-host3d' ref={elm => this.container = elm}> <div className='msp-viewport-host3d' ref={this.container}>
<canvas ref={elm => { <canvas ref={this.canvas} />
if (!!this.canvas && this.canvas !== elm) console.warn('changed viewport canvas')
this.canvas = elm
}} />
</div> </div>
</div>; </div>;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment