@shapediver/viewer.data-engine.tag3d-engine 2.12.8 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Tag3dEngine.d.ts +4 -4
- package/dist/Tag3dEngine.d.ts.map +1 -1
- package/dist/Tag3dEngine.js +40 -139
- package/dist/Tag3dEngine.js.map +1 -1
- package/package.json +6 -10
- package/src/Tag3dEngine.ts +35 -134
- package/dist/font.d.ts +0 -2365
- package/dist/font.d.ts.map +0 -1
- package/dist/font.js +0 -6
- package/dist/font.js.map +0 -1
- package/dist/three/geometries/TextGeometry.d.ts +0 -22
- package/dist/three/geometries/TextGeometry.d.ts.map +0 -1
- package/dist/three/geometries/TextGeometry.js +0 -45
- package/dist/three/geometries/TextGeometry.js.map +0 -1
- package/dist/three/loaders/FontLoader.d.ts +0 -15
- package/dist/three/loaders/FontLoader.d.ts.map +0 -1
- package/dist/three/loaders/FontLoader.js +0 -118
- package/dist/three/loaders/FontLoader.js.map +0 -1
- package/src/font.ts +0 -2
- package/src/three/geometries/TextGeometry.ts +0 -58
- package/src/three/loaders/FontLoader.ts +0 -205
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import {
|
|
3
|
-
FileLoader,
|
|
4
|
-
Loader,
|
|
5
|
-
LoadingManager,
|
|
6
|
-
ShapePath
|
|
7
|
-
} from 'three';
|
|
8
|
-
|
|
9
|
-
class FontLoader extends Loader {
|
|
10
|
-
|
|
11
|
-
constructor( manager: LoadingManager | undefined ) {
|
|
12
|
-
|
|
13
|
-
super( manager );
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
load( url: string,
|
|
18
|
-
onLoad?: (responseFont: Font) => void,
|
|
19
|
-
onProgress?: (event: ProgressEvent) => void,
|
|
20
|
-
onError?: (event: ErrorEvent) => void, ) {
|
|
21
|
-
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
23
|
-
const scope = this;
|
|
24
|
-
|
|
25
|
-
const loader = new FileLoader( this.manager );
|
|
26
|
-
loader.setPath( this.path );
|
|
27
|
-
loader.setRequestHeader( this.requestHeader );
|
|
28
|
-
loader.setWithCredentials( scope.withCredentials );
|
|
29
|
-
loader.load( url, function ( text ) {
|
|
30
|
-
|
|
31
|
-
let json;
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
|
|
35
|
-
json = JSON.parse( (text as string) );
|
|
36
|
-
|
|
37
|
-
} catch ( e ) {
|
|
38
|
-
|
|
39
|
-
console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
|
|
40
|
-
json = JSON.parse( (text as string).substring( 65, (text as string).length - 2 ) );
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const font = scope.parse( json );
|
|
45
|
-
|
|
46
|
-
if ( onLoad ) onLoad( font );
|
|
47
|
-
|
|
48
|
-
}, onProgress, onError );
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
parse( json: any ) {
|
|
53
|
-
|
|
54
|
-
return new Font( json );
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
class Font {
|
|
63
|
-
data: any;
|
|
64
|
-
type: string;
|
|
65
|
-
isFont: boolean = true;
|
|
66
|
-
|
|
67
|
-
constructor( data: any ) {
|
|
68
|
-
|
|
69
|
-
this.type = 'Font';
|
|
70
|
-
|
|
71
|
-
this.data = data;
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
generateShapes( text: any, size = 100 ) {
|
|
76
|
-
|
|
77
|
-
const shapes: any[] = [];
|
|
78
|
-
const paths = createPaths( text, size, this.data );
|
|
79
|
-
|
|
80
|
-
for ( let p = 0, pl = paths.length; p < pl; p ++ ) {
|
|
81
|
-
|
|
82
|
-
Array.prototype.push.apply( shapes, (paths[ p ] as any).toShapes() );
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return shapes;
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function createPaths( text: Iterable<unknown> | ArrayLike<unknown>, size: number, data: { resolution: number; boundingBox: { yMax: number; yMin: number; }; underlineThickness: number; } ) {
|
|
93
|
-
|
|
94
|
-
const chars = Array.from( text );
|
|
95
|
-
const scale = size / data.resolution;
|
|
96
|
-
const line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
|
|
97
|
-
|
|
98
|
-
const paths = [];
|
|
99
|
-
|
|
100
|
-
let offsetX = 0, offsetY = 0;
|
|
101
|
-
|
|
102
|
-
for ( let i = 0; i < chars.length; i ++ ) {
|
|
103
|
-
|
|
104
|
-
const char = chars[ i ];
|
|
105
|
-
|
|
106
|
-
if ( char === '\n' ) {
|
|
107
|
-
|
|
108
|
-
offsetX = 0;
|
|
109
|
-
offsetY -= line_height;
|
|
110
|
-
|
|
111
|
-
} else {
|
|
112
|
-
|
|
113
|
-
const ret = createPath( char, scale, offsetX, offsetY, data )!;
|
|
114
|
-
offsetX += ret.offsetX;
|
|
115
|
-
paths.push( ret.path );
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return paths;
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function createPath( char: any, scale: number, offsetX: number, offsetY: number, data: { resolution?: number; boundingBox?: { yMax: number; yMin: number; }; underlineThickness?: number; glyphs?: any; familyName?: any; } ) {
|
|
126
|
-
|
|
127
|
-
const glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
|
|
128
|
-
|
|
129
|
-
if ( ! glyph ) {
|
|
130
|
-
|
|
131
|
-
console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
|
|
132
|
-
|
|
133
|
-
return;
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const path = new ShapePath();
|
|
138
|
-
|
|
139
|
-
let x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
|
|
140
|
-
|
|
141
|
-
if ( glyph.o ) {
|
|
142
|
-
|
|
143
|
-
const outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
|
|
144
|
-
|
|
145
|
-
for ( let i = 0, l = outline.length; i < l; ) {
|
|
146
|
-
|
|
147
|
-
const action = outline[ i ++ ];
|
|
148
|
-
|
|
149
|
-
switch ( action ) {
|
|
150
|
-
|
|
151
|
-
case 'm': // moveTo
|
|
152
|
-
|
|
153
|
-
x = outline[ i ++ ] * scale + offsetX;
|
|
154
|
-
y = outline[ i ++ ] * scale + offsetY;
|
|
155
|
-
|
|
156
|
-
path.moveTo( x, y );
|
|
157
|
-
|
|
158
|
-
break;
|
|
159
|
-
|
|
160
|
-
case 'l': // lineTo
|
|
161
|
-
|
|
162
|
-
x = outline[ i ++ ] * scale + offsetX;
|
|
163
|
-
y = outline[ i ++ ] * scale + offsetY;
|
|
164
|
-
|
|
165
|
-
path.lineTo( x, y );
|
|
166
|
-
|
|
167
|
-
break;
|
|
168
|
-
|
|
169
|
-
case 'q': // quadraticCurveTo
|
|
170
|
-
|
|
171
|
-
cpx = outline[ i ++ ] * scale + offsetX;
|
|
172
|
-
cpy = outline[ i ++ ] * scale + offsetY;
|
|
173
|
-
cpx1 = outline[ i ++ ] * scale + offsetX;
|
|
174
|
-
cpy1 = outline[ i ++ ] * scale + offsetY;
|
|
175
|
-
|
|
176
|
-
path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
|
|
177
|
-
|
|
178
|
-
break;
|
|
179
|
-
|
|
180
|
-
case 'b': // bezierCurveTo
|
|
181
|
-
|
|
182
|
-
cpx = outline[ i ++ ] * scale + offsetX;
|
|
183
|
-
cpy = outline[ i ++ ] * scale + offsetY;
|
|
184
|
-
cpx1 = outline[ i ++ ] * scale + offsetX;
|
|
185
|
-
cpy1 = outline[ i ++ ] * scale + offsetY;
|
|
186
|
-
cpx2 = outline[ i ++ ] * scale + offsetX;
|
|
187
|
-
cpy2 = outline[ i ++ ] * scale + offsetY;
|
|
188
|
-
|
|
189
|
-
path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
|
|
190
|
-
|
|
191
|
-
break;
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return { offsetX: glyph.ha * scale, path: path };
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
Font.prototype.isFont = true;
|
|
204
|
-
|
|
205
|
-
export { FontLoader, Font };
|