Skip to content

Commit 2cfd05c

Browse files
committed
Fix index attribute on BufferGeometry
Ensure it gets set also if set from reference
1 parent b8f5305 commit 2cfd05c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

js/scripts/three-class-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ module.exports = {
371371
relativePath: './core/BufferGeometry',
372372
superClass: 'BaseBufferGeometry',
373373
properties: {
374+
index: new Types.ThreeType(['BufferAttribute', 'InterleavedBufferAttribute']),
374375
attributes: new Types.ThreeTypeDict(['BufferAttribute', 'InterleavedBufferAttribute']),
375376
morphAttributes: new Types.BufferMorphAttributes(),
376377
MaxIndex: new Types.Int(65535),

js/src/core/BufferGeometry.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ var BufferGeometryModel = AutogenBufferGeometryModel.extend({
3535
Promise.all(_.map(_.values(ref.get('morphAttributes')), function(attr) {
3636
return attr.initPromise;
3737
}))
38-
);
38+
).then(function() {
39+
// Wait for index attribute
40+
return ref.get('index').then(function(index) {
41+
return index.initPromise;
42+
});
43+
});
3944
}
4045

4146
// Create three.js BufferAttributes from ref.
@@ -80,6 +85,15 @@ var BufferGeometryModel = AutogenBufferGeometryModel.extend({
8085
}).then(function(attribModelKVs) {
8186
toSet.morphAttributes = _.object(attribModelKVs);
8287

88+
// Then create models for index attribute:
89+
}).then(function() {
90+
if (result.index) {
91+
var modelCtor = result.index.isInterleavedBufferAttribute ? InterleavedBufferAttributeModel : BufferAttributeModel;
92+
return createModel(modelCtor, this.widget_manager, result.index).then(function(model) {
93+
toSet.index = model;
94+
}, this);
95+
}
96+
8397
// Sync out all properties that have been set:
8498
}).then(function() {
8599
// Add other fields that needs to be synced out:

pythreejs/core/BufferGeometry.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ def validate(self, proposal):
3535
def _gen_repr_from_keys(self, keys):
3636
# Hide data in repr to avoid overly large datasets
3737
# Replace with uuids of buffer attributes
38+
data_keys = ('attributes', 'morphAttributes', 'index')
3839
class_name = self.__class__.__name__
3940
signature_parts = [
4041
'%s=%r' % (key, getattr(self, key))
41-
for key in keys if key not in ('attributes', 'morphAttributes')
42+
for key in keys if key not in data_keys
4243
]
44+
if not self._compare(self.index, self.__class__.index.default_value):
45+
signature_parts.append('index=%s' % _attr_value_repr(self.index))
4346
for name in ('attributes', 'morphAttributes'):
4447
if not _dict_is_default(self, name):
4548
signature_parts.append('%s=%s' % (name, _attr_dict_repr(getattr(self, name))))

0 commit comments

Comments
 (0)