Skip to content

Commit f36d3d1

Browse files
committed
fixing issues with constructing Geometries classes
1 parent b7ea9eb commit f36d3d1

File tree

412 files changed

+822
-754
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

412 files changed

+822
-754
lines changed

examples/Geometries.ipynb

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": null,
66
"metadata": {
77
"collapsed": true
88
},
@@ -117,7 +117,7 @@
117117
},
118118
{
119119
"cell_type": "code",
120-
"execution_count": 2,
120+
"execution_count": null,
121121
"metadata": {
122122
"collapsed": false
123123
},
@@ -152,7 +152,7 @@
152152
},
153153
{
154154
"cell_type": "code",
155-
"execution_count": 3,
155+
"execution_count": null,
156156
"metadata": {
157157
"collapsed": true
158158
},
@@ -169,22 +169,21 @@
169169
},
170170
"outputs": [],
171171
"source": [
172-
"# TODO: points array not getting sent over properly\n",
173172
"LatheBufferGeometry(\n",
174173
" points=[\n",
175-
" [ 0, 0, 0 ],\n",
174+
" [ 0, -10, 0 ],\n",
175+
" [ 10, -5, 0 ],\n",
176176
" [ 5, 5, 0 ],\n",
177-
" [ 3, 10, 0 ],\n",
178-
" [ 0, 15, 0 ]\n",
177+
" [ 0, 10, 0 ]\n",
179178
" ],\n",
180-
" segments=8,\n",
179+
" segments=16,\n",
181180
" phiStart=0.0,\n",
182-
" phiLength=2.0*pi)"
181+
" phiLength=2.0*pi, _flat=True)"
183182
]
184183
},
185184
{
186185
"cell_type": "code",
187-
"execution_count": 4,
186+
"execution_count": null,
188187
"metadata": {
189188
"collapsed": true
190189
},
@@ -195,7 +194,7 @@
195194
},
196195
{
197196
"cell_type": "code",
198-
"execution_count": 5,
197+
"execution_count": null,
199198
"metadata": {
200199
"collapsed": true
201200
},
@@ -339,7 +338,7 @@
339338
},
340339
{
341340
"cell_type": "code",
342-
"execution_count": 6,
341+
"execution_count": null,
343342
"metadata": {
344343
"collapsed": true
345344
},
@@ -451,15 +450,23 @@
451450
},
452451
"outputs": [],
453452
"source": [
454-
"# TODO:\n",
455-
"# WireframeGeometry(geometry=TorusGeometry(\n",
456-
"# radius=20,\n",
457-
"# tube=5,\n",
458-
"# radialSegments=20,\n",
459-
"# tubularSegments=6,\n",
460-
"# arc=2.0*pi\n",
461-
"# ))"
453+
"WireframeGeometry(geometry=TorusBufferGeometry(\n",
454+
" radius=20,\n",
455+
" tube=5,\n",
456+
" radialSegments=6,\n",
457+
" tubularSegments=20,\n",
458+
" arc=2.0*pi\n",
459+
"))"
462460
]
461+
},
462+
{
463+
"cell_type": "code",
464+
"execution_count": null,
465+
"metadata": {
466+
"collapsed": true
467+
},
468+
"outputs": [],
469+
"source": []
463470
}
464471
],
465472
"metadata": {
@@ -480,46 +487,6 @@
480487
"nbconvert_exporter": "python",
481488
"pygments_lexer": "ipython2",
482489
"version": "2.7.12"
483-
},
484-
"widgets": {
485-
"state": {
486-
"345bb19e86e8492ab984784d5e28b4ea": {
487-
"views": [
488-
{
489-
"cell_index": 10
490-
}
491-
]
492-
},
493-
"91929632315b4de9a9dbc9820e74c5bc": {
494-
"views": [
495-
{
496-
"cell_index": 12
497-
}
498-
]
499-
},
500-
"97beb4476542488885d834cf97285479": {
501-
"views": [
502-
{
503-
"cell_index": 13
504-
}
505-
]
506-
},
507-
"edf315d5a75b42b2909bb96c91e7654a": {
508-
"views": [
509-
{
510-
"cell_index": 22
511-
}
512-
]
513-
},
514-
"fa3df762942744dbbda986a316f570ef": {
515-
"views": [
516-
{
517-
"cell_index": 7
518-
}
519-
]
520-
}
521-
},
522-
"version": "1.2.0"
523490
}
524491
},
525492
"nbformat": 4,

js/scripts/generate-wrappers.js

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,33 @@ function isDir(filePath) {
5454
return stats.isDirectory();
5555
}
5656

