three-base 0.0.1 → 1.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 -2
- package/lib/ApngTexture.ts +91 -0
- package/lib/ApngTextureManage.ts +130 -0
- package/lib/EventMesh.ts +79 -0
- package/lib/ExtrudeMesh.ts +569 -0
- package/lib/FPScontrol.ts +209 -0
- package/lib/PointLight.ts +78 -0
- package/lib/ThreeBasic.ts +399 -0
- package/lib/ThreeMouse.ts +464 -0
- package/lib/Transition.ts +256 -0
- package/lib/draco/README.md +32 -0
- package/lib/draco/draco_decoder.js +52 -0
- package/lib/draco/draco_decoder.wasm +0 -0
- package/lib/draco/draco_encoder.js +33 -0
- package/lib/draco/draco_wasm_wrapper.js +104 -0
- package/lib/index.ts +30 -112
- package/lib/keyContorls.ts +127 -0
- package/lib/shaders.ts +264 -0
- package/lib/text/Text2D.ts +63 -0
- package/lib/text/Text3D.ts +20 -0
- package/lib/threeLoader.ts +119 -0
- package/lib/threeUtils.ts +84 -0
- package/lib/type.ts +11 -0
- package/package.json +45 -27
- package/.gitattributes +0 -2
- package/.github/workflows/npm-publish.yml +0 -22
- package/LICENSE +0 -21
- package/example/index.html +0 -27
- package/example/index.js +0 -0
- package/tsconfig.json +0 -11
package/lib/shaders.ts
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-03-24 16:38:35
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2022-04-02 18:28:38
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { BufferGeometry, Color, Float32BufferAttribute, Mesh, NoBlending, OrthographicCamera, ShaderChunk, ShaderMaterial, Vector2, WebGLRenderer } from "three";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// https://github.com/mrdoob/three.js/pull/21358
|
|
13
|
+
|
|
14
|
+
const _geometry = new BufferGeometry();
|
|
15
|
+
_geometry.setAttribute("position", new Float32BufferAttribute([- 1, 3, 0, - 1, - 1, 0, 3, - 1, 0], 3));
|
|
16
|
+
_geometry.setAttribute("uv", new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2));
|
|
17
|
+
|
|
18
|
+
class FullScreenQuad {
|
|
19
|
+
constructor() {
|
|
20
|
+
this._mesh = new Mesh(_geometry);
|
|
21
|
+
}
|
|
22
|
+
_mesh!: Mesh;
|
|
23
|
+
dispose() {
|
|
24
|
+
this._mesh.geometry.dispose();
|
|
25
|
+
}
|
|
26
|
+
render(renderer: WebGLRenderer) {
|
|
27
|
+
renderer.render(this._mesh, orthographicCamera);
|
|
28
|
+
}
|
|
29
|
+
get material() {
|
|
30
|
+
return this._mesh.material;
|
|
31
|
+
}
|
|
32
|
+
set material(value) {
|
|
33
|
+
this._mesh.material = value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// 常用着色器及工具
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// 全屏渲染模型
|
|
42
|
+
export const fullScreenMesh = new FullScreenQuad();
|
|
43
|
+
|
|
44
|
+
export const orthographicCamera = new OrthographicCamera(- 1, 1, 1, - 1, 0, 1);
|
|
45
|
+
|
|
46
|
+
// 清理着色器
|
|
47
|
+
export const clearShader = new ShaderMaterial({
|
|
48
|
+
vertexShader: `
|
|
49
|
+
varying vec2 vUv;
|
|
50
|
+
void main() {
|
|
51
|
+
vUv = uv;
|
|
52
|
+
gl_Position = vec4(position, 1.0);
|
|
53
|
+
}
|
|
54
|
+
`,
|
|
55
|
+
fragmentShader: `
|
|
56
|
+
void main() {
|
|
57
|
+
gl_FragColor = vec4(0.0);
|
|
58
|
+
}
|
|
59
|
+
`,
|
|
60
|
+
blending: NoBlending, // 渲染时不与背景融合计算 直接替换
|
|
61
|
+
depthTest: false,
|
|
62
|
+
depthWrite: false,
|
|
63
|
+
transparent: true
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// 交集着色器提取相同的像素点
|
|
67
|
+
export const intersectionShader = new ShaderMaterial({
|
|
68
|
+
uniforms: {
|
|
69
|
+
map1: { value: null }, // 贴图纹理1
|
|
70
|
+
map2: { value: null }, // 贴图纹理2
|
|
71
|
+
},
|
|
72
|
+
vertexShader: `
|
|
73
|
+
${ShaderChunk.common}
|
|
74
|
+
${ShaderChunk.logdepthbuf_pars_vertex}
|
|
75
|
+
varying vec2 vUv;
|
|
76
|
+
void main() {
|
|
77
|
+
vUv = uv;
|
|
78
|
+
gl_Position = vec4(position, 1.0);
|
|
79
|
+
${ShaderChunk.logdepthbuf_vertex}
|
|
80
|
+
}
|
|
81
|
+
`,
|
|
82
|
+
fragmentShader: `
|
|
83
|
+
${ShaderChunk.logdepthbuf_pars_fragment}
|
|
84
|
+
uniform sampler2D map1;
|
|
85
|
+
uniform sampler2D map2;
|
|
86
|
+
varying vec2 vUv;
|
|
87
|
+
void main() {
|
|
88
|
+
if(texture2D(map1, vUv) == texture2D(map2, vUv)){
|
|
89
|
+
gl_FragColor = texture2D(map1, vUv);
|
|
90
|
+
}else{
|
|
91
|
+
discard;
|
|
92
|
+
}
|
|
93
|
+
${ShaderChunk.logdepthbuf_fragment}
|
|
94
|
+
}
|
|
95
|
+
`,
|
|
96
|
+
blending: NoBlending, // 渲染时不与背景融合计算 直接替换
|
|
97
|
+
depthTest: true,
|
|
98
|
+
depthWrite: true,
|
|
99
|
+
transparent: true
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
// 拷贝着色器
|
|
104
|
+
export const coptyShader = new ShaderMaterial({
|
|
105
|
+
uniforms: {
|
|
106
|
+
map: { value: null }, // 纹理
|
|
107
|
+
opacity: { value: 1.0 } // 透明度
|
|
108
|
+
},
|
|
109
|
+
vertexShader: `
|
|
110
|
+
varying vec2 vUv;
|
|
111
|
+
void main() {
|
|
112
|
+
vUv = uv;
|
|
113
|
+
gl_Position = vec4(position, 1.0);
|
|
114
|
+
}
|
|
115
|
+
`,
|
|
116
|
+
fragmentShader: `
|
|
117
|
+
uniform sampler2D map;
|
|
118
|
+
uniform float opacity;
|
|
119
|
+
varying vec2 vUv;
|
|
120
|
+
void main() {
|
|
121
|
+
|
|
122
|
+
gl_FragColor = texture2D(map, vUv) * opacity;
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
`,
|
|
126
|
+
// blending: NoBlending, // 渲染时不与背景融合计算 直接替换
|
|
127
|
+
depthTest: true,
|
|
128
|
+
depthWrite: true,
|
|
129
|
+
transparent: true,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
// 描边着色器
|
|
134
|
+
export const strokeShader = new ShaderMaterial({
|
|
135
|
+
uniforms: {
|
|
136
|
+
map: { value: null }, // 贴图纹理
|
|
137
|
+
resolution: { value: new Vector2(512, 512) }, // 分辨率
|
|
138
|
+
strokeWidth: { value: 1.0 }, // 描边宽度
|
|
139
|
+
strokeColor: { value: new Color("#B2F2FF") }, // 描边颜色
|
|
140
|
+
opacity: { value: 1.0 } // 透明度
|
|
141
|
+
},
|
|
142
|
+
vertexShader: `
|
|
143
|
+
varying vec2 vUv;
|
|
144
|
+
void main() {
|
|
145
|
+
vUv = uv;
|
|
146
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
147
|
+
}
|
|
148
|
+
`,
|
|
149
|
+
fragmentShader: `
|
|
150
|
+
uniform sampler2D map;
|
|
151
|
+
uniform vec2 resolution;
|
|
152
|
+
uniform vec3 strokeColor; // 描边颜色
|
|
153
|
+
uniform float strokeWidth; // 描边厚度
|
|
154
|
+
uniform float opacity; // 透明度
|
|
155
|
+
|
|
156
|
+
varying vec2 vUv;
|
|
157
|
+
|
|
158
|
+
// 获取当前叠加vu坐标偏移量的颜色值
|
|
159
|
+
vec4 offsetColor(vec2 vu){
|
|
160
|
+
return texture2D(map, vUv + (vu * (strokeWidth / resolution) ) );
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
vec4 fragColor(){
|
|
164
|
+
|
|
165
|
+
vec4 currentColor = offsetColor(vec2(0.0, 0.0));
|
|
166
|
+
|
|
167
|
+
if(
|
|
168
|
+
currentColor.a < min(0.2, opacity) && (
|
|
169
|
+
offsetColor(vec2(0.0, 1.0)).a > 0.0 ||
|
|
170
|
+
offsetColor(vec2(0.0, -1.0)).a > 0.0 ||
|
|
171
|
+
offsetColor(vec2(1.0, 0.0)).a > 0.0 ||
|
|
172
|
+
offsetColor(vec2(-1.0, 0.0)).a > 0.0 ||
|
|
173
|
+
|
|
174
|
+
offsetColor(vec2(1.0) * 0.7).a > 0.0 ||
|
|
175
|
+
offsetColor(vec2(-1.0) * 0.7).a > 0.0 ||
|
|
176
|
+
offsetColor(vec2(-1.0, 1.0) * 0.7).a > 0.0 ||
|
|
177
|
+
offsetColor(vec2(1.0, -1.0) * 0.7).a > 0.0
|
|
178
|
+
)
|
|
179
|
+
){
|
|
180
|
+
return vec4( strokeColor, opacity);
|
|
181
|
+
}else{
|
|
182
|
+
// discard;
|
|
183
|
+
return offsetColor(vec2(0.0, 0.0));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
void main() {
|
|
189
|
+
gl_FragColor = fragColor();
|
|
190
|
+
}
|
|
191
|
+
`,
|
|
192
|
+
blending: NoBlending, // 渲染时不与背景融合计算 直接替换
|
|
193
|
+
depthTest: true,
|
|
194
|
+
depthWrite: true,
|
|
195
|
+
transparent: true
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
// 高斯模糊着色器 让颜色过渡更自然
|
|
200
|
+
export const gaussBlurShader = new ShaderMaterial({
|
|
201
|
+
uniforms: {
|
|
202
|
+
map: { value: null }, // 纹理
|
|
203
|
+
opacity: { value: 1.0 }, // 透明度
|
|
204
|
+
radius: { value: 3.0 }, // 模糊半径
|
|
205
|
+
resolution: { value: new Vector2(512, 512) }, // 渲染器的分辨率
|
|
206
|
+
},
|
|
207
|
+
vertexShader: `
|
|
208
|
+
varying vec2 vUv;
|
|
209
|
+
void main() {
|
|
210
|
+
vUv = uv;
|
|
211
|
+
gl_Position = vec4(position, 1.0);
|
|
212
|
+
}
|
|
213
|
+
`,
|
|
214
|
+
fragmentShader: `
|
|
215
|
+
uniform sampler2D map;
|
|
216
|
+
uniform float opacity;
|
|
217
|
+
uniform vec2 resolution;
|
|
218
|
+
uniform float radius;
|
|
219
|
+
varying vec2 vUv;
|
|
220
|
+
|
|
221
|
+
vec4 offsetColor( vec2 uv){
|
|
222
|
+
return texture2D(map, vUv + (uv / resolution * radius) );
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
vec4 blurColor(){
|
|
226
|
+
|
|
227
|
+
vec4 leftColor = offsetColor( vec2(-1.0, 0.0) );
|
|
228
|
+
|
|
229
|
+
vec4 rightColor = offsetColor( vec2(1.0, 0.0) );
|
|
230
|
+
|
|
231
|
+
// 左右颜色混合
|
|
232
|
+
vec4 leftRightColor = vec4(
|
|
233
|
+
mix( leftColor.rgb ,rightColor.rgb, rightColor.a / (leftColor.a + rightColor.a)),
|
|
234
|
+
(leftColor.a + rightColor.a) / 2.0
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
vec4 downColor = offsetColor( vec2(0.0, -1.0));
|
|
238
|
+
|
|
239
|
+
vec4 upColor = offsetColor( vec2(0.0, 1.0));
|
|
240
|
+
|
|
241
|
+
// 上下颜色混合
|
|
242
|
+
vec4 upDownColor = vec4(
|
|
243
|
+
mix( downColor.rgb, upColor.rgb, upColor.a / (downColor.a + upColor.a) ),
|
|
244
|
+
(downColor.a + upColor.a) / 2.0
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
vec4 color = vec4(
|
|
248
|
+
mix( leftRightColor.rgb, upDownColor.rgb, upDownColor.a / (leftRightColor.a + upDownColor.a) ),
|
|
249
|
+
(leftRightColor.a + upDownColor.a) / 2.0
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
return color;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
void main() {
|
|
256
|
+
gl_FragColor = blurColor();
|
|
257
|
+
gl_FragColor.a *= opacity;
|
|
258
|
+
}
|
|
259
|
+
`,
|
|
260
|
+
blending: NoBlending, // 渲染时不与背景融合计算
|
|
261
|
+
depthTest: false,
|
|
262
|
+
depthWrite: false,
|
|
263
|
+
transparent: true
|
|
264
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-05-23 13:53:06
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2022-05-23 19:38:24
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { DoubleSide, Mesh, MeshBasicMaterial, PlaneGeometry, Vector3 } from "three";
|
|
9
|
+
import SpriteText from "three-spritetext";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
text?: string;
|
|
15
|
+
textHeight?: number;
|
|
16
|
+
color?: string;
|
|
17
|
+
backgroundColor?: string;
|
|
18
|
+
fontFace?: string;
|
|
19
|
+
fontSize?: number;
|
|
20
|
+
fontWeight?: string;
|
|
21
|
+
padding?: number | [number, number];
|
|
22
|
+
borderWidth?: number;
|
|
23
|
+
borderRadius?: number;
|
|
24
|
+
borderColor?: string;
|
|
25
|
+
strokeWidth?: number;
|
|
26
|
+
strokeColor?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 2d文字
|
|
31
|
+
* @export
|
|
32
|
+
* @class PlaneBtn
|
|
33
|
+
* @extends {Mesh}
|
|
34
|
+
*/
|
|
35
|
+
export default class Text2D extends Mesh {
|
|
36
|
+
|
|
37
|
+
constructor(text: string = "Text2D") {
|
|
38
|
+
super(Text2D.geometry);
|
|
39
|
+
this.set({ text });
|
|
40
|
+
this.material = new MeshBasicMaterial({ transparent: true, side: DoubleSide, map: this.spriteText.material.map });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type = "Text2D";
|
|
44
|
+
|
|
45
|
+
static geometry = new PlaneGeometry(1, 1, 1, 1);
|
|
46
|
+
|
|
47
|
+
spriteText = new SpriteText("");
|
|
48
|
+
|
|
49
|
+
material = new MeshBasicMaterial({ transparent: true, side: DoubleSide, map: this.spriteText.material.map });
|
|
50
|
+
|
|
51
|
+
minScale = new Vector3(0.1, 0.1, 0.1);
|
|
52
|
+
|
|
53
|
+
set(parame: Props) {
|
|
54
|
+
for (let key in parame) {
|
|
55
|
+
//@ts-ignore
|
|
56
|
+
this.spriteText[key] = parame[key];
|
|
57
|
+
}
|
|
58
|
+
this.scale.copy(this.spriteText.scale);
|
|
59
|
+
this.scale.multiplyScalar(0.1);
|
|
60
|
+
this.scale.max(this.minScale);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-06-14 09:48:00
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2022-06-14 10:01:13
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Mesh } from "three";
|
|
9
|
+
|
|
10
|
+
// 三维空间中的3D文字模型
|
|
11
|
+
export default class Text3D extends Mesh {
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-04-07 16:42:26
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-02-07 11:11:48
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { DefaultLoadingManager, EventDispatcher, RepeatWrapping, Texture, TextureLoader } from "three";
|
|
9
|
+
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
|
|
10
|
+
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
|
11
|
+
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
12
|
+
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
|
|
13
|
+
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
|
14
|
+
|
|
15
|
+
// 引入静态资源
|
|
16
|
+
//@ts-ignore
|
|
17
|
+
import dracoWasmWrapperJS from "./draco/draco_wasm_wrapper.js?url";
|
|
18
|
+
//@ts-ignore
|
|
19
|
+
import dracoDecoderJS from "./draco/draco_decoder.js?url";
|
|
20
|
+
//@ts-ignore
|
|
21
|
+
import dracoDecoderWASM from "./draco/draco_decoder.wasm?url";
|
|
22
|
+
|
|
23
|
+
// 加载器
|
|
24
|
+
class ThreeLoader extends EventDispatcher {
|
|
25
|
+
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
|
|
29
|
+
DefaultLoadingManager.onStart = () => {
|
|
30
|
+
this.onload = false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 有资源加载完成时通知渲染器
|
|
34
|
+
DefaultLoadingManager.onProgress = () => {
|
|
35
|
+
this.dispatchEvent({ type: "progress" });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
DefaultLoadingManager.onLoad = () => {
|
|
39
|
+
this.onload = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 各向异性
|
|
44
|
+
anisotropy = 1;
|
|
45
|
+
|
|
46
|
+
// 设置各向异性 由渲染器来调用并设置
|
|
47
|
+
setAnisotropy(v: number) {
|
|
48
|
+
this.anisotropy = v;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// 纹理对向缓存
|
|
52
|
+
textureMap = new Map() as Map<string, Texture>;
|
|
53
|
+
|
|
54
|
+
// 纹理加载器
|
|
55
|
+
textureLoader = new TextureLoader();
|
|
56
|
+
|
|
57
|
+
// 获取地址对应的单例纹理对象
|
|
58
|
+
getTexture(src: string) {
|
|
59
|
+
|
|
60
|
+
let texture = this.textureMap.get(src);
|
|
61
|
+
|
|
62
|
+
if (!texture) {
|
|
63
|
+
texture = this.textureLoader.load(src, tex => {
|
|
64
|
+
tex.image.crossOrigin = "anonymous";
|
|
65
|
+
});
|
|
66
|
+
this.textureMap.set(src, texture);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
texture.wrapS = texture.wrapT = RepeatWrapping;
|
|
70
|
+
|
|
71
|
+
texture.anisotropy = this.anisotropy;
|
|
72
|
+
|
|
73
|
+
return texture as Texture;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// fbx模型加载器
|
|
77
|
+
fbxLoader = new FBXLoader();
|
|
78
|
+
|
|
79
|
+
//obj 加载器
|
|
80
|
+
objLoader = new OBJLoader();
|
|
81
|
+
|
|
82
|
+
// 材质加载器
|
|
83
|
+
mtlLoader = new MTLLoader();
|
|
84
|
+
|
|
85
|
+
// gltf 加载器
|
|
86
|
+
gltfLoader = (() => {
|
|
87
|
+
const loader = new GLTFLoader();
|
|
88
|
+
const dracoLoader = new class ThreePlusDRACOLoader extends DRACOLoader {
|
|
89
|
+
|
|
90
|
+
_loadLibrary(url: string, responseType: string) {
|
|
91
|
+
//@ts-ignore
|
|
92
|
+
let urlConf = (process.env.NODE_ENV === "development") ? {
|
|
93
|
+
"draco_decoder.js": "draco_decoder.js",
|
|
94
|
+
"draco_wasm_wrapper.js": "draco_wasm_wrapper.js",
|
|
95
|
+
"draco_decoder.wasm": "draco_decoder.wasm"
|
|
96
|
+
} : {
|
|
97
|
+
"draco_decoder.js": dracoWasmWrapperJS,
|
|
98
|
+
"draco_wasm_wrapper.js": dracoDecoderJS,
|
|
99
|
+
"draco_decoder.wasm": dracoDecoderWASM
|
|
100
|
+
}
|
|
101
|
+
//@ts-ignore
|
|
102
|
+
return super._loadLibrary(urlConf[url], responseType);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}();
|
|
106
|
+
//@ts-ignore
|
|
107
|
+
dracoLoader.setDecoderPath((process.env.NODE_ENV === "development") ? '/node_modules/three/examples/js/libs/draco/' : '');
|
|
108
|
+
loader.setDRACOLoader(dracoLoader);
|
|
109
|
+
return loader;
|
|
110
|
+
})()
|
|
111
|
+
|
|
112
|
+
// 是否加载完成
|
|
113
|
+
onload = true;
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const threeLoader = new ThreeLoader();
|
|
118
|
+
export default threeLoader;
|
|
119
|
+
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-02-24 22:49:42
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2022-06-21 16:45:33
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Box3, Clock, EventDispatcher, Object3D, Vector3 } from "three";
|
|
9
|
+
|
|
10
|
+
class ThreeUtils extends EventDispatcher {
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
|
|
15
|
+
this.requestAnimationFrame();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
isProd = process.env.NODE_ENV === "production";
|
|
19
|
+
|
|
20
|
+
isDev = process.env.NODE_ENV === "development";
|
|
21
|
+
|
|
22
|
+
timeTemp = performance.now();
|
|
23
|
+
|
|
24
|
+
accumulate = 0;// 事件分发次数
|
|
25
|
+
|
|
26
|
+
box3 = new Box3();
|
|
27
|
+
size = new Vector3();
|
|
28
|
+
center = new Vector3();
|
|
29
|
+
|
|
30
|
+
clock = new Clock();
|
|
31
|
+
|
|
32
|
+
requestAnimationFrame() {
|
|
33
|
+
this.accumulate += 1;
|
|
34
|
+
const timeTemp = this.timeTemp = performance.now();
|
|
35
|
+
this.dispatchEvent({
|
|
36
|
+
type: "requestAnimationFrame",
|
|
37
|
+
timeTemp,
|
|
38
|
+
accumulate: this.accumulate
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
this.requestAnimationFrame();
|
|
43
|
+
}, 45 - this.clock.getDelta());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 获取模型大小
|
|
47
|
+
getSize(object3d: Object3D) {
|
|
48
|
+
this.box3.setFromObject(object3d);
|
|
49
|
+
this.box3.getSize(this.size);
|
|
50
|
+
return this.size;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 模型对齐底面
|
|
54
|
+
alignButton(object3d: Object3D, y = 0) {
|
|
55
|
+
this.box3.setFromObject(object3d);
|
|
56
|
+
this.box3.getCenter(this.center);
|
|
57
|
+
this.box3.getSize(this.size);
|
|
58
|
+
object3d.position.y -= (this.center.y - (this.size.y * 0.5));
|
|
59
|
+
object3d.position.y += y;
|
|
60
|
+
object3d.updateMatrixWorld(true);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 居中对象
|
|
64
|
+
centerObject3D(object3d: Object3D) {
|
|
65
|
+
this.box3.setFromObject(object3d);
|
|
66
|
+
this.box3.getCenter(this.center);
|
|
67
|
+
object3d.position.sub(this.center);
|
|
68
|
+
object3d.updateMatrixWorld(true);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//缩放至指定大小
|
|
72
|
+
scaleTo(object3d: Object3D, size: number = 1) {
|
|
73
|
+
this.box3.setFromObject(object3d);
|
|
74
|
+
this.box3.getSize(this.size);
|
|
75
|
+
const scale = size / Math.max(this.size.x, this.size.y, this.size.z);
|
|
76
|
+
object3d.scale.multiplyScalar(scale);
|
|
77
|
+
object3d.updateMatrixWorld(true);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const threeUtils = new ThreeUtils();
|
|
83
|
+
|
|
84
|
+
export default threeUtils;
|
package/lib/type.ts
ADDED
package/package.json
CHANGED
|
@@ -1,27 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "three-base",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "three 3d three-basic",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"three",
|
|
7
|
+
"3d",
|
|
8
|
+
"three-base",
|
|
9
|
+
"three-basic",
|
|
10
|
+
"xsh"
|
|
11
|
+
],
|
|
12
|
+
"main": "lib/index.ts",
|
|
13
|
+
"module": "lib/index.ts",
|
|
14
|
+
"types": "lib/index.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"declare.d.ts",
|
|
17
|
+
"lib/*.js",
|
|
18
|
+
"lib/*.ts",
|
|
19
|
+
"lib/**/*.ts",
|
|
20
|
+
"lib/**/*.js",
|
|
21
|
+
"lib/**/*.tsx",
|
|
22
|
+
"lib/**/*.css",
|
|
23
|
+
"lib/**/*.jpg",
|
|
24
|
+
"lib/**/*.png",
|
|
25
|
+
"lib/**/*.jpeg",
|
|
26
|
+
"lib/**/*.svg",
|
|
27
|
+
"lib/**/*.obj",
|
|
28
|
+
"lib/**/*.gltf",
|
|
29
|
+
"lib/**/*.fbx",
|
|
30
|
+
"lib/**/*.glb",
|
|
31
|
+
"lib/**/*.json",
|
|
32
|
+
"lib/**/*.wasm"
|
|
33
|
+
],
|
|
34
|
+
"license": "ISC",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/three": "^0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"apng-js": "^1",
|
|
40
|
+
"element-resize-event": "^3",
|
|
41
|
+
"lodash": "^4",
|
|
42
|
+
"three": "^0",
|
|
43
|
+
"three-spritetext": "^1"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/.gitattributes
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
name: Node.js Package
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
publish-npm:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v2
|
|
13
|
-
- uses: actions/setup-node@v2
|
|
14
|
-
with:
|
|
15
|
-
node-version: 14
|
|
16
|
-
registry-url: https://registry.npmjs.org/
|
|
17
|
-
- run: npm install
|
|
18
|
-
- run: npm build
|
|
19
|
-
- run: npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
|
|
20
|
-
- run: npm publish
|
|
21
|
-
env:
|
|
22
|
-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 肛肠科冯主任
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|