three-base 1.129.14 → 1.129.17
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.js +6 -2
- package/index.ts +9 -3
- package/lib/ExtrudeMesh.js +1 -0
- package/lib/ExtrudeMesh.ts +2 -0
- package/lib/PlaneText.d.ts +7 -7
- package/lib/PlaneText.js +2 -2
- package/lib/PlaneText.ts +2 -3
- package/lib/PlaneWithHtml.d.ts +11 -0
- package/lib/PlaneWithHtml.js +67 -0
- package/lib/PlaneWithHtml.ts +84 -0
- package/lib/{PointLight.d.ts → PointLight/PointLight.d.ts} +4 -4
- package/lib/PointLight/PointLight.js +63 -0
- package/lib/PointLight/PointLight.ts +74 -0
- package/lib/PointLight/pointLight_map.png +0 -0
- package/lib/SpriteText.d.ts +45 -0
- package/lib/SpriteText.js +162 -0
- package/lib/SpriteText.ts +189 -0
- package/lib/SpriteText2.d.ts +47 -0
- package/lib/SpriteText2.js +197 -0
- package/lib/SpriteText2.ts +236 -0
- package/lib/Text3D/Text3D.js +2 -1
- package/lib/Text3D/Text3D.ts +2 -1
- package/lib/Text3D/fontController.ts +1 -1
- package/lib/ThreeBase.d.ts +3 -3
- package/lib/ThreeBase.js +14 -7
- package/lib/ThreeBase.ts +20 -9
- package/lib/Transition.d.ts +1 -3
- package/lib/Transition.js +8 -5
- package/lib/Transition.ts +10 -6
- package/lib/planeModal1/PlaneModal1.d.ts +0 -1
- package/lib/planeModal1/PlaneModal1.js +1 -1
- package/lib/planeModal1/PlaneModal1.ts +1 -2
- package/lib/spriteModal1/SpriteModal1.d.ts +0 -1
- package/lib/spriteModal1/SpriteModal1.js +1 -1
- package/lib/spriteModal1/SpriteModal1.ts +1 -2
- package/lib/stroke_pass/FullScreenQuad.d.ts +7 -0
- package/lib/stroke_pass/FullScreenQuad.js +25 -0
- package/lib/stroke_pass/FullScreenQuad.ts +33 -0
- package/lib/stroke_pass/stroke_pass.d.ts +2 -0
- package/lib/stroke_pass/stroke_pass.js +190 -0
- package/lib/stroke_pass/stroke_pass.ts +211 -0
- package/lib/threeUtils.js +5 -5
- package/lib/threeUtils.ts +6 -5
- package/package.json +5 -8
- package/lib/PointLight.js +0 -64
- package/lib/PointLight.ts +0 -78
|
@@ -0,0 +1,236 @@
|
|
|
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
|
+
|
|
8
|
+
|
|
9
|
+
import { Intersection, LinearFilter, Raycaster, Sprite, SpriteMaterial, Texture } from 'three';
|
|
10
|
+
|
|
11
|
+
// 带箭头的精灵文字
|
|
12
|
+
export default class SpriteText2 extends Sprite {
|
|
13
|
+
constructor(text = '', textHeight = 10, color: `rgb(${string})` | `rgba(${string})` | `#${string}` = 'rgba(255, 255, 255, 1)') {
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
this._text = `${text}`;
|
|
17
|
+
this._textHeight = textHeight;
|
|
18
|
+
this._color = color;
|
|
19
|
+
this._backgroundColor = false; // no background color
|
|
20
|
+
|
|
21
|
+
this._padding = 0;
|
|
22
|
+
this._borderWidth = 0;
|
|
23
|
+
this._borderRadius = 0;
|
|
24
|
+
this._borderColor = 'white';
|
|
25
|
+
|
|
26
|
+
this._strokeWidth = 0;
|
|
27
|
+
this._strokeColor = 'white';
|
|
28
|
+
|
|
29
|
+
this._fontFace = 'Arial';
|
|
30
|
+
this._fontSize = 90; // defines text resolution
|
|
31
|
+
this._fontWeight = 'normal';
|
|
32
|
+
|
|
33
|
+
this._genCanvas();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
_text = "";
|
|
37
|
+
_textHeight = 0;
|
|
38
|
+
_color: `rgb(${string})` | `rgba(${string})` | `#${string}` = "#ffffff";
|
|
39
|
+
_backgroundColor: `rgb(${string})` | `rgba(${string})` | `#${string}` | false = false; // no background color
|
|
40
|
+
|
|
41
|
+
_padding = 0;
|
|
42
|
+
_borderWidth = 0;
|
|
43
|
+
_borderRadius = 0;
|
|
44
|
+
_borderColor = 'white';
|
|
45
|
+
|
|
46
|
+
_strokeWidth = 0;
|
|
47
|
+
_strokeColor = 'white';
|
|
48
|
+
|
|
49
|
+
_fontFace = 'Arial';
|
|
50
|
+
_fontSize = 90; // defines text resolution
|
|
51
|
+
_fontWeight = 'normal';
|
|
52
|
+
_canvas = document.createElement('canvas');
|
|
53
|
+
|
|
54
|
+
get text() { return this._text; }
|
|
55
|
+
set text(text) { this._text = text; this._genCanvas(); }
|
|
56
|
+
get textHeight() { return this._textHeight; }
|
|
57
|
+
set textHeight(textHeight) { this._textHeight = textHeight; this._genCanvas(); }
|
|
58
|
+
get color() { return this._color; }
|
|
59
|
+
set color(color) { this._color = color; this._genCanvas(); }
|
|
60
|
+
get backgroundColor() { return this._backgroundColor; }
|
|
61
|
+
set backgroundColor(color) { this._backgroundColor = color; this._genCanvas(); }
|
|
62
|
+
get padding() { return this._padding; }
|
|
63
|
+
set padding(padding) { this._padding = padding; this._genCanvas(); }
|
|
64
|
+
get borderWidth() { return this._borderWidth; }
|
|
65
|
+
set borderWidth(borderWidth) { this._borderWidth = borderWidth; this._genCanvas(); }
|
|
66
|
+
get borderRadius() { return this._borderRadius; }
|
|
67
|
+
set borderRadius(borderRadius) { this._borderRadius = borderRadius; this._genCanvas(); }
|
|
68
|
+
get borderColor() { return this._borderColor; }
|
|
69
|
+
set borderColor(borderColor) { this._borderColor = borderColor; this._genCanvas(); }
|
|
70
|
+
get fontFace() { return this._fontFace; }
|
|
71
|
+
set fontFace(fontFace) { this._fontFace = fontFace; this._genCanvas(); }
|
|
72
|
+
get fontSize() { return this._fontSize; }
|
|
73
|
+
set fontSize(fontSize) { this._fontSize = fontSize; this._genCanvas(); }
|
|
74
|
+
get fontWeight() { return this._fontWeight; }
|
|
75
|
+
set fontWeight(fontWeight) { this._fontWeight = fontWeight; this._genCanvas(); }
|
|
76
|
+
get strokeWidth() { return this._strokeWidth; }
|
|
77
|
+
set strokeWidth(strokeWidth) { this._strokeWidth = strokeWidth; this._genCanvas(); }
|
|
78
|
+
get strokeColor() { return this._strokeColor; }
|
|
79
|
+
set strokeColor(strokeColor) { this._strokeColor = strokeColor; this._genCanvas(); }
|
|
80
|
+
|
|
81
|
+
_genCanvas() {
|
|
82
|
+
const canvas = this._canvas;
|
|
83
|
+
const ctx = canvas.getContext('2d')!;
|
|
84
|
+
|
|
85
|
+
const border = Array.isArray(this.borderWidth) ? this.borderWidth : [this.borderWidth, this.borderWidth]; // x,y border
|
|
86
|
+
const relBorder: number[] = border.map(b => b * this.fontSize * 0.1); // border in canvas units
|
|
87
|
+
|
|
88
|
+
const borderRadius = Array.isArray(this.borderRadius) ? this.borderRadius : [this.borderRadius, this.borderRadius, this.borderRadius, this.borderRadius]; // tl tr br bl corners
|
|
89
|
+
const relBorderRadius = borderRadius.map(b => b * this.fontSize * 0.1); // border radius in canvas units
|
|
90
|
+
|
|
91
|
+
const padding = Array.isArray(this.padding) ? this.padding : [this.padding, this.padding]; // x,y padding
|
|
92
|
+
const relPadding = padding.map(p => p * this.fontSize * 0.1); // padding in canvas units
|
|
93
|
+
|
|
94
|
+
const lines = this.text.split('\n');
|
|
95
|
+
const font = `${this.fontWeight} ${this.fontSize}px ${this.fontFace}`;
|
|
96
|
+
|
|
97
|
+
ctx.font = font; // measure canvas with appropriate font
|
|
98
|
+
const innerWidth = Math.max(...lines.map(line => ctx.measureText(line).width));
|
|
99
|
+
const innerHeight = this.fontSize * lines.length;
|
|
100
|
+
canvas.width = innerWidth + relBorder[0] * 2 + relPadding[0] * 2;
|
|
101
|
+
canvas.height = (innerHeight + relBorder[1] * 2 + relPadding[1] * 2) * 2 + 40;
|
|
102
|
+
|
|
103
|
+
// paint border
|
|
104
|
+
if (this.borderWidth) {
|
|
105
|
+
ctx.strokeStyle = this.borderColor;
|
|
106
|
+
|
|
107
|
+
if (relBorder[0]) { // left + right borders
|
|
108
|
+
const hb = relBorder[0] / 2;
|
|
109
|
+
ctx.lineWidth = relBorder[0];
|
|
110
|
+
ctx.beginPath();
|
|
111
|
+
ctx.moveTo(hb, relBorderRadius[0]);
|
|
112
|
+
ctx.lineTo(hb, ((canvas.height - 40) / 2) - relBorderRadius[3]);
|
|
113
|
+
ctx.moveTo(canvas.width - hb, relBorderRadius[1]);
|
|
114
|
+
ctx.lineTo(canvas.width - hb, ((canvas.height - 40) / 2) - relBorderRadius[2]);
|
|
115
|
+
ctx.stroke();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (relBorder[1]) { // top + bottom borders
|
|
119
|
+
const hb = relBorder[1] / 2;
|
|
120
|
+
ctx.lineWidth = relBorder[1];
|
|
121
|
+
ctx.beginPath();
|
|
122
|
+
ctx.moveTo(Math.max(relBorder[0], relBorderRadius[0]), hb);
|
|
123
|
+
ctx.lineTo(canvas.width - Math.max(relBorder[0], relBorderRadius[1]), hb);
|
|
124
|
+
ctx.moveTo(Math.max(relBorder[0], relBorderRadius[3]), ((canvas.height - 40) / 2) - hb);
|
|
125
|
+
|
|
126
|
+
ctx.lineTo((canvas.width / 2 - 20), ((canvas.height - 40) / 2) - hb);
|
|
127
|
+
ctx.lineTo((canvas.width / 2), ((canvas.height - 40) / 2) + 20 - hb);
|
|
128
|
+
ctx.lineTo((canvas.width / 2 + 20), ((canvas.height - 40) / 2) - hb);
|
|
129
|
+
|
|
130
|
+
ctx.lineTo(canvas.width - Math.max(relBorder[0], relBorderRadius[2]), ((canvas.height - 40) / 2) - hb);
|
|
131
|
+
ctx.stroke();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (this.borderRadius) { // strike rounded corners
|
|
135
|
+
const cornerWidth = Math.max(...relBorder);
|
|
136
|
+
const hb = cornerWidth / 2;
|
|
137
|
+
ctx.lineWidth = cornerWidth;
|
|
138
|
+
ctx.beginPath();
|
|
139
|
+
([
|
|
140
|
+
!!relBorderRadius[0] && [relBorderRadius[0], hb, hb, relBorderRadius[0]],
|
|
141
|
+
!!relBorderRadius[1] && [canvas.width - relBorderRadius[1], canvas.width - hb, hb, relBorderRadius[1]],
|
|
142
|
+
!!relBorderRadius[2] && [canvas.width - relBorderRadius[2], canvas.width - hb, ((canvas.height - 40) / 2) - hb, ((canvas.height - 40) / 2) - relBorderRadius[2]],
|
|
143
|
+
!!relBorderRadius[3] && [relBorderRadius[3], hb, ((canvas.height - 40) / 2) - hb, ((canvas.height - 40) / 2) - relBorderRadius[3]]
|
|
144
|
+
].filter(d => d) as [number, number, number, number][]).forEach(([x0, x1, y0, y1]) => {
|
|
145
|
+
ctx.moveTo(x0, y0);
|
|
146
|
+
ctx.quadraticCurveTo(x1, y0, x1, y1);
|
|
147
|
+
});
|
|
148
|
+
ctx.stroke();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// paint background
|
|
153
|
+
if (this.backgroundColor) {
|
|
154
|
+
ctx.fillStyle = this.backgroundColor;
|
|
155
|
+
if (!this.borderRadius) {
|
|
156
|
+
ctx.fillRect(relBorder[0], relBorder[1], canvas.width - relBorder[0] * 2, ((canvas.height - 40) / 2) - relBorder[1] * 2);
|
|
157
|
+
} else { // fill with rounded corners
|
|
158
|
+
ctx.beginPath();
|
|
159
|
+
ctx.moveTo(relBorder[0], relBorderRadius[0]);
|
|
160
|
+
|
|
161
|
+
ctx.quadraticCurveTo(relBorder[0], relBorder[1], relBorderRadius[0], relBorder[1]);
|
|
162
|
+
ctx.lineTo(canvas.width - relBorderRadius[1], relBorder[1]);
|
|
163
|
+
ctx.quadraticCurveTo(canvas.width - relBorder[0], relBorder[1], canvas.width - relBorder[0], relBorderRadius[1]);
|
|
164
|
+
ctx.lineTo(canvas.width - relBorder[0], ((canvas.height - 40) / 2) - relBorderRadius[2]);
|
|
165
|
+
ctx.quadraticCurveTo(canvas.width - relBorder[0], ((canvas.height - 40) / 2) - relBorder[1], canvas.width - relBorderRadius[2], ((canvas.height - 40) / 2) - relBorder[1]);
|
|
166
|
+
|
|
167
|
+
ctx.lineTo((canvas.width / 2 + 20), ((canvas.height - 40) / 2) - relBorder[1]);
|
|
168
|
+
ctx.lineTo((canvas.width / 2), ((canvas.height - 40) / 2) + 20 - relBorder[1]);
|
|
169
|
+
ctx.lineTo((canvas.width / 2 - 20), ((canvas.height - 40) / 2) - relBorder[1]);
|
|
170
|
+
|
|
171
|
+
ctx.lineTo(relBorderRadius[3], ((canvas.height - 40) / 2) - relBorder[1]);
|
|
172
|
+
ctx.quadraticCurveTo(relBorder[0], ((canvas.height - 40) / 2) - relBorder[1], relBorder[0], ((canvas.height - 40) / 2) - relBorderRadius[3]);
|
|
173
|
+
|
|
174
|
+
ctx.closePath();
|
|
175
|
+
ctx.fill();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
ctx.translate(relBorder[0], relBorder[1]);
|
|
180
|
+
ctx.translate(relPadding[0], relPadding[0]);
|
|
181
|
+
|
|
182
|
+
// paint text
|
|
183
|
+
ctx.font = font; // Set font again after canvas is resized, as context properties are reset
|
|
184
|
+
ctx.fillStyle = this.color;
|
|
185
|
+
ctx.textBaseline = 'bottom';
|
|
186
|
+
|
|
187
|
+
const drawTextStroke = this.strokeWidth > 0;
|
|
188
|
+
if (drawTextStroke) {
|
|
189
|
+
ctx.lineWidth = this.strokeWidth * this.fontSize / 10;
|
|
190
|
+
ctx.strokeStyle = this.strokeColor;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
lines.forEach((line, index) => {
|
|
194
|
+
const lineX = (innerWidth - ctx.measureText(line).width) / 2;
|
|
195
|
+
const lineY = (index + 1) * this.fontSize;
|
|
196
|
+
|
|
197
|
+
drawTextStroke && ctx.strokeText(line, lineX, lineY);
|
|
198
|
+
ctx.fillText(line, lineX, lineY);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Inject canvas into sprite
|
|
202
|
+
if (this.material.map) this.material.map.dispose(); // gc previous texture
|
|
203
|
+
const texture = this.material.map = new Texture(canvas);
|
|
204
|
+
texture.minFilter = LinearFilter;
|
|
205
|
+
texture.needsUpdate = true;
|
|
206
|
+
|
|
207
|
+
const yScale = this.textHeight * lines.length + border[1] * 2 + padding[1] * 2;
|
|
208
|
+
this.scale.set(yScale * canvas.width / canvas.height, yScale, 0);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
//鼠标拾取计算
|
|
212
|
+
raycast(raycaster: Raycaster, intersects: Intersection[]) {
|
|
213
|
+
|
|
214
|
+
let intersect: Intersection[] = [];
|
|
215
|
+
super.raycast(raycaster, intersect);
|
|
216
|
+
let inte = intersect[0];
|
|
217
|
+
if (inte && (inte.uv!.y > 0.55)) {
|
|
218
|
+
intersects.push(inte);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
copy(source: SpriteText2) {
|
|
224
|
+
this.color = source.color;
|
|
225
|
+
this.backgroundColor = source.backgroundColor;
|
|
226
|
+
this.padding = source.padding;
|
|
227
|
+
this.borderWidth = source.borderWidth;
|
|
228
|
+
this.borderColor = source.borderColor;
|
|
229
|
+
this.fontFace = source.fontFace;
|
|
230
|
+
this.fontSize = source.fontSize;
|
|
231
|
+
this.fontWeight = source.fontWeight;
|
|
232
|
+
this.strokeWidth = source.strokeWidth;
|
|
233
|
+
this.strokeColor = source.strokeColor;
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
}
|
package/lib/Text3D/Text3D.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: xiaosihan
|
|
3
3
|
* @Date: 2022-06-14 09:48:00
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-04-
|
|
5
|
+
* @Last Modified time: 2023-04-07 21:52:03
|
|
6
6
|
*/
|
|
7
7
|
import { Mesh, MeshStandardMaterial, TextGeometry } from "three";
|
|
8
8
|
import fontContorller from "./fontController";
|
|
@@ -53,6 +53,7 @@ export default class Text3D extends Mesh {
|
|
|
53
53
|
bevelSegments: this._config.bevelSegments, //斜角分段
|
|
54
54
|
});
|
|
55
55
|
this.geometry.center();
|
|
56
|
+
this.dispatchEvent({ type: "loaded" });
|
|
56
57
|
}
|
|
57
58
|
});
|
|
58
59
|
}
|
package/lib/Text3D/Text3D.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: xiaosihan
|
|
3
3
|
* @Date: 2022-06-14 09:48:00
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-04-
|
|
5
|
+
* @Last Modified time: 2023-04-07 21:52:03
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { Mesh, MeshStandardMaterial, TextGeometry } from "three";
|
|
@@ -80,6 +80,7 @@ export default class Text3D extends Mesh {
|
|
|
80
80
|
bevelSegments: this._config.bevelSegments,//斜角分段
|
|
81
81
|
});
|
|
82
82
|
this.geometry.center();
|
|
83
|
+
this.dispatchEvent({ type: "loaded" });
|
|
83
84
|
}
|
|
84
85
|
})
|
|
85
86
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import Dexie, { Table } from "dexie";
|
|
9
|
-
import
|
|
9
|
+
import { filter, first, isEmpty } from "lodash";
|
|
10
10
|
import { Font } from "three";
|
|
11
11
|
import threeUtils from "../threeUtils";
|
|
12
12
|
import gentilisJSON from "./gentilis.json";
|
package/lib/ThreeBase.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BufferGeometry, EventDispatcher, Object3D,
|
|
1
|
+
import { BufferGeometry, Camera, EventDispatcher, Object3D, Scene, Texture, Vector2, Vector3, WebGLRenderer, WebGLRenderTarget } from "three";
|
|
2
2
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
3
3
|
import ThreeMouse from "./ThreeMouse";
|
|
4
4
|
import Transition from "./Transition";
|
|
@@ -10,7 +10,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
10
10
|
tempVector3: Vector3;
|
|
11
11
|
size: Vector2;
|
|
12
12
|
renderer: WebGLRenderer;
|
|
13
|
-
camera:
|
|
13
|
+
camera: Camera;
|
|
14
14
|
scene: Scene;
|
|
15
15
|
threeMouse: ThreeMouse;
|
|
16
16
|
controls: OrbitControls;
|
|
@@ -42,7 +42,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
42
42
|
needRender: boolean;
|
|
43
43
|
stopRender(): void;
|
|
44
44
|
render(): void;
|
|
45
|
-
renderBindThis
|
|
45
|
+
private renderBindThis;
|
|
46
46
|
download(fileName?: string): void;
|
|
47
47
|
private _preMesh;
|
|
48
48
|
private _preRT;
|
package/lib/ThreeBase.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: xiaosihan
|
|
3
3
|
* @Date: 2021-12-20 13:38:22
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-
|
|
5
|
+
* @Last Modified time: 2023-05-09 01:11:17
|
|
6
6
|
*/
|
|
7
7
|
import { round } from "lodash";
|
|
8
8
|
import { AxesHelper, EventDispatcher, GridHelper, LinearFilter, Mesh, MOUSE, NoBlending, NormalBlending, PerspectiveCamera, RGBAFormat, Scene, TOUCH, Vector2, Vector3, WebGLRenderer, WebGLRenderTarget } from "three";
|
|
@@ -13,6 +13,7 @@ import threeLoader from "./threeLoader";
|
|
|
13
13
|
import ThreeMouse from "./ThreeMouse";
|
|
14
14
|
import threeUtils from "./threeUtils";
|
|
15
15
|
import Transition from "./Transition";
|
|
16
|
+
import stroke_pass from "./stroke_pass/stroke_pass";
|
|
16
17
|
// three.js 的基础对象
|
|
17
18
|
export default class ThreeBase extends EventDispatcher {
|
|
18
19
|
constructor() {
|
|
@@ -70,10 +71,8 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
70
71
|
// 设置 dom 容器
|
|
71
72
|
async setContainer(div) {
|
|
72
73
|
if (div) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
for (let c of canvas)
|
|
76
|
-
c.remove();
|
|
74
|
+
div.style.overflow = "hidden";
|
|
75
|
+
div.innerHTML = "";
|
|
77
76
|
div.append(this.renderer.domElement);
|
|
78
77
|
// 如果上下文被销毁了, 就恢复上下文
|
|
79
78
|
if (this.isRendererContextLost) {
|
|
@@ -91,8 +90,10 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
91
90
|
}
|
|
92
91
|
// 修改尺寸
|
|
93
92
|
setsize(width, height) {
|
|
94
|
-
this.camera
|
|
95
|
-
|
|
93
|
+
if (this.camera instanceof PerspectiveCamera) {
|
|
94
|
+
this.camera.aspect = width / height;
|
|
95
|
+
this.camera.updateProjectionMatrix();
|
|
96
|
+
}
|
|
96
97
|
this.renderer.setPixelRatio(window.devicePixelRatio);
|
|
97
98
|
this.renderer.setSize(width, height);
|
|
98
99
|
this.size.set(width, height);
|
|
@@ -254,6 +255,12 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
254
255
|
// 渲染场景
|
|
255
256
|
this.dispatchEvent({ type: "beforeRender" });
|
|
256
257
|
this.renderer.render(this.scene, this.camera);
|
|
258
|
+
// 查找需要绘制描边的对象,并且绘制描边
|
|
259
|
+
this.scene.traverse(obj => {
|
|
260
|
+
if (obj.userData.stroke_enable) {
|
|
261
|
+
stroke_pass(this.renderer, this.camera, obj);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
257
264
|
this.dispatchEvent({ type: "afterRender" });
|
|
258
265
|
}
|
|
259
266
|
renderBindThis = this.render.bind(this);
|
package/lib/ThreeBase.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @Author: xiaosihan
|
|
3
3
|
* @Date: 2021-12-20 13:38:22
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-
|
|
5
|
+
* @Last Modified time: 2023-05-09 01:11:17
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { round } from "lodash";
|
|
9
|
-
import { AxesHelper, BufferGeometry, EventDispatcher, GridHelper, LinearFilter, Mesh, MeshBasicMaterial, MOUSE, NoBlending, NormalBlending, Object3D, PerspectiveCamera, RGBAFormat, Scene, Texture, TOUCH, Vector2, Vector3, WebGLRenderer, WebGLRenderTarget } from "three";
|
|
9
|
+
import { AxesHelper, BufferGeometry, Camera, EventDispatcher, GridHelper, LinearFilter, Mesh, MeshBasicMaterial, MOUSE, NoBlending, NormalBlending, Object3D, PerspectiveCamera, RGBAFormat, Scene, Texture, TOUCH, Vector2, Vector3, WebGLRenderer, WebGLRenderTarget } from "three";
|
|
10
10
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
11
11
|
import { generateUUID } from "three/src/math/MathUtils";
|
|
12
12
|
import { clearShader, coptyShader, fullScreenMesh, gaussBlurShader, strokeShader } from "./shaders";
|
|
@@ -14,6 +14,7 @@ import threeLoader from "./threeLoader";
|
|
|
14
14
|
import ThreeMouse from "./ThreeMouse";
|
|
15
15
|
import threeUtils from "./threeUtils";
|
|
16
16
|
import Transition from "./Transition";
|
|
17
|
+
import stroke_pass from "./stroke_pass/stroke_pass";
|
|
17
18
|
|
|
18
19
|
// three.js 的基础对象
|
|
19
20
|
export default class ThreeBase extends EventDispatcher {
|
|
@@ -58,7 +59,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
58
59
|
})();
|
|
59
60
|
|
|
60
61
|
//透视相机
|
|
61
|
-
camera = new PerspectiveCamera(45, 1, 0.0001, 10000);
|
|
62
|
+
camera: Camera = new PerspectiveCamera(45, 1, 0.0001, 10000);
|
|
62
63
|
|
|
63
64
|
// 场景对象
|
|
64
65
|
scene = new Scene();
|
|
@@ -86,9 +87,8 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
86
87
|
// 设置 dom 容器
|
|
87
88
|
async setContainer(div: HTMLDivElement | null) {
|
|
88
89
|
if (div) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
for (let c of canvas) c.remove();
|
|
90
|
+
div.style.overflow = "hidden";
|
|
91
|
+
div.innerHTML = "";
|
|
92
92
|
div.append(this.renderer.domElement);
|
|
93
93
|
|
|
94
94
|
// 如果上下文被销毁了, 就恢复上下文
|
|
@@ -110,8 +110,11 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
110
110
|
|
|
111
111
|
// 修改尺寸
|
|
112
112
|
setsize(width: number, height: number) {
|
|
113
|
-
this.camera
|
|
114
|
-
|
|
113
|
+
if (this.camera instanceof PerspectiveCamera) {
|
|
114
|
+
this.camera.aspect = width / height;
|
|
115
|
+
this.camera.updateProjectionMatrix();
|
|
116
|
+
}
|
|
117
|
+
|
|
115
118
|
this.renderer.setPixelRatio(window.devicePixelRatio);
|
|
116
119
|
this.renderer.setSize(width, height);
|
|
117
120
|
this.size.set(width, height);
|
|
@@ -305,10 +308,18 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
305
308
|
// 渲染场景
|
|
306
309
|
this.dispatchEvent({ type: "beforeRender" });
|
|
307
310
|
this.renderer.render(this.scene, this.camera);
|
|
311
|
+
|
|
312
|
+
// 查找需要绘制描边的对象,并且绘制描边
|
|
313
|
+
this.scene.traverse(obj => {
|
|
314
|
+
if (obj.userData.stroke_enable) {
|
|
315
|
+
stroke_pass(this.renderer, this.camera, obj);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
308
319
|
this.dispatchEvent({ type: "afterRender" });
|
|
309
320
|
}
|
|
310
321
|
|
|
311
|
-
renderBindThis = this.render.bind(this);
|
|
322
|
+
private renderBindThis = this.render.bind(this);
|
|
312
323
|
|
|
313
324
|
// 下载渲染图
|
|
314
325
|
download(fileName: string = "download") {
|
package/lib/Transition.d.ts
CHANGED
package/lib/Transition.js
CHANGED
|
@@ -23,7 +23,7 @@ export default class Transition {
|
|
|
23
23
|
constructor(param = {}, bezier = [0.8, 0, 0.2, 1], duration = 500) {
|
|
24
24
|
this.setDuration(duration);
|
|
25
25
|
this.setBezier(bezier);
|
|
26
|
-
this.
|
|
26
|
+
this.reset(param);
|
|
27
27
|
}
|
|
28
28
|
// 所有的 key 的枚举
|
|
29
29
|
_keys = [];
|
|
@@ -57,7 +57,7 @@ export default class Transition {
|
|
|
57
57
|
}
|
|
58
58
|
// 存储 每个参数的 起始位置 起始时间 终止位置 终止时间
|
|
59
59
|
_ = {};
|
|
60
|
-
onChangeCall;
|
|
60
|
+
onChangeCall = (josn) => { };
|
|
61
61
|
// 执行过度动画
|
|
62
62
|
run({ timeTemp }) {
|
|
63
63
|
this.timeTemp = timeTemp;
|
|
@@ -73,7 +73,7 @@ export default class Transition {
|
|
|
73
73
|
// 设置动画对象的回调事件
|
|
74
74
|
onChange(onChangeCall) {
|
|
75
75
|
this.onChangeCall = onChangeCall;
|
|
76
|
-
|
|
76
|
+
this.onChangeCall(this.getJson());
|
|
77
77
|
return this;
|
|
78
78
|
}
|
|
79
79
|
// 计算当前 key 的值
|
|
@@ -133,9 +133,9 @@ export default class Transition {
|
|
|
133
133
|
// // 执行状态未完成
|
|
134
134
|
// this._isDone = false;
|
|
135
135
|
}
|
|
136
|
-
threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
|
|
137
|
-
threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
|
|
138
136
|
if (!this._isDone) {
|
|
137
|
+
threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
|
|
138
|
+
threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
|
|
139
139
|
await new Promise(resolve => setTimeout(resolve, this._duration + 50));
|
|
140
140
|
}
|
|
141
141
|
return this;
|
|
@@ -143,6 +143,9 @@ export default class Transition {
|
|
|
143
143
|
// 重置起始和终止位置
|
|
144
144
|
reset(param) {
|
|
145
145
|
for (let key in param) {
|
|
146
|
+
if (!this._keys.includes(key)) {
|
|
147
|
+
this._keys.push(key);
|
|
148
|
+
}
|
|
146
149
|
this._[key + "_start"] = param[key];
|
|
147
150
|
this._[key + "_end"] = param[key];
|
|
148
151
|
this._[key + "_startTime"] = -this._duration;
|
package/lib/Transition.ts
CHANGED
|
@@ -36,7 +36,7 @@ export default class Transition {
|
|
|
36
36
|
|
|
37
37
|
this.setBezier(bezier);
|
|
38
38
|
|
|
39
|
-
this.
|
|
39
|
+
this.reset(param);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// 所有的 key 的枚举
|
|
@@ -82,7 +82,7 @@ export default class Transition {
|
|
|
82
82
|
// 存储 每个参数的 起始位置 起始时间 终止位置 终止时间
|
|
83
83
|
_: { [key: string]: number } = {};
|
|
84
84
|
|
|
85
|
-
onChangeCall
|
|
85
|
+
private onChangeCall = (josn: { [key: string]: number }) => { };
|
|
86
86
|
|
|
87
87
|
// 执行过度动画
|
|
88
88
|
run({ timeTemp }: any) {
|
|
@@ -100,7 +100,7 @@ export default class Transition {
|
|
|
100
100
|
// 设置动画对象的回调事件
|
|
101
101
|
onChange(onChangeCall: (josn: { [key: string]: number }) => void): this {
|
|
102
102
|
this.onChangeCall = onChangeCall;
|
|
103
|
-
|
|
103
|
+
this.onChangeCall(this.getJson());
|
|
104
104
|
return this;
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -185,10 +185,9 @@ export default class Transition {
|
|
|
185
185
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
|
|
189
|
-
threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
|
|
190
|
-
|
|
191
188
|
if (!this._isDone) {
|
|
189
|
+
threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
|
|
190
|
+
threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
|
|
192
191
|
await new Promise(resolve => setTimeout(resolve, this._duration + 50));
|
|
193
192
|
}
|
|
194
193
|
|
|
@@ -198,6 +197,11 @@ export default class Transition {
|
|
|
198
197
|
reset(param: TParam): this {
|
|
199
198
|
|
|
200
199
|
for (let key in param) {
|
|
200
|
+
|
|
201
|
+
if (!this._keys.includes(key)) {
|
|
202
|
+
this._keys.push(key);
|
|
203
|
+
}
|
|
204
|
+
|
|
201
205
|
this._[key + "_start"] = param[key];
|
|
202
206
|
this._[key + "_end"] = param[key];
|
|
203
207
|
this._[key + "_startTime"] = -this._duration;
|
|
@@ -14,7 +14,6 @@ export default class PlaneModal1 extends Mesh {
|
|
|
14
14
|
this.material.map = this.texture;
|
|
15
15
|
this.scale.set(10, 10, 10);
|
|
16
16
|
}
|
|
17
|
-
renderOrder = 99;
|
|
18
17
|
geometry = new PlaneGeometry(1 * 0.65, 0.728 * 0.65, 1, 1);
|
|
19
18
|
material = new MeshBasicMaterial({
|
|
20
19
|
side: DoubleSide,
|
|
@@ -100,5 +99,6 @@ export default class PlaneModal1 extends Mesh {
|
|
|
100
99
|
textPos.y += size;
|
|
101
100
|
});
|
|
102
101
|
this.texture.needsUpdate = true;
|
|
102
|
+
this.dispatchEvent({ type: "loaded" });
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -30,8 +30,6 @@ export default class PlaneModal1 extends Mesh {
|
|
|
30
30
|
this.scale.set(10, 10, 10);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
renderOrder = 99;
|
|
34
|
-
|
|
35
33
|
geometry = new PlaneGeometry(1 * 0.65, 0.728 * 0.65, 1, 1);
|
|
36
34
|
|
|
37
35
|
material = new MeshBasicMaterial({
|
|
@@ -145,6 +143,7 @@ export default class PlaneModal1 extends Mesh {
|
|
|
145
143
|
|
|
146
144
|
this.texture.needsUpdate = true;
|
|
147
145
|
|
|
146
|
+
this.dispatchEvent({ type: "loaded" });
|
|
148
147
|
}
|
|
149
148
|
|
|
150
149
|
|
|
@@ -15,7 +15,6 @@ export default class SpritModal1 extends Sprite {
|
|
|
15
15
|
this.material.transparent = true;
|
|
16
16
|
this.material.alphaTest = 0.01;
|
|
17
17
|
}
|
|
18
|
-
renderOrder = 99;
|
|
19
18
|
// 背景图
|
|
20
19
|
static img = (() => {
|
|
21
20
|
const img = new Image();
|
|
@@ -96,6 +95,7 @@ export default class SpritModal1 extends Sprite {
|
|
|
96
95
|
textPos.y += size;
|
|
97
96
|
});
|
|
98
97
|
this.texture.needsUpdate = true;
|
|
98
|
+
this.dispatchEvent({ type: "loaded" });
|
|
99
99
|
}
|
|
100
100
|
//鼠标拾取计算
|
|
101
101
|
raycast(raycaster, intersects) {
|
|
@@ -34,8 +34,6 @@ export default class SpritModal1 extends Sprite {
|
|
|
34
34
|
this.material.alphaTest = 0.01;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
renderOrder = 99;
|
|
38
|
-
|
|
39
37
|
// 背景图
|
|
40
38
|
static img = (() => {
|
|
41
39
|
const img = new Image();
|
|
@@ -142,6 +140,7 @@ export default class SpritModal1 extends Sprite {
|
|
|
142
140
|
|
|
143
141
|
this.texture.needsUpdate = true;
|
|
144
142
|
|
|
143
|
+
this.dispatchEvent({ type: "loaded" });
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
//鼠标拾取计算
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BufferGeometry, Material, Mesh, OrthographicCamera, Scene, WebGLRenderer } from "three";
|
|
2
|
+
export default class FullScreenQuad extends Scene {
|
|
3
|
+
constructor();
|
|
4
|
+
mesh: Mesh<BufferGeometry, Material>;
|
|
5
|
+
orthographicCamera: OrthographicCamera;
|
|
6
|
+
render(renderer: WebGLRenderer, material: Material): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2023-05-09 01:36:35
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-05-09 01:47:07
|
|
6
|
+
*/
|
|
7
|
+
import { BufferGeometry, Float32BufferAttribute, Mesh, MeshBasicMaterial, OrthographicCamera, Scene } from "three";
|
|
8
|
+
export default class FullScreenQuad extends Scene {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
}
|
|
12
|
+
mesh = (() => {
|
|
13
|
+
const geometry = new BufferGeometry();
|
|
14
|
+
geometry.setAttribute("position", new Float32BufferAttribute([-1, 3, 0, -1, -1, 0, 3, -1, 0], 3));
|
|
15
|
+
geometry.setAttribute("uv", new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2));
|
|
16
|
+
const mesh = new Mesh(geometry, new MeshBasicMaterial());
|
|
17
|
+
this.add(mesh);
|
|
18
|
+
return mesh;
|
|
19
|
+
})();
|
|
20
|
+
orthographicCamera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
21
|
+
render(renderer, material) {
|
|
22
|
+
this.mesh.material = material;
|
|
23
|
+
renderer.render(this, this.orthographicCamera);
|
|
24
|
+
}
|
|
25
|
+
}
|