three-base 2.0.67 → 2.0.69

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 (83) 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/EventMesh.d.ts +18 -18
  6. package/EventMesh.js +59 -59
  7. package/ExtrudeMesh.d.ts +111 -111
  8. package/ExtrudeMesh.js +363 -363
  9. package/FPScontrol.d.ts +45 -45
  10. package/FPScontrol.js +171 -171
  11. package/Fire/Fire.d.ts +28 -28
  12. package/Fire/Fire.js +79 -79
  13. package/Fire/FireGromtry.d.ts +9 -9
  14. package/Fire/FireGromtry.js +40 -40
  15. package/Fire/FireMaterial.d.ts +28 -28
  16. package/Fire/FireMaterial.js +32 -32
  17. package/InstancedMeshBase.d.ts +33 -24
  18. package/InstancedMeshBase.js +217 -190
  19. package/InstancedMeshBase.ts +57 -2
  20. package/KeyFrameAnimation.d.ts +25 -25
  21. package/KeyFrameAnimation.js +78 -78
  22. package/MeshBase.d.ts +32 -32
  23. package/MeshBase.js +172 -172
  24. package/Mirror.d.ts +25 -25
  25. package/Mirror.js +139 -139
  26. package/PlaneModal1/PlaneModal1.d.ts +31 -31
  27. package/PlaneModal1/PlaneModal1.js +105 -105
  28. package/PlaneModal1/index.d.ts +1 -1
  29. package/PlaneModal1/index.js +1 -1
  30. package/PlaneText.d.ts +44 -44
  31. package/PlaneText.js +30 -30
  32. package/PlaneWithHtml.d.ts +11 -11
  33. package/PlaneWithHtml.js +68 -68
  34. package/PointLight/PointLight.d.ts +13 -13
  35. package/PointLight/PointLight.js +64 -64
  36. package/PointLight/index.d.ts +1 -1
  37. package/PointLight/index.js +1 -1
  38. package/Sky/Sky.d.ts +13 -13
  39. package/Sky/Sky.js +28 -28
  40. package/Sky/index.d.ts +1 -1
  41. package/Sky/index.js +1 -1
  42. package/SpriteModal1/SpriteModal1.d.ts +30 -30
  43. package/SpriteModal1/SpriteModal1.js +110 -110
  44. package/SpriteModal1/index.d.ts +1 -1
  45. package/SpriteModal1/index.js +1 -1
  46. package/SpriteText.d.ts +45 -45
  47. package/SpriteText.js +163 -163
  48. package/SpriteText2.d.ts +47 -47
  49. package/SpriteText2.js +198 -198
  50. package/SpriteWithHtml.d.ts +7 -7
  51. package/SpriteWithHtml.js +49 -49
  52. package/Text3D/Text3D.d.ts +20 -20
  53. package/Text3D/Text3D.js +62 -62
  54. package/Text3D/fontController.d.ts +59 -59
  55. package/Text3D/fontController.js +200 -200
  56. package/Text3D/index.d.ts +1 -1
  57. package/Text3D/index.js +1 -1
  58. package/ThreeBase.d.ts +91 -91
  59. package/ThreeBase.js +611 -611
  60. package/ThreeMouse.d.ts +39 -39
  61. package/ThreeMouse.js +359 -359
  62. package/Transition.d.ts +40 -40
  63. package/Transition.js +207 -207
  64. package/index.d.ts +1 -1
  65. package/index.js +2 -2
  66. package/keyContorls.d.ts +25 -25
  67. package/keyContorls.js +98 -98
  68. package/package.json +1 -1
  69. package/pass/FullScreenQuad.d.ts +7 -7
  70. package/pass/FullScreenQuad.js +25 -25
  71. package/pass/glow_pass.d.ts +2 -2
  72. package/pass/glow_pass.js +236 -236
  73. package/pass/stroke_pass.d.ts +2 -2
  74. package/pass/stroke_pass.js +202 -202
  75. package/shaders/FXAAShaderMaterial.d.ts +3 -3
  76. package/shaders/FXAAShaderMaterial.js +21 -21
  77. package/shaders.d.ts +17 -17
  78. package/shaders.js +99 -99
  79. package/threeLoader.d.ts +26 -26
  80. package/threeLoader.js +189 -189
  81. package/threeLoader.ts +2 -2
  82. package/threeUtils.d.ts +47 -47
  83. package/threeUtils.js +266 -266
