Skip to content

Commit 6196144

Browse files
committed
Clean up manual/auto definitions (partially)
1 parent dc7c28a commit 6196144

File tree

4 files changed

+148
-562
lines changed

4 files changed

+148
-562
lines changed

js/scripts/generate-wrappers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ function createTopLevelPythonModuleFile() {
824824

825825
var CUSTOM_CLASSES = [
826826
'textures/ImageTexture.js',
827+
'textures/TextTexture.js',
827828
];
828829

829830
function createJavascriptFiles() {

js/scripts/three-class-config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,19 @@ module.exports = {
774774
},
775775
Line: {
776776
relativePath: './objects/Line',
777+
constructorArgs: [ 'geometry', 'material' ],
778+
properties: {
779+
material: new Types.ThreeType('Material'),
780+
geometry: new Types.ThreeType(['Geometry', 'BufferGeometry']),
781+
}
777782
},
778783
LineSegments: {
779784
relativePath: './objects/LineSegments',
785+
constructorArgs: [ 'geometry', 'material' ],
786+
properties: {
787+
material: new Types.ThreeType('Material'),
788+
geometry: new Types.ThreeType(['Geometry', 'BufferGeometry']),
789+
}
780790
},
781791
Mesh: {
782792
relativePath: './objects/Mesh',
@@ -798,6 +808,12 @@ module.exports = {
798808
},
799809
Sprite: {
800810
relativePath: './objects/Sprite',
811+
superClass: 'Object3D',
812+
constructorArgs: [ 'material' ],
813+
properties: {
814+
material: new Types.ThreeType('SpriteMaterial'),
815+
},
816+
propsDefinedByThree: [ 'isSprite' ]
801817
},
802818
WebGLRenderTarget: {
803819
relativePath: './renderers/WebGLRenderTarget',
@@ -884,6 +900,18 @@ module.exports = {
884900
},
885901
constructorArgs: [ 'imageUri', 'mapping', 'wrapS', 'wrapT', 'magFilter', 'minFilter', 'format', 'type', 'anisotropy' ],
886902
},
903+
TextTexture: {
904+
relativePath: './textures/TextTexture',
905+
superClass: 'Texture',
906+
properties: {
907+
color: new Types.Color('white'),
908+
fontFace: new Types.String('Arial'),
909+
size: new Types.Int(12),
910+
string: new Types.String(''),
911+
squareTexture: new Types.Bool(true),
912+
},
913+
constructorArgs: ['string'],
914+
},
887915
VideoTexture: {
888916
relativePath: './textures/VideoTexture',
889917
},

js/src/textures/TextTexture.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var _ = require('underscore');
2+
var Promise = require('bluebird');
3+
var TextTextureBase = require('./TextTexture.autogen');
4+
5+
var TextTextureView = TextTextureBase.TextTextureView.extend({});
6+
7+
var TextTextureModel = TextTextureBase.TextTextureModel.extend({
8+
9+
constructThreeObjectAsync: function() {
10+
var fontFace = this.get('fontFace');
11+
var size = this.get('size');
12+
var color = this.get('color');
13+
var string = this.get('string');
14+
15+
var self = this;
16+
17+
var p = new Promise(function(resolve, reject) {
18+
var canvas = document.createElement('canvas');
19+
var context = canvas.getContext('2d');
20+
21+
canvas.height = size;
22+
var font = 'Normal ' + size + 'px ' + fontFace;
23+
context.font = font;
24+
25+
var metrics = context.measureText(string);
26+
var textWidth = metrics.width;
27+
canvas.width = textWidth;
28+
29+
if (self.get('squareTexture')) {
30+
canvas.height = canvas.width;
31+
}
32+
33+
self.aspect = canvas.width / canvas.height;
34+
35+
context.textAlign = 'center';
36+
context.textBaseline = 'middle';
37+
context.fillStyle = color;
38+
// Must set the font again for the fillText call
39+
context.font = font;
40+
context.fillText(string, canvas.width / 2, canvas.height / 2);
41+
42+
return resolve(new THREE.Texture(canvas));
43+
});
44+
return p;
45+
},
46+
47+
});
48+
49+
module.exports = {
50+
TextTextureModel: TextTextureModel,
51+
TextTextureView: TextTextureView,
52+
};

0 commit comments

Comments
 (0)