three-base 2.0.1 → 2.0.3
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/ApngTexture.d.ts +13 -0
- package/ApngTexture.js +61 -0
- package/ApngTexture.ts +91 -0
- package/ApngTextureManage.d.ts +18 -0
- package/ApngTextureManage.js +87 -0
- package/ApngTextureManage.ts +130 -0
- package/EventMesh.d.ts +18 -0
- package/EventMesh.js +59 -0
- package/EventMesh.ts +79 -0
- package/ExtrudeMesh.d.ts +111 -0
- package/ExtrudeMesh.js +363 -0
- package/ExtrudeMesh.ts +571 -0
- package/FPScontrol.d.ts +44 -0
- package/FPScontrol.js +170 -0
- package/FPScontrol.ts +209 -0
- package/InstancedGroupMesh.d.ts +10 -0
- package/InstancedGroupMesh.js +63 -0
- package/InstancedGroupMesh.ts +80 -0
- package/KeyFrameAnimation.d.ts +25 -0
- package/KeyFrameAnimation.js +78 -0
- package/KeyFrameAnimation.ts +122 -0
- package/PlaneModal1/PlaneModal1.d.ts +31 -0
- package/PlaneModal1/PlaneModal1.js +105 -0
- package/PlaneModal1/PlaneModal1.ts +151 -0
- package/PlaneModal1/index.d.ts +1 -0
- package/PlaneModal1/index.js +1 -0
- package/PlaneModal1/index.ts +1 -0
- package/PlaneModal1/planeModal.png +0 -0
- package/PlaneText.d.ts +37 -0
- package/PlaneText.js +30 -0
- package/PlaneText.ts +58 -0
- package/PlaneWithHtml.d.ts +11 -0
- package/PlaneWithHtml.js +67 -0
- package/PlaneWithHtml.ts +84 -0
- package/PointLight/PointLight.d.ts +13 -0
- package/PointLight/PointLight.js +63 -0
- package/PointLight/PointLight.ts +74 -0
- package/PointLight/index.d.ts +1 -0
- package/PointLight/index.js +1 -0
- package/PointLight/index.ts +1 -0
- package/PointLight/pointLight_map.png +0 -0
- package/README.md +1 -1
- package/Sky/Sky.d.ts +13 -0
- package/Sky/Sky.js +28 -0
- package/Sky/Sky.ts +36 -0
- package/Sky/bluesky.jpg +0 -0
- package/Sky/index.d.ts +1 -0
- package/Sky/index.js +1 -0
- package/Sky/index.ts +1 -0
- package/SpriteModal1/SpriteModal1.d.ts +30 -0
- package/SpriteModal1/SpriteModal1.js +110 -0
- package/SpriteModal1/SpriteModal1.ts +160 -0
- package/SpriteModal1/index.d.ts +1 -0
- package/SpriteModal1/index.js +1 -0
- package/SpriteModal1/index.ts +1 -0
- package/SpriteModal1/spriteModal1.png +0 -0
- package/SpriteText.d.ts +45 -0
- package/SpriteText.js +162 -0
- package/SpriteText.ts +189 -0
- package/SpriteText2.d.ts +47 -0
- package/SpriteText2.js +197 -0
- package/SpriteText2.ts +236 -0
- package/Text3D/Text3D.d.ts +20 -0
- package/Text3D/Text3D.js +62 -0
- package/Text3D/Text3D.ts +93 -0
- package/Text3D/fontController.d.ts +59 -0
- package/Text3D/fontController.js +200 -0
- package/Text3D/fontController.ts +285 -0
- package/Text3D/gentilis.json +811 -0
- package/Text3D/index.d.ts +1 -0
- package/Text3D/index.js +1 -0
- package/Text3D/index.ts +1 -0
- package/ThreeBase.d.ts +61 -0
- package/ThreeBase.js +403 -0
- package/ThreeBase.ts +484 -0
- package/ThreeMouse.d.ts +39 -0
- package/ThreeMouse.js +359 -0
- package/ThreeMouse.ts +465 -0
- package/Transition.d.ts +43 -0
- package/Transition.js +196 -0
- package/Transition.ts +268 -0
- package/index.d.ts +1 -0
- package/keyContorls.d.ts +25 -0
- package/keyContorls.js +98 -0
- package/keyContorls.ts +127 -0
- package/package.json +15 -20
- package/pass/FullScreenQuad.d.ts +7 -0
- package/pass/FullScreenQuad.js +25 -0
- package/pass/FullScreenQuad.ts +33 -0
- package/pass/stroke_pass.d.ts +2 -0
- package/pass/stroke_pass.js +190 -0
- package/pass/stroke_pass.ts +211 -0
- package/shaders.d.ts +17 -0
- package/shaders.js +245 -0
- package/shaders.ts +264 -0
- package/threeLoader.d.ts +20 -0
- package/threeLoader.js +118 -0
- package/threeLoader.ts +147 -0
- package/threeUtils.d.ts +44 -0
- package/threeUtils.js +233 -0
- package/threeUtils.ts +271 -0
- package/tsconfig.json +39 -0
package/PlaneWithHtml.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
|
|
8
|
+
import html2canvas from "html2canvas";
|
|
9
|
+
import { CanvasTexture, DoubleSide, Mesh, MeshBasicMaterial, PlaneGeometry, Vector2 } from "three";
|
|
10
|
+
import { degToRad } from "three/src/math/MathUtils";
|
|
11
|
+
import threeLoader from "./threeLoader";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// html 文本面板
|
|
15
|
+
export default class PlaneWithHtml extends Mesh {
|
|
16
|
+
|
|
17
|
+
constructor(html: string = "", backgroundColor: `#${string}` = "#00000000") {
|
|
18
|
+
super();
|
|
19
|
+
this.setHtml(html, backgroundColor);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
visible = false;
|
|
23
|
+
|
|
24
|
+
size = new Vector2(10, 10);
|
|
25
|
+
|
|
26
|
+
geometry = (() => {
|
|
27
|
+
const geometry = new PlaneGeometry(10, 10, 1, 1);
|
|
28
|
+
geometry.rotateX(degToRad(-90));
|
|
29
|
+
return geometry;
|
|
30
|
+
})();
|
|
31
|
+
|
|
32
|
+
material = new MeshBasicMaterial({
|
|
33
|
+
side: DoubleSide,
|
|
34
|
+
transparent: true
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
div = (() => {
|
|
38
|
+
const div = document.createElement("div");
|
|
39
|
+
div.style.position = "fixed";
|
|
40
|
+
div.style.top = "100%";
|
|
41
|
+
div.style.left = "100%";
|
|
42
|
+
div.style.pointerEvents = "none";
|
|
43
|
+
div.style.userSelect = "none";
|
|
44
|
+
div.style.lineHeight = "1";
|
|
45
|
+
div.style.whiteSpace = "nowrap";
|
|
46
|
+
return div;
|
|
47
|
+
})();
|
|
48
|
+
|
|
49
|
+
// 设置网格尺寸
|
|
50
|
+
setGeoSize(width: number, height: number) {
|
|
51
|
+
this.size.set(width, height);
|
|
52
|
+
this.geometry.dispose();
|
|
53
|
+
const geometry = new PlaneGeometry(width, height, 1, 1);
|
|
54
|
+
geometry.rotateX(degToRad(-90));
|
|
55
|
+
this.geometry = geometry;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async setHtml(html: string = "", backgroundColor: `#${string}` = "#00000000") {
|
|
59
|
+
this.div.innerHTML = html;
|
|
60
|
+
document.body.appendChild(this.div);
|
|
61
|
+
|
|
62
|
+
await new Promise<void>((resolve, reject) => {
|
|
63
|
+
|
|
64
|
+
html2canvas(this.div, {
|
|
65
|
+
backgroundColor,
|
|
66
|
+
removeContainer: true
|
|
67
|
+
}).then(async (canvas) => {
|
|
68
|
+
this.setGeoSize(canvas.width, canvas.height);
|
|
69
|
+
this.material.map = new CanvasTexture(canvas);
|
|
70
|
+
this.material.map.anisotropy = threeLoader.anisotropy;
|
|
71
|
+
this.material.needsUpdate = true;
|
|
72
|
+
this.visible = true;
|
|
73
|
+
await new Promise(resolve => requestAnimationFrame(resolve));
|
|
74
|
+
this.div.remove();
|
|
75
|
+
resolve();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this.dispatchEvent({ type: "loaded" });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Sprite, PointLight as THREEPointLight } from "three";
|
|
2
|
+
import SpriteText from "../SpriteText";
|
|
3
|
+
/**
|
|
4
|
+
* 点光源
|
|
5
|
+
* @export
|
|
6
|
+
* @class PointLight
|
|
7
|
+
* @extends {THREEPointLight}
|
|
8
|
+
*/
|
|
9
|
+
export default class PointLight extends THREEPointLight {
|
|
10
|
+
constructor(color?: string, intensity?: number, distance?: number, decay?: number);
|
|
11
|
+
pointLinghtHelper: Sprite;
|
|
12
|
+
label: SpriteText;
|
|
13
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-05-18 16:02:55
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-05-03 02:55:28
|
|
6
|
+
*/
|
|
7
|
+
import { Sprite, PointLight as THREEPointLight } from "three";
|
|
8
|
+
import threeLoader from "../threeLoader";
|
|
9
|
+
import threeUtils from "../threeUtils";
|
|
10
|
+
import pointLight_mapPNG from "./pointLight_map.png";
|
|
11
|
+
import SpriteText from "../SpriteText";
|
|
12
|
+
/**
|
|
13
|
+
* 点光源
|
|
14
|
+
* @export
|
|
15
|
+
* @class PointLight
|
|
16
|
+
* @extends {THREEPointLight}
|
|
17
|
+
*/
|
|
18
|
+
export default class PointLight extends THREEPointLight {
|
|
19
|
+
constructor(color = "#fff", intensity, distance, decay) {
|
|
20
|
+
super(color, intensity, distance, decay);
|
|
21
|
+
}
|
|
22
|
+
// 灯光辅助器
|
|
23
|
+
pointLinghtHelper = threeUtils.isDev && (() => {
|
|
24
|
+
const pointLinghtHelper = new Sprite();
|
|
25
|
+
pointLinghtHelper.scale.set(0.05, 0.05, 0.05);
|
|
26
|
+
pointLinghtHelper.material.color = this.color;
|
|
27
|
+
pointLinghtHelper.material.map = threeLoader.getTexture(pointLight_mapPNG);
|
|
28
|
+
pointLinghtHelper.material.sizeAttenuation = false;
|
|
29
|
+
pointLinghtHelper.userData = {
|
|
30
|
+
cursor: "pointer"
|
|
31
|
+
};
|
|
32
|
+
pointLinghtHelper.addEventListener("mouseenter", () => {
|
|
33
|
+
if (this.label) {
|
|
34
|
+
this.label.visible = true;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
pointLinghtHelper.addEventListener("mouseleave", () => {
|
|
38
|
+
if (this.label) {
|
|
39
|
+
this.label.visible = false;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
this.add(pointLinghtHelper);
|
|
43
|
+
return pointLinghtHelper;
|
|
44
|
+
})();
|
|
45
|
+
label = threeUtils.isDev && (() => {
|
|
46
|
+
const label = new SpriteText("点光源\n\n\n");
|
|
47
|
+
label.renderOrder = Infinity;
|
|
48
|
+
// label.backgroundColor = "rgba(0, 0, 0, 0.5)";
|
|
49
|
+
label.padding = 4;
|
|
50
|
+
label.strokeColor = "#333";
|
|
51
|
+
label.strokeWidth = 2;
|
|
52
|
+
// label.borderRadius = 4;
|
|
53
|
+
// label.borderWidth = 1;
|
|
54
|
+
label.position.set(0, 0, 0);
|
|
55
|
+
label.visible = false;
|
|
56
|
+
label.material.color = this.color;
|
|
57
|
+
label.material.depthTest = false;
|
|
58
|
+
label.material.sizeAttenuation = false;
|
|
59
|
+
label.scale.multiplyScalar(0.002);
|
|
60
|
+
this.add(label);
|
|
61
|
+
return label;
|
|
62
|
+
})();
|
|
63
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-05-18 16:02:55
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-05-03 02:55:28
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Sprite, PointLight as THREEPointLight } from "three";
|
|
9
|
+
import threeLoader from "../threeLoader";
|
|
10
|
+
import threeUtils from "../threeUtils";
|
|
11
|
+
import pointLight_mapPNG from "./pointLight_map.png";
|
|
12
|
+
import SpriteText from "../SpriteText";
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 点光源
|
|
17
|
+
* @export
|
|
18
|
+
* @class PointLight
|
|
19
|
+
* @extends {THREEPointLight}
|
|
20
|
+
*/
|
|
21
|
+
export default class PointLight extends THREEPointLight {
|
|
22
|
+
|
|
23
|
+
constructor(color = "#fff", intensity?: number, distance?: number, decay?: number) {
|
|
24
|
+
super(color, intensity, distance, decay);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 灯光辅助器
|
|
28
|
+
pointLinghtHelper = threeUtils.isDev && (() => {
|
|
29
|
+
const pointLinghtHelper = new Sprite();
|
|
30
|
+
pointLinghtHelper.scale.set(0.05, 0.05, 0.05);
|
|
31
|
+
pointLinghtHelper.material.color = this.color;
|
|
32
|
+
pointLinghtHelper.material.map = threeLoader.getTexture(pointLight_mapPNG);
|
|
33
|
+
pointLinghtHelper.material.sizeAttenuation = false;
|
|
34
|
+
|
|
35
|
+
pointLinghtHelper.userData = {
|
|
36
|
+
cursor: "pointer"
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
pointLinghtHelper.addEventListener("mouseenter", () => {
|
|
40
|
+
if (this.label) {
|
|
41
|
+
this.label.visible = true;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
pointLinghtHelper.addEventListener("mouseleave", () => {
|
|
46
|
+
if (this.label) {
|
|
47
|
+
this.label.visible = false;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
this.add(pointLinghtHelper);
|
|
52
|
+
return pointLinghtHelper;
|
|
53
|
+
})();
|
|
54
|
+
|
|
55
|
+
label = threeUtils.isDev && (() => {
|
|
56
|
+
const label = new SpriteText("点光源\n\n\n");
|
|
57
|
+
label.renderOrder = Infinity;
|
|
58
|
+
// label.backgroundColor = "rgba(0, 0, 0, 0.5)";
|
|
59
|
+
label.padding = 4;
|
|
60
|
+
label.strokeColor = "#333";
|
|
61
|
+
label.strokeWidth = 2;
|
|
62
|
+
// label.borderRadius = 4;
|
|
63
|
+
// label.borderWidth = 1;
|
|
64
|
+
label.position.set(0, 0, 0);
|
|
65
|
+
label.visible = false;
|
|
66
|
+
label.material.color = this.color;
|
|
67
|
+
label.material.depthTest = false;
|
|
68
|
+
label.material.sizeAttenuation = false;
|
|
69
|
+
label.scale.multiplyScalar(0.002);
|
|
70
|
+
this.add(label);
|
|
71
|
+
return label;
|
|
72
|
+
})();
|
|
73
|
+
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./PointLight";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./PointLight";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./PointLight";
|
|
Binary file
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
```tsx
|
|
2
2
|
.创建一个 homeRender.ts 模块
|
|
3
3
|
import { AmbientLight, BoxGeometry, Mesh, MeshLambertMaterial, PointLight } from "three";
|
|
4
|
-
import ThreeBase
|
|
4
|
+
import ThreeBase from "three-base";
|
|
5
5
|
import Transition from "three-base/Transition";
|
|
6
6
|
|
|
7
7
|
// 做项目找我 qq:389652405
|
package/Sky/Sky.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Mesh, MeshBasicMaterial, SphereGeometry } from "three";
|
|
2
|
+
/**
|
|
3
|
+
* 天空球
|
|
4
|
+
*/
|
|
5
|
+
export default class Sky extends Mesh {
|
|
6
|
+
constructor();
|
|
7
|
+
static geometry: SphereGeometry;
|
|
8
|
+
material: MeshBasicMaterial;
|
|
9
|
+
/**
|
|
10
|
+
*设置贴图
|
|
11
|
+
*/
|
|
12
|
+
setMap(src: string): void;
|
|
13
|
+
}
|
package/Sky/Sky.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-05-20 18:03:58
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2022-12-27 09:54:23
|
|
6
|
+
*/
|
|
7
|
+
import { DoubleSide, Mesh, MeshBasicMaterial, SphereGeometry } from "three";
|
|
8
|
+
import threeLoader from "../threeLoader";
|
|
9
|
+
import blueskyJPG from "./blueSky.jpg";
|
|
10
|
+
/**
|
|
11
|
+
* 天空球
|
|
12
|
+
*/
|
|
13
|
+
export default class Sky extends Mesh {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(Sky.geometry);
|
|
16
|
+
}
|
|
17
|
+
static geometry = new SphereGeometry(500000, 100, 100);
|
|
18
|
+
material = new MeshBasicMaterial({
|
|
19
|
+
side: DoubleSide,
|
|
20
|
+
map: threeLoader.getTexture(blueskyJPG)
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
*设置贴图
|
|
24
|
+
*/
|
|
25
|
+
setMap(src) {
|
|
26
|
+
this.material.map = threeLoader.getTexture(src);
|
|
27
|
+
}
|
|
28
|
+
}
|
package/Sky/Sky.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-05-20 18:03:58
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2022-12-27 09:54:23
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { DoubleSide, Mesh, MeshBasicMaterial, SphereGeometry } from "three";
|
|
9
|
+
import threeLoader from "../threeLoader";
|
|
10
|
+
|
|
11
|
+
import blueskyJPG from "./blueSky.jpg";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 天空球
|
|
15
|
+
*/
|
|
16
|
+
export default class Sky extends Mesh {
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
super(Sky.geometry);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static geometry = new SphereGeometry(500000, 100, 100);
|
|
23
|
+
|
|
24
|
+
material = new MeshBasicMaterial({
|
|
25
|
+
side: DoubleSide,
|
|
26
|
+
map: threeLoader.getTexture(blueskyJPG)
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*设置贴图
|
|
31
|
+
*/
|
|
32
|
+
setMap(src: string) {
|
|
33
|
+
this.material.map = threeLoader.getTexture(src);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
package/Sky/bluesky.jpg
ADDED
|
Binary file
|
package/Sky/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Sky";
|
package/Sky/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Sky";
|
package/Sky/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Sky";
|
|
@@ -0,0 +1,30 @@
|
|
|
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 | import("three").Texture;
|
|
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
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2023-03-08 00:01:34
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-03-08 02:05:25
|
|
6
|
+
*/
|
|
7
|
+
import { Sprite, Vector2 } from "three";
|
|
8
|
+
import spriteModal1PNG from "./spriteModal1.png";
|
|
9
|
+
import threeLoader from "../threeLoader";
|
|
10
|
+
// sprit弹窗1
|
|
11
|
+
export default class SpritModal1 extends Sprite {
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
super();
|
|
14
|
+
this.updata(config);
|
|
15
|
+
this.material.map = this.texture;
|
|
16
|
+
this.material.transparent = true;
|
|
17
|
+
this.material.alphaTest = 0.01;
|
|
18
|
+
}
|
|
19
|
+
// 背景图
|
|
20
|
+
static img = (() => {
|
|
21
|
+
const img = new Image();
|
|
22
|
+
img.src = spriteModal1PNG;
|
|
23
|
+
return img;
|
|
24
|
+
})();
|
|
25
|
+
canvas = (() => {
|
|
26
|
+
const canvas = document.createElement("canvas");
|
|
27
|
+
canvas.width = 1024;
|
|
28
|
+
canvas.height = 1024;
|
|
29
|
+
return canvas;
|
|
30
|
+
})();
|
|
31
|
+
context = this.canvas.getContext("2d");
|
|
32
|
+
texture = threeLoader.getTexture(this.canvas);
|
|
33
|
+
// 配置
|
|
34
|
+
_config = {
|
|
35
|
+
size: 10,
|
|
36
|
+
title: "SpritModal1",
|
|
37
|
+
titleColor: "#ffffff",
|
|
38
|
+
texts: []
|
|
39
|
+
// [
|
|
40
|
+
// {
|
|
41
|
+
// text: "1",
|
|
42
|
+
// color: "#ffff00",
|
|
43
|
+
// size: 40
|
|
44
|
+
// },
|
|
45
|
+
// {
|
|
46
|
+
// text: "2",
|
|
47
|
+
// color: "#ff00ff",
|
|
48
|
+
// size: 40
|
|
49
|
+
// },
|
|
50
|
+
// ]
|
|
51
|
+
};
|
|
52
|
+
async updata(config) {
|
|
53
|
+
Object.assign(this._config, config);
|
|
54
|
+
//绘制背景
|
|
55
|
+
this.context.clearRect(0, 0, 1024, 1024);
|
|
56
|
+
while (!SpritModal1.img.complete) {
|
|
57
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
58
|
+
}
|
|
59
|
+
// 设置大小
|
|
60
|
+
this.scale.set(this._config.size, this._config.size, this._config.size);
|
|
61
|
+
// this.context.fillStyle = "#00000088";
|
|
62
|
+
// this.context.fillRect(0, 0, 1024, 1024);
|
|
63
|
+
//绘制背景
|
|
64
|
+
this.context.drawImage(SpritModal1.img, 186, 0);
|
|
65
|
+
// 绘制标题
|
|
66
|
+
this.context.fillStyle = this._config.titleColor;
|
|
67
|
+
this.context.font = '40px serif'; // 设置字体大小
|
|
68
|
+
this.context.textAlign = "left";
|
|
69
|
+
this.context.textBaseline = "top";
|
|
70
|
+
this.context.fillText(this._config.title, 250, 72);
|
|
71
|
+
let textPos = new Vector2(250, 150);
|
|
72
|
+
let maxWidth = 530;
|
|
73
|
+
// 绘制内容
|
|
74
|
+
this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
|
|
75
|
+
this.context.fillStyle = color;
|
|
76
|
+
this.context.font = `${size}px serif`; // 设置字体大小
|
|
77
|
+
this.context.textAlign = "left";
|
|
78
|
+
this.context.textBaseline = "top";
|
|
79
|
+
// 字符分隔为数组
|
|
80
|
+
var arrText = text.split('');
|
|
81
|
+
var line = '';
|
|
82
|
+
// 文字自动换行计算
|
|
83
|
+
for (var n = 0; n < arrText.length; n++) {
|
|
84
|
+
var metrics = this.context.measureText(line + arrText[n]);
|
|
85
|
+
var testWidth = metrics.width;
|
|
86
|
+
if ((testWidth > maxWidth && n > 0) || arrText[n] === "\n") {
|
|
87
|
+
this.context.fillText(line, textPos.x, textPos.y);
|
|
88
|
+
line = "";
|
|
89
|
+
textPos.y += size;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
line += arrText[n];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
this.context.fillText(line, textPos.x, textPos.y);
|
|
96
|
+
textPos.y += size;
|
|
97
|
+
});
|
|
98
|
+
this.texture.needsUpdate = true;
|
|
99
|
+
this.dispatchEvent({ type: "loaded" });
|
|
100
|
+
}
|
|
101
|
+
//鼠标拾取计算
|
|
102
|
+
raycast(raycaster, intersects) {
|
|
103
|
+
let intersect = [];
|
|
104
|
+
super.raycast(raycaster, intersect);
|
|
105
|
+
let inte = intersect[0];
|
|
106
|
+
if (inte && (inte.uv.x > 0.22 && inte.uv.x < 0.78) && (inte.uv.y > 0.54 && inte.uv.y < 0.94)) {
|
|
107
|
+
intersects.push(inte);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2023-03-08 00:01:34
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-03-08 02:05:25
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
import { Sprite, CanvasTexture, Vector2, Raycaster, Intersection } from "three";
|
|
13
|
+
import spriteModal1PNG from "./spriteModal1.png";
|
|
14
|
+
import threeLoader from "../threeLoader";
|
|
15
|
+
|
|
16
|
+
export type SpritModal1Config = {
|
|
17
|
+
size?: number,
|
|
18
|
+
title?: string,
|
|
19
|
+
titleColor?: string,
|
|
20
|
+
texts?: Array<{
|
|
21
|
+
text?: string,
|
|
22
|
+
color?: string,
|
|
23
|
+
size?: number
|
|
24
|
+
}>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// sprit弹窗1
|
|
28
|
+
export default class SpritModal1 extends Sprite {
|
|
29
|
+
|
|
30
|
+
constructor(config: SpritModal1Config = {}) {
|
|
31
|
+
super();
|
|
32
|
+
this.updata(config);
|
|
33
|
+
this.material.map = this.texture;
|
|
34
|
+
this.material.transparent = true;
|
|
35
|
+
this.material.alphaTest = 0.01;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 背景图
|
|
39
|
+
static img = (() => {
|
|
40
|
+
const img = new Image();
|
|
41
|
+
img.src = spriteModal1PNG;
|
|
42
|
+
return img;
|
|
43
|
+
})();
|
|
44
|
+
|
|
45
|
+
canvas = (() => {
|
|
46
|
+
const canvas = document.createElement("canvas");
|
|
47
|
+
canvas.width = 1024;
|
|
48
|
+
canvas.height = 1024;
|
|
49
|
+
return canvas;
|
|
50
|
+
})();
|
|
51
|
+
|
|
52
|
+
context = this.canvas.getContext("2d")!;
|
|
53
|
+
|
|
54
|
+
texture = threeLoader.getTexture(this.canvas);
|
|
55
|
+
|
|
56
|
+
// 配置
|
|
57
|
+
_config: {
|
|
58
|
+
size: number,
|
|
59
|
+
title: string,
|
|
60
|
+
titleColor: string,
|
|
61
|
+
texts: Array<{
|
|
62
|
+
text: string,
|
|
63
|
+
color: string,
|
|
64
|
+
size: number
|
|
65
|
+
}>
|
|
66
|
+
} = {
|
|
67
|
+
size: 10,
|
|
68
|
+
title: "SpritModal1",
|
|
69
|
+
titleColor: "#ffffff",
|
|
70
|
+
texts: []
|
|
71
|
+
// [
|
|
72
|
+
// {
|
|
73
|
+
// text: "1",
|
|
74
|
+
// color: "#ffff00",
|
|
75
|
+
// size: 40
|
|
76
|
+
// },
|
|
77
|
+
// {
|
|
78
|
+
// text: "2",
|
|
79
|
+
// color: "#ff00ff",
|
|
80
|
+
// size: 40
|
|
81
|
+
// },
|
|
82
|
+
// ]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async updata(config: SpritModal1Config) {
|
|
86
|
+
|
|
87
|
+
Object.assign(this._config, config)
|
|
88
|
+
|
|
89
|
+
//绘制背景
|
|
90
|
+
this.context.clearRect(0, 0, 1024, 1024);
|
|
91
|
+
|
|
92
|
+
while (!SpritModal1.img.complete) {
|
|
93
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 设置大小
|
|
97
|
+
this.scale.set(this._config.size, this._config.size, this._config.size);
|
|
98
|
+
|
|
99
|
+
// this.context.fillStyle = "#00000088";
|
|
100
|
+
// this.context.fillRect(0, 0, 1024, 1024);
|
|
101
|
+
|
|
102
|
+
//绘制背景
|
|
103
|
+
this.context.drawImage(SpritModal1.img, 186, 0);
|
|
104
|
+
|
|
105
|
+
// 绘制标题
|
|
106
|
+
this.context.fillStyle = this._config.titleColor;
|
|
107
|
+
this.context.font = '40px serif';// 设置字体大小
|
|
108
|
+
this.context.textAlign = "left";
|
|
109
|
+
this.context.textBaseline = "top";
|
|
110
|
+
this.context.fillText(this._config.title, 250, 72);
|
|
111
|
+
|
|
112
|
+
let textPos = new Vector2(250, 150);
|
|
113
|
+
let maxWidth = 530;
|
|
114
|
+
// 绘制内容
|
|
115
|
+
this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
|
|
116
|
+
this.context.fillStyle = color;
|
|
117
|
+
this.context.font = `${size}px serif`;// 设置字体大小
|
|
118
|
+
this.context.textAlign = "left";
|
|
119
|
+
this.context.textBaseline = "top";
|
|
120
|
+
|
|
121
|
+
// 字符分隔为数组
|
|
122
|
+
var arrText = text.split('');
|
|
123
|
+
var line = '';
|
|
124
|
+
|
|
125
|
+
// 文字自动换行计算
|
|
126
|
+
for (var n = 0; n < arrText.length; n++) {
|
|
127
|
+
var metrics = this.context.measureText(line + arrText[n]);
|
|
128
|
+
var testWidth = metrics.width;
|
|
129
|
+
if ((testWidth > maxWidth && n > 0) || arrText[n] === "\n") {
|
|
130
|
+
this.context.fillText(line, textPos.x, textPos.y);
|
|
131
|
+
line = "";
|
|
132
|
+
textPos.y += size;
|
|
133
|
+
} else {
|
|
134
|
+
line += arrText[n];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this.context.fillText(line, textPos.x, textPos.y);
|
|
139
|
+
textPos.y += size;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
this.texture.needsUpdate = true;
|
|
143
|
+
|
|
144
|
+
this.dispatchEvent({ type: "loaded" });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
//鼠标拾取计算
|
|
148
|
+
raycast(raycaster: Raycaster, intersects: Intersection[]) {
|
|
149
|
+
|
|
150
|
+
let intersect: Intersection[] = [];
|
|
151
|
+
super.raycast(raycaster, intersect);
|
|
152
|
+
let inte = intersect[0];
|
|
153
|
+
if (inte && (inte.uv!.x > 0.22 && inte.uv!.x < 0.78) && (inte.uv!.y > 0.54 && inte.uv!.y < 0.94)) {
|
|
154
|
+
intersects.push(inte);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./SpriteModal1";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./SpriteModal1";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./SpriteModal1";
|
|
Binary file
|