57-
function getClassConfig(className) {
57+
function getClassConfig(className, doLog) {
5858

5959
// console.log('getClassConfig: ' + className);
6060
className = className.replace(/\./g, '_')
6161
if (!(className in classConfigs)) {
6262
throw new Error('invalid class name: ' + className);
6363
}
6464

65-
var result = classConfigs[className];
65+
var curClass = classConfigs[className];
66+
67+
var result = {};
68+
_.extend(result, curClass);
69+
70+
// combine cur props with superclass properties for allProperties
71+
result.allProperties = {};
72+
if (curClass.superClass && curClass.superClass !== classConfigs._defaults.superClass) {
73+
var superClassConfig = getClassConfig(curClass.superClass);
74+
_.extend(result.allProperties, superClassConfig.allProperties);
75+
}
76+
_.extend(result.allProperties, curClass.properties);
77+
78+
// add defaults
6679
_.defaults(
6780
result,
6881
classConfigs._defaults
6982
);
7083

71-
// console.log(result);
72-
7384
return result;
7485
}
7586

@@ -231,9 +242,7 @@ _.extend(JavascriptWrapper.prototype, {
231242
}
232243

233244
} else {
234-
235245
throw new Error('invalid classDescriptor: ' + classDescriptor);
236-
237246
}
238247

239248
result.modelName = result.className + 'Model';
@@ -273,7 +282,13 @@ _.extend(JavascriptWrapper.prototype, {
273282

274283
if (prop instanceof Types.ThreeType || prop instanceof Types.ThreeTypeArray || prop instanceof Types.ThreeTypeDict) {
275284
if (prop.typeName !== 'this') {
276-
result[prop.typeName] = this.getRequireInfoFromClassDescriptor(prop.typeName);
285+
if (typeof prop.typeName === 'string') {
286+
result[prop.typeName] = this.getRequireInfoFromClassDescriptor(prop.typeName);
287+
} else if (prop.typeName instanceof Array) {
288+
prop.typeName.forEach(function(typeName) {
289+
result[typeName] = this.getRequireInfoFromClassDescriptor(typeName);
290+
}, this);
291+
}
277292
}
278293
}
279294
return result;
@@ -363,7 +378,10 @@ _.extend(JavascriptWrapper.prototype, {
363378
},
364379

365380
getModelToThreeGetter: function(propName) {
366-
var prop = this.config.properties[propName];
381+
var prop = this.config.allProperties[propName];
382+
if (!prop) {
383+
throw new Error('invalid propName: ' + propName);
384+
}
367385
var converter = prop.propToValueConverterFn();
368386
if (converter) {
369387
return "this." + converter + "(this.get('" + propName + "'))";
@@ -383,6 +401,8 @@ function createJavascriptWrapper(modulePath) {
383401
try {
384402
var wrapper = new JavascriptWrapper(modulePath);
385403
} catch (e) {
404+
console.log('error creating wrapper: ');
405+
console.log(e);
386406
console.log('skipping: ' + modulePath);
387407
return Promise.resolve(false);
388408
}
@@ -562,9 +582,7 @@ _.extend(PythonWrapper.prototype, {
562582
}
563583

564584
} else {
565-
566585
throw new Error('invalid classDescriptor: ' + classDescriptor);
567-
568586
}
569587

570588
// get path of dependency relative to module dir
@@ -608,7 +626,13 @@ _.extend(PythonWrapper.prototype, {
608626

609627
if (prop instanceof Types.ThreeType || prop instanceof Types.ThreeTypeArray || prop instanceof Types.ThreeTypeDict) {
610628
if (prop.typeName !== 'this') {
611-
result[prop.typeName] = this.getRequireInfoFromClassDescriptor(prop.typeName);
629+
if (typeof prop.typeName === 'string') {
630+
result[prop.typeName] = this.getRequireInfoFromClassDescriptor(prop.typeName);
631+
} else if (prop.typeName instanceof Array) {
632+
prop.typeName.forEach(function(typeName) {
633+
result[typeName] = this.getRequireInfoFromClassDescriptor(typeName);
634+
}, this);
635+
}
612636
}
613637
}
614638
return result;

js/scripts/prop-types.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,29 @@ function ThreeType(typeName) {
1717
}
1818
_.extend(ThreeType.prototype, BaseType.prototype, {
1919
getTraitlet: function() {
20+
// allow type unions
21+
if (this.typeName instanceof Array) {
22+
// TODO: only instan
23+
var instances = this.typeName.map(function(typeName) {
24+
return ' Instance(' + typeName + ', allow_none=True).tag(sync=True, **widget_serialization)';
25+
});
26+
return 'Union([\n' + instances.join(',\n') + '\n ])';
27+
28+
// return 'Any()';
29+
}
30+
2031
if (this.typeName.toLowerCase() === 'this') {
2132
return 'This().tag(sync=True, **widget_serialization)';
2233
}
34+
2335
return 'Instance(' + this.typeName + ', allow_none=True).tag(sync=True, **widget_serialization)';
2436
},
2537
getPropArrayName: function() {
2638
return 'three_properties';
2739
},
40+
propToValueConverterFn: function() {
41+
return 'convertThreeTypeModelToThree';
42+
},
2843
});
2944

3045
function ThreeTypeArray(typeName) {
@@ -44,6 +59,9 @@ _.extend(ThreeTypeArray.prototype, BaseType.prototype, {
4459
getPropArrayName: function() {
4560
return 'three_array_properties';
4661
},
62+
propToValueConverterFn: function() {
63+
return 'convertThreeTypeArrayModelToThree';
64+
},
4765
});
4866

4967
function ThreeTypeDict(typeName) {
@@ -61,6 +79,9 @@ _.extend(ThreeTypeDict.prototype, BaseType.prototype, {
6179
getPropArrayName: function() {
6280
return 'three_dict_properties';
6381
},
82+
propToValueConverterFn: function() {
83+
return 'convertThreeTypeDictModelToThree';
84+
},
6485
});
6586

6687
function Bool(defaultValue) {
@@ -227,6 +248,21 @@ _.extend(Vector4.prototype, BaseType.prototype, {
227248
},
228249
});
229250

251+
function VectorArray() {
252+
this.defaultValue = [];
253+
}
254+
_.extend(VectorArray.prototype, BaseType.prototype, {
255+
getTraitlet: function() {
256+
return 'List(trait=List()).tag(sync=True)';
257+
},
258+
getPropArrayName: function() {
259+
return 'array_properties';
260+
},
261+
propToValueConverterFn: function() {
262+
return 'convertVectorArrayModelToThree';
263+
},
264+
});
265+
230266
function Matrix3() {
231267
this.defaultValue = [
232268
1, 0, 0,
@@ -284,6 +320,7 @@ module.exports = {
284320
Vector2: Vector2,
285321
Vector3: Vector3,
286322
Vector4: Vector4,
323+
VectorArray: VectorArray,
287324
Matrix3: Matrix3,
288325
Matrix4: Matrix4,
289326
};

js/scripts/templates/py_wrapper.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ipywidgets import Widget, DOMWidget, widget_serialization, Color
2-
from traitlets import Unicode, Int, CInt, Instance, This, Enum, Tuple, List, Dict, Float, CFloat, Bool
2+
from traitlets import Unicode, Int, CInt, Instance, This, Enum, Tuple, List, Dict, Float, CFloat, Bool, Union, Any
33

44
from {{ py_base_relative_path }}enums import *
55
from {{ py_base_relative_path }}traits import *

js/scripts/three-class-config.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ module.exports = {
10151015
superClass: 'BufferGeometry',
10161016
constructorArgs: [ 'points', 'segments', 'phiStart', 'phiLength' ],
10171017
properties: {
1018-
points: new Types.ThreeTypeArray('Vector2'), // need vector_array type?
1018+
points: new Types.VectorArray(),
10191019
segments: new Types.Int(12),
10201020
phiStart: new Types.Float(0.0),
10211021
phiLength: new Types.Float(Math.PI * 2.0),
@@ -1026,7 +1026,7 @@ module.exports = {
10261026
superClass: 'Geometry',
10271027
constructorArgs: [ 'points', 'segments', 'phiStart', 'phiLength' ],
10281028
properties: {
1029-
points: new Types.ThreeTypeArray('Vector2'), // need vector_array type?
1029+
points: new Types.VectorArray(),
10301030
segments: new Types.Int(12),
10311031
phiStart: new Types.Float(0.0),
10321032
phiLength: new Types.Float(Math.PI * 2.0),
@@ -1116,7 +1116,7 @@ module.exports = {
11161116
ShapeGeometry: {
11171117
relativePath: './extras/geometries/ShapeGeometry',
11181118
superClass: 'Geometry',
1119-
constructorArgs: [ 'shape' ],
1119+
constructorArgs: [ 'shapes' ],
11201120
properties: {
11211121
shapes: new Types.ThreeTypeArray('Shape'),
11221122
curveSegments: new Types.Int(12), // NOTE: docs say this is unused
@@ -1230,6 +1230,11 @@ module.exports = {
12301230
WireframeGeometry: {
12311231
relativePath: './extras/geometries/WireframeGeometry',
12321232
superClass: 'Geometry',
1233+
constructorArgs: [ 'geometry' ],
1234+
properties: {
1235+
geometry: new Types.ThreeType(['Geometry', 'BufferGeometry']),
1236+
// geometry: new Types.ThreeType('Geometry'),
1237+
},
12331238
},
12341239
ArrowHelper: {
12351240
relativePath: './extras/helpers/ArrowHelper',

0 commit comments

Comments
 (0)