package/Mirror.js CHANGED
@@ -1,51 +1,51 @@
1
- /*
2
- * @Author: xiaosihan
3
- * @Date: 2023-08-04 17:17:15
4
- * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2024-01-20 05:33:51
6
- */
7
- import { Color, DoubleSide, HalfFloatType, Matrix4, Mesh, PerspectiveCamera, Plane, PlaneGeometry, ShaderMaterial, Vector3, Vector4, WebGLRenderTarget } from "three";
8
- // 镜子模型
9
- export default class Mirror extends Mesh {
10
- constructor(geometry = Mirror.geometry) {
11
- super(geometry);
12
- }
13
- // 正方形网格
14
- static geometry = (() => {
15
- const geometry = new PlaneGeometry(10, 10, 1, 1);
16
- return geometry;
17
- })();
18
- isReflector = true;
19
- type = 'Reflector';
20
- camera = new PerspectiveCamera();
21
- reflectorPlane = new Plane();
22
- normal = new Vector3();
23
- reflectorWorldPosition = new Vector3();
24
- cameraWorldPosition = new Vector3();
25
- rotationMatrix = new Matrix4();
26
- lookAtPosition = new Vector3(0, 0, -1);
27
- clipPlane = new Vector4();
28
- view = new Vector3();
29
- target = new Vector3();
30
- q = new Vector4();
31
- textureMatrix = new Matrix4();
32
- virtualCamera = this.camera;
33
- renderTarget = new WebGLRenderTarget(2048, 2048, { samples: 0, type: HalfFloatType });
34
- material = new ShaderMaterial({
35
- uniforms: {
36
- 'color': {
37
- value: new Color("#b6b6b6")
38
- },
39
- 'tDiffuse': {
40
- value: this.renderTarget.texture
41
- },
42
- 'textureMatrix': {
43
- value: this.textureMatrix
44
- },
45
- blurAmount: {
46
- value: 0.5
47
- } // 模糊程度,可以根据需求调整
48
- },
1
+ /*
2
+ * @Author: xiaosihan
3
+ * @Date: 2023-08-04 17:17:15
4
+ * @Last Modified by: xiaosihan
5
+ * @Last Modified time: 2024-01-20 05:33:51
6
+ */
7
+ import { Color, DoubleSide, HalfFloatType, Matrix4, Mesh, PerspectiveCamera, Plane, PlaneGeometry, ShaderMaterial, Vector3, Vector4, WebGLRenderTarget } from "three";
8
+ // 镜子模型
9
+ export default class Mirror extends Mesh {
10
+ constructor(geometry = Mirror.geometry) {
11
+ super(geometry);
12
+ }
13
+ // 正方形网格
14
+ static geometry = (() => {
15
+ const geometry = new PlaneGeometry(10, 10, 1, 1);
16
+ return geometry;
17
+ })();
18
+ isReflector = true;
19
+ type = 'Reflector';
20
+ camera = new PerspectiveCamera();
21
+ reflectorPlane = new Plane();
22
+ normal = new Vector3();
23
+ reflectorWorldPosition = new Vector3();
24
+ cameraWorldPosition = new Vector3();
25
+ rotationMatrix = new Matrix4();
26
+ lookAtPosition = new Vector3(0, 0, -1);
27
+ clipPlane = new Vector4();
28
+ view = new Vector3();
29
+ target = new Vector3();
30
+ q = new Vector4();
31
+ textureMatrix = new Matrix4();
32
+ virtualCamera = this.camera;
33
+ renderTarget = new WebGLRenderTarget(2048, 2048, { samples: 0, type: HalfFloatType });
34
+ material = new ShaderMaterial({
35
+ uniforms: {
36
+ 'color': {
37
+ value: new Color("#b6b6b6")
38
+ },
39
+ 'tDiffuse': {
40
+ value: this.renderTarget.texture
41
+ },
42
+ 'textureMatrix': {
43
+ value: this.textureMatrix
44
+ },
45
+ blurAmount: {
46
+ value: 0.5
47
+ } // 模糊程度,可以根据需求调整
48
+ },
49
49
  vertexShader: /* glsl */ `
50
50
  uniform mat4 textureMatrix;
51
51
  varying vec4 vUv;
@@ -61,7 +61,7 @@ export default class Mirror extends Mesh {
61
61
 
62
62
  #include <logdepthbuf_vertex>
63
63
 
64
- }`,
64
+ }`,
65
65
  fragmentShader: /* glsl */ `
66
66
  uniform vec3 color;
67
67
  uniform sampler2D tDiffuse;
@@ -104,93 +104,93 @@ export default class Mirror extends Mesh {
104
104
 
105
105
  #include <tonemapping_fragment>
106
106
  #include <colorspace_fragment>
107
- }`,
108
- depthTest: true,
109
- depthWrite: true,
110
- transparent: true,
111
- side: DoubleSide
112
- });
113
- onBeforeRender = (renderer, scene, camera, geometry, material, group) => {
114
- this.reflectorWorldPosition.setFromMatrixPosition(this.matrixWorld);
115
- this.cameraWorldPosition.setFromMatrixPosition(camera.matrixWorld);
116
- this.rotationMatrix.extractRotation(this.matrixWorld);
117
- this.normal.set(0, 0, 1);
118
- this.normal.applyMatrix4(this.rotationMatrix);
119
- this.view.subVectors(this.reflectorWorldPosition, this.cameraWorldPosition);
120
- // Avoid rendering when reflector is facing away
121
- if (this.view.dot(this.normal) > 0) {
122
- this.normal.set(0, 0, -1);
123
- }
124
- ;
125
- this.view.reflect(this.normal).negate();
126
- this.view.add(this.reflectorWorldPosition);
127
- this.rotationMatrix.extractRotation(camera.matrixWorld);
128
- this.lookAtPosition.set(0, 0, -1);
129
- this.lookAtPosition.applyMatrix4(this.rotationMatrix);
130
- this.lookAtPosition.add(this.cameraWorldPosition);
131
- this.target.subVectors(this.reflectorWorldPosition, this.lookAtPosition);
132
- this.target.reflect(this.normal).negate();
133
- this.target.add(this.reflectorWorldPosition);
134
- this.virtualCamera.position.copy(this.view);
135
- this.virtualCamera.up.set(0, 1, 0);
136
- this.virtualCamera.up.applyMatrix4(this.rotationMatrix);
137
- this.virtualCamera.up.reflect(this.normal);
138
- this.virtualCamera.lookAt(this.target);
139
- this.virtualCamera.far = this.camera.far; // Used in WebGLBackground
140
- this.virtualCamera.updateMatrixWorld();
141
- this.virtualCamera.projectionMatrix.copy(camera.projectionMatrix);
142
- // Update the texture matrix
143
- this.textureMatrix.set(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
144
- this.textureMatrix.multiply(this.virtualCamera.projectionMatrix);
145
- this.textureMatrix.multiply(this.virtualCamera.matrixWorldInverse);
146
- this.textureMatrix.multiply(this.matrixWorld);
147
- // Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
148
- // Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
149
- this.reflectorPlane.setFromNormalAndCoplanarPoint(this.normal, this.reflectorWorldPosition);
150
- this.reflectorPlane.applyMatrix4(this.virtualCamera.matrixWorldInverse);
151
- this.clipPlane.set(this.reflectorPlane.normal.x, this.reflectorPlane.normal.y, this.reflectorPlane.normal.z, this.reflectorPlane.constant);
152
- const projectionMatrix = this.virtualCamera.projectionMatrix;
153
- this.q.x = (Math.sign(this.clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
154
- this.q.y = (Math.sign(this.clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
155
- this.q.z = -1.0;
156
- this.q.w = (1.0 + projectionMatrix.elements[10]) / projectionMatrix.elements[14];
157
- // Calculate the scaled plane vector
158
- this.clipPlane.multiplyScalar(2.0 / this.clipPlane.dot(this.q));
159
- // Replacing the third row of the projection matrix
160
- projectionMatrix.elements[2] = this.clipPlane.x;
161
- projectionMatrix.elements[6] = this.clipPlane.y;
162
- projectionMatrix.elements[10] = this.clipPlane.z + 1.0 - 0.003;
163
- projectionMatrix.elements[14] = this.clipPlane.w;
164
- // Render
165
- this.visible = false;
166
- const currentRenderTarget = renderer.getRenderTarget();
167
- const currentXrEnabled = renderer.xr.enabled;
168
- const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
169
- renderer.xr.enabled = false; // Avoid camera modification
170
- renderer.shadowMap.autoUpdate = false; // Avoid re-computing shadows
171
- renderer.setRenderTarget(this.renderTarget);
172
- renderer.state.buffers.depth.setMask(true); // make sure the depth buffer is writable so it can be properly cleared, see #18897
173
- if (renderer.autoClear === false)
174
- renderer.clear();
175
- renderer.render(scene, this.virtualCamera);
176
- renderer.xr.enabled = currentXrEnabled;
177
- renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
178
- renderer.setRenderTarget(currentRenderTarget);
179
- // Restore viewport
180
- //@ts-ignore
181
- const viewport = this.camera.viewport;
182
- if (viewport !== undefined) {
183
- renderer.state.viewport(viewport);
184
- }
185
- this.visible = true;
186
- };
187
- getRenderTarget() {
188
- return this.renderTarget;
189
- }
190
- ;
191
- dispose() {
192
- this.renderTarget.dispose();
193
- // this.material.dispose();
194
- }
195
- ;
196
- }
107
+ }`,
108
+ depthTest: true,
109
+ depthWrite: true,
110
+ transparent: true,
111
+ side: DoubleSide
112
+ });
113
+ onBeforeRender = (renderer, scene, camera, geometry, material, group) => {
114
+ this.reflectorWorldPosition.setFromMatrixPosition(this.matrixWorld);
115
+ this.cameraWorldPosition.setFromMatrixPosition(camera.matrixWorld);
116
+ this.rotationMatrix.extractRotation(this.matrixWorld);
117
+ this.normal.set(0, 0, 1);
118
+ this.normal.applyMatrix4(this.rotationMatrix);
119
+ this.view.subVectors(this.reflectorWorldPosition, this.cameraWorldPosition);
120
+ // Avoid rendering when reflector is facing away
121
+ if (this.view.dot(this.normal) > 0) {
122
+ this.normal.set(0, 0, -1);
123
+ }
124
+ ;
125
+ this.view.reflect(this.normal).negate();
126
+ this.view.add(this.reflectorWorldPosition);
127
+ this.rotationMatrix.extractRotation(camera.matrixWorld);
128
+ this.lookAtPosition.set(0, 0, -1);
129
+ this.lookAtPosition.applyMatrix4(this.rotationMatrix);
130
+ this.lookAtPosition.add(this.cameraWorldPosition);
131
+ this.target.subVectors(this.reflectorWorldPosition, this.lookAtPosition);
132
+ this.target.reflect(this.normal).negate();
133
+ this.target.add(this.reflectorWorldPosition);
134
+ this.virtualCamera.position.copy(this.view);
135
+ this.virtualCamera.up.set(0, 1, 0);
136
+ this.virtualCamera.up.applyMatrix4(this.rotationMatrix);
137
+ this.virtualCamera.up.reflect(this.normal);
138
+ this.virtualCamera.lookAt(this.target);
139
+ this.virtualCamera.far = this.camera.far; // Used in WebGLBackground
140
+ this.virtualCamera.updateMatrixWorld();
141
+ this.virtualCamera.projectionMatrix.copy(camera.projectionMatrix);
142
+ // Update the texture matrix
143
+ this.textureMatrix.set(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
144
+ this.textureMatrix.multiply(this.virtualCamera.projectionMatrix);
145
+ this.textureMatrix.multiply(this.virtualCamera.matrixWorldInverse);
146
+ this.textureMatrix.multiply(this.matrixWorld);
147
+ // Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
148
+ // Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
149
+ this.reflectorPlane.setFromNormalAndCoplanarPoint(this.normal, this.reflectorWorldPosition);
150
+ this.reflectorPlane.applyMatrix4(this.virtualCamera.matrixWorldInverse);
151
+ this.clipPlane.set(this.reflectorPlane.normal.x, this.reflectorPlane.normal.y, this.reflectorPlane.normal.z, this.reflectorPlane.constant);
152
+ const projectionMatrix = this.virtualCamera.projectionMatrix;
153
+ this.q.x = (Math.sign(this.clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
154
+ this.q.y = (Math.sign(this.clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
155
+ this.q.z = -1.0;
156
+ this.q.w = (1.0 + projectionMatrix.elements[10]) / projectionMatrix.elements[14];
157
+ // Calculate the scaled plane vector
158
+ this.clipPlane.multiplyScalar(2.0 / this.clipPlane.dot(this.q));
159
+ // Replacing the third row of the projection matrix
160
+ projectionMatrix.elements[2] = this.clipPlane.x;
161
+ projectionMatrix.elements[6] = this.clipPlane.y;
162
+ projectionMatrix.elements[10] = this.clipPlane.z + 1.0 - 0.003;
163
+ projectionMatrix.elements[14] = this.clipPlane.w;
164
+ // Render
165
+ this.visible = false;
166
+ const currentRenderTarget = renderer.getRenderTarget();
167
+ const currentXrEnabled = renderer.xr.enabled;
168
+ const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
169
+ renderer.xr.enabled = false; // Avoid camera modification
170
+ renderer.shadowMap.autoUpdate = false; // Avoid re-computing shadows
171
+ renderer.setRenderTarget(this.renderTarget);
172
+ renderer.state.buffers.depth.setMask(true); // make sure the depth buffer is writable so it can be properly cleared, see #18897
173
+ if (renderer.autoClear === false)
174
+ renderer.clear();
175
+ renderer.render(scene, this.virtualCamera);
176
+ renderer.xr.enabled = currentXrEnabled;
177
+ renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
178
+ renderer.setRenderTarget(currentRenderTarget);
179
+ // Restore viewport
180
+ //@ts-ignore
181
+ const viewport = this.camera.viewport;
182
+ if (viewport !== undefined) {
183
+ renderer.state.viewport(viewport);
184
+ }
185
+ this.visible = true;
186
+ };
187
+ getRenderTarget() {
188
+ return this.renderTarget;
189
+ }
190
+ ;
191
+ dispose() {
192
+ this.renderTarget.dispose();
193
+ // this.material.dispose();
194
+ }
195
+ ;
196
+ }
@@ -1,31 +1,31 @@
1
- import { Mesh, MeshBasicMaterial, PlaneGeometry } from "three";
2
- export type PlaneModal1Config = {
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 PlaneModal1 extends Mesh {
13
- constructor(config?: PlaneModal1Config);
14
- geometry: PlaneGeometry;
15
- material: MeshBasicMaterial;
16
- static img: HTMLImageElement;
17
- canvas: HTMLCanvasElement;
18
- context: CanvasRenderingContext2D;
19
- texture: import("three").Texture;
20
- _config: {
21
- size: number;
22
- title: string;
23
- titleColor: string;
24
- texts: Array<{
25
- text: string;
26
- color: string;
27
- size: number;
28
- }>;
29
- };
30
- updata(config: PlaneModal1Config): Promise<void>;
31
- }
1
+ import { Mesh, MeshBasicMaterial, PlaneGeometry } from "three";
2
+ export type PlaneModal1Config = {
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 PlaneModal1 extends Mesh {
13
+ constructor(config?: PlaneModal1Config);
14
+ geometry: PlaneGeometry;
15
+ material: MeshBasicMaterial;
16
+ static img: HTMLImageElement;
17
+ canvas: HTMLCanvasElement;
18
+ context: CanvasRenderingContext2D;
19
+ texture: import("three").Texture;
20
+ _config: {
21
+ size: number;
22
+ title: string;
23
+ titleColor: string;
24
+ texts: Array<{
25
+ text: string;
26
+ color: string;
27
+ size: number;
28
+ }>;
29
+ };
30
+ updata(config: PlaneModal1Config): Promise<void>;
31
+ }
@@ -1,105 +1,105 @@
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
- import { DoubleSide, Mesh, MeshBasicMaterial, PlaneGeometry, Vector2 } from "three";
8
- import threeLoader from "../threeLoader";
9
- import planeModalPNG from "./planeModal.png";
10
- // 平面模型弹窗
11
- export default class PlaneModal1 extends Mesh {
12
- constructor(config = {}) {
13
- super();
14
- this.updata(config);
15
- this.material.map = this.texture;
16
- this.scale.set(10, 10, 10);
17
- }
18
- geometry = new PlaneGeometry(1 * 0.65, 0.728 * 0.65, 1, 1);
19
- material = new MeshBasicMaterial({
20
- side: DoubleSide,
21
- transparent: true,
22
- alphaTest: 0.01
23
- });
24
- // 背景图
25
- static img = (() => {
26
- const img = new Image();
27
- img.src = planeModalPNG;
28
- return img;
29
- })();
30
- canvas = (() => {
31
- const canvas = document.createElement("canvas");
32
- canvas.width = 660;
33
- canvas.height = 481;
34
- return canvas;
35
- })();
36
- context = this.canvas.getContext("2d");
37
- texture = threeLoader.getTexture(this.canvas);
38
- // 配置
39
- _config = {
40
- size: 10,
41
- title: "PlaneModal1",
42
- titleColor: "#ffffff",
43
- texts: []
44
- // [
45
- // {
46
- // text: "1",
47
- // color: "#ffff00",
48
- // size: 40
49
- // },
50
- // {
51
- // text: "2",
52
- // color: "#ff00ff",
53
- // size: 40
54
- // },
55
- // ]
56
- };
57
- async updata(config) {
58
- Object.assign(this._config, config);
59
- //绘制背景
60
- this.context.clearRect(0, 0, 660, 481);
61
- while (!PlaneModal1.img.complete) {
62
- await new Promise(resolve => setTimeout(resolve, 100));
63
- }
64
- // 设置大小
65
- this.scale.set(this._config.size, this._config.size, this._config.size);
66
- // this.context.fillStyle = "#00000088";
67
- // this.context.fillRect(0, 0, 660, 481);
68
- //绘制背景
69
- this.context.drawImage(PlaneModal1.img, 0, 0);
70
- // 绘制标题
71
- this.context.fillStyle = this._config.titleColor;
72
- this.context.font = '40px serif'; // 设置字体大小
73
- this.context.textAlign = "left";
74
- this.context.textBaseline = "top";
75
- this.context.fillText(this._config.title, 60, 72);
76
- let textPos = new Vector2(60, 150);
77
- let maxWidth = 530;
78
- // 绘制内容
79
- this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
80
- this.context.fillStyle = color;
81
- this.context.font = `${size}px serif`; // 设置字体大小
82
- this.context.textAlign = "left";
83
- this.context.textBaseline = "top";
84
- // 字符分隔为数组
85
- var arrText = text.split('');
86
- var line = '';
87
- for (var n = 0; n < arrText.length; n++) {
88
- var metrics = this.context.measureText(line + arrText[n]);
89
- var testWidth = metrics.width;
90
- if ((testWidth > maxWidth && n > 0) || arrText[n] === "\n") {
91
- this.context.fillText(line, textPos.x, textPos.y);
92
- line = "";
93
- textPos.y += size;
94
- }
95
- else {
96
- line += arrText[n];
97
- }
98
- }
99
- this.context.fillText(line, textPos.x, textPos.y);
100
- textPos.y += size;
101
- });
102
- this.texture.needsUpdate = true;
103
- this.dispatchEvent({ type: "loaded" });
104
- }
105
- }
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
+ import { DoubleSide, Mesh, MeshBasicMaterial, PlaneGeometry, Vector2 } from "three";
8
+ import threeLoader from "../threeLoader";
9
+ import planeModalPNG from "./planeModal.png";
10
+ // 平面模型弹窗
11
+ export default class PlaneModal1 extends Mesh {
12
+ constructor(config = {}) {
13
+ super();
14
+ this.updata(config);
15
+ this.material.map = this.texture;
16
+ this.scale.set(10, 10, 10);
17
+ }
18
+ geometry = new PlaneGeometry(1 * 0.65, 0.728 * 0.65, 1, 1);
19
+ material = new MeshBasicMaterial({
20
+ side: DoubleSide,
21
+ transparent: true,
22
+ alphaTest: 0.01
23
+ });
24
+ // 背景图
25
+ static img = (() => {
26
+ const img = new Image();
27
+ img.src = planeModalPNG;
28
+ return img;
29
+ })();
30
+ canvas = (() => {
31
+ const canvas = document.createElement("canvas");
32
+ canvas.width = 660;
33
+ canvas.height = 481;
34
+ return canvas;
35
+ })();
36
+ context = this.canvas.getContext("2d");
37
+ texture = threeLoader.getTexture(this.canvas);
38
+ // 配置
39
+ _config = {
40
+ size: 10,
41
+ title: "PlaneModal1",
42
+ titleColor: "#ffffff",
43
+ texts: []
44
+ // [
45
+ // {
46
+ // text: "1",
47
+ // color: "#ffff00",
48
+ // size: 40
49
+ // },
50
+ // {
51
+ // text: "2",
52
+ // color: "#ff00ff",
53
+ // size: 40
54
+ // },
55
+ // ]
56
+ };
57
+ async updata(config) {
58
+ Object.assign(this._config, config);
59
+ //绘制背景
60
+ this.context.clearRect(0, 0, 660, 481);
61
+ while (!PlaneModal1.img.complete) {
62
+ await new Promise(resolve => setTimeout(resolve, 100));
63
+ }
64
+ // 设置大小
65
+ this.scale.set(this._config.size, this._config.size, this._config.size);
66
+ // this.context.fillStyle = "#00000088";
67
+ // this.context.fillRect(0, 0, 660, 481);
68
+ //绘制背景
69
+ this.context.drawImage(PlaneModal1.img, 0, 0);
70
+ // 绘制标题
71
+ this.context.fillStyle = this._config.titleColor;
72
+ this.context.font = '40px serif'; // 设置字体大小
73
+ this.context.textAlign = "left";
74
+ this.context.textBaseline = "top";
75
+ this.context.fillText(this._config.title, 60, 72);
76
+ let textPos = new Vector2(60, 150);
77
+ let maxWidth = 530;
78
+ // 绘制内容
79
+ this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
80
+ this.context.fillStyle = color;
81
+ this.context.font = `${size}px serif`; // 设置字体大小
82
+ this.context.textAlign = "left";
83
+ this.context.textBaseline = "top";
84
+ // 字符分隔为数组
85
+ var arrText = text.split('');
86
+ var line = '';
87
+ for (var n = 0; n < arrText.length; n++) {
88
+ var metrics = this.context.measureText(line + arrText[n]);
89
+ var testWidth = metrics.width;
90
+ if ((testWidth > maxWidth && n > 0) || arrText[n] === "\n") {
91
+ this.context.fillText(line, textPos.x, textPos.y);
92
+ line = "";
93
+ textPos.y += size;
94
+ }
95
+ else {
96
+ line += arrText[n];
97
+ }
98
+ }
99
+ this.context.fillText(line, textPos.x, textPos.y);
100
+ textPos.y += size;
101
+ });
102
+ this.texture.needsUpdate = true;
103
+ this.dispatchEvent({ type: "loaded" });
104
+ }
105
+ }
@@ -1 +1 @@
1
- export { default } from "./PlaneModal1";
1
+ export { default } from "./PlaneModal1";
@@ -1 +1 @@
1
- export { default } from "./PlaneModal1";
1
+ export { default } from "./PlaneModal1";