Browse Source

ensure rendering after scene changes

- add/remove/update representations
Alexander Rose 4 years ago
parent
commit
fc10b9bf7b
2 changed files with 13 additions and 7 deletions
  1. 12 1
      src/mol-canvas3d/canvas3d.ts
  2. 1 6
      src/mol-plugin/behavior/static/representation.ts

+ 12 - 1
src/mol-canvas3d/canvas3d.ts

@@ -265,6 +265,7 @@ namespace Canvas3D {
         }
 
         let forceNextDraw = false;
+        let forceDrawAfterAllCommited = false;
         let currentTime = 0;
 
         function draw(force?: boolean) {
@@ -300,7 +301,13 @@ namespace Canvas3D {
         function commit(isSynchronous: boolean = false) {
             const allCommited = commitScene(isSynchronous);
             // Only reset the camera after the full scene has been commited.
-            if (allCommited) resolveCameraReset();
+            if (allCommited) {
+                resolveCameraReset();
+                if (forceDrawAfterAllCommited) {
+                    draw(true);
+                    forceDrawAfterAllCommited = false;
+                }
+            }
         }
 
         function resolveCameraReset() {
@@ -393,6 +400,7 @@ namespace Canvas3D {
             reprRenderObjects.set(repr, newRO);
 
             scene.update(repr.renderObjects, false);
+            forceDrawAfterAllCommited = true;
             if (isDebugMode) consoleStats();
         }
 
@@ -404,6 +412,7 @@ namespace Canvas3D {
                 renderObjects.forEach(o => scene.remove(o));
                 reprRenderObjects.delete(repr);
                 scene.update(repr.renderObjects, false, true);
+                forceDrawAfterAllCommited = true;
                 if (isDebugMode) consoleStats();
             }
         }
@@ -470,6 +479,7 @@ namespace Canvas3D {
                 } else {
                     scene.update(void 0, !!keepSphere);
                 }
+                forceDrawAfterAllCommited = true;
             },
             clear: () => {
                 reprUpdatedSubscriptions.forEach(v => v.unsubscribe());
@@ -489,6 +499,7 @@ namespace Canvas3D {
                 if (scene.syncVisibility()) {
                     if (debugHelper.isEnabled) debugHelper.update();
                 }
+                requestDraw(true);
             },
 
             // draw,

+ 1 - 6
src/mol-plugin/behavior/static/representation.ts

@@ -26,7 +26,6 @@ export function SyncRepresentationToCanvas(ctx: PluginContext) {
     events.object.updated.subscribe(e => {
         if (e.oldObj && SO.isRepresentation3D(e.oldObj)) {
             ctx.canvas3d?.remove(e.oldObj.data.repr);
-            ctx.canvas3d?.requestDraw(true);
             e.oldObj.data.repr.destroy();
         }
 
@@ -43,7 +42,7 @@ export function SyncRepresentationToCanvas(ctx: PluginContext) {
     events.object.removed.subscribe(e => {
         if (!SO.isRepresentation3D(e.obj)) return;
         ctx.canvas3d?.remove(e.obj.data.repr);
-        ctx.canvas3d?.requestDraw(true);
+
         e.obj.data.repr.destroy();
     });
 }
@@ -57,21 +56,18 @@ export function SyncStructureRepresentation3DState(ctx: PluginContext) {
         const data = e.obj.data as SO.Molecule.Structure.Representation3DStateData;
         data.source.data.repr.setState(data.state);
         ctx.canvas3d?.update(data.source.data.repr);
-        ctx.canvas3d?.requestDraw(true);
     });
     events.object.updated.subscribe(e => {
         if (!SO.Molecule.Structure.Representation3DState.is(e.obj)) return;
         const data = e.obj.data as SO.Molecule.Structure.Representation3DStateData;
         data.source.data.repr.setState(data.state);
         ctx.canvas3d?.update(data.source.data.repr);
-        ctx.canvas3d?.requestDraw(true);
     });
     events.object.removed.subscribe(e => {
         if (!SO.Molecule.Structure.Representation3DState.is(e.obj)) return;
         const data = e.obj.data as SO.Molecule.Structure.Representation3DStateData;
         data.source.data.repr.setState(data.initialState);
         ctx.canvas3d?.update(data.source.data.repr);
-        ctx.canvas3d?.requestDraw(true);
     });
 }
 
@@ -82,7 +78,6 @@ export function UpdateRepresentationVisibility(ctx: PluginContext) {
         if (!SO.isRepresentation3D(cell.obj)) return;
         updateVisibility(cell, cell.obj.data.repr);
         ctx.canvas3d?.syncVisibility();
-        ctx.canvas3d?.requestDraw(true);
     });
 }