Skip to content

Commit ca0941c

Browse files
committed
properly convert function properties, plus geometries examples
1 parent 738f719 commit ca0941c

File tree

404 files changed

+997
-439
lines changed

Some content is hidden

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

404 files changed

+997
-439
lines changed

examples/Geometries.ipynb

Lines changed: 490 additions & 0 deletions
Large diffs are not rendered by default.

js/scripts/generate-wrappers.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ _.extend(JavascriptWrapper.prototype, {
319319
var result = [ '{' ];
320320

321321
result = result.concat(_.keys(this.config.properties).map(function(propName) {
322-
return ' ' + propName + ": this.get('" + propName + "'),";
322+
return ' ' + propName + ": " + this.getModelToThreeGetter(propName) + ',';
323323
}, this))
324324

325325
result.push(' }');
@@ -330,7 +330,7 @@ _.extend(JavascriptWrapper.prototype, {
330330
if (propName === 'parameters') {
331331
return getConstructorParametersObject.bind(this)().join('\n');
332332
} else {
333-
return "this.get('" + propName + "')";
333+
return this.getModelToThreeGetter(propName);
334334
}
335335
}, this);
336336

@@ -362,6 +362,16 @@ _.extend(JavascriptWrapper.prototype, {
362362

363363
},
364364

365+
getModelToThreeGetter: function(propName) {
366+
var prop = this.config.properties[propName];
367+
var converter = prop.propToValueConverterFn();
368+
if (converter) {
369+
return "this." + converter + "(this.get('" + propName + "'))";
370+
} else {
371+
return "this.get('" + propName + "')";
372+
}
373+
},
374+
365375
getOutputFilename: function() {
366376
return this.jsAutoDestPath;
367377
},

js/scripts/prop-types.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ _.extend(BaseType.prototype, {
55
getJSPropertyValue: function() {
66
return JSON.stringify(this.defaultValue);
77
},
8+
propToValueConverterFn: function() {
9+
return null;
10+
},
811
})
912

1013
function ThreeType(typeName) {
@@ -174,6 +177,9 @@ _.extend(FunctionType.prototype, BaseType.prototype, {
174177
getJSPropertyValue: function() {
175178
return this.defaultValue.toString();
176179
},
180+
propToValueConverterFn: function() {
181+
return 'convertFunctionModelToThree';
182+
},
177183
});
178184

179185
function Vector2(x, y) {
@@ -186,6 +192,9 @@ _.extend(Vector2.prototype, BaseType.prototype, {
186192
getPropArrayName: function() {
187193
return 'vector_properties';
188194
},
195+
propToValueConverterFn: function() {
196+
return 'convertVectorModelToThree';
197+
},
189198
});
190199

191200
function Vector3(x, y, z) {
@@ -198,6 +207,9 @@ _.extend(Vector3.prototype, BaseType.prototype, {
198207
getPropArrayName: function() {
199208
return 'vector_properties';
200209
},
210+
propToValueConverterFn: function() {
211+
return 'convertVectorModelToThree';
212+
},
201213
});
202214

203215
function Vector4(x, y, z, w) {
@@ -210,6 +222,9 @@ _.extend(Vector4.prototype, BaseType.prototype, {
210222
getPropArrayName: function() {
211223
return 'vector_properties';
212224
},
225+
propToValueConverterFn: function() {
226+
return 'convertVectorModelToThree';
227+
},
213228
});
214229

215230
function Matrix3() {
@@ -227,6 +242,9 @@ _.extend(Matrix3.prototype, BaseType.prototype, {
227242
getPropArrayName: function() {
228243
return 'vector_properties';
229244
},
245+
propToValueConverterFn: function() {
246+
return 'convertMatrixModelToThree';
247+
},
230248
});
231249

232250
function Matrix4() {
@@ -244,6 +262,9 @@ _.extend(Matrix4.prototype, BaseType.prototype, {
244262
getPropArrayName: function() {
245263
return 'vector_properties';
246264
},
265+
propToValueConverterFn: function() {
266+
return 'convertMatrixModelToThree';
267+
},
247268
});
248269

249270

js/scripts/three-class-config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,10 +1079,12 @@ module.exports = {
10791079
constructorArgs: [ 'vertices', 'faces', 'radius', 'detail' ],
10801080
properties: {
10811081
vertices: new Types.Array(),
1082-
faces: new Types.Array(),
1082+
indices: new Types.Array(),
10831083
radius: new Types.Float(1.0),
10841084
detail: new Types.Float(0.0),
1085+
faces: new Types.Array(),
10851086
},
1087+
propsDefinedByThree: [ 'faces' ],
10861088
},
10871089
RingBufferGeometry: {
10881090
relativePath: './extras/geometries/RingBufferGeometry',

js/src/_base/Three.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var ThreeView = widgets.DOMWidgetView.extend({
4343
this.acquireRenderer();
4444

4545
this.camera = new THREE.PerspectiveCamera(60, 1.0); // aspect is updated by this.updateSize()
46-
this.camera.position.set(0, 0, 50);
46+
this.camera.position.set(-40, 40, 40);
4747
this.camera.lookAt(new THREE.Vector3(0,0,0));
4848

4949
this.updateSize();
@@ -745,6 +745,36 @@ var ThreeModel = widgets.DOMWidgetModel.extend({
745745
syncVectorToModel: function(propName) {
746746
this.set(propName, this.obj[propName].toArray());
747747
},
748+
749+
convertVectorModelToThree: function(v) {
750+
var result;
751+
switch(v.length) {
752+
case 2: result = new THREE.Vector2(); break;
753+
case 3: result = new THREE.Vector3(); break;
754+
case 4: result = new THREE.Vector4(); break;
755+
default:
756+
throw new Error('model vector has invalid length: ' + v.length);
757+
}
758+
result.fromArray(v);
759+
return result;
760+
},
761+
762+
convertMatrixModelToThree: function(m) {
763+
var result;
764+
switch(m.length) {
765+
case 9: result = new THREE.Matrix3(); break;
766+
case 16: result = new THREE.Matrix4(); break;
767+
default:
768+
throw new Error('model matrix has invalid length: ' + m.length);
769+
}
770+
result.fromArray(m);
771+
return result;
772+
},
773+
774+
convertFunctionModelToThree: function(fnStr) {
775+
eval('var fn = ' + fnStr);
776+
return fn;
777+
},
748778

749779
}, {
750780

js/src/_base/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//
22
// This file auto-generated with generate-wrappers.js
3-
// Date: Tue Oct 18 2016 14:57:28 GMT-0700 (PDT)
3+
// Date: Thu Oct 20 2016 12:05:53 GMT-0700 (PDT)
44
//
55
// Load all three.js python wrappers
66
var loadedModules = [
7+
require('./RendererPool.js'),
78
require('./Three.js'),
89
require('./enums.js'),
910
];

js/src/animation/AnimationClip.autogen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// This file auto-generated with generate-wrappers.js
3-
// Date: Tue Oct 18 2016 14:57:27 GMT-0700 (PDT)
3+
// Date: Thu Oct 20 2016 12:05:52 GMT-0700 (PDT)
44
//
55

66
var _ = require('underscore');

js/src/animation/AnimationMixer.autogen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// This file auto-generated with generate-wrappers.js
3-
// Date: Tue Oct 18 2016 14:57:27 GMT-0700 (PDT)
3+
// Date: Thu Oct 20 2016 12:05:52 GMT-0700 (PDT)
44
//
55

66
var _ = require('underscore');

js/src/animation/AnimationObjectGroup.autogen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// This file auto-generated with generate-wrappers.js
3-
// Date: Tue Oct 18 2016 14:57:27 GMT-0700 (PDT)
3+
// Date: Thu Oct 20 2016 12:05:52 GMT-0700 (PDT)
44
//
55

66
var _ = require('underscore');

js/src/animation/AnimationUtils.autogen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// This file auto-generated with generate-wrappers.js
3-
// Date: Tue Oct 18 2016 14:57:27 GMT-0700 (PDT)
3+
// Date: Thu Oct 20 2016 12:05:52 GMT-0700 (PDT)
44
//
55

66
var _ = require('underscore');

0 commit comments

Comments
 (0)