Skip to content

Commit 6dcaf1f

Browse files
committed
Add backrgound opacity attribute
1 parent 5f6e7da commit 6dcaf1f

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

examples/Examples.ipynb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@
3232
},
3333
"outputs": [],
3434
"source": [
35-
"ball = Mesh(geometry=SphereGeometry(radius=1), material=LambertMaterial(color='red'), position=[2,1,0])\n",
36-
"scene = Scene(children=[ball, AmbientLight(color='#777777'), make_text('Hello World!', height=.6)])\n",
37-
"c = PerspectiveCamera(position=[0, 5, 5],\n",
38-
" up=[0, 0, 1],\n",
39-
" children=[DirectionalLight(color='white', position=[3, 5, 1], intensity=0.5)])\n",
40-
"renderer = Renderer(camera=c, scene=scene, controls=[OrbitControls(controlling=c)])\n",
35+
"ball = Mesh(geometry=SphereGeometry(radius=1), \n",
36+
" material=LambertMaterial(color='red'),\n",
37+
" position=[2, 1, 0])\n",
38+
"\n",
39+
"scene = Scene(children=[ball, AmbientLight(color='#777777')])\n",
40+
"\n",
41+
"c = PerspectiveCamera(position=[0, 5, 5], up=[0, 0, 1],\n",
42+
" children=[DirectionalLight(color='white', \n",
43+
" position=[3, 5, 1], \n",
44+
" intensity=0.5)])\n",
45+
"renderer = Renderer(camera=c, \n",
46+
" scene=scene, \n",
47+
" controls=[OrbitControls(controlling=c)])\n",
4148
"display(renderer)"
4249
]
4350
},

js/src/jupyter-threejs.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@ define(["jupyter-js-widgets", "underscore", "three"],
5656
});
5757
}
5858
view_promises.push(effect_promise.then(function() {
59-
that.effectrenderer.setSize(that.model.get('width'),
60-
that.model.get('height'));
61-
if (that.model.get('background')) {
62-
that.effectrenderer.setClearColor(that.model.get('background'))
63-
}
59+
that.effectrenderer.setSize(that.model.get('width'), that.model.get('height'));
60+
that.effectrenderer.setClearColor(that.model.get('background'), that.model.get('background_opacity'))
6461
}));
6562
this.view_promises = Promise.all(view_promises).then(function(objs) {
6663
that.scene.obj.add(that.camera.obj);
@@ -114,11 +111,8 @@ define(["jupyter-js-widgets", "underscore", "three"],
114111
update : function(){
115112
var that = this;
116113
this.view_promises.then(function() {
117-
that.effectrenderer.setSize(that.model.get('width'),
118-
that.model.get('height'));
119-
if (that.model.get('background')) {
120-
that.effectrenderer.setClearColor(that.model.get('background'))
121-
}
114+
that.effectrenderer.setSize(that.model.get('width'), that.model.get('height'));
115+
that.effectrenderer.setClearColor(that.model.get('background'), that.model.get('background_opacity'));
122116
});
123117

124118
widgets.DOMWidgetView.prototype.update.call(that);
@@ -1944,7 +1938,8 @@ define(["jupyter-js-widgets", "underscore", "three"],
19441938
camera: undefined,
19451939
controls: [],
19461940
effect: null,
1947-
background: 'black'
1941+
background: 'black',
1942+
background_opacity: 0.0
19481943
})
19491944
}, {
19501945
serializers: _.extend({

pythreejs/pythreejs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,13 +758,14 @@ class Renderer(DOMWidget):
758758
_model_name = Unicode('RendererModel').tag(sync=True)
759759

760760
width = Unicode('600').tag(sync=True) # TODO: stop relying on deprecated DOMWidget attribute
761-
height = Unicode('400').tag(sync=True)
761+
height = Unicode('400').tag(sync=True)
762762
renderer_type = Enum(['webgl', 'canvas', 'auto'], 'auto').tag(sync=True)
763763
scene = Instance(Scene).tag(sync=True, **widget_serialization)
764764
camera = Instance(Camera).tag(sync=True, **widget_serialization)
765765
controls = List(Instance(Controls)).tag(sync=True, **widget_serialization)
766766
effect = Instance(Effect, allow_none=True).tag(sync=True, **widget_serialization)
767767
background = Color('black', allow_none=True).tag(sync=True)
768+
backgroud_opacity = Float(min=0.0, max=1.0).tag(sync=True)
768769

769770

770771
class Light(Object3d):

0 commit comments

Comments
 (0)