three-stdlib 2.6.4 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- package/controls/ArcballControls.cjs.js +1 -1
- package/controls/ArcballControls.d.ts +164 -0
- package/controls/ArcballControls.js +512 -197
- package/controls/OrbitControls.cjs.js +1 -1
- package/controls/OrbitControls.d.ts +1 -0
- package/controls/OrbitControls.js +13 -2
- package/geometries/TextGeometry.cjs.js +1 -0
- package/geometries/TextGeometry.d.ts +16 -0
- package/geometries/TextGeometry.js +26 -0
- package/index.cjs.js +1 -1
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/loaders/FontLoader.cjs.js +1 -0
- package/loaders/FontLoader.d.ts +32 -0
- package/loaders/FontLoader.js +139 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
@@ -246,6 +246,7 @@ export * from './geometries/RoundedBoxGeometry';
|
|
246
246
|
export * from './geometries/BoxLineGeometry';
|
247
247
|
export * from './geometries/DecalGeometry';
|
248
248
|
export * from './geometries/TeapotGeometry';
|
249
|
+
export * from './geometries/TextGeometry';
|
249
250
|
export * from './csm/CSM';
|
250
251
|
export * from './csm/Shader';
|
251
252
|
export * from './csm/CSMHelper';
|
@@ -312,6 +313,7 @@ export * from './effects/AnaglyphEffect';
|
|
312
313
|
export * from './effects/AsciiEffect';
|
313
314
|
export * from './effects/StereoEffect';
|
314
315
|
export * from './loaders/FBXLoader';
|
316
|
+
export * from './loaders/FontLoader';
|
315
317
|
export * from './loaders/TGALoader';
|
316
318
|
export * from './loaders/LUTCubeLoader';
|
317
319
|
export * from './loaders/NRRDLoader';
|
package/index.js
CHANGED
@@ -191,6 +191,7 @@ export { RoundedBoxGeometry } from './geometries/RoundedBoxGeometry.js';
|
|
191
191
|
export { BoxLineGeometry } from './geometries/BoxLineGeometry.js';
|
192
192
|
export { DecalGeometry, DecalVertex } from './geometries/DecalGeometry.js';
|
193
193
|
export { TeapotGeometry } from './geometries/TeapotGeometry.js';
|
194
|
+
export { TextGeometry as TextBufferGeometry, TextGeometry } from './geometries/TextGeometry.js';
|
194
195
|
export { CSM } from './csm/CSM.js';
|
195
196
|
export { CSMHelper } from './csm/CSMHelper.js';
|
196
197
|
export { SMAABlendShader, SMAAEdgesShader, SMAAWeightsShader } from './shaders/SMAAShader.js';
|
@@ -255,6 +256,7 @@ export { AnaglyphEffect } from './effects/AnaglyphEffect.js';
|
|
255
256
|
export { AsciiEffect } from './effects/AsciiEffect.js';
|
256
257
|
export { StereoEffect } from './effects/StereoEffect.js';
|
257
258
|
export { FBXLoader } from './loaders/FBXLoader.js';
|
259
|
+
export { Font, FontLoader } from './loaders/FontLoader.js';
|
258
260
|
export { TGALoader } from './loaders/TGALoader.js';
|
259
261
|
export { LUTCubeLoader } from './loaders/LUTCubeLoader.js';
|
260
262
|
export { NRRDLoader } from './loaders/NRRDLoader.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("three");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(e);class a extends t.Loader{constructor(e){super(e)}load(e,r,s,a){const n=new t.FileLoader(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(e,(e=>{if("string"!=typeof e)throw new Error("unsupported data type");const t=JSON.parse(e),s=this.parse(t);r&&r(s)}),s,a)}parse(e){return new n(e)}}class n{constructor(e){s.default(this,"data",void 0),this.data=e}generateShapes(e,t=100){const r=[],s=function(e,t,r){const s=Array.from(e),a=t/r.resolution,n=(r.boundingBox.yMax-r.boundingBox.yMin+r.underlineThickness)*a,i=[];let p=0,l=0;for(let e=0;e<s.length;e++){const t=s[e];if("\n"===t)p=0,l-=n;else{const e=o(t,a,p,l,r);e&&(p+=e.offsetX,i.push(e.path))}}return i}(e,t,this.data);for(let e=0,t=s.length;e<t;e++)Array.prototype.push.apply(r,s[e].toShapes(!1));return r}}function o(e,r,s,a,n){const o=n.glyphs[e]||n.glyphs["?"];if(!o)return void console.error('THREE.Font: character "'+e+'" does not exists in font family '+n.familyName+".");const i=new t.ShapePath;let p,l,u,c,d,h,f,y;if(o.o){const e=o._cachedOutline||(o._cachedOutline=o.o.split(" "));for(let t=0,n=e.length;t<n;){switch(e[t++]){case"m":p=parseInt(e[t++])*r+s,l=parseInt(e[t++])*r+a,i.moveTo(p,l);break;case"l":p=parseInt(e[t++])*r+s,l=parseInt(e[t++])*r+a,i.lineTo(p,l);break;case"q":u=parseInt(e[t++])*r+s,c=parseInt(e[t++])*r+a,d=parseInt(e[t++])*r+s,h=parseInt(e[t++])*r+a,i.quadraticCurveTo(d,h,u,c);break;case"b":u=parseInt(e[t++])*r+s,c=parseInt(e[t++])*r+a,d=parseInt(e[t++])*r+s,h=parseInt(e[t++])*r+a,f=parseInt(e[t++])*r+s,y=parseInt(e[t++])*r+a,i.bezierCurveTo(d,h,f,y,u,c)}}}return{offsetX:o.ha*r,path:i}}s.default(n,"isFont",void 0),s.default(n,"type",void 0),exports.Font=n,exports.FontLoader=a;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { Loader } from 'three';
|
2
|
+
import type { LoadingManager, Shape } from 'three';
|
3
|
+
export declare class FontLoader extends Loader {
|
4
|
+
constructor(manager?: LoadingManager);
|
5
|
+
load(url: string, onLoad?: (responseFont: Font) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): void;
|
6
|
+
parse(json: FontData): Font;
|
7
|
+
}
|
8
|
+
declare type Glyph = {
|
9
|
+
_cachedOutline: string[];
|
10
|
+
ha: number;
|
11
|
+
o: string;
|
12
|
+
};
|
13
|
+
declare type FontData = {
|
14
|
+
boundingBox: {
|
15
|
+
yMax: number;
|
16
|
+
yMin: number;
|
17
|
+
};
|
18
|
+
familyName: string;
|
19
|
+
glyphs: {
|
20
|
+
[k: string]: Glyph;
|
21
|
+
};
|
22
|
+
resolution: number;
|
23
|
+
underlineThickness: number;
|
24
|
+
};
|
25
|
+
export declare class Font {
|
26
|
+
data: FontData;
|
27
|
+
static isFont: true;
|
28
|
+
static type: 'Font';
|
29
|
+
constructor(data: FontData);
|
30
|
+
generateShapes(text: string, size?: number): Shape[];
|
31
|
+
}
|
32
|
+
export {};
|
@@ -0,0 +1,139 @@
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
2
|
+
import { Loader, FileLoader, ShapePath } from 'three';
|
3
|
+
|
4
|
+
class FontLoader extends Loader {
|
5
|
+
constructor(manager) {
|
6
|
+
super(manager);
|
7
|
+
}
|
8
|
+
|
9
|
+
load(url, onLoad, onProgress, onError) {
|
10
|
+
const loader = new FileLoader(this.manager);
|
11
|
+
loader.setPath(this.path);
|
12
|
+
loader.setRequestHeader(this.requestHeader);
|
13
|
+
loader.setWithCredentials(this.withCredentials);
|
14
|
+
loader.load(url, response => {
|
15
|
+
if (typeof response !== 'string') throw new Error('unsupported data type');
|
16
|
+
const json = JSON.parse(response);
|
17
|
+
const font = this.parse(json);
|
18
|
+
if (onLoad) onLoad(font);
|
19
|
+
}, onProgress, onError);
|
20
|
+
}
|
21
|
+
|
22
|
+
parse(json) {
|
23
|
+
return new Font(json);
|
24
|
+
}
|
25
|
+
|
26
|
+
}
|
27
|
+
class Font {
|
28
|
+
constructor(data) {
|
29
|
+
_defineProperty(this, "data", void 0);
|
30
|
+
|
31
|
+
this.data = data;
|
32
|
+
}
|
33
|
+
|
34
|
+
generateShapes(text, size = 100) {
|
35
|
+
const shapes = [];
|
36
|
+
const paths = createPaths(text, size, this.data);
|
37
|
+
|
38
|
+
for (let p = 0, pl = paths.length; p < pl; p++) {
|
39
|
+
Array.prototype.push.apply(shapes, paths[p].toShapes(false));
|
40
|
+
}
|
41
|
+
|
42
|
+
return shapes;
|
43
|
+
}
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
_defineProperty(Font, "isFont", void 0);
|
48
|
+
|
49
|
+
_defineProperty(Font, "type", void 0);
|
50
|
+
|
51
|
+
function createPaths(text, size, data) {
|
52
|
+
const chars = Array.from(text);
|
53
|
+
const scale = size / data.resolution;
|
54
|
+
const line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
|
55
|
+
const paths = [];
|
56
|
+
let offsetX = 0,
|
57
|
+
offsetY = 0;
|
58
|
+
|
59
|
+
for (let i = 0; i < chars.length; i++) {
|
60
|
+
const char = chars[i];
|
61
|
+
|
62
|
+
if (char === '\n') {
|
63
|
+
offsetX = 0;
|
64
|
+
offsetY -= line_height;
|
65
|
+
} else {
|
66
|
+
const ret = createPath(char, scale, offsetX, offsetY, data);
|
67
|
+
|
68
|
+
if (ret) {
|
69
|
+
offsetX += ret.offsetX;
|
70
|
+
paths.push(ret.path);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
return paths;
|
76
|
+
}
|
77
|
+
|
78
|
+
function createPath(char, scale, offsetX, offsetY, data) {
|
79
|
+
const glyph = data.glyphs[char] || data.glyphs['?'];
|
80
|
+
|
81
|
+
if (!glyph) {
|
82
|
+
console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
|
86
|
+
const path = new ShapePath();
|
87
|
+
let x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
|
88
|
+
|
89
|
+
if (glyph.o) {
|
90
|
+
const outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
|
91
|
+
|
92
|
+
for (let i = 0, l = outline.length; i < l;) {
|
93
|
+
const action = outline[i++];
|
94
|
+
|
95
|
+
switch (action) {
|
96
|
+
case 'm':
|
97
|
+
// moveTo
|
98
|
+
x = parseInt(outline[i++]) * scale + offsetX;
|
99
|
+
y = parseInt(outline[i++]) * scale + offsetY;
|
100
|
+
path.moveTo(x, y);
|
101
|
+
break;
|
102
|
+
|
103
|
+
case 'l':
|
104
|
+
// lineTo
|
105
|
+
x = parseInt(outline[i++]) * scale + offsetX;
|
106
|
+
y = parseInt(outline[i++]) * scale + offsetY;
|
107
|
+
path.lineTo(x, y);
|
108
|
+
break;
|
109
|
+
|
110
|
+
case 'q':
|
111
|
+
// quadraticCurveTo
|
112
|
+
cpx = parseInt(outline[i++]) * scale + offsetX;
|
113
|
+
cpy = parseInt(outline[i++]) * scale + offsetY;
|
114
|
+
cpx1 = parseInt(outline[i++]) * scale + offsetX;
|
115
|
+
cpy1 = parseInt(outline[i++]) * scale + offsetY;
|
116
|
+
path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
|
117
|
+
break;
|
118
|
+
|
119
|
+
case 'b':
|
120
|
+
// bezierCurveTo
|
121
|
+
cpx = parseInt(outline[i++]) * scale + offsetX;
|
122
|
+
cpy = parseInt(outline[i++]) * scale + offsetY;
|
123
|
+
cpx1 = parseInt(outline[i++]) * scale + offsetX;
|
124
|
+
cpy1 = parseInt(outline[i++]) * scale + offsetY;
|
125
|
+
cpx2 = parseInt(outline[i++]) * scale + offsetX;
|
126
|
+
cpy2 = parseInt(outline[i++]) * scale + offsetY;
|
127
|
+
path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
|
128
|
+
break;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
return {
|
134
|
+
offsetX: glyph.ha * scale,
|
135
|
+
path
|
136
|
+
};
|
137
|
+
}
|
138
|
+
|
139
|
+
export { Font, FontLoader };
|