Skip to content

Commit 701ceb6

Browse files
authored
Merge pull request #112 from vidartf/blackbox
Add custom object Blackbox
2 parents 6355466 + 775d78c commit 701ceb6

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

js/scripts/generate-wrappers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var CUSTOM_CLASSES = [
4141
'geometries/PlainGeometry.js',
4242
'geometries/PlainBufferGeometry.js',
4343
'objects/CloneArray.js',
44+
'objects/Blackbox.js',
4445
];
4546

4647

js/scripts/three-class-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ module.exports = {
354354
},
355355
propsDefinedByThree: [ 'type' ]
356356
},
357+
Blackbox: {
358+
superClass: 'Object3D',
359+
relativePath: './objects/Blackbox'
360+
},
357361
Raycaster: {
358362
relativePath: './core/Raycaster',
359363
properties: {

js/src/objects/Blackbox.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var _ = require('underscore');
2+
var BlackboxAutogen = require('./Blackbox.autogen').BlackboxModel;
3+
4+
/**
5+
* This object is intended as an extension point. It differs from
6+
* a normal Object3D in that it does not sync back child objects to
7+
* the models. This allows extensions to build sub-scene graphs that
8+
* might not be possible/feasible/desirable to sync.
9+
*
10+
* To implement an extended object based on this:
11+
* - Extend this model
12+
* - Override defaults/serializers as normal for a widget. Remember
13+
* to call the super methods!
14+
* - Override initialize method. Call super, and then put any
15+
* extension code that relies on the THREE object inside
16+
* a "then" to `initPromise:
17+
*
18+
* this.initPromise.then(() => {
19+
* // Do your stuff here
20+
* });
21+
* - If you do not want a basic Object3D as the "root" of your black
22+
* box, you need to override constructThreeObject[Async].
23+
*/
24+
var BlackboxModel = BlackboxAutogen.extend({
25+
26+
defaults: function() {
27+
var superdef = BlackboxAutogen.prototype.defaults.call(this);
28+
delete superdef['children'];
29+
return superdef;
30+
},
31+
32+
33+
createPropertiesArrays: function() {
34+
35+
BlackboxAutogen.prototype.createPropertiesArrays.call(this);
36+
delete this.three_array_properties['children'];
37+
delete this.property_converters['children'];
38+
39+
}
40+
41+
});

pythreejs/objects/Blackbox.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from .Blackbox_autogen import Blackbox as BaseBlackbox
2+
3+
4+
class Blackbox(BaseBlackbox):
5+
"""A widget with unsynced children.
6+
7+
This widget allows extension authors to expose scene control
8+
of a given three object, without attempting to sync its
9+
children. This makes it possible for a library to give
10+
access to an outer object, without exposing the full object
11+
three, and can be useful in avoiding possibly heavy sync
12+
operations.
13+
"""
14+
children = None

0 commit comments

Comments
 (0)