Skip to content

Commit 0b4add5

Browse files
committed
WIP Buffer geometries
1 parent 9952553 commit 0b4add5

File tree

8 files changed

+75
-108
lines changed

8 files changed

+75
-108
lines changed

js/scripts/generate-wrappers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var CUSTOM_CLASSES = [
3939
'controls/FlyControls.js',
4040
'controls/Picker.js',
4141
'geometries/PlainGeometry.js',
42+
'geometries/PlainBufferGeometry.js',
4243
'objects/CloneArray.js',
4344
];
4445

js/scripts/prop-types.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ function ArrayBufferType(arrayType) {
264264
}
265265
_.extend(ArrayBufferType.prototype, BaseType.prototype, {
266266
getTraitlet: function() {
267-
return 'List().tag(sync=True)';
267+
return 'Array().tag(sync=True, **array_serialization)';
268268
},
269269
getPropertyConverterFn: function() {
270270
return 'convertArrayBuffer';
@@ -372,30 +372,6 @@ _.extend(FaceArray.prototype, BaseType.prototype, {
372372
},
373373
});
374374

375-
function BufferAttribute() {
376-
this.defaultValue = null;
377-
}
378-
_.extend(BufferAttribute.prototype, BaseType.prototype, {
379-
getTraitlet: function() {
380-
return 'BufferAttribute(default_value=None, allow_none=True).tag(sync=True)';
381-
},
382-
getPropertyConverterFn: function() {
383-
return 'convertBufferAttribute';
384-
},
385-
});
386-
387-
function BufferAttributeDict() {
388-
this.defaultValue = {};
389-
}
390-
_.extend(BufferAttributeDict.prototype, BaseType.prototype, {
391-
getTraitlet: function() {
392-
return 'Tuple().tag(sync=True)';
393-
},
394-
getPropertyConverterFn: function() {
395-
return 'convertBufferAttributeDict';
396-
},
397-
});
398-
399375
function Matrix3() {
400376
this.defaultValue = [
401377
1, 0, 0,
@@ -469,8 +445,6 @@ module.exports = {
469445
ColorArray: ColorArray,
470446
Array: ArrayType,
471447
ArrayBuffer: ArrayBufferType,
472-
BufferAttribute: BufferAttribute,
473-
BufferAttributeDict: BufferAttributeDict,
474448
Dict: DictType,
475449
Function: FunctionType,
476450
Vector2: Vector2,

js/scripts/three-class-config.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ module.exports = {
194194
relativePath: './core/BufferAttribute',
195195
properties: {
196196
array: new Types.ArrayBuffer(),
197+
count: new Types.Int(0),
197198
dynamic: new Types.Bool(false),
198199
itemSize: new Types.Int(1),
199-
count: new Types.Int(0),
200200
needsUpdate: new Types.Bool(false),
201201
normalized: new Types.Bool(true),
202202
version: new Types.Int(-1),
@@ -209,11 +209,6 @@ module.exports = {
209209
properties: {
210210
name: new Types.String(''),
211211
type: new Types.String(''),
212-
attributes: new Types.BufferAttributeDict(),
213-
position: new Types.BufferAttribute(),
214-
normal: new Types.BufferAttribute(),
215-
color: new Types.BufferAttribute(),
216-
index: new Types.BufferAttribute(),
217212
},
218213
propsDefinedByThree: [ 'type' ]
219214
},
@@ -270,6 +265,22 @@ module.exports = {
270265
_ref_geometry: new Types.ThreeType('Geometry', {allowNull: false}),
271266
},
272267
},
268+
PlainBufferGeometry: {
269+
relativePath: './geometries/PlainGeometry',
270+
superClass: 'Geometry',
271+
properties: {
272+
attributes: new Types.ThreeTypeDict('BufferAttribute'),
273+
position: new Types.ThreeType('BufferAttribute'),
274+
normal: new Types.ThreeType('BufferAttribute'),
275+
color: new Types.ThreeType('BufferAttribute'),
276+
index: new Types.ThreeType('BufferAttribute'),
277+
morphAttributes: new Types.ThreeTypeDict('BufferAttribute'),
278+
MaxIndex: new Types.Int(65535),
279+
//groups: new Types.Group(),
280+
//drawRange: new Types.DrawRange(),
281+
_ref_geometry: new Types.ThreeType('Geometry', {allowNull: false}),
282+
},
283+
},
273284
InstancedBufferAttribute: {
274285
relativePath: './core/InstancedBufferAttribute',
275286
},

js/src/_base/Three.js

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -674,71 +674,6 @@ var ThreeModel = widgets.WidgetModel.extend({
674674
return "#" + c.getHexString();
675675
},
676676

677-
// BufferAttribute
678-
convertBufferAttributeModelToThree: function(ba, propName) {
679-
680-
// null array means null attribute
681-
// this is necessary because plain Tuple traits cannot set allow_none=True
682-
if (!ba[0]) {
683-
return null;
684-
}
685-
686-
var uuid = ba[3];
687-
var cached = this.getThreeObjectFromCache({ uuid: uuid });
688-
var result;
689-
if (cached) {
690-
result = cached;
691-
692-
// TODO: currently array and itemsize cannot be changed
693-
// result.array = new Float32Array(ba[0]);
694-
// result.itemSize = ba[1];
695-
} else {
696-
result = new THREE.BufferAttribute(
697-
ba[0], // array
698-
ba[1] // itemSize
699-
);
700-
this.putThreeObjectIntoCache({ uuid: result.uuid }, result);
701-
}
702-
703-
result.dynamic = ba[2];
704-
result.uuid = ba[3];
705-
result.version = ba[4];
706-
result.needsUpdate = true;
707-
708-
return result;
709-
},
710-
711-
convertBufferAttributeThreeToModel: function(ba, propName) {
712-
if (!ba || !ba.array) {
713-
return [ null, -1, false, '', -1 ];
714-
}
715-
716-
// make sure buffer attributes are cached before sending on
717-
this.putThreeObjectIntoCache({ uuid: ba.uuid }, ba);
718-
719-
return [
720-
Array.prototype.slice.call(ba.array),
721-
ba.itemSize,
722-
ba.dynamic,
723-
ba.uuid,
724-
ba.version
725-
];
726-
},
727-
728-
// BufferAttributeDict
729-
convertBufferAttributeDictModelToThree: function(baList, propName) {
730-
return _.reduce(baList, function(result, ba, name) {
731-
result[ba[0]] = this.convertBufferAttributeModelToThree(ba[1], propName);
732-
return result;
733-
}, {}, this);
734-
},
735-
736-
convertBufferAttributeDictThreeToModel: function(baDict, propName) {
737-
return _.map(baDict, function(ba, name) {
738-
return [ name, this.convertBufferAttributeThreeToModel(ba, propName) ];
739-
}, this);
740-
},
741-
742677
});
743678

744679
module.exports = {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var AutogenPlainBufferGeometryModel = require('../geometries/PlainGeometry').PlainBufferGeometryModel;
2+
3+
4+
var PlainBufferGeometryModel = AutogenPlainBufferGeometryModel.extend({
5+
6+
constructThreeObject: function() {
7+
8+
var result = new THREE.BufferGeometry();
9+
10+
var ref = this.get('_ref_geometry');
11+
if (ref) {
12+
return ref.initPromise.bind(this).then(function() {
13+
result.copy(ref.obj);
14+
15+
// A bit of a hack:
16+
// Sync out all copied properties before returning
17+
this.obj = result;
18+
var old_three = this.props_created_by_three;
19+
this.props_created_by_three = {};
20+
[
21+
'name', 'colors', 'faces', 'vertices', 'faceVertexUvs', 'morphTargets',
22+
'morphNormals', 'skinWeights', 'skinIndices', 'lineDistances',
23+
'boundingBox', 'boundingSphere'
24+
].forEach(key => {
25+
this.props_created_by_three[key] = true;
26+
});
27+
this.syncToModel();
28+
this.props_created_by_three = old_three;
29+
return result;
30+
});
31+
}
32+
33+
return Promise.resolve(result);
34+
35+
},
36+
37+
});
38+
39+
module.exports = {
40+
PlainBufferGeometryModel: PlainBufferGeometryModel,
41+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
from .PlainBufferGeometry_autogen import PlainBufferGeometry as PlainBufferGeometryBase
3+
4+
5+
class PlainBufferGeometry(PlainBufferGeometryBase):
6+
7+
@classmethod
8+
def from_geometry(cls, geometry):
9+
"""Creates a PlainBufferGeometry of another geometry.
10+
"""
11+
return cls(_ref_geometry=geometry)
12+
13+
14+

pythreejs/geometries/PlainGeometry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def from_geometry(cls, geometry):
99
"""Creates a PlainGeometry of another geometry.
1010
1111
NOTE:
12-
The PlainGeometry will copy the arrays from the source geometry.abs
12+
The PlainGeometry will copy the arrays from the source geometry.
1313
To avoid this, use PlainBufferGeometry (TODO).
1414
"""
1515
return cls(_ref_geometry=geometry)

pythreejs/traits.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ def Matrix4(trait_type=CFloat, default=None, **kwargs):
3737

3838
def Face3(**kwargs):
3939
return Tuple(CInt(), CInt(), CInt(), Vector3(), Unicode(), CInt(), Tuple(), Tuple())
40-
41-
def BufferAttribute(trait_type=CFloat, **kwargs):
42-
return Tuple(
43-
List(allow_none=True), # 0. array
44-
CInt(allow_none=False), # 1. itemSize
45-
Bool(default_value=False), # 2. dynamic
46-
Unicode(), # 3. uuid
47-
CInt(), # 6. version
48-
default_value=(None, -1, False, "", -1)
4940
)
5041

5142
def Euler(default=None, **kwargs):

0 commit comments

Comments
 (0)