three-base 2.0.130 → 2.0.134

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.
Files changed (123) hide show
  1. package/ApngTexture.d.ts +13 -13
  2. package/ApngTexture.js +61 -61
  3. package/ApngTextureManage.d.ts +18 -18
  4. package/ApngTextureManage.js +87 -87
  5. package/DirectionalLight.d.ts +6 -0
  6. package/DirectionalLight.js +68 -0
  7. package/EventMesh.d.ts +18 -18
  8. package/EventMesh.js +59 -59
  9. package/ExtrudeMesh.d.ts +112 -112
  10. package/ExtrudeMesh.js +366 -366
  11. package/FPScontrol.d.ts +71 -50
  12. package/FPScontrol.js +505 -232
  13. package/Fire/Fire.d.ts +28 -28
  14. package/Fire/Fire.js +79 -79
  15. package/Fire/FireGromtry.d.ts +9 -9
  16. package/Fire/FireGromtry.js +40 -40
  17. package/Fire/FireMaterial.d.ts +28 -28
  18. package/Fire/FireMaterial.js +32 -32
  19. package/Fire/index.d.ts +1 -1
  20. package/Fire/index.js +1 -1
  21. package/Grass/Grass.d.ts +8 -8
  22. package/Grass/Grass.js +38 -38
  23. package/Grass/index.d.ts +1 -1
  24. package/Grass/index.js +1 -1
  25. package/Ground1/Ground1.d.ts +11 -11
  26. package/Ground1/Ground1.js +54 -54
  27. package/Ground1/index.d.ts +1 -1
  28. package/Ground1/index.js +1 -1
  29. package/InstancedMeshBase.d.ts +39 -39
  30. package/InstancedMeshBase.js +293 -293
  31. package/KeyFrameAnimation.d.ts +25 -25
  32. package/KeyFrameAnimation.js +78 -78
  33. package/MeshBase.d.ts +35 -35
  34. package/MeshBase.js +223 -223
  35. package/Mirror.d.ts +25 -25
  36. package/Mirror.js +139 -139
  37. package/PipeMesh/PathGeometry.d.ts +44 -44
  38. package/PipeMesh/PathGeometry.js +300 -300
  39. package/PipeMesh/PathPoint.d.ts +17 -17
  40. package/PipeMesh/PathPoint.js +31 -31
  41. package/PipeMesh/PathPointList.d.ts +31 -31
  42. package/PipeMesh/PathPointList.js +208 -208
  43. package/PipeMesh/PathTubeGeometry.d.ts +25 -25
  44. package/PipeMesh/PathTubeGeometry.js +130 -130
  45. package/PipeMesh/PipeMesh.d.ts +25 -25
  46. package/PipeMesh/PipeMesh.js +63 -63
  47. package/PipeMesh/index.d.ts +1 -1
  48. package/PipeMesh/index.js +1 -1
  49. package/PlaneModal1/PlaneModal1.d.ts +31 -31
  50. package/PlaneModal1/PlaneModal1.js +105 -105
  51. package/PlaneModal1/index.d.ts +1 -1
  52. package/PlaneModal1/index.js +1 -1
  53. package/PlaneText.d.ts +39 -39
  54. package/PlaneText.js +30 -30
  55. package/PlaneWithHtml.d.ts +11 -11
  56. package/PlaneWithHtml.js +63 -68
  57. package/PointLight/PointLight.d.ts +14 -13
  58. package/PointLight/PointLight.js +70 -64
  59. package/PointLight/index.d.ts +1 -1
  60. package/PointLight/index.js +1 -1
  61. package/Sky/Sky.d.ts +9 -9
  62. package/Sky/Sky.js +22 -22
  63. package/Sky/index.d.ts +1 -1
  64. package/Sky/index.js +1 -1
  65. package/SpotLight.d.ts +6 -0
  66. package/SpotLight.js +72 -0
  67. package/SpriteModal1/SpriteModal1.d.ts +30 -30
  68. package/SpriteModal1/SpriteModal1.js +110 -110
  69. package/SpriteModal1/index.d.ts +1 -1
  70. package/SpriteModal1/index.js +1 -1
  71. package/SpriteText.d.ts +45 -45
  72. package/SpriteText.js +163 -163
  73. package/SpriteText2.d.ts +47 -47
  74. package/SpriteText2.js +198 -198
  75. package/SpriteWithHtml.d.ts +7 -7
  76. package/SpriteWithHtml.js +44 -49
  77. package/Text3D/Text3D.d.ts +20 -20
  78. package/Text3D/Text3D.js +62 -62
  79. package/Text3D/fontController.d.ts +59 -59
  80. package/Text3D/fontController.js +199 -199
  81. package/Text3D/index.d.ts +1 -1
  82. package/Text3D/index.js +1 -1
  83. package/ThreeBase.d.ts +97 -81
  84. package/ThreeBase.js +613 -560
  85. package/ThreeMouse.d.ts +40 -40
  86. package/ThreeMouse.js +407 -407
  87. package/Transition.d.ts +40 -40
  88. package/Transition.js +210 -210
  89. package/Water/Water.d.ts +5 -0
  90. package/Water/Water.js +26 -0
  91. package/Water/waternormals.jpg +0 -0
  92. package/declare.d.ts +167 -0
  93. package/index.d.ts +1 -1
  94. package/index.js +2 -2
  95. package/keyContorls.d.ts +25 -25
  96. package/keyContorls.js +98 -98
  97. package/package.json +1 -1
  98. package/pass/bloom_pass.d.ts +2 -2
  99. package/pass/bloom_pass.js +99 -99
  100. package/pass/cover_pass.d.ts +2 -2
  101. package/pass/cover_pass.js +95 -95
  102. package/pass/frosted_glass_pass.d.ts +2 -0
  103. package/pass/frosted_glass_pass.js +275 -0
  104. package/pass/fsQuad.d.ts +9 -9
  105. package/pass/fsQuad.js +28 -28
  106. package/pass/glow_pass.d.ts +2 -2
  107. package/pass/glow_pass.js +310 -254
  108. package/pass/ssao_pass.d.ts +11 -0
  109. package/pass/ssao_pass.js +294 -0
  110. package/pass/stroke_pass.d.ts +2 -2
  111. package/pass/stroke_pass.js +199 -199
  112. package/shaders/FXAAShaderMaterial.d.ts +3 -3
  113. package/shaders/FXAAShaderMaterial.js +21 -21
  114. package/shaders/baseTextureToRenderShader.d.ts +2 -2
  115. package/shaders/baseTextureToRenderShader.js +14 -14
  116. package/shaders/copyShader.d.ts +3 -3
  117. package/shaders/copyShader.js +14 -14
  118. package/shaders.d.ts +5 -5
  119. package/shaders.js +42 -42
  120. package/threeLoader.d.ts +34 -34
  121. package/threeLoader.js +527 -527
  122. package/threeUtils.d.ts +52 -52
  123. 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
+ }
@@ -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 html2canvas from "html2canvas";
8
- import { CanvasTexture, 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
- await new Promise((resolve, reject) => {
32
- html2canvas(this.div, {
33
- backgroundColor,
34
- removeContainer: true
35
- }).then(async (canvas) => {
36
- this.scale.set(canvas.width, canvas.height, 1);
37
- this.material.map = new CanvasTexture(canvas);
38
- this.material.map.anisotropy = threeLoader.anisotropy;
39
- this.material.alphaTest = 0.1;
40
- this.material.needsUpdate = true;
41
- await new Promise(resolve => requestAnimationFrame(resolve));
42
- this.visible = true;
43
- this.div.remove();
44
- resolve();
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
+ }
@@ -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
+ }