three-base 2.0.130 → 2.0.137
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/ApngTexture.d.ts +13 -13
- package/ApngTexture.js +61 -61
- package/ApngTextureManage.d.ts +18 -18
- package/ApngTextureManage.js +87 -87
- package/DirectionalLight.d.ts +6 -0
- package/DirectionalLight.js +68 -0
- package/EventMesh.d.ts +18 -18
- package/EventMesh.js +59 -59
- package/ExtrudeMesh.d.ts +112 -112
- package/ExtrudeMesh.js +366 -366
- package/FPScontrol.d.ts +78 -50
- package/FPScontrol.js +617 -232
- package/Fire/Fire.d.ts +28 -28
- package/Fire/Fire.js +79 -79
- package/Fire/FireGromtry.d.ts +9 -9
- package/Fire/FireGromtry.js +40 -40
- package/Fire/FireMaterial.d.ts +28 -28
- package/Fire/FireMaterial.js +32 -32
- package/Fire/index.d.ts +1 -1
- package/Fire/index.js +1 -1
- package/Grass/Grass.d.ts +8 -8
- package/Grass/Grass.js +38 -38
- package/Grass/index.d.ts +1 -1
- package/Grass/index.js +1 -1
- package/Ground1/Ground1.d.ts +11 -11
- package/Ground1/Ground1.js +54 -54
- package/Ground1/index.d.ts +1 -1
- package/Ground1/index.js +1 -1
- package/InstancedMeshBase.d.ts +39 -39
- package/InstancedMeshBase.js +293 -293
- package/KeyFrameAnimation.d.ts +25 -25
- package/KeyFrameAnimation.js +78 -78
- package/MeshBase.d.ts +35 -35
- package/MeshBase.js +223 -223
- package/Mirror.d.ts +25 -25
- package/Mirror.js +139 -139
- package/PipeMesh/PathGeometry.d.ts +44 -44
- package/PipeMesh/PathGeometry.js +300 -300
- package/PipeMesh/PathPoint.d.ts +17 -17
- package/PipeMesh/PathPoint.js +31 -31
- package/PipeMesh/PathPointList.d.ts +31 -31
- package/PipeMesh/PathPointList.js +208 -208
- package/PipeMesh/PathTubeGeometry.d.ts +25 -25
- package/PipeMesh/PathTubeGeometry.js +130 -130
- package/PipeMesh/PipeMesh.d.ts +25 -25
- package/PipeMesh/PipeMesh.js +63 -63
- package/PipeMesh/index.d.ts +1 -1
- package/PipeMesh/index.js +1 -1
- package/PlaneModal1/PlaneModal1.d.ts +31 -31
- package/PlaneModal1/PlaneModal1.js +105 -105
- package/PlaneModal1/index.d.ts +1 -1
- package/PlaneModal1/index.js +1 -1
- package/PlaneText.d.ts +39 -39
- package/PlaneText.js +30 -30
- package/PlaneWithHtml.d.ts +11 -11
- package/PlaneWithHtml.js +63 -68
- package/PointLight/PointLight.d.ts +14 -13
- package/PointLight/PointLight.js +70 -64
- package/PointLight/index.d.ts +1 -1
- package/PointLight/index.js +1 -1
- package/Sky/Sky.d.ts +9 -9
- package/Sky/Sky.js +22 -22
- package/Sky/index.d.ts +1 -1
- package/Sky/index.js +1 -1
- package/SpotLight.d.ts +6 -0
- package/SpotLight.js +72 -0
- package/SpriteModal1/SpriteModal1.d.ts +30 -30
- package/SpriteModal1/SpriteModal1.js +110 -110
- package/SpriteModal1/index.d.ts +1 -1
- package/SpriteModal1/index.js +1 -1
- package/SpriteText.d.ts +45 -45
- package/SpriteText.js +163 -163
- package/SpriteText2.d.ts +47 -47
- package/SpriteText2.js +198 -198
- package/SpriteWithHtml.d.ts +7 -7
- package/SpriteWithHtml.js +44 -49
- package/Text3D/Text3D.d.ts +20 -20
- package/Text3D/Text3D.js +62 -62
- package/Text3D/fontController.d.ts +59 -59
- package/Text3D/fontController.js +199 -199
- package/Text3D/index.d.ts +1 -1
- package/Text3D/index.js +1 -1
- package/ThreeBase.d.ts +111 -81
- package/ThreeBase.js +656 -560
- package/ThreeMouse.d.ts +40 -40
- package/ThreeMouse.js +407 -407
- package/Transition.d.ts +40 -40
- package/Transition.js +210 -210
- package/Water/Water.d.ts +5 -0
- package/Water/Water.js +26 -0
- package/Water/waternormals.jpg +0 -0
- package/declare.d.ts +167 -0
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/keyContorls.d.ts +25 -25
- package/keyContorls.js +98 -98
- package/package.json +3 -2
- package/pass/bloom_pass.d.ts +2 -2
- package/pass/bloom_pass.js +99 -99
- package/pass/cover_pass.d.ts +2 -2
- package/pass/cover_pass.js +95 -95
- package/pass/emissive_ao_pass.d.ts +13 -0
- package/pass/emissive_ao_pass.js +370 -0
- package/pass/frosted_glass_pass.d.ts +2 -0
- package/pass/frosted_glass_pass.js +275 -0
- package/pass/fsQuad.d.ts +9 -9
- package/pass/fsQuad.js +28 -28
- package/pass/glow_pass.d.ts +2 -2
- package/pass/glow_pass.js +310 -254
- package/pass/ssao_pass.d.ts +13 -0
- package/pass/ssao_pass.js +372 -0
- package/pass/stroke_pass.d.ts +2 -2
- package/pass/stroke_pass.js +199 -199
- package/shaders/FXAAShaderMaterial.d.ts +3 -3
- package/shaders/FXAAShaderMaterial.js +21 -21
- package/shaders/baseTextureToRenderShader.d.ts +2 -2
- package/shaders/baseTextureToRenderShader.js +14 -14
- package/shaders/copyShader.d.ts +3 -3
- package/shaders/copyShader.js +14 -14
- package/shaders.d.ts +5 -5
- package/shaders.js +42 -42
- package/threeLoader.d.ts +34 -34
- package/threeLoader.js +527 -527
- package/threeUtils.d.ts +52 -52
- package/threeUtils.js +330 -330
package/SpriteText2.js
CHANGED
|
@@ -1,198 +1,198 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2023-04-24 15:31:02
|
|
4
|
-
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-04-24 16:18:47
|
|
6
|
-
*/
|
|
7
|
-
import { LinearFilter, Sprite, Texture } from 'three';
|
|
8
|
-
// 带箭头的精灵文字
|
|
9
|
-
export default class SpriteText2 extends Sprite {
|
|
10
|
-
constructor(text = '', textHeight = 10, color = 'rgba(255, 255, 255, 1)') {
|
|
11
|
-
super();
|
|
12
|
-
this.material.alphaTest = 0.1;
|
|
13
|
-
this._text = `${text}`;
|
|
14
|
-
this._textHeight = textHeight;
|
|
15
|
-
this._color = color;
|
|
16
|
-
this._backgroundColor = false; // no background color
|
|
17
|
-
this._padding = 0;
|
|
18
|
-
this._borderWidth = 0;
|
|
19
|
-
this._borderRadius = 0;
|
|
20
|
-
this._borderColor = 'white';
|
|
21
|
-
this._strokeWidth = 0;
|
|
22
|
-
this._strokeColor = 'white';
|
|
23
|
-
this._fontFace = 'Arial';
|
|
24
|
-
this._fontSize = 90; // defines text resolution
|
|
25
|
-
this._fontWeight = 'normal';
|
|
26
|
-
this._genCanvas();
|
|
27
|
-
}
|
|
28
|
-
_text = "";
|
|
29
|
-
_textHeight = 0;
|
|
30
|
-
_color = "#ffffff";
|
|
31
|
-
_backgroundColor = false; // no background color
|
|
32
|
-
_padding = 0;
|
|
33
|
-
_borderWidth = 0;
|
|
34
|
-
_borderRadius = 0;
|
|
35
|
-
_borderColor = 'white';
|
|
36
|
-
_strokeWidth = 0;
|
|
37
|
-
_strokeColor = 'white';
|
|
38
|
-
_fontFace = 'Arial';
|
|
39
|
-
_fontSize = 90; // defines text resolution
|
|
40
|
-
_fontWeight = 'normal';
|
|
41
|
-
_canvas = document.createElement('canvas');
|
|
42
|
-
get text() { return this._text; }
|
|
43
|
-
set text(text) { this._text = text; this._genCanvas(); }
|
|
44
|
-
get textHeight() { return this._textHeight; }
|
|
45
|
-
set textHeight(textHeight) { this._textHeight = textHeight; this._genCanvas(); }
|
|
46
|
-
get color() { return this._color; }
|
|
47
|
-
set color(color) { this._color = color; this._genCanvas(); }
|
|
48
|
-
get backgroundColor() { return this._backgroundColor; }
|
|
49
|
-
set backgroundColor(color) { this._backgroundColor = color; this._genCanvas(); }
|
|
50
|
-
get padding() { return this._padding; }
|
|
51
|
-
set padding(padding) { this._padding = padding; this._genCanvas(); }
|
|
52
|
-
get borderWidth() { return this._borderWidth; }
|
|
53
|
-
set borderWidth(borderWidth) { this._borderWidth = borderWidth; this._genCanvas(); }
|
|
54
|
-
get borderRadius() { return this._borderRadius; }
|
|
55
|
-
set borderRadius(borderRadius) { this._borderRadius = borderRadius; this._genCanvas(); }
|
|
56
|
-
get borderColor() { return this._borderColor; }
|
|
57
|
-
set borderColor(borderColor) { this._borderColor = borderColor; this._genCanvas(); }
|
|
58
|
-
get fontFace() { return this._fontFace; }
|
|
59
|
-
set fontFace(fontFace) { this._fontFace = fontFace; this._genCanvas(); }
|
|
60
|
-
get fontSize() { return this._fontSize; }
|
|
61
|
-
set fontSize(fontSize) { this._fontSize = fontSize; this._genCanvas(); }
|
|
62
|
-
get fontWeight() { return this._fontWeight; }
|
|
63
|
-
set fontWeight(fontWeight) { this._fontWeight = fontWeight; this._genCanvas(); }
|
|
64
|
-
get strokeWidth() { return this._strokeWidth; }
|
|
65
|
-
set strokeWidth(strokeWidth) { this._strokeWidth = strokeWidth; this._genCanvas(); }
|
|
66
|
-
get strokeColor() { return this._strokeColor; }
|
|
67
|
-
set strokeColor(strokeColor) { this._strokeColor = strokeColor; this._genCanvas(); }
|
|
68
|
-
_genCanvas() {
|
|
69
|
-
const canvas = this._canvas;
|
|
70
|
-
const ctx = canvas.getContext('2d');
|
|
71
|
-
const border = Array.isArray(this.borderWidth) ? this.borderWidth : [this.borderWidth, this.borderWidth]; // x,y border
|
|
72
|
-
const relBorder = border.map(b => b * this.fontSize * 0.1); // border in canvas units
|
|
73
|
-
const borderRadius = Array.isArray(this.borderRadius) ? this.borderRadius : [this.borderRadius, this.borderRadius, this.borderRadius, this.borderRadius]; // tl tr br bl corners
|
|
74
|
-
const relBorderRadius = borderRadius.map(b => b * this.fontSize * 0.1); // border radius in canvas units
|
|
75
|
-
const padding = Array.isArray(this.padding) ? this.padding : [this.padding, this.padding]; // x,y padding
|
|
76
|
-
const relPadding = padding.map(p => p * this.fontSize * 0.1); // padding in canvas units
|
|
77
|
-
const lines = this.text.split('\n');
|
|
78
|
-
const font = `${this.fontWeight} ${this.fontSize}px ${this.fontFace}`;
|
|
79
|
-
ctx.font = font; // measure canvas with appropriate font
|
|
80
|
-
const innerWidth = Math.max(...lines.map(line => ctx.measureText(line).width));
|
|
81
|
-
const innerHeight = this.fontSize * lines.length;
|
|
82
|
-
canvas.width = innerWidth + relBorder[0] * 2 + relPadding[0] * 2;
|
|
83
|
-
canvas.height = (innerHeight + relBorder[1] * 2 + relPadding[1] * 2) * 2 + 40;
|
|
84
|
-
// paint border
|
|
85
|
-
if (this.borderWidth) {
|
|
86
|
-
ctx.strokeStyle = this.borderColor;
|
|
87
|
-
if (relBorder[0]) { // left + right borders
|
|
88
|
-
const hb = relBorder[0] / 2;
|
|
89
|
-
ctx.lineWidth = relBorder[0];
|
|
90
|
-
ctx.beginPath();
|
|
91
|
-
ctx.moveTo(hb, relBorderRadius[0]);
|
|
92
|
-
ctx.lineTo(hb, ((canvas.height - 40) / 2) - relBorderRadius[3]);
|
|
93
|
-
ctx.moveTo(canvas.width - hb, relBorderRadius[1]);
|
|
94
|
-
ctx.lineTo(canvas.width - hb, ((canvas.height - 40) / 2) - relBorderRadius[2]);
|
|
95
|
-
ctx.stroke();
|
|
96
|
-
}
|
|
97
|
-
if (relBorder[1]) { // top + bottom borders
|
|
98
|
-
const hb = relBorder[1] / 2;
|
|
99
|
-
ctx.lineWidth = relBorder[1];
|
|
100
|
-
ctx.beginPath();
|
|
101
|
-
ctx.moveTo(Math.max(relBorder[0], relBorderRadius[0]), hb);
|
|
102
|
-
ctx.lineTo(canvas.width - Math.max(relBorder[0], relBorderRadius[1]), hb);
|
|
103
|
-
ctx.moveTo(Math.max(relBorder[0], relBorderRadius[3]), ((canvas.height - 40) / 2) - hb);
|
|
104
|
-
ctx.lineTo((canvas.width / 2 - 20), ((canvas.height - 40) / 2) - hb);
|
|
105
|
-
ctx.lineTo((canvas.width / 2), ((canvas.height - 40) / 2) + 20 - hb);
|
|
106
|
-
ctx.lineTo((canvas.width / 2 + 20), ((canvas.height - 40) / 2) - hb);
|
|
107
|
-
ctx.lineTo(canvas.width - Math.max(relBorder[0], relBorderRadius[2]), ((canvas.height - 40) / 2) - hb);
|
|
108
|
-
ctx.stroke();
|
|
109
|
-
}
|
|
110
|
-
if (this.borderRadius) { // strike rounded corners
|
|
111
|
-
const cornerWidth = Math.max(...relBorder);
|
|
112
|
-
const hb = cornerWidth / 2;
|
|
113
|
-
ctx.lineWidth = cornerWidth;
|
|
114
|
-
ctx.beginPath();
|
|
115
|
-
[
|
|
116
|
-
!!relBorderRadius[0] && [relBorderRadius[0], hb, hb, relBorderRadius[0]],
|
|
117
|
-
!!relBorderRadius[1] && [canvas.width - relBorderRadius[1], canvas.width - hb, hb, relBorderRadius[1]],
|
|
118
|
-
!!relBorderRadius[2] && [canvas.width - relBorderRadius[2], canvas.width - hb, ((canvas.height - 40) / 2) - hb, ((canvas.height - 40) / 2) - relBorderRadius[2]],
|
|
119
|
-
!!relBorderRadius[3] && [relBorderRadius[3], hb, ((canvas.height - 40) / 2) - hb, ((canvas.height - 40) / 2) - relBorderRadius[3]]
|
|
120
|
-
].filter(d => d).forEach(([x0, x1, y0, y1]) => {
|
|
121
|
-
ctx.moveTo(x0, y0);
|
|
122
|
-
ctx.quadraticCurveTo(x1, y0, x1, y1);
|
|
123
|
-
});
|
|
124
|
-
ctx.stroke();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// paint background
|
|
128
|
-
if (this.backgroundColor) {
|
|
129
|
-
ctx.fillStyle = this.backgroundColor;
|
|
130
|
-
if (!this.borderRadius) {
|
|
131
|
-
ctx.fillRect(relBorder[0], relBorder[1], canvas.width - relBorder[0] * 2, ((canvas.height - 40) / 2) - relBorder[1] * 2);
|
|
132
|
-
}
|
|
133
|
-
else { // fill with rounded corners
|
|
134
|
-
ctx.beginPath();
|
|
135
|
-
ctx.moveTo(relBorder[0], relBorderRadius[0]);
|
|
136
|
-
ctx.quadraticCurveTo(relBorder[0], relBorder[1], relBorderRadius[0], relBorder[1]);
|
|
137
|
-
ctx.lineTo(canvas.width - relBorderRadius[1], relBorder[1]);
|
|
138
|
-
ctx.quadraticCurveTo(canvas.width - relBorder[0], relBorder[1], canvas.width - relBorder[0], relBorderRadius[1]);
|
|
139
|
-
ctx.lineTo(canvas.width - relBorder[0], ((canvas.height - 40) / 2) - relBorderRadius[2]);
|
|
140
|
-
ctx.quadraticCurveTo(canvas.width - relBorder[0], ((canvas.height - 40) / 2) - relBorder[1], canvas.width - relBorderRadius[2], ((canvas.height - 40) / 2) - relBorder[1]);
|
|
141
|
-
ctx.lineTo((canvas.width / 2 + 20), ((canvas.height - 40) / 2) - relBorder[1]);
|
|
142
|
-
ctx.lineTo((canvas.width / 2), ((canvas.height - 40) / 2) + 20 - relBorder[1]);
|
|
143
|
-
ctx.lineTo((canvas.width / 2 - 20), ((canvas.height - 40) / 2) - relBorder[1]);
|
|
144
|
-
ctx.lineTo(relBorderRadius[3], ((canvas.height - 40) / 2) - relBorder[1]);
|
|
145
|
-
ctx.quadraticCurveTo(relBorder[0], ((canvas.height - 40) / 2) - relBorder[1], relBorder[0], ((canvas.height - 40) / 2) - relBorderRadius[3]);
|
|
146
|
-
ctx.closePath();
|
|
147
|
-
ctx.fill();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
ctx.translate(relBorder[0], relBorder[1]);
|
|
151
|
-
ctx.translate(relPadding[0], relPadding[0]);
|
|
152
|
-
// paint text
|
|
153
|
-
ctx.font = font; // Set font again after canvas is resized, as context properties are reset
|
|
154
|
-
ctx.fillStyle = this.color;
|
|
155
|
-
ctx.textBaseline = 'bottom';
|
|
156
|
-
const drawTextStroke = this.strokeWidth > 0;
|
|
157
|
-
if (drawTextStroke) {
|
|
158
|
-
ctx.lineWidth = this.strokeWidth * this.fontSize / 10;
|
|
159
|
-
ctx.strokeStyle = this.strokeColor;
|
|
160
|
-
}
|
|
161
|
-
lines.forEach((line, index) => {
|
|
162
|
-
const lineX = (innerWidth - ctx.measureText(line).width) / 2;
|
|
163
|
-
const lineY = (index + 1) * this.fontSize;
|
|
164
|
-
drawTextStroke && ctx.strokeText(line, lineX, lineY);
|
|
165
|
-
ctx.fillText(line, lineX, lineY);
|
|
166
|
-
});
|
|
167
|
-
// Inject canvas into sprite
|
|
168
|
-
if (this.material.map)
|
|
169
|
-
this.material.map.dispose(); // gc previous texture
|
|
170
|
-
const texture = this.material.map = new Texture(canvas);
|
|
171
|
-
texture.minFilter = LinearFilter;
|
|
172
|
-
texture.needsUpdate = true;
|
|
173
|
-
const yScale = this.textHeight * lines.length + border[1] * 2 + padding[1] * 2;
|
|
174
|
-
this.scale.set(yScale * canvas.width / canvas.height, yScale, 0);
|
|
175
|
-
}
|
|
176
|
-
//鼠标拾取计算
|
|
177
|
-
raycast(raycaster, intersects) {
|
|
178
|
-
let intersect = [];
|
|
179
|
-
super.raycast(raycaster, intersect);
|
|
180
|
-
let inte = intersect[0];
|
|
181
|
-
if (inte && (inte.uv.y > 0.55)) {
|
|
182
|
-
intersects.push(inte);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
copy(source) {
|
|
186
|
-
this.color = source.color;
|
|
187
|
-
this.backgroundColor = source.backgroundColor;
|
|
188
|
-
this.padding = source.padding;
|
|
189
|
-
this.borderWidth = source.borderWidth;
|
|
190
|
-
this.borderColor = source.borderColor;
|
|
191
|
-
this.fontFace = source.fontFace;
|
|
192
|
-
this.fontSize = source.fontSize;
|
|
193
|
-
this.fontWeight = source.fontWeight;
|
|
194
|
-
this.strokeWidth = source.strokeWidth;
|
|
195
|
-
this.strokeColor = source.strokeColor;
|
|
196
|
-
return this;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2023-04-24 15:31:02
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-04-24 16:18:47
|
|
6
|
+
*/
|
|
7
|
+
import { LinearFilter, Sprite, Texture } from 'three';
|
|
8
|
+
// 带箭头的精灵文字
|
|
9
|
+
export default class SpriteText2 extends Sprite {
|
|
10
|
+
constructor(text = '', textHeight = 10, color = 'rgba(255, 255, 255, 1)') {
|
|
11
|
+
super();
|
|
12
|
+
this.material.alphaTest = 0.1;
|
|
13
|
+
this._text = `${text}`;
|
|
14
|
+
this._textHeight = textHeight;
|
|
15
|
+
this._color = color;
|
|
16
|
+
this._backgroundColor = false; // no background color
|
|
17
|
+
this._padding = 0;
|
|
18
|
+
this._borderWidth = 0;
|
|
19
|
+
this._borderRadius = 0;
|
|
20
|
+
this._borderColor = 'white';
|
|
21
|
+
this._strokeWidth = 0;
|
|
22
|
+
this._strokeColor = 'white';
|
|
23
|
+
this._fontFace = 'Arial';
|
|
24
|
+
this._fontSize = 90; // defines text resolution
|
|
25
|
+
this._fontWeight = 'normal';
|
|
26
|
+
this._genCanvas();
|
|
27
|
+
}
|
|
28
|
+
_text = "";
|
|
29
|
+
_textHeight = 0;
|
|
30
|
+
_color = "#ffffff";
|
|
31
|
+
_backgroundColor = false; // no background color
|
|
32
|
+
_padding = 0;
|
|
33
|
+
_borderWidth = 0;
|
|
34
|
+
_borderRadius = 0;
|
|
35
|
+
_borderColor = 'white';
|
|
36
|
+
_strokeWidth = 0;
|
|
37
|
+
_strokeColor = 'white';
|
|
38
|
+
_fontFace = 'Arial';
|
|
39
|
+
_fontSize = 90; // defines text resolution
|
|
40
|
+
_fontWeight = 'normal';
|
|
41
|
+
_canvas = document.createElement('canvas');
|
|
42
|
+
get text() { return this._text; }
|
|
43
|
+
set text(text) { this._text = text; this._genCanvas(); }
|
|
44
|
+
get textHeight() { return this._textHeight; }
|
|
45
|
+
set textHeight(textHeight) { this._textHeight = textHeight; this._genCanvas(); }
|
|
46
|
+
get color() { return this._color; }
|
|
47
|
+
set color(color) { this._color = color; this._genCanvas(); }
|
|
48
|
+
get backgroundColor() { return this._backgroundColor; }
|
|
49
|
+
set backgroundColor(color) { this._backgroundColor = color; this._genCanvas(); }
|
|
50
|
+
get padding() { return this._padding; }
|
|
51
|
+
set padding(padding) { this._padding = padding; this._genCanvas(); }
|
|
52
|
+
get borderWidth() { return this._borderWidth; }
|
|
53
|
+
set borderWidth(borderWidth) { this._borderWidth = borderWidth; this._genCanvas(); }
|
|
54
|
+
get borderRadius() { return this._borderRadius; }
|
|
55
|
+
set borderRadius(borderRadius) { this._borderRadius = borderRadius; this._genCanvas(); }
|
|
56
|
+
get borderColor() { return this._borderColor; }
|
|
57
|
+
set borderColor(borderColor) { this._borderColor = borderColor; this._genCanvas(); }
|
|
58
|
+
get fontFace() { return this._fontFace; }
|
|
59
|
+
set fontFace(fontFace) { this._fontFace = fontFace; this._genCanvas(); }
|
|
60
|
+
get fontSize() { return this._fontSize; }
|
|
61
|
+
set fontSize(fontSize) { this._fontSize = fontSize; this._genCanvas(); }
|
|
62
|
+
get fontWeight() { return this._fontWeight; }
|
|
63
|
+
set fontWeight(fontWeight) { this._fontWeight = fontWeight; this._genCanvas(); }
|
|
64
|
+
get strokeWidth() { return this._strokeWidth; }
|
|
65
|
+
set strokeWidth(strokeWidth) { this._strokeWidth = strokeWidth; this._genCanvas(); }
|
|
66
|
+
get strokeColor() { return this._strokeColor; }
|
|
67
|
+
set strokeColor(strokeColor) { this._strokeColor = strokeColor; this._genCanvas(); }
|
|
68
|
+
_genCanvas() {
|
|
69
|
+
const canvas = this._canvas;
|
|
70
|
+
const ctx = canvas.getContext('2d');
|
|
71
|
+
const border = Array.isArray(this.borderWidth) ? this.borderWidth : [this.borderWidth, this.borderWidth]; // x,y border
|
|
72
|
+
const relBorder = border.map(b => b * this.fontSize * 0.1); // border in canvas units
|
|
73
|
+
const borderRadius = Array.isArray(this.borderRadius) ? this.borderRadius : [this.borderRadius, this.borderRadius, this.borderRadius, this.borderRadius]; // tl tr br bl corners
|
|
74
|
+
const relBorderRadius = borderRadius.map(b => b * this.fontSize * 0.1); // border radius in canvas units
|
|
75
|
+
const padding = Array.isArray(this.padding) ? this.padding : [this.padding, this.padding]; // x,y padding
|
|
76
|
+
const relPadding = padding.map(p => p * this.fontSize * 0.1); // padding in canvas units
|
|
77
|
+
const lines = this.text.split('\n');
|
|
78
|
+
const font = `${this.fontWeight} ${this.fontSize}px ${this.fontFace}`;
|
|
79
|
+
ctx.font = font; // measure canvas with appropriate font
|
|
80
|
+
const innerWidth = Math.max(...lines.map(line => ctx.measureText(line).width));
|
|
81
|
+
const innerHeight = this.fontSize * lines.length;
|
|
82
|
+
canvas.width = innerWidth + relBorder[0] * 2 + relPadding[0] * 2;
|
|
83
|
+
canvas.height = (innerHeight + relBorder[1] * 2 + relPadding[1] * 2) * 2 + 40;
|
|
84
|
+
// paint border
|
|
85
|
+
if (this.borderWidth) {
|
|
86
|
+
ctx.strokeStyle = this.borderColor;
|
|
87
|
+
if (relBorder[0]) { // left + right borders
|
|
88
|
+
const hb = relBorder[0] / 2;
|
|
89
|
+
ctx.lineWidth = relBorder[0];
|
|
90
|
+
ctx.beginPath();
|
|
91
|
+
ctx.moveTo(hb, relBorderRadius[0]);
|
|
92
|
+
ctx.lineTo(hb, ((canvas.height - 40) / 2) - relBorderRadius[3]);
|
|
93
|
+
ctx.moveTo(canvas.width - hb, relBorderRadius[1]);
|
|
94
|
+
ctx.lineTo(canvas.width - hb, ((canvas.height - 40) / 2) - relBorderRadius[2]);
|
|
95
|
+
ctx.stroke();
|
|
96
|
+
}
|
|
97
|
+
if (relBorder[1]) { // top + bottom borders
|
|
98
|
+
const hb = relBorder[1] / 2;
|
|
99
|
+
ctx.lineWidth = relBorder[1];
|
|
100
|
+
ctx.beginPath();
|
|
101
|
+
ctx.moveTo(Math.max(relBorder[0], relBorderRadius[0]), hb);
|
|
102
|
+
ctx.lineTo(canvas.width - Math.max(relBorder[0], relBorderRadius[1]), hb);
|
|
103
|
+
ctx.moveTo(Math.max(relBorder[0], relBorderRadius[3]), ((canvas.height - 40) / 2) - hb);
|
|
104
|
+
ctx.lineTo((canvas.width / 2 - 20), ((canvas.height - 40) / 2) - hb);
|
|
105
|
+
ctx.lineTo((canvas.width / 2), ((canvas.height - 40) / 2) + 20 - hb);
|
|
106
|
+
ctx.lineTo((canvas.width / 2 + 20), ((canvas.height - 40) / 2) - hb);
|
|
107
|
+
ctx.lineTo(canvas.width - Math.max(relBorder[0], relBorderRadius[2]), ((canvas.height - 40) / 2) - hb);
|
|
108
|
+
ctx.stroke();
|
|
109
|
+
}
|
|
110
|
+
if (this.borderRadius) { // strike rounded corners
|
|
111
|
+
const cornerWidth = Math.max(...relBorder);
|
|
112
|
+
const hb = cornerWidth / 2;
|
|
113
|
+
ctx.lineWidth = cornerWidth;
|
|
114
|
+
ctx.beginPath();
|
|
115
|
+
[
|
|
116
|
+
!!relBorderRadius[0] && [relBorderRadius[0], hb, hb, relBorderRadius[0]],
|
|
117
|
+
!!relBorderRadius[1] && [canvas.width - relBorderRadius[1], canvas.width - hb, hb, relBorderRadius[1]],
|
|
118
|
+
!!relBorderRadius[2] && [canvas.width - relBorderRadius[2], canvas.width - hb, ((canvas.height - 40) / 2) - hb, ((canvas.height - 40) / 2) - relBorderRadius[2]],
|
|
119
|
+
!!relBorderRadius[3] && [relBorderRadius[3], hb, ((canvas.height - 40) / 2) - hb, ((canvas.height - 40) / 2) - relBorderRadius[3]]
|
|
120
|
+
].filter(d => d).forEach(([x0, x1, y0, y1]) => {
|
|
121
|
+
ctx.moveTo(x0, y0);
|
|
122
|
+
ctx.quadraticCurveTo(x1, y0, x1, y1);
|
|
123
|
+
});
|
|
124
|
+
ctx.stroke();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// paint background
|
|
128
|
+
if (this.backgroundColor) {
|
|
129
|
+
ctx.fillStyle = this.backgroundColor;
|
|
130
|
+
if (!this.borderRadius) {
|
|
131
|
+
ctx.fillRect(relBorder[0], relBorder[1], canvas.width - relBorder[0] * 2, ((canvas.height - 40) / 2) - relBorder[1] * 2);
|
|
132
|
+
}
|
|
133
|
+
else { // fill with rounded corners
|
|
134
|
+
ctx.beginPath();
|
|
135
|
+
ctx.moveTo(relBorder[0], relBorderRadius[0]);
|
|
136
|
+
ctx.quadraticCurveTo(relBorder[0], relBorder[1], relBorderRadius[0], relBorder[1]);
|
|
137
|
+
ctx.lineTo(canvas.width - relBorderRadius[1], relBorder[1]);
|
|
138
|
+
ctx.quadraticCurveTo(canvas.width - relBorder[0], relBorder[1], canvas.width - relBorder[0], relBorderRadius[1]);
|
|
139
|
+
ctx.lineTo(canvas.width - relBorder[0], ((canvas.height - 40) / 2) - relBorderRadius[2]);
|
|
140
|
+
ctx.quadraticCurveTo(canvas.width - relBorder[0], ((canvas.height - 40) / 2) - relBorder[1], canvas.width - relBorderRadius[2], ((canvas.height - 40) / 2) - relBorder[1]);
|
|
141
|
+
ctx.lineTo((canvas.width / 2 + 20), ((canvas.height - 40) / 2) - relBorder[1]);
|
|
142
|
+
ctx.lineTo((canvas.width / 2), ((canvas.height - 40) / 2) + 20 - relBorder[1]);
|
|
143
|
+
ctx.lineTo((canvas.width / 2 - 20), ((canvas.height - 40) / 2) - relBorder[1]);
|
|
144
|
+
ctx.lineTo(relBorderRadius[3], ((canvas.height - 40) / 2) - relBorder[1]);
|
|
145
|
+
ctx.quadraticCurveTo(relBorder[0], ((canvas.height - 40) / 2) - relBorder[1], relBorder[0], ((canvas.height - 40) / 2) - relBorderRadius[3]);
|
|
146
|
+
ctx.closePath();
|
|
147
|
+
ctx.fill();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
ctx.translate(relBorder[0], relBorder[1]);
|
|
151
|
+
ctx.translate(relPadding[0], relPadding[0]);
|
|
152
|
+
// paint text
|
|
153
|
+
ctx.font = font; // Set font again after canvas is resized, as context properties are reset
|
|
154
|
+
ctx.fillStyle = this.color;
|
|
155
|
+
ctx.textBaseline = 'bottom';
|
|
156
|
+
const drawTextStroke = this.strokeWidth > 0;
|
|
157
|
+
if (drawTextStroke) {
|
|
158
|
+
ctx.lineWidth = this.strokeWidth * this.fontSize / 10;
|
|
159
|
+
ctx.strokeStyle = this.strokeColor;
|
|
160
|
+
}
|
|
161
|
+
lines.forEach((line, index) => {
|
|
162
|
+
const lineX = (innerWidth - ctx.measureText(line).width) / 2;
|
|
163
|
+
const lineY = (index + 1) * this.fontSize;
|
|
164
|
+
drawTextStroke && ctx.strokeText(line, lineX, lineY);
|
|
165
|
+
ctx.fillText(line, lineX, lineY);
|
|
166
|
+
});
|
|
167
|
+
// Inject canvas into sprite
|
|
168
|
+
if (this.material.map)
|
|
169
|
+
this.material.map.dispose(); // gc previous texture
|
|
170
|
+
const texture = this.material.map = new Texture(canvas);
|
|
171
|
+
texture.minFilter = LinearFilter;
|
|
172
|
+
texture.needsUpdate = true;
|
|
173
|
+
const yScale = this.textHeight * lines.length + border[1] * 2 + padding[1] * 2;
|
|
174
|
+
this.scale.set(yScale * canvas.width / canvas.height, yScale, 0);
|
|
175
|
+
}
|
|
176
|
+
//鼠标拾取计算
|
|
177
|
+
raycast(raycaster, intersects) {
|
|
178
|
+
let intersect = [];
|
|
179
|
+
super.raycast(raycaster, intersect);
|
|
180
|
+
let inte = intersect[0];
|
|
181
|
+
if (inte && (inte.uv.y > 0.55)) {
|
|
182
|
+
intersects.push(inte);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
copy(source) {
|
|
186
|
+
this.color = source.color;
|
|
187
|
+
this.backgroundColor = source.backgroundColor;
|
|
188
|
+
this.padding = source.padding;
|
|
189
|
+
this.borderWidth = source.borderWidth;
|
|
190
|
+
this.borderColor = source.borderColor;
|
|
191
|
+
this.fontFace = source.fontFace;
|
|
192
|
+
this.fontSize = source.fontSize;
|
|
193
|
+
this.fontWeight = source.fontWeight;
|
|
194
|
+
this.strokeWidth = source.strokeWidth;
|
|
195
|
+
this.strokeColor = source.strokeColor;
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
}
|
package/SpriteWithHtml.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Sprite } from "three";
|
|
2
|
-
export default class SpriteWithHtml extends Sprite {
|
|
3
|
-
constructor(html?: string, backgroundColor?: `#${string}`);
|
|
4
|
-
visible: boolean;
|
|
5
|
-
div: HTMLDivElement;
|
|
6
|
-
setHtml(html?: string, backgroundColor?: `#${string}`): Promise<void>;
|
|
7
|
-
}
|
|
1
|
+
import { Sprite } from "three";
|
|
2
|
+
export default class SpriteWithHtml extends Sprite {
|
|
3
|
+
constructor(html?: string, backgroundColor?: `#${string}`);
|
|
4
|
+
visible: boolean;
|
|
5
|
+
div: HTMLDivElement;
|
|
6
|
+
setHtml(html?: string, backgroundColor?: `#${string}`): Promise<void>;
|
|
7
|
+
}
|
package/SpriteWithHtml.js
CHANGED
|
@@ -1,49 +1,44 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2023-04-15 11:26:32
|
|
4
|
-
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-04-15 12:38:09
|
|
6
|
-
*/
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import threeLoader from "./threeLoader";
|
|
10
|
-
// html 文本面板
|
|
11
|
-
export default class SpriteWithHtml extends Sprite {
|
|
12
|
-
constructor(html = "", backgroundColor = "#00000000") {
|
|
13
|
-
super();
|
|
14
|
-
this.setHtml(html, backgroundColor);
|
|
15
|
-
}
|
|
16
|
-
visible = false;
|
|
17
|
-
div = (() => {
|
|
18
|
-
const div = document.createElement("div");
|
|
19
|
-
div.style.position = "fixed";
|
|
20
|
-
div.style.top = "100%";
|
|
21
|
-
div.style.left = "100%";
|
|
22
|
-
div.style.pointerEvents = "none";
|
|
23
|
-
div.style.userSelect = "none";
|
|
24
|
-
div.style.lineHeight = "1";
|
|
25
|
-
div.style.whiteSpace = "nowrap";
|
|
26
|
-
return div;
|
|
27
|
-
})();
|
|
28
|
-
async setHtml(html = "", backgroundColor = "#00000000") {
|
|
29
|
-
this.div.innerHTML = html;
|
|
30
|
-
document.body.appendChild(this.div);
|
|
31
|
-
await
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
this.dispatchEvent({ type: "loaded" });
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2023-04-15 11:26:32
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-04-15 12:38:09
|
|
6
|
+
*/
|
|
7
|
+
import { snapdom } from "@zumer/snapdom";
|
|
8
|
+
import { Texture, Sprite } from "three";
|
|
9
|
+
import threeLoader from "./threeLoader";
|
|
10
|
+
// html 文本面板
|
|
11
|
+
export default class SpriteWithHtml extends Sprite {
|
|
12
|
+
constructor(html = "", backgroundColor = "#00000000") {
|
|
13
|
+
super();
|
|
14
|
+
this.setHtml(html, backgroundColor);
|
|
15
|
+
}
|
|
16
|
+
visible = false;
|
|
17
|
+
div = (() => {
|
|
18
|
+
const div = document.createElement("div");
|
|
19
|
+
div.style.position = "fixed";
|
|
20
|
+
div.style.top = "100%";
|
|
21
|
+
div.style.left = "100%";
|
|
22
|
+
div.style.pointerEvents = "none";
|
|
23
|
+
div.style.userSelect = "none";
|
|
24
|
+
div.style.lineHeight = "1";
|
|
25
|
+
div.style.whiteSpace = "nowrap";
|
|
26
|
+
return div;
|
|
27
|
+
})();
|
|
28
|
+
async setHtml(html = "", backgroundColor = "#00000000") {
|
|
29
|
+
this.div.innerHTML = html;
|
|
30
|
+
document.body.appendChild(this.div);
|
|
31
|
+
const img = await snapdom.toPng(this.div, { backgroundColor });
|
|
32
|
+
this.scale.set(img.naturalWidth, img.naturalHeight, 1);
|
|
33
|
+
const texture = new Texture(img);
|
|
34
|
+
texture.needsUpdate = true;
|
|
35
|
+
this.material.map = texture;
|
|
36
|
+
this.material.map.anisotropy = threeLoader.anisotropy;
|
|
37
|
+
this.material.alphaTest = 0.1;
|
|
38
|
+
this.material.needsUpdate = true;
|
|
39
|
+
await new Promise(resolve => requestAnimationFrame(resolve));
|
|
40
|
+
this.visible = true;
|
|
41
|
+
this.div.remove();
|
|
42
|
+
this.dispatchEvent({ type: "loaded" });
|
|
43
|
+
}
|
|
44
|
+
}
|
package/Text3D/Text3D.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { Mesh, MeshStandardMaterial } from "three";
|
|
2
|
-
export type Text3DProps = {
|
|
3
|
-
text?: string;
|
|
4
|
-
fontType?: string;
|
|
5
|
-
size?: number | undefined;
|
|
6
|
-
depth?: number | undefined;
|
|
7
|
-
curveSegments?: number | undefined;
|
|
8
|
-
bevelEnabled?: boolean | undefined;
|
|
9
|
-
bevelThickness?: number | undefined;
|
|
10
|
-
bevelSize?: number | undefined;
|
|
11
|
-
bevelOffset?: number | undefined;
|
|
12
|
-
bevelSegments?: number | undefined;
|
|
13
|
-
};
|
|
14
|
-
export default class Text3D extends Mesh {
|
|
15
|
-
constructor(text?: string);
|
|
16
|
-
static path: string;
|
|
17
|
-
material: MeshStandardMaterial;
|
|
18
|
-
_config: Text3DProps;
|
|
19
|
-
setText(text3DProps: Text3DProps): void;
|
|
20
|
-
}
|
|
1
|
+
import { Mesh, MeshBasicMaterial, MeshLambertMaterial, MeshPhysicalMaterial, MeshStandardMaterial } from "three";
|
|
2
|
+
export type Text3DProps = {
|
|
3
|
+
text?: string;
|
|
4
|
+
fontType?: string;
|
|
5
|
+
size?: number | undefined;
|
|
6
|
+
depth?: number | undefined;
|
|
7
|
+
curveSegments?: number | undefined;
|
|
8
|
+
bevelEnabled?: boolean | undefined;
|
|
9
|
+
bevelThickness?: number | undefined;
|
|
10
|
+
bevelSize?: number | undefined;
|
|
11
|
+
bevelOffset?: number | undefined;
|
|
12
|
+
bevelSegments?: number | undefined;
|
|
13
|
+
};
|
|
14
|
+
export default class Text3D extends Mesh {
|
|
15
|
+
constructor(text?: string);
|
|
16
|
+
static path: string;
|
|
17
|
+
material: MeshStandardMaterial | MeshBasicMaterial | MeshPhysicalMaterial | MeshLambertMaterial;
|
|
18
|
+
_config: Text3DProps;
|
|
19
|
+
setText(text3DProps: Text3DProps): void;
|
|
20
|
+
}
|