Skip to content

Add resize to Renderable.js #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ build/
*.py[cod]
node_modules/
.vscode
.venv

# Compiled javascript
pythreejs/static/
Expand Down
27 changes: 27 additions & 0 deletions js/src/_base/Renderable.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,29 @@ var RenderableView = widgets.DOMWidgetView.extend({

},

// resize the renderer
resize: function() {
const { width, height } = this.el.getBoundingClientRect();
this.renderer.setSize(width, height);

this.camera.aspect = width / height;
this.camera.updateProjectionMatrix();

// if (this.controls) {
// try {
// this.controls.handleResize();
// this.controls.screen.width = width;
// this.controls.screen.height = height;
// } catch (error) {
// this.log("unable to update controls");
// this.log(error);
// }
// }

// finally render
this.render()
},

teardownViewer: function() {

this.$renderer.off('mouseenter');
Expand Down Expand Up @@ -494,11 +517,15 @@ var RenderableView = widgets.DOMWidgetView.extend({
});
},

// Permit custom calls from pythreejs
onCustomMessage: function(content, buffers) {
switch(content.type) {
case 'freeze':
this.freeze();
break;
case 'resize':
this.resize();
break;
default:
}
},
Expand Down
8 changes: 7 additions & 1 deletion pythreejs/_base/renderable.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def send_msg(self, message_type, payload=None):

def log(self, msg):
content = {
'type': 'print',
'type': 'log',
'msg': msg
}
self.send(content=content, buffers=None)
Expand All @@ -66,6 +66,12 @@ def freeze(self):
}
self.send(content)

def resize(self):
content = {
"type": "resize"
}
self.send(content)


class Preview(RenderableWidget):
# renderer properties
Expand Down
6 changes: 6 additions & 0 deletions pythreejs/core/Renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def freeze(self):
}
self.send(content)

def resize(self):
content = {
"type": "resize"
}
self.send(content)

@contextmanager
def hold(self):
self._pause_autorender = True
Expand Down
5 changes: 5 additions & 0 deletions pythreejs/renderers/WebGLRenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ def freeze(self):
}
self.send(content)

def resize(self):
content = {
"type": "resize"
}
self.send(content)
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
'nbval',
'pytest-check-links',
'numpy>=1.14',
'matplotlib',
'ipywebrtc',
'scikit-image',
],
'examples': [
'scipy',
Expand Down