OSDN Git Service

three.jsをThirdPartyに追加
[webglgame/webgl_framework.git] / webglFramework / Thirdparty / three.js-master / src / geometries / TextGeometry.js
1 /**
2  * @author zz85 / http://www.lab4games.net/zz85/blog
3  * @author alteredq / http://alteredqualia.com/
4  *
5  * Text = 3D Text
6  *
7  * parameters = {
8  *  font: <THREE.Font>, // font
9  *
10  *  size: <float>, // size of the text
11  *  height: <float>, // thickness to extrude text
12  *  curveSegments: <int>, // number of points on the curves
13  *
14  *  bevelEnabled: <bool>, // turn on bevel
15  *  bevelThickness: <float>, // how deep into text bevel goes
16  *  bevelSize: <float> // how far from text outline is bevel
17  * }
18  */
19
20 import { Geometry } from '../core/Geometry';
21 import { ExtrudeBufferGeometry } from './ExtrudeGeometry';
22
23 // TextGeometry
24
25 function TextGeometry(  text, parameters ) {
26
27         Geometry.call( this );
28
29         this.type = 'TextGeometry';
30
31         this.parameters = {
32                 text: text,
33                 parameters: parameters
34         };
35
36         this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
37         this.mergeVertices();
38
39 }
40
41 TextGeometry.prototype = Object.create( Geometry.prototype );
42 TextGeometry.prototype.constructor = TextGeometry;
43
44 // TextBufferGeometry
45
46 function TextBufferGeometry( text, parameters ) {
47
48         parameters = parameters || {};
49
50         var font = parameters.font;
51
52         if ( ! ( font && font.isFont ) ) {
53
54                 console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
55                 return new Geometry();
56
57         }
58
59         var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
60
61         // translate parameters to ExtrudeGeometry API
62
63         parameters.amount = parameters.height !== undefined ? parameters.height : 50;
64
65         // defaults
66
67         if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
68         if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
69         if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
70
71         ExtrudeBufferGeometry.call( this, shapes, parameters );
72
73         this.type = 'TextBufferGeometry';
74
75 }
76
77 TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
78 TextBufferGeometry.prototype.constructor = TextBufferGeometry;
79
80
81 export { TextGeometry, TextBufferGeometry };