Skip to content

Commit d72ff2f

Browse files
committed
Allow PlainGeometry initialization from Geometry
This allows access to vertices etc. generated by geometry creator classes.
1 parent f283a13 commit d72ff2f

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

js/scripts/three-class-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ module.exports = {
267267
morphNormals: new Types.Array(),
268268
skinWeights: new Types.Array(),
269269
skinIndices: new Types.Array(),
270+
_ref_geometry: new Types.ThreeType('Geometry', {allowNull: false}),
270271
},
271272
},
272273
InstancedBufferAttribute: {

js/src/geometries/PlainGeometry.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ var PlainGeometryModel = AutogenPlainGeometryModel.extend({
66
constructThreeObject: function() {
77

88
var result = new THREE.Geometry();
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+
933
return Promise.resolve(result);
1034

1135
},

pythreejs/geometries/PlainGeometry.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
from .PlainGeometry_autogen import PlainGeometry as PlainGeometryBase
3+
4+
5+
class PlainGeometry(PlainGeometryBase):
6+
7+
@classmethod
8+
def from_geometry(cls, geometry):
9+
"""Creates a PlainGeometry of another geometry.
10+
11+
NOTE:
12+
The PlainGeometry will copy the arrays from the source geometry.abs
13+
To avoid this, use PlainBufferGeometry (TODO).
14+
"""
15+
return cls(_ref_geometry=geometry)
16+
17+
18+

0 commit comments

Comments
 (0)