three-base 1.129.17 → 2.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.
Files changed (91) hide show
  1. package/README.md +1 -0
  2. package/index.js +1 -37
  3. package/index.ts +1 -61
  4. package/package.json +4 -4
  5. package/lib/ApngTexture.d.ts +0 -13
  6. package/lib/ApngTexture.js +0 -61
  7. package/lib/ApngTexture.ts +0 -91
  8. package/lib/ApngTextureManage.d.ts +0 -18
  9. package/lib/ApngTextureManage.js +0 -87
  10. package/lib/ApngTextureManage.ts +0 -130
  11. package/lib/EventMesh.d.ts +0 -18
  12. package/lib/EventMesh.js +0 -59
  13. package/lib/EventMesh.ts +0 -79
  14. package/lib/ExtrudeMesh.d.ts +0 -111
  15. package/lib/ExtrudeMesh.js +0 -363
  16. package/lib/ExtrudeMesh.ts +0 -571
  17. package/lib/FPScontrol.d.ts +0 -44
  18. package/lib/FPScontrol.js +0 -170
  19. package/lib/FPScontrol.ts +0 -209
  20. package/lib/InstancedGroupMesh.d.ts +0 -10
  21. package/lib/InstancedGroupMesh.js +0 -63
  22. package/lib/InstancedGroupMesh.ts +0 -80
  23. package/lib/KeyFrameAnimation.d.ts +0 -25
  24. package/lib/KeyFrameAnimation.js +0 -78
  25. package/lib/KeyFrameAnimation.ts +0 -122
  26. package/lib/PlaneText.d.ts +0 -37
  27. package/lib/PlaneText.js +0 -30
  28. package/lib/PlaneText.ts +0 -58
  29. package/lib/PlaneWithHtml.d.ts +0 -11
  30. package/lib/PlaneWithHtml.js +0 -67
  31. package/lib/PlaneWithHtml.ts +0 -84
  32. package/lib/PointLight/PointLight.d.ts +0 -13
  33. package/lib/PointLight/PointLight.js +0 -63
  34. package/lib/PointLight/PointLight.ts +0 -74
  35. package/lib/PointLight/pointLight_map.png +0 -0
  36. package/lib/Sky/Sky.d.ts +0 -13
  37. package/lib/Sky/Sky.js +0 -28
  38. package/lib/Sky/Sky.ts +0 -36
  39. package/lib/Sky/bluesky.jpg +0 -0
  40. package/lib/SpriteText.d.ts +0 -45
  41. package/lib/SpriteText.js +0 -162
  42. package/lib/SpriteText.ts +0 -189
  43. package/lib/SpriteText2.d.ts +0 -47
  44. package/lib/SpriteText2.js +0 -197
  45. package/lib/SpriteText2.ts +0 -236
  46. package/lib/Text3D/Text3D.d.ts +0 -20
  47. package/lib/Text3D/Text3D.js +0 -61
  48. package/lib/Text3D/Text3D.ts +0 -92
  49. package/lib/Text3D/fontController.d.ts +0 -59
  50. package/lib/Text3D/fontController.js +0 -200
  51. package/lib/Text3D/fontController.ts +0 -285
  52. package/lib/Text3D/gentilis.json +0 -811
  53. package/lib/ThreeBase.d.ts +0 -59
  54. package/lib/ThreeBase.js +0 -395
  55. package/lib/ThreeBase.ts +0 -475
  56. package/lib/ThreeMouse.d.ts +0 -39
  57. package/lib/ThreeMouse.js +0 -357
  58. package/lib/ThreeMouse.ts +0 -464
  59. package/lib/Transition.d.ts +0 -43
  60. package/lib/Transition.js +0 -196
  61. package/lib/Transition.ts +0 -268
  62. package/lib/index.d.ts +0 -22
  63. package/lib/keyContorls.d.ts +0 -25
  64. package/lib/keyContorls.js +0 -98
  65. package/lib/keyContorls.ts +0 -127
  66. package/lib/planeModal1/PlaneModal1.d.ts +0 -31
  67. package/lib/planeModal1/PlaneModal1.js +0 -104
  68. package/lib/planeModal1/PlaneModal1.ts +0 -150
  69. package/lib/planeModal1/planeModal.png +0 -0
  70. package/lib/shaders.d.ts +0 -17
  71. package/lib/shaders.js +0 -245
  72. package/lib/shaders.ts +0 -264
  73. package/lib/spriteModal1/SpriteModal1.d.ts +0 -30
  74. package/lib/spriteModal1/SpriteModal1.js +0 -109
  75. package/lib/spriteModal1/SpriteModal1.ts +0 -159
  76. package/lib/spriteModal1/spriteModal1.png +0 -0
  77. package/lib/stroke_pass/FullScreenQuad.d.ts +0 -7
  78. package/lib/stroke_pass/FullScreenQuad.js +0 -25
  79. package/lib/stroke_pass/FullScreenQuad.ts +0 -33
  80. package/lib/stroke_pass/stroke_pass.d.ts +0 -2
  81. package/lib/stroke_pass/stroke_pass.js +0 -190
  82. package/lib/stroke_pass/stroke_pass.ts +0 -211
  83. package/lib/threeLoader.d.ts +0 -20
  84. package/lib/threeLoader.js +0 -110
  85. package/lib/threeLoader.ts +0 -136
  86. package/lib/threeUtils.d.ts +0 -41
  87. package/lib/threeUtils.js +0 -179
  88. package/lib/threeUtils.ts +0 -212
  89. package/lib/type.d.ts +0 -0
  90. package/lib/type.js +0 -10
  91. package/lib/type.ts +0 -13
