three-base 1.0.46 → 1.0.48

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/index.ts CHANGED
@@ -40,4 +40,10 @@ export { default as FPScontrol } from "./lib/FPScontrol";
40
40
  export { default as PlaneText } from "./lib/PlaneText";
41
41
 
42
42
  // 精灵文字
43
- export { default as SpriteText } from "three-spritetext";
43
+ export { default as SpriteText } from "three-spritetext";
44
+
45
+ //精灵文本框
46
+ export { default as SpriteModal1 } from "./lib/spriteModal1/SpriteModal1";
47
+
48
+ //平面文本框
49
+ export { default as PlaneModal1 } from "./lib/planeModal1/PlaneModal1";
@@ -0,0 +1,148 @@
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
+ });
39
+
40
+ // 背景图
41
+ static img = (() => {
42
+ const img = new Image();
43
+ img.src = planeModalPNG;
44
+ return img;
45
+ })();
46
+
47
+ canvas = (() => {
48
+ const canvas = document.createElement("canvas");
49
+ canvas.width = 660;
50
+ canvas.height = 481;
51
+ return canvas;
52
+ })();
53
+
54
+ context = this.canvas.getContext("2d")!;
55
+
56
+ texture = new CanvasTexture(this.canvas);
57
+
58
+ // 配置
59
+ _config: {
60
+ size: number,
61
+ title: string,
62
+ titleColor: string,
63
+ texts: Array<{
64
+ text: string,
65
+ color: string,
66
+ size: number
67
+ }>
68
+ } = {
69
+ size: 10,
70
+ title: "PlaneModal1",
71
+ titleColor: "#ffffff",
72
+ texts: []
73
+ // [
74
+ // {
75
+ // text: "1",
76
+ // color: "#ffff00",
77
+ // size: 40
78
+ // },
79
+ // {
80
+ // text: "2",
81
+ // color: "#ff00ff",
82
+ // size: 40
83
+ // },
84
+ // ]
85
+ }
86
+
87
+ async updata(config: PlaneModal1Config) {
88
+
89
+ Object.assign(this._config, config)
90
+
91
+ //绘制背景
92
+ this.context.clearRect(0, 0, 660, 481);
93
+
94
+ while (!PlaneModal1.img.complete) {
95
+ await new Promise(resolve => setTimeout(resolve, 100));
96
+ }
97
+
98
+ // 设置大小
99
+ this.scale.set(this._config.size, this._config.size, this._config.size);
100
+
101
+ // this.context.fillStyle = "#00000088";
102
+ // this.context.fillRect(0, 0, 660, 481);
103
+
104
+ //绘制背景
105
+ this.context.drawImage(PlaneModal1.img, 0, 0);
106
+
107
+ // 绘制标题
108
+ this.context.fillStyle = this._config.titleColor;
109
+ this.context.font = '40px serif';// 设置字体大小
110
+ this.context.textAlign = "left";
111
+ this.context.textBaseline = "top";
112
+ this.context.fillText(this._config.title, 60, 72);
113
+
114
+ let textPos = new Vector2(60, 150);
115
+ let maxWidth = 530;
116
+ // 绘制内容
117
+ this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
118
+ this.context.fillStyle = color;
119
+ this.context.font = `${size}px serif`;// 设置字体大小
120
+ this.context.textAlign = "left";
121
+ this.context.textBaseline = "top";
122
+
123
+ // 字符分隔为数组
124
+ var arrText = text.split('');
125
+ var line = '';
126
+
127
+ for (var n = 0; n < arrText.length; n++) {
128
+ var metrics = this.context.measureText(line + arrText[n]);
129
+ var testWidth = metrics.width;
130
+ if ((testWidth > maxWidth && n > 0) || arrText[n] === "\n") {
131
+ this.context.fillText(line, textPos.x, textPos.y);
132
+ line = "";
133
+ textPos.y += size;
134
+ } else {
135
+ line += arrText[n];
136
+ }
137
+ }
138
+
139
+ this.context.fillText(line, textPos.x, textPos.y);
140
+ textPos.y += size;
141
+ });
142
+
143
+ this.texture.needsUpdate = true;
144
+
145
+ }
146
+
147
+
148
+ }
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-base",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "three 3d three-base",
5
5
  "repository": {
6
6
  "type": "git",