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.
- package/README.md +1 -0
- package/index.js +1 -37
- package/index.ts +1 -61
- package/package.json +4 -4
- package/lib/ApngTexture.d.ts +0 -13
- package/lib/ApngTexture.js +0 -61
- package/lib/ApngTexture.ts +0 -91
- package/lib/ApngTextureManage.d.ts +0 -18
- package/lib/ApngTextureManage.js +0 -87
- package/lib/ApngTextureManage.ts +0 -130
- package/lib/EventMesh.d.ts +0 -18
- package/lib/EventMesh.js +0 -59
- package/lib/EventMesh.ts +0 -79
- package/lib/ExtrudeMesh.d.ts +0 -111
- package/lib/ExtrudeMesh.js +0 -363
- package/lib/ExtrudeMesh.ts +0 -571
- package/lib/FPScontrol.d.ts +0 -44
- package/lib/FPScontrol.js +0 -170
- package/lib/FPScontrol.ts +0 -209
- package/lib/InstancedGroupMesh.d.ts +0 -10
- package/lib/InstancedGroupMesh.js +0 -63
- package/lib/InstancedGroupMesh.ts +0 -80
- package/lib/KeyFrameAnimation.d.ts +0 -25
- package/lib/KeyFrameAnimation.js +0 -78
- package/lib/KeyFrameAnimation.ts +0 -122
- package/lib/PlaneText.d.ts +0 -37
- package/lib/PlaneText.js +0 -30
- package/lib/PlaneText.ts +0 -58
- package/lib/PlaneWithHtml.d.ts +0 -11
- package/lib/PlaneWithHtml.js +0 -67
- package/lib/PlaneWithHtml.ts +0 -84
- package/lib/PointLight/PointLight.d.ts +0 -13
- package/lib/PointLight/PointLight.js +0 -63
- package/lib/PointLight/PointLight.ts +0 -74
- package/lib/PointLight/pointLight_map.png +0 -0
- package/lib/Sky/Sky.d.ts +0 -13
- package/lib/Sky/Sky.js +0 -28
- package/lib/Sky/Sky.ts +0 -36
- package/lib/Sky/bluesky.jpg +0 -0
- package/lib/SpriteText.d.ts +0 -45
- package/lib/SpriteText.js +0 -162
- package/lib/SpriteText.ts +0 -189
- package/lib/SpriteText2.d.ts +0 -47
- package/lib/SpriteText2.js +0 -197
- package/lib/SpriteText2.ts +0 -236
- package/lib/Text3D/Text3D.d.ts +0 -20
- package/lib/Text3D/Text3D.js +0 -61
- package/lib/Text3D/Text3D.ts +0 -92
- package/lib/Text3D/fontController.d.ts +0 -59
- package/lib/Text3D/fontController.js +0 -200
- package/lib/Text3D/fontController.ts +0 -285
- package/lib/Text3D/gentilis.json +0 -811
- package/lib/ThreeBase.d.ts +0 -59
- package/lib/ThreeBase.js +0 -395
- package/lib/ThreeBase.ts +0 -475
- package/lib/ThreeMouse.d.ts +0 -39
- package/lib/ThreeMouse.js +0 -357
- package/lib/ThreeMouse.ts +0 -464
- package/lib/Transition.d.ts +0 -43
- package/lib/Transition.js +0 -196
- package/lib/Transition.ts +0 -268
- package/lib/index.d.ts +0 -22
- package/lib/keyContorls.d.ts +0 -25
- package/lib/keyContorls.js +0 -98
- package/lib/keyContorls.ts +0 -127
- package/lib/planeModal1/PlaneModal1.d.ts +0 -31
- package/lib/planeModal1/PlaneModal1.js +0 -104
- package/lib/planeModal1/PlaneModal1.ts +0 -150
- package/lib/planeModal1/planeModal.png +0 -0
- package/lib/shaders.d.ts +0 -17
- package/lib/shaders.js +0 -245
- package/lib/shaders.ts +0 -264
- package/lib/spriteModal1/SpriteModal1.d.ts +0 -30
- package/lib/spriteModal1/SpriteModal1.js +0 -109
- package/lib/spriteModal1/SpriteModal1.ts +0 -159
- package/lib/spriteModal1/spriteModal1.png +0 -0
- package/lib/stroke_pass/FullScreenQuad.d.ts +0 -7
- package/lib/stroke_pass/FullScreenQuad.js +0 -25
- package/lib/stroke_pass/FullScreenQuad.ts +0 -33
- package/lib/stroke_pass/stroke_pass.d.ts +0 -2
- package/lib/stroke_pass/stroke_pass.js +0 -190
- package/lib/stroke_pass/stroke_pass.ts +0 -211
- package/lib/threeLoader.d.ts +0 -20
- package/lib/threeLoader.js +0 -110
- package/lib/threeLoader.ts +0 -136
- package/lib/threeUtils.d.ts +0 -41
- package/lib/threeUtils.js +0 -179
- package/lib/threeUtils.ts +0 -212
- package/lib/type.d.ts +0 -0
- package/lib/type.js +0 -10
- package/lib/type.ts +0 -13
|
@@ -1,109 +0,0 @@
|
|
|
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, CanvasTexture, Vector2 } from "three";
|
|
8
|
-
import spriteModal1PNG from "./spriteModal1.png";
|
|
9
|
-
// sprit弹窗1
|
|
10
|
-
export default class SpritModal1 extends Sprite {
|
|
11
|
-
constructor(config = {}) {
|
|
12
|
-
super();
|
|
13
|
-
this.updata(config);
|
|
14
|
-
this.material.map = this.texture;
|
|
15
|
-
this.material.transparent = true;
|
|
16
|
-
this.material.alphaTest = 0.01;
|
|
17
|
-
}
|
|
18
|
-
// 背景图
|
|
19
|
-
static img = (() => {
|
|
20
|
-
const img = new Image();
|
|
21
|
-
img.src = spriteModal1PNG;
|
|
22
|
-
return img;
|
|
23
|
-
})();
|
|
24
|
-
canvas = (() => {
|
|
25
|
-
const canvas = document.createElement("canvas");
|
|
26
|
-
canvas.width = 1024;
|
|
27
|
-
canvas.height = 1024;
|
|
28
|
-
return canvas;
|
|
29
|
-
})();
|
|
30
|
-
context = this.canvas.getContext("2d");
|
|
31
|
-
texture = new CanvasTexture(this.canvas);
|
|
32
|
-
// 配置
|
|
33
|
-
_config = {
|
|
34
|
-
size: 10,
|
|
35
|
-
title: "SpritModal1",
|
|
36
|
-
titleColor: "#ffffff",
|
|
37
|
-
texts: []
|
|
38
|
-
// [
|
|
39
|
-
// {
|
|
40
|
-
// text: "1",
|
|
41
|
-
// color: "#ffff00",
|
|
42
|
-
// size: 40
|
|
43
|
-
// },
|
|
44
|
-
// {
|
|
45
|
-
// text: "2",
|
|
46
|
-
// color: "#ff00ff",
|
|
47
|
-
// size: 40
|
|
48
|
-
// },
|
|
49
|
-
// ]
|
|
50
|
-
};
|
|
51
|
-
async updata(config) {
|
|
52
|
-
Object.assign(this._config, config);
|
|
53
|
-
//绘制背景
|
|
54
|
-
this.context.clearRect(0, 0, 1024, 1024);
|
|
55
|
-
while (!SpritModal1.img.complete) {
|
|
56
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
57
|
-
}
|
|
58
|
-
// 设置大小
|
|
59
|
-
this.scale.set(this._config.size, this._config.size, this._config.size);
|
|
60
|
-
// this.context.fillStyle = "#00000088";
|
|
61
|
-
// this.context.fillRect(0, 0, 1024, 1024);
|
|
62
|
-
//绘制背景
|
|
63
|
-
this.context.drawImage(SpritModal1.img, 186, 0);
|
|
64
|
-
// 绘制标题
|
|
65
|
-
this.context.fillStyle = this._config.titleColor;
|
|
66
|
-
this.context.font = '40px serif'; // 设置字体大小
|
|
67
|
-
this.context.textAlign = "left";
|
|
68
|
-
this.context.textBaseline = "top";
|
|
69
|
-
this.context.fillText(this._config.title, 250, 72);
|
|
70
|
-
let textPos = new Vector2(250, 150);
|
|
71
|
-
let maxWidth = 530;
|
|
72
|
-
// 绘制内容
|
|
73
|
-
this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
|
|
74
|
-
this.context.fillStyle = color;
|
|
75
|
-
this.context.font = `${size}px serif`; // 设置字体大小
|
|
76
|
-
this.context.textAlign = "left";
|
|
77
|
-
this.context.textBaseline = "top";
|
|
78
|
-
// 字符分隔为数组
|
|
79
|
-
var arrText = text.split('');
|
|
80
|
-
var line = '';
|
|
81
|
-
// 文字自动换行计算
|
|
82
|
-
for (var n = 0; n < arrText.length; n++) {
|
|
83
|
-
var metrics = this.context.measureText(line + arrText[n]);
|
|
84
|
-
var testWidth = metrics.width;
|
|
85
|
-
if ((testWidth > maxWidth && n > 0) || arrText[n] === "\n") {
|
|
86
|
-
this.context.fillText(line, textPos.x, textPos.y);
|
|
87
|
-
line = "";
|
|
88
|
-
textPos.y += size;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
line += arrText[n];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
this.context.fillText(line, textPos.x, textPos.y);
|
|
95
|
-
textPos.y += size;
|
|
96
|
-
});
|
|
97
|
-
this.texture.needsUpdate = true;
|
|
98
|
-
this.dispatchEvent({ type: "loaded" });
|
|
99
|
-
}
|
|
100
|
-
//鼠标拾取计算
|
|
101
|
-
raycast(raycaster, intersects) {
|
|
102
|
-
let intersect = [];
|
|
103
|
-
super.raycast(raycaster, intersect);
|
|
104
|
-
let inte = intersect[0];
|
|
105
|
-
if (inte && (inte.uv.x > 0.22 && inte.uv.x < 0.78) && (inte.uv.y > 0.54 && inte.uv.y < 0.94)) {
|
|
106
|
-
intersects.push(inte);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
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
|
-
|
|
15
|
-
export type SpritModal1Config = {
|
|
16
|
-
size?: number,
|
|
17
|
-
title?: string,
|
|
18
|
-
titleColor?: string,
|
|
19
|
-
texts?: Array<{
|
|
20
|
-
text?: string,
|
|
21
|
-
color?: string,
|
|
22
|
-
size?: number
|
|
23
|
-
}>
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// sprit弹窗1
|
|
27
|
-
export default class SpritModal1 extends Sprite {
|
|
28
|
-
|
|
29
|
-
constructor(config: SpritModal1Config = {}) {
|
|
30
|
-
super();
|
|
31
|
-
this.updata(config);
|
|
32
|
-
this.material.map = this.texture;
|
|
33
|
-
this.material.transparent = true;
|
|
34
|
-
this.material.alphaTest = 0.01;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 背景图
|
|
38
|
-
static img = (() => {
|
|
39
|
-
const img = new Image();
|
|
40
|
-
img.src = spriteModal1PNG;
|
|
41
|
-
return img;
|
|
42
|
-
})();
|
|
43
|
-
|
|
44
|
-
canvas = (() => {
|
|
45
|
-
const canvas = document.createElement("canvas");
|
|
46
|
-
canvas.width = 1024;
|
|
47
|
-
canvas.height = 1024;
|
|
48
|
-
return canvas;
|
|
49
|
-
})();
|
|
50
|
-
|
|
51
|
-
context = this.canvas.getContext("2d")!;
|
|
52
|
-
|
|
53
|
-
texture = new CanvasTexture(this.canvas);
|
|
54
|
-
|
|
55
|
-
// 配置
|
|
56
|
-
_config: {
|
|
57
|
-
size: number,
|
|
58
|
-
title: string,
|
|
59
|
-
titleColor: string,
|
|
60
|
-
texts: Array<{
|
|
61
|
-
text: string,
|
|
62
|
-
color: string,
|
|
63
|
-
size: number
|
|
64
|
-
}>
|
|
65
|
-
} = {
|
|
66
|
-
size: 10,
|
|
67
|
-
title: "SpritModal1",
|
|
68
|
-
titleColor: "#ffffff",
|
|
69
|
-
texts: []
|
|
70
|
-
// [
|
|
71
|
-
// {
|
|
72
|
-
// text: "1",
|
|
73
|
-
// color: "#ffff00",
|
|
74
|
-
// size: 40
|
|
75
|
-
// },
|
|
76
|
-
// {
|
|
77
|
-
// text: "2",
|
|
78
|
-
// color: "#ff00ff",
|
|
79
|
-
// size: 40
|
|
80
|
-
// },
|
|
81
|
-
// ]
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async updata(config: SpritModal1Config) {
|
|
85
|
-
|
|
86
|
-
Object.assign(this._config, config)
|
|
87
|
-
|
|
88
|
-
//绘制背景
|
|
89
|
-
this.context.clearRect(0, 0, 1024, 1024);
|
|
90
|
-
|
|
91
|
-
while (!SpritModal1.img.complete) {
|
|
92
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// 设置大小
|
|
96
|
-
this.scale.set(this._config.size, this._config.size, this._config.size);
|
|
97
|
-
|
|
98
|
-
// this.context.fillStyle = "#00000088";
|
|
99
|
-
// this.context.fillRect(0, 0, 1024, 1024);
|
|
100
|
-
|
|
101
|
-
//绘制背景
|
|
102
|
-
this.context.drawImage(SpritModal1.img, 186, 0);
|
|
103
|
-
|
|
104
|
-
// 绘制标题
|
|
105
|
-
this.context.fillStyle = this._config.titleColor;
|
|
106
|
-
this.context.font = '40px serif';// 设置字体大小
|
|
107
|
-
this.context.textAlign = "left";
|
|
108
|
-
this.context.textBaseline = "top";
|
|
109
|
-
this.context.fillText(this._config.title, 250, 72);
|
|
110
|
-
|
|
111
|
-
let textPos = new Vector2(250, 150);
|
|
112
|
-
let maxWidth = 530;
|
|
113
|
-
// 绘制内容
|
|
114
|
-
this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
|
|
115
|
-
this.context.fillStyle = color;
|
|
116
|
-
this.context.font = `${size}px serif`;// 设置字体大小
|
|
117
|
-
this.context.textAlign = "left";
|
|
118
|
-
this.context.textBaseline = "top";
|
|
119
|
-
|
|
120
|
-
// 字符分隔为数组
|
|
121
|
-
var arrText = text.split('');
|
|
122
|
-
var line = '';
|
|
123
|
-
|
|
124
|
-
// 文字自动换行计算
|
|
125
|
-
for (var n = 0; n < arrText.length; n++) {
|
|
126
|
-
var metrics = this.context.measureText(line + arrText[n]);
|
|
127
|
-
var testWidth = metrics.width;
|
|
128
|
-
if ((testWidth > maxWidth && n > 0) || arrText[n] === "\n") {
|
|
129
|
-
this.context.fillText(line, textPos.x, textPos.y);
|
|
130
|
-
line = "";
|
|
131
|
-
textPos.y += size;
|
|
132
|
-
} else {
|
|
133
|
-
line += arrText[n];
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
this.context.fillText(line, textPos.x, textPos.y);
|
|
138
|
-
textPos.y += size;
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
this.texture.needsUpdate = true;
|
|
142
|
-
|
|
143
|
-
this.dispatchEvent({ type: "loaded" });
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
//鼠标拾取计算
|
|
147
|
-
raycast(raycaster: Raycaster, intersects: Intersection[]) {
|
|
148
|
-
|
|
149
|
-
let intersect: Intersection[] = [];
|
|
150
|
-
super.raycast(raycaster, intersect);
|
|
151
|
-
let inte = intersect[0];
|
|
152
|
-
if (inte && (inte.uv!.x > 0.22 && inte.uv!.x < 0.78) && (inte.uv!.y > 0.54 && inte.uv!.y < 0.94)) {
|
|
153
|
-
intersects.push(inte);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
Binary file
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
import { BufferGeometry, Float32BufferAttribute, Material, Mesh, MeshBasicMaterial, OrthographicCamera, Scene, WebGLRenderer } from "three";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export default class FullScreenQuad extends Scene {
|
|
13
|
-
constructor() {
|
|
14
|
-
super();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
mesh = (() => {
|
|
18
|
-
const geometry = new BufferGeometry();
|
|
19
|
-
geometry.setAttribute("position", new Float32BufferAttribute([- 1, 3, 0, - 1, - 1, 0, 3, - 1, 0], 3));
|
|
20
|
-
geometry.setAttribute("uv", new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2));
|
|
21
|
-
const mesh = new Mesh<BufferGeometry, Material>(geometry, new MeshBasicMaterial());
|
|
22
|
-
this.add(mesh);
|
|
23
|
-
return mesh;
|
|
24
|
-
})();
|
|
25
|
-
|
|
26
|
-
orthographicCamera = new OrthographicCamera(- 1, 1, 1, - 1, 0, 1);
|
|
27
|
-
|
|
28
|
-
render(renderer: WebGLRenderer, material: Material) {
|
|
29
|
-
this.mesh.material = material;
|
|
30
|
-
renderer.render(this, this.orthographicCamera);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2023-05-09 00:35:17
|
|
4
|
-
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-05-09 02:33:28
|
|
6
|
-
*/
|
|
7
|
-
import { LinearFilter, RGBAFormat, Vector2, WebGLRenderTarget, NoBlending, Scene, RawShaderMaterial, Color, NormalBlending } from "three";
|
|
8
|
-
import FullScreenQuad from "./FullScreenQuad";
|
|
9
|
-
// 选中对象的纹理
|
|
10
|
-
const selectTextureTarget = new WebGLRenderTarget(512, 512, { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat });
|
|
11
|
-
// 由于不能同时读写自己的纹理
|
|
12
|
-
const blur1TextureTarget = new WebGLRenderTarget(512, 512, { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat });
|
|
13
|
-
// 所以需要用2个模糊纹理相互读写
|
|
14
|
-
const blur2TextureTarget = new WebGLRenderTarget(512, 512, { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat });
|
|
15
|
-
const size = new Vector2();
|
|
16
|
-
// 创建一个渲染工具 用于处理纹理
|
|
17
|
-
const fsQuad = new FullScreenQuad(); // 渲染辅助器
|
|
18
|
-
// 描边着色器
|
|
19
|
-
const blurShader = new RawShaderMaterial({
|
|
20
|
-
uniforms: {
|
|
21
|
-
tDiffuse: { value: null },
|
|
22
|
-
color: { value: new Color("#0f0") },
|
|
23
|
-
width: { value: 1.0 },
|
|
24
|
-
opacity: { value: 1.0 },
|
|
25
|
-
resolution: { value: new Vector2(1 / 512, 1 / 512) },
|
|
26
|
-
offset: {
|
|
27
|
-
value: [
|
|
28
|
-
new Vector2(0.000, 1.000),
|
|
29
|
-
new Vector2(0.259, 0.966),
|
|
30
|
-
new Vector2(0.500, 0.866),
|
|
31
|
-
new Vector2(0.707, 0.707),
|
|
32
|
-
new Vector2(0.866, 0.500),
|
|
33
|
-
new Vector2(0.966, 0.259),
|
|
34
|
-
new Vector2(1.000, 0.000),
|
|
35
|
-
new Vector2(0.966, -0.259),
|
|
36
|
-
new Vector2(0.866, -0.500),
|
|
37
|
-
new Vector2(0.707, -0.707),
|
|
38
|
-
new Vector2(0.500, -0.866),
|
|
39
|
-
new Vector2(0.259, -0.966),
|
|
40
|
-
new Vector2(0.000, -1.000),
|
|
41
|
-
new Vector2(-0.259, -0.966),
|
|
42
|
-
new Vector2(-0.500, -0.866),
|
|
43
|
-
new Vector2(-0.707, -0.707),
|
|
44
|
-
new Vector2(-0.866, -0.500),
|
|
45
|
-
new Vector2(-0.966, -0.259),
|
|
46
|
-
new Vector2(-1.000, -0.000),
|
|
47
|
-
new Vector2(-0.966, 0.259),
|
|
48
|
-
new Vector2(-0.866, 0.500),
|
|
49
|
-
new Vector2(-0.707, 0.707),
|
|
50
|
-
new Vector2(-0.500, 0.866),
|
|
51
|
-
new Vector2(-0.259, 0.966)
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
vertexShader: `
|
|
56
|
-
attribute vec3 position;
|
|
57
|
-
attribute vec2 uv;
|
|
58
|
-
varying vec2 vUv;
|
|
59
|
-
void main() {
|
|
60
|
-
vUv = uv;
|
|
61
|
-
gl_Position = vec4(position, 1.0);
|
|
62
|
-
}`,
|
|
63
|
-
fragmentShader: `
|
|
64
|
-
#ifdef GL_ES
|
|
65
|
-
precision highp float;
|
|
66
|
-
#endif
|
|
67
|
-
uniform sampler2D tDiffuse;
|
|
68
|
-
uniform vec3 color;
|
|
69
|
-
uniform float width;
|
|
70
|
-
uniform float opacity;
|
|
71
|
-
uniform vec2 resolution;
|
|
72
|
-
uniform vec2 offset[24];
|
|
73
|
-
varying vec2 vUv;
|
|
74
|
-
vec2 piexl = resolution * width; // 描边厚度
|
|
75
|
-
|
|
76
|
-
vec4 stroke(){
|
|
77
|
-
vec4 blurColor = vec4(0.0);
|
|
78
|
-
vec4 Color = vec4(0.0);
|
|
79
|
-
int vSum = 0; // 周围像素点中和 visibleColor 相似的数量
|
|
80
|
-
for (int i = 0; i < 24; i++ ) {
|
|
81
|
-
Color = texture2D(tDiffuse, vUv + (offset[i] * piexl));
|
|
82
|
-
if (Color.a > 0.0) {
|
|
83
|
-
blurColor += Color;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (blurColor.a < 0.001) {
|
|
87
|
-
return vec4(0.0);
|
|
88
|
-
} else {
|
|
89
|
-
return vec4(color, opacity);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
void main() {
|
|
93
|
-
vec4 Color = texture2D(tDiffuse, vUv);
|
|
94
|
-
if (Color.a > 0.0 || width == 0.0) {
|
|
95
|
-
gl_FragColor = Color;
|
|
96
|
-
} else {
|
|
97
|
-
gl_FragColor = stroke();
|
|
98
|
-
}
|
|
99
|
-
}`,
|
|
100
|
-
blending: NoBlending,
|
|
101
|
-
depthTest: false,
|
|
102
|
-
depthWrite: false,
|
|
103
|
-
transparent: true
|
|
104
|
-
});
|
|
105
|
-
// 过滤着色器
|
|
106
|
-
const filterSelectShader = new RawShaderMaterial({
|
|
107
|
-
uniforms: {
|
|
108
|
-
selectTexture: { value: null },
|
|
109
|
-
blurTexture: { value: null }
|
|
110
|
-
},
|
|
111
|
-
vertexShader: `
|
|
112
|
-
attribute vec3 position;
|
|
113
|
-
attribute vec2 uv;
|
|
114
|
-
varying vec2 vUv;
|
|
115
|
-
void main() {
|
|
116
|
-
vUv = uv;
|
|
117
|
-
gl_Position = vec4(position, 1.0);
|
|
118
|
-
}
|
|
119
|
-
`,
|
|
120
|
-
fragmentShader: `
|
|
121
|
-
#ifdef GL_ES
|
|
122
|
-
precision highp float;
|
|
123
|
-
#endif
|
|
124
|
-
uniform sampler2D selectTexture;
|
|
125
|
-
uniform sampler2D blurTexture;
|
|
126
|
-
varying vec2 vUv;
|
|
127
|
-
|
|
128
|
-
void main() {
|
|
129
|
-
gl_FragColor = texture2D(blurTexture, vUv);
|
|
130
|
-
gl_FragColor.a -= (texture2D(selectTexture, vUv).a);
|
|
131
|
-
}
|
|
132
|
-
`,
|
|
133
|
-
blending: NoBlending,
|
|
134
|
-
depthTest: false,
|
|
135
|
-
depthWrite: false,
|
|
136
|
-
transparent: true
|
|
137
|
-
});
|
|
138
|
-
// 场景对象
|
|
139
|
-
const scene = new Scene();
|
|
140
|
-
// 对象描边
|
|
141
|
-
export default function stroke_pass(renderer, camera, object3d) {
|
|
142
|
-
const { stroke_enable = false, stroke_color = "#04fa12", stroke_width = 1 } = object3d.userData;
|
|
143
|
-
if (!stroke_enable) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
// 保存原帧缓冲区
|
|
147
|
-
const originRenderTarget = renderer.getRenderTarget();
|
|
148
|
-
// 设置选中目标的帧缓冲区
|
|
149
|
-
renderer.getSize(size);
|
|
150
|
-
selectTextureTarget.setSize(size.x, size.y);
|
|
151
|
-
blur1TextureTarget.setSize(size.x, size.y);
|
|
152
|
-
blur2TextureTarget.setSize(size.x, size.y);
|
|
153
|
-
renderer.setRenderTarget(selectTextureTarget);
|
|
154
|
-
scene.children = [object3d];
|
|
155
|
-
renderer.clear();
|
|
156
|
-
renderer.render(object3d, camera);
|
|
157
|
-
// 设置描边着色器的分辨率
|
|
158
|
-
blurShader.uniforms.resolution.value.set(1 / size.x, 1 / size.y);
|
|
159
|
-
//描边颜色
|
|
160
|
-
blurShader.uniforms.color.value.set(stroke_color);
|
|
161
|
-
blurShader.uniforms.width.value = stroke_width / 4;
|
|
162
|
-
//一次描边
|
|
163
|
-
renderer.setRenderTarget(blur1TextureTarget);
|
|
164
|
-
blurShader.uniforms.tDiffuse.value = selectTextureTarget.texture;
|
|
165
|
-
fsQuad.render(renderer, blurShader);
|
|
166
|
-
//二次描边
|
|
167
|
-
renderer.setRenderTarget(blur2TextureTarget);
|
|
168
|
-
blurShader.uniforms.tDiffuse.value = blur1TextureTarget.texture;
|
|
169
|
-
fsQuad.render(renderer, blurShader);
|
|
170
|
-
//三次描边
|
|
171
|
-
renderer.setRenderTarget(blur1TextureTarget);
|
|
172
|
-
blurShader.uniforms.tDiffuse.value = blur2TextureTarget.texture;
|
|
173
|
-
fsQuad.render(renderer, blurShader);
|
|
174
|
-
//四次描边
|
|
175
|
-
renderer.setRenderTarget(blur2TextureTarget);
|
|
176
|
-
blurShader.uniforms.tDiffuse.value = blur1TextureTarget.texture;
|
|
177
|
-
fsQuad.render(renderer, blurShader);
|
|
178
|
-
// 还原帧缓冲区 减去原始纹理保留描边
|
|
179
|
-
renderer.setRenderTarget(originRenderTarget);
|
|
180
|
-
filterSelectShader.uniforms.selectTexture.value = selectTextureTarget.texture;
|
|
181
|
-
filterSelectShader.uniforms.blurTexture.value = blur2TextureTarget.texture;
|
|
182
|
-
filterSelectShader.blending = NormalBlending; // 与有的纹理融合计算 保留前面通道传递下来的纹理
|
|
183
|
-
fsQuad.render(renderer, filterSelectShader);
|
|
184
|
-
// 调试代码
|
|
185
|
-
// renderer.setRenderTarget(null);
|
|
186
|
-
// renderer.clearDepth();
|
|
187
|
-
// copyShader.uniforms.tDiffuse.value = blur2TextureTarget.texture;
|
|
188
|
-
// fsQuad.render(renderer, copyShader);
|
|
189
|
-
// return;
|
|
190
|
-
}
|