@@ -1,150 +0,0 @@
1
- /*
2
- * @Author: xiaosihan
3
- * @Date: 2023-03-09 18:51:11
4
- * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2023-03-09 19:15:35
6
- */
7
-
8
- import { MeshBasicMaterial, Mesh, DoubleSide, CanvasTexture, Vector2, BufferGeometry, PlaneGeometry } from "three";
9
- import planeModalPNG from "./planeModal.png";
10
-
11
-
12
- export type PlaneModal1Config = {
13
- size?: number,
14
- title?: string,
15
- titleColor?: string,
16
- texts?: Array<{
17
- text?: string,
18
- color?: string,
19
- size?: number
20
- }>
21
- }
22
-
23
- // 平面模型弹窗
24
- export default class PlaneModal1 extends Mesh {
25
-
26
- constructor(config: PlaneModal1Config = {}) {
27
- super();
28
- this.updata(config);
29
- this.material.map = this.texture;
30
- this.scale.set(10, 10, 10);
31
- }
32
-
33
- geometry = new PlaneGeometry(1 * 0.65, 0.728 * 0.65, 1, 1);
34
-
35
- material = new MeshBasicMaterial({
36
- side: DoubleSide,
37
- transparent: true,
38
- alphaTest: 0.01
39
- });
40
-
41
- // 背景图
42
- static img = (() => {
43
- const img = new Image();
44
- img.src = planeModalPNG;
45
- return img;
46
- })();
47
-
48
- canvas = (() => {
49
- const canvas = document.createElement("canvas");
50
- canvas.width = 660;
51
- canvas.height = 481;
52
- return canvas;
53
- })();
54
-
55
- context = this.canvas.getContext("2d")!;
56
-
57
- texture = new CanvasTexture(this.canvas);
58
-
59
- // 配置
60
- _config: {
61
- size: number,
62
- title: string,
63
- titleColor: string,
64
- texts: Array<{
65
- text: string,
66
- color: string,
67
- size: number
68
- }>
69
- } = {
70
- size: 10,
71
- title: "PlaneModal1",
72
- titleColor: "#ffffff",
73
- texts: []
74
- // [
75
- // {
76
- // text: "1",
77
- // color: "#ffff00",
78
- // size: 40
79
- // },
80
- // {
81
- // text: "2",
82
- // color: "#ff00ff",
83
- // size: 40
84
- // },
85
- // ]
86
- }
87
-
88
- async updata(config: PlaneModal1Config) {
89
-
90
- Object.assign(this._config, config)
91
-
92
- //绘制背景
93
- this.context.clearRect(0, 0, 660, 481);
94
-
95
- while (!PlaneModal1.img.complete) {
96
- await new Promise(resolve => setTimeout(resolve, 100));
97
- }
98
-
99
- // 设置大小
100
- this.scale.set(this._config.size, this._config.size, this._config.size);
101
-
102
- // this.context.fillStyle = "#00000088";
103
- // this.context.fillRect(0, 0, 660, 481);
104
-
105
- //绘制背景
106
- this.context.drawImage(PlaneModal1.img, 0, 0);
107
-
108
- // 绘制标题
109
- this.context.fillStyle = this._config.titleColor;
110
- this.context.font = '40px serif';// 设置字体大小
111
- this.context.textAlign = "left";
112
- this.context.textBaseline = "top";
113
- this.context.fillText(this._config.title, 60, 72);
114
-
115
- let textPos = new Vector2(60, 150);
116
- let maxWidth = 530;
117
- // 绘制内容
118
- this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
119
- this.context.fillStyle = color;
120
- this.context.font = `${size}px serif`;// 设置字体大小
121
- this.context.textAlign = "left";
122
- this.context.textBaseline = "top";
123
-
124
- // 字符分隔为数组
125
- var arrText = text.split('');
126
- var line = '';
127
-
128
- for (var n = 0; n < arrText.length; n++) {
129
- var metrics = this.context.measureText(line + arrText[n]);
130
- var testWidth = metrics.width;
131
- if ((testWidth > maxWidth && n > 0) || arrText[n] === "\n") {
132
- this.context.fillText(line, textPos.x, textPos.y);
133
- line = "";
134
- textPos.y += size;
135
- } else {
136
- line += arrText[n];
137
- }
138
- }
139
-
140
- this.context.fillText(line, textPos.x, textPos.y);
141
- textPos.y += size;
142
- });
143
-
144
- this.texture.needsUpdate = true;
145
-
146
- this.dispatchEvent({ type: "loaded" });
147
- }
148
-
149
-
150
- }
Binary file
package/lib/shaders.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import { Mesh, OrthographicCamera, ShaderMaterial, WebGLRenderer } from "three";
2
- declare class FullScreenQuad {
3
- constructor();
4
- _mesh: Mesh;
5
- dispose(): void;
6
- render(renderer: WebGLRenderer): void;
7
- get material(): import("three").Material | import("three").Material[];
8
- set material(value: import("three").Material | import("three").Material[]);
9
- }
10
- export declare const fullScreenMesh: FullScreenQuad;
11
- export declare const orthographicCamera: OrthographicCamera;
12
- export declare const clearShader: ShaderMaterial;
13
- export declare const intersectionShader: ShaderMaterial;
14
- export declare const coptyShader: ShaderMaterial;
15
- export declare const strokeShader: ShaderMaterial;
16
- export declare const gaussBlurShader: ShaderMaterial;
17
- export {};
package/lib/shaders.js DELETED
@@ -1,245 +0,0 @@
1
- /*
2
- * @Author: xiaosihan
3
- * @Date: 2022-03-24 16:38:35
4
- * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2022-04-02 18:28:38
6
- */
7
- import { BufferGeometry, Color, Float32BufferAttribute, Mesh, NoBlending, OrthographicCamera, ShaderChunk, ShaderMaterial, Vector2 } from "three";
8
- // https://github.com/mrdoob/three.js/pull/21358
9
- const _geometry = new BufferGeometry();
10
- _geometry.setAttribute("position", new Float32BufferAttribute([-1, 3, 0, -1, -1, 0, 3, -1, 0], 3));
11
- _geometry.setAttribute("uv", new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2));
12
- class FullScreenQuad {
13
- constructor() {
14
- this._mesh = new Mesh(_geometry);
15
- }
16
- _mesh;
17
- dispose() {
18
- this._mesh.geometry.dispose();
19
- }
20
- render(renderer) {
21
- renderer.render(this._mesh, orthographicCamera);
22
- }
23
- get material() {
24
- return this._mesh.material;
25
- }
26
- set material(value) {
27
- this._mesh.material = value;
28
- }
29
- }
30
- // 常用着色器及工具
31
- // 全屏渲染模型
32
- export const fullScreenMesh = new FullScreenQuad();
33
- export const orthographicCamera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
34
- // 清理着色器
35
- export const clearShader = new ShaderMaterial({
36
- vertexShader: `
37
- varying vec2 vUv;
38
- void main() {
39
- vUv = uv;
40
- gl_Position = vec4(position, 1.0);
41
- }
42
- `,
43
- fragmentShader: `
44
- void main() {
45
- gl_FragColor = vec4(0.0);
46
- }
47
- `,
48
- blending: NoBlending,
49
- depthTest: false,
50
- depthWrite: false,
51
- transparent: true
52
- });
53
- // 交集着色器提取相同的像素点
54
- export const intersectionShader = new ShaderMaterial({
55
- uniforms: {
56
- map1: { value: null },
57
- map2: { value: null }, // 贴图纹理2
58
- },
59
- vertexShader: `
60
- ${ShaderChunk.common}
61
- ${ShaderChunk.logdepthbuf_pars_vertex}
62
- varying vec2 vUv;
63
- void main() {
64
- vUv = uv;
65
- gl_Position = vec4(position, 1.0);
66
- ${ShaderChunk.logdepthbuf_vertex}
67
- }
68
- `,
69
- fragmentShader: `
70
- ${ShaderChunk.logdepthbuf_pars_fragment}
71
- uniform sampler2D map1;
72
- uniform sampler2D map2;
73
- varying vec2 vUv;
74
- void main() {
75
- if(texture2D(map1, vUv) == texture2D(map2, vUv)){
76
- gl_FragColor = texture2D(map1, vUv);
77
- }else{
78
- discard;
79
- }
80
- ${ShaderChunk.logdepthbuf_fragment}
81
- }
82
- `,
83
- blending: NoBlending,
84
- depthTest: true,
85
- depthWrite: true,
86
- transparent: true
87
- });
88
- // 拷贝着色器
89
- export const coptyShader = new ShaderMaterial({
90
- uniforms: {
91
- map: { value: null },
92
- opacity: { value: 1.0 } // 透明度
93
- },
94
- vertexShader: `
95
- varying vec2 vUv;
96
- void main() {
97
- vUv = uv;
98
- gl_Position = vec4(position, 1.0);
99
- }
100
- `,
101
- fragmentShader: `
102
- uniform sampler2D map;
103
- uniform float opacity;
104
- varying vec2 vUv;
105
- void main() {
106
-
107
- gl_FragColor = texture2D(map, vUv) * opacity;
108
-
109
- }
110
- `,
111
- // blending: NoBlending, // 渲染时不与背景融合计算 直接替换
112
- depthTest: true,
113
- depthWrite: true,
114
- transparent: true,
115
- });
116
- // 描边着色器
117
- export const strokeShader = new ShaderMaterial({
118
- uniforms: {
119
- map: { value: null },
120
- resolution: { value: new Vector2(512, 512) },
121
- strokeWidth: { value: 1.0 },
122
- strokeColor: { value: new Color("#B2F2FF") },
123
- opacity: { value: 1.0 } // 透明度
124
- },
125
- vertexShader: `
126
- varying vec2 vUv;
127
- void main() {
128
- vUv = uv;
129
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
130
- }
131
- `,
132
- fragmentShader: `
133
- uniform sampler2D map;
134
- uniform vec2 resolution;
135
- uniform vec3 strokeColor; // 描边颜色
136
- uniform float strokeWidth; // 描边厚度
137
- uniform float opacity; // 透明度
138
-
139
- varying vec2 vUv;
140
-
141
- // 获取当前叠加vu坐标偏移量的颜色值
142
- vec4 offsetColor(vec2 vu){
143
- return texture2D(map, vUv + (vu * (strokeWidth / resolution) ) );
144
- }
145
-
146
- vec4 fragColor(){
147
-
148
- vec4 currentColor = offsetColor(vec2(0.0, 0.0));
149
-
150
- if(
151
- currentColor.a < min(0.2, opacity) && (
152
- offsetColor(vec2(0.0, 1.0)).a > 0.0 ||
153
- offsetColor(vec2(0.0, -1.0)).a > 0.0 ||
154
- offsetColor(vec2(1.0, 0.0)).a > 0.0 ||
155
- offsetColor(vec2(-1.0, 0.0)).a > 0.0 ||
156
-
157
- offsetColor(vec2(1.0) * 0.7).a > 0.0 ||
158
- offsetColor(vec2(-1.0) * 0.7).a > 0.0 ||
159
- offsetColor(vec2(-1.0, 1.0) * 0.7).a > 0.0 ||
160
- offsetColor(vec2(1.0, -1.0) * 0.7).a > 0.0
161
- )
162
- ){
163
- return vec4( strokeColor, opacity);
164
- }else{
165
- // discard;
166
- return offsetColor(vec2(0.0, 0.0));
167
- }
168
-
169
- }
170
-
171
- void main() {
172
- gl_FragColor = fragColor();
173
- }
174
- `,
175
- blending: NoBlending,
176
- depthTest: true,
177
- depthWrite: true,
178
- transparent: true
179
- });
180
- // 高斯模糊着色器 让颜色过渡更自然
181
- export const gaussBlurShader = new ShaderMaterial({
182
- uniforms: {
183
- map: { value: null },
184
- opacity: { value: 1.0 },
185
- radius: { value: 3.0 },
186
- resolution: { value: new Vector2(512, 512) }, // 渲染器的分辨率
187
- },
188
- vertexShader: `
189
- varying vec2 vUv;
190
- void main() {
191
- vUv = uv;
192
- gl_Position = vec4(position, 1.0);
193
- }
194
- `,
195
- fragmentShader: `
196
- uniform sampler2D map;
197
- uniform float opacity;
198
- uniform vec2 resolution;
199
- uniform float radius;
200
- varying vec2 vUv;
201
-
202
- vec4 offsetColor( vec2 uv){
203
- return texture2D(map, vUv + (uv / resolution * radius) );
204
- }
205
-
206
- vec4 blurColor(){
207
-
208
- vec4 leftColor = offsetColor( vec2(-1.0, 0.0) );
209
-
210
- vec4 rightColor = offsetColor( vec2(1.0, 0.0) );
211
-
212
- // 左右颜色混合
213
- vec4 leftRightColor = vec4(
214
- mix( leftColor.rgb ,rightColor.rgb, rightColor.a / (leftColor.a + rightColor.a)),
215
- (leftColor.a + rightColor.a) / 2.0
216
- );
217
-
218
- vec4 downColor = offsetColor( vec2(0.0, -1.0));
219
-
220
- vec4 upColor = offsetColor( vec2(0.0, 1.0));
221
-
222
- // 上下颜色混合
223
- vec4 upDownColor = vec4(
224
- mix( downColor.rgb, upColor.rgb, upColor.a / (downColor.a + upColor.a) ),
225
- (downColor.a + upColor.a) / 2.0
226
- );
227
-
228
- vec4 color = vec4(
229
- mix( leftRightColor.rgb, upDownColor.rgb, upDownColor.a / (leftRightColor.a + upDownColor.a) ),
230
- (leftRightColor.a + upDownColor.a) / 2.0
231
- );
232
-
233
- return color;
234
- }
235
-
236
- void main() {
237
- gl_FragColor = blurColor();
238
- gl_FragColor.a *= opacity;
239
- }
240
- `,
241
- blending: NoBlending,
242
- depthTest: false,
243
- depthWrite: false,
244
- transparent: true
245
- });
package/lib/shaders.ts DELETED
@@ -1,264 +0,0 @@
1
- /*
2
- * @Author: xiaosihan
3
- * @Date: 2022-03-24 16:38:35
4
- * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2022-04-02 18:28:38
6
- */
7
-
8
- import { BufferGeometry, Color, Float32BufferAttribute, Mesh, NoBlending, OrthographicCamera, ShaderChunk, ShaderMaterial, Vector2, WebGLRenderer } from "three";
9
-
10
-
11
-
12
- // https://github.com/mrdoob/three.js/pull/21358
13
-
14
- const _geometry = new BufferGeometry();
15
- _geometry.setAttribute("position", new Float32BufferAttribute([- 1, 3, 0, - 1, - 1, 0, 3, - 1, 0], 3));
16
- _geometry.setAttribute("uv", new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2));
17
-
18
- class FullScreenQuad {
19
- constructor() {
20
- this._mesh = new Mesh(_geometry);
21
- }
22
- _mesh!: Mesh;
23
- dispose() {
24
- this._mesh.geometry.dispose();
25
- }
26
- render(renderer: WebGLRenderer) {
27
- renderer.render(this._mesh, orthographicCamera);
28
- }
29
- get material() {
30
- return this._mesh.material;
31
- }
32
- set material(value) {
33
- this._mesh.material = value;
34
- }
35
- }
36
-
37
-
38
- // 常用着色器及工具
39
-
40
-
41
- // 全屏渲染模型
42
- export const fullScreenMesh = new FullScreenQuad();
43
-
44
- export const orthographicCamera = new OrthographicCamera(- 1, 1, 1, - 1, 0, 1);
45
-
46
- // 清理着色器
47
- export const clearShader = new ShaderMaterial({
48
- vertexShader: `
49
- varying vec2 vUv;
50
- void main() {
51
- vUv = uv;
52
- gl_Position = vec4(position, 1.0);
53
- }
54
- `,
55
- fragmentShader: `
56
- void main() {
57
- gl_FragColor = vec4(0.0);
58
- }
59
- `,
60
- blending: NoBlending, // 渲染时不与背景融合计算 直接替换
61
- depthTest: false,
62
- depthWrite: false,
63
- transparent: true
64
- });
65
-
66
- // 交集着色器提取相同的像素点
67
- export const intersectionShader = new ShaderMaterial({
68
- uniforms: {
69
- map1: { value: null }, // 贴图纹理1
70
- map2: { value: null }, // 贴图纹理2
71
- },
72
- vertexShader: `
73
- ${ShaderChunk.common}
74
- ${ShaderChunk.logdepthbuf_pars_vertex}
75
- varying vec2 vUv;
76
- void main() {
77
- vUv = uv;
78
- gl_Position = vec4(position, 1.0);
79
- ${ShaderChunk.logdepthbuf_vertex}
80
- }
81
- `,
82
- fragmentShader: `
83
- ${ShaderChunk.logdepthbuf_pars_fragment}
84
- uniform sampler2D map1;
85
- uniform sampler2D map2;
86
- varying vec2 vUv;
87
- void main() {
88
- if(texture2D(map1, vUv) == texture2D(map2, vUv)){
89
- gl_FragColor = texture2D(map1, vUv);
90
- }else{
91
- discard;
92
- }
93
- ${ShaderChunk.logdepthbuf_fragment}
94
- }
95
- `,
96
- blending: NoBlending, // 渲染时不与背景融合计算 直接替换
97
- depthTest: true,
98
- depthWrite: true,
99
- transparent: true
100
- });
101
-
102
-
103
- // 拷贝着色器
104
- export const coptyShader = new ShaderMaterial({
105
- uniforms: {
106
- map: { value: null }, // 纹理
107
- opacity: { value: 1.0 } // 透明度
108
- },
109
- vertexShader: `
110
- varying vec2 vUv;
111
- void main() {
112
- vUv = uv;
113
- gl_Position = vec4(position, 1.0);
114
- }
115
- `,
116
- fragmentShader: `
117
- uniform sampler2D map;
118
- uniform float opacity;
119
- varying vec2 vUv;
120
- void main() {
121
-
122
- gl_FragColor = texture2D(map, vUv) * opacity;
123
-
124
- }
125
- `,
126
- // blending: NoBlending, // 渲染时不与背景融合计算 直接替换
127
- depthTest: true,
128
- depthWrite: true,
129
- transparent: true,
130
- });
131
-
132
-
133
- // 描边着色器
134
- export const strokeShader = new ShaderMaterial({
135
- uniforms: {
136
- map: { value: null }, // 贴图纹理
137
- resolution: { value: new Vector2(512, 512) }, // 分辨率
138
- strokeWidth: { value: 1.0 }, // 描边宽度
139
- strokeColor: { value: new Color("#B2F2FF") }, // 描边颜色
140
- opacity: { value: 1.0 } // 透明度
141
- },
142
- vertexShader: `
143
- varying vec2 vUv;
144
- void main() {
145
- vUv = uv;
146
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
147
- }
148
- `,
149
- fragmentShader: `
150
- uniform sampler2D map;
151
- uniform vec2 resolution;
152
- uniform vec3 strokeColor; // 描边颜色
153
- uniform float strokeWidth; // 描边厚度
154
- uniform float opacity; // 透明度
155
-
156
- varying vec2 vUv;
157
-
158
- // 获取当前叠加vu坐标偏移量的颜色值
159
- vec4 offsetColor(vec2 vu){
160
- return texture2D(map, vUv + (vu * (strokeWidth / resolution) ) );
161
- }
162
-
163
- vec4 fragColor(){
164
-
165
- vec4 currentColor = offsetColor(vec2(0.0, 0.0));
166
-
167
- if(
168
- currentColor.a < min(0.2, opacity) && (
169
- offsetColor(vec2(0.0, 1.0)).a > 0.0 ||
170
- offsetColor(vec2(0.0, -1.0)).a > 0.0 ||
171
- offsetColor(vec2(1.0, 0.0)).a > 0.0 ||
172
- offsetColor(vec2(-1.0, 0.0)).a > 0.0 ||
173
-
174
- offsetColor(vec2(1.0) * 0.7).a > 0.0 ||
175
- offsetColor(vec2(-1.0) * 0.7).a > 0.0 ||
176
- offsetColor(vec2(-1.0, 1.0) * 0.7).a > 0.0 ||
177
- offsetColor(vec2(1.0, -1.0) * 0.7).a > 0.0
178
- )
179
- ){
180
- return vec4( strokeColor, opacity);
181
- }else{
182
- // discard;
183
- return offsetColor(vec2(0.0, 0.0));
184
- }
185
-
186
- }
187
-
188
- void main() {
189
- gl_FragColor = fragColor();
190
- }
191
- `,
192
- blending: NoBlending, // 渲染时不与背景融合计算 直接替换
193
- depthTest: true,
194
- depthWrite: true,
195
- transparent: true
196
- });
197
-
198
-
199
- // 高斯模糊着色器 让颜色过渡更自然
200
- export const gaussBlurShader = new ShaderMaterial({
201
- uniforms: {
202
- map: { value: null }, // 纹理
203
- opacity: { value: 1.0 }, // 透明度
204
- radius: { value: 3.0 }, // 模糊半径
205
- resolution: { value: new Vector2(512, 512) }, // 渲染器的分辨率
206
- },
207
- vertexShader: `
208
- varying vec2 vUv;
209
- void main() {
210
- vUv = uv;
211
- gl_Position = vec4(position, 1.0);
212
- }
213
- `,
214
- fragmentShader: `
215
- uniform sampler2D map;
216
- uniform float opacity;
217
- uniform vec2 resolution;
218
- uniform float radius;
219
- varying vec2 vUv;
220
-
221
- vec4 offsetColor( vec2 uv){
222
- return texture2D(map, vUv + (uv / resolution * radius) );
223
- }
224
-
225
- vec4 blurColor(){
226
-
227
- vec4 leftColor = offsetColor( vec2(-1.0, 0.0) );
228
-
229
- vec4 rightColor = offsetColor( vec2(1.0, 0.0) );
230
-
231
- // 左右颜色混合
232
- vec4 leftRightColor = vec4(
233
- mix( leftColor.rgb ,rightColor.rgb, rightColor.a / (leftColor.a + rightColor.a)),
234
- (leftColor.a + rightColor.a) / 2.0
235
- );
236
-
237
- vec4 downColor = offsetColor( vec2(0.0, -1.0));
238
-
239
- vec4 upColor = offsetColor( vec2(0.0, 1.0));
240
-
241
- // 上下颜色混合
242
- vec4 upDownColor = vec4(
243
- mix( downColor.rgb, upColor.rgb, upColor.a / (downColor.a + upColor.a) ),
244
- (downColor.a + upColor.a) / 2.0
245
- );
246
-
247
- vec4 color = vec4(
248
- mix( leftRightColor.rgb, upDownColor.rgb, upDownColor.a / (leftRightColor.a + upDownColor.a) ),
249
- (leftRightColor.a + upDownColor.a) / 2.0
250
- );
251
-
252
- return color;
253
- }
254
-
255
- void main() {
256
- gl_FragColor = blurColor();
257
- gl_FragColor.a *= opacity;
258
- }
259
- `,
260
- blending: NoBlending, // 渲染时不与背景融合计算
261
- depthTest: false,
262
- depthWrite: false,
263
- transparent: true
264
- });
@@ -1,30 +0,0 @@
1
- import { Sprite, CanvasTexture, Raycaster, Intersection } from "three";
2
- export type SpritModal1Config = {
3
- size?: number;
4
- title?: string;
5
- titleColor?: string;
6
- texts?: Array<{
7
- text?: string;
8
- color?: string;
9
- size?: number;
10
- }>;
11
- };
12
- export default class SpritModal1 extends Sprite {
13
- constructor(config?: SpritModal1Config);
14
- static img: HTMLImageElement;
15
- canvas: HTMLCanvasElement;
16
- context: CanvasRenderingContext2D;
17
- texture: CanvasTexture;
18
- _config: {
19
- size: number;
20
- title: string;
21
- titleColor: string;
22
- texts: Array<{
23
- text: string;
24
- color: string;
25
- size: number;
26
- }>;
27
- };
28
- updata(config: SpritModal1Config): Promise<void>;
29
- raycast(raycaster: Raycaster, intersects: Intersection[]): void;
30
- }