three-base 1.129.1 → 1.129.2

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.
Files changed (53) hide show
  1. package/index.js +34 -0
  2. package/index.ts +5 -1
  3. package/lib/{ApngTexture.ts → ApngTexture.js} +11 -41
  4. package/lib/{ApngTextureManage.ts → ApngTextureManage.js} +13 -56
  5. package/lib/EventMesh.js +59 -0
  6. package/lib/{ExtrudeMesh.ts → ExtrudeMesh.js} +77 -284
  7. package/lib/{FPScontrol.ts → FPScontrol.js} +25 -64
  8. package/lib/InstancedGroupMesh.js +63 -0
  9. package/lib/{KeyFrameAnimation.ts → KeyFrameAnimation.js} +19 -63
  10. package/lib/{PlaneText.ts → PlaneText.js} +5 -34
  11. package/lib/{PointLight.ts → PointLight.js} +4 -18
  12. package/lib/Sky/{Sky.ts → Sky.js} +4 -12
  13. package/lib/Text3D/Text3D.js +60 -0
  14. package/lib/Text3D/fontController.js +200 -0
  15. package/lib/Text3D/gentilis.json +811 -0
  16. package/lib/{ThreeBase.ts → ThreeBase.js} +75 -131
  17. package/lib/{ThreeMouse.ts → ThreeMouse.js} +61 -168
  18. package/lib/{Transition.ts → Transition.js} +30 -101
  19. package/lib/index.d.ts +22 -0
  20. package/lib/{keyContorls.ts → keyContorls.js} +11 -40
  21. package/lib/lib/ApngTexture.d.ts +13 -0
  22. package/lib/lib/ApngTextureManage.d.ts +18 -0
  23. package/lib/lib/EventMesh.d.ts +18 -0
  24. package/lib/lib/ExtrudeMesh.d.ts +111 -0
  25. package/lib/lib/FPScontrol.d.ts +44 -0
  26. package/lib/lib/InstancedGroupMesh.d.ts +10 -0
  27. package/lib/lib/KeyFrameAnimation.d.ts +25 -0
  28. package/lib/lib/PlaneText.d.ts +37 -0
  29. package/lib/lib/PointLight.d.ts +13 -0
  30. package/lib/lib/Sky/Sky.d.ts +13 -0
  31. package/lib/lib/Text3D/Text3D.d.ts +20 -0
  32. package/lib/lib/Text3D/fontController.d.ts +59 -0
  33. package/lib/lib/ThreeBase.d.ts +59 -0
  34. package/lib/lib/ThreeMouse.d.ts +39 -0
  35. package/lib/lib/Transition.d.ts +45 -0
  36. package/lib/lib/keyContorls.d.ts +25 -0
  37. package/lib/lib/planeModal1/PlaneModal1.d.ts +32 -0
  38. package/lib/lib/shaders.d.ts +17 -0
  39. package/lib/lib/spriteModal1/SpriteModal1.d.ts +31 -0
  40. package/lib/lib/threeLoader.d.ts +20 -0
  41. package/lib/lib/threeUtils.d.ts +41 -0
  42. package/lib/lib/type.d.ts +0 -0
  43. package/lib/planeModal1/{PlaneModal1.ts → PlaneModal1.js} +33 -77
  44. package/lib/{shaders.ts → shaders.js} +19 -38
  45. package/lib/spriteModal1/{SpriteModal1.ts → SpriteModal1.js} +33 -80
  46. package/lib/{threeLoader.ts → threeLoader.js} +19 -45
  47. package/lib/{threeUtils.ts → threeUtils.js} +81 -82
  48. package/lib/{type.ts → type.js} +1 -4
  49. package/package.json +7 -6
  50. package/lib/EventMesh.ts +0 -79
  51. package/lib/InstancedGroupMesh.ts +0 -80
  52. package/lib/text/Text2D.ts +0 -41
  53. package/lib/text/Text3D.ts +0 -20
@@ -4,26 +4,20 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2022-04-02 18:28:38
6
6
  */
7
-
8
- import { BufferGeometry, Color, Float32BufferAttribute, Mesh, NoBlending, OrthographicCamera, ShaderChunk, ShaderMaterial, Vector2, WebGLRenderer } from "three";
9
-
10
-
11
-
7
+ import { BufferGeometry, Color, Float32BufferAttribute, Mesh, NoBlending, OrthographicCamera, ShaderChunk, ShaderMaterial, Vector2 } from "three";
12
8
  // https://github.com/mrdoob/three.js/pull/21358
13
-
14
9
  const _geometry = new BufferGeometry();
15
- _geometry.setAttribute("position", new Float32BufferAttribute([- 1, 3, 0, - 1, - 1, 0, 3, - 1, 0], 3));
10
+ _geometry.setAttribute("position", new Float32BufferAttribute([-1, 3, 0, -1, -1, 0, 3, -1, 0], 3));
16
11
  _geometry.setAttribute("uv", new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2));
17
-
18
12
  class FullScreenQuad {
19
13
  constructor() {
20
14
  this._mesh = new Mesh(_geometry);
21
15
  }
22
- _mesh!: Mesh;
16
+ _mesh;
23
17
  dispose() {
24
18
  this._mesh.geometry.dispose();
25
19
  }
26
- render(renderer: WebGLRenderer) {
20
+ render(renderer) {
27
21
  renderer.render(this._mesh, orthographicCamera);
28
22
  }
29
23
  get material() {
@@ -33,16 +27,10 @@ class FullScreenQuad {
33
27
  this._mesh.material = value;
34
28
  }
35
29
  }
36
-
37
-
38
30
  // 常用着色器及工具
39
-
40
-
41
31
  // 全屏渲染模型
42
32
  export const fullScreenMesh = new FullScreenQuad();
43
-
44
- export const orthographicCamera = new OrthographicCamera(- 1, 1, 1, - 1, 0, 1);
45
-
33
+ export const orthographicCamera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
46
34
  // 清理着色器
47
35
  export const clearShader = new ShaderMaterial({
48
36
  vertexShader: `
@@ -57,16 +45,15 @@ export const clearShader = new ShaderMaterial({
57
45
  gl_FragColor = vec4(0.0);
58
46
  }
59
47
  `,
60
- blending: NoBlending, // 渲染时不与背景融合计算 直接替换
48
+ blending: NoBlending,
61
49
  depthTest: false,
62
50
  depthWrite: false,
63
51
  transparent: true
64
52
  });
65
-
66
53
  // 交集着色器提取相同的像素点
67
54
  export const intersectionShader = new ShaderMaterial({
68
55
  uniforms: {
69
- map1: { value: null }, // 贴图纹理1
56
+ map1: { value: null },
70
57
  map2: { value: null }, // 贴图纹理2
71
58
  },
72
59
  vertexShader: `
@@ -93,17 +80,15 @@ export const intersectionShader = new ShaderMaterial({
93
80
  ${ShaderChunk.logdepthbuf_fragment}
94
81
  }
95
82
  `,
96
- blending: NoBlending, // 渲染时不与背景融合计算 直接替换
83
+ blending: NoBlending,
97
84
  depthTest: true,
98
85
  depthWrite: true,
99
86
  transparent: true
100
87
  });
101
-
102
-
103
88
  // 拷贝着色器
104
89
  export const coptyShader = new ShaderMaterial({
105
90
  uniforms: {
106
- map: { value: null }, // 纹理
91
+ map: { value: null },
107
92
  opacity: { value: 1.0 } // 透明度
108
93
  },
109
94
  vertexShader: `
@@ -128,15 +113,13 @@ export const coptyShader = new ShaderMaterial({
128
113
  depthWrite: true,
129
114
  transparent: true,
130
115
  });
131
-
132
-
133
116
  // 描边着色器
134
117
  export const strokeShader = new ShaderMaterial({
135
118
  uniforms: {
136
- map: { value: null }, // 贴图纹理
137
- resolution: { value: new Vector2(512, 512) }, // 分辨率
138
- strokeWidth: { value: 1.0 }, // 描边宽度
139
- strokeColor: { value: new Color("#B2F2FF") }, // 描边颜色
119
+ map: { value: null },
120
+ resolution: { value: new Vector2(512, 512) },
121
+ strokeWidth: { value: 1.0 },
122
+ strokeColor: { value: new Color("#B2F2FF") },
140
123
  opacity: { value: 1.0 } // 透明度
141
124
  },
142
125
  vertexShader: `
@@ -189,19 +172,17 @@ export const strokeShader = new ShaderMaterial({
189
172
  gl_FragColor = fragColor();
190
173
  }
191
174
  `,
192
- blending: NoBlending, // 渲染时不与背景融合计算 直接替换
175
+ blending: NoBlending,
193
176
  depthTest: true,
194
177
  depthWrite: true,
195
178
  transparent: true
196
179
  });
197
-
198
-
199
180
  // 高斯模糊着色器 让颜色过渡更自然
200
181
  export const gaussBlurShader = new ShaderMaterial({
201
182
  uniforms: {
202
- map: { value: null }, // 纹理
203
- opacity: { value: 1.0 }, // 透明度
204
- radius: { value: 3.0 }, // 模糊半径
183
+ map: { value: null },
184
+ opacity: { value: 1.0 },
185
+ radius: { value: 3.0 },
205
186
  resolution: { value: new Vector2(512, 512) }, // 渲染器的分辨率
206
187
  },
207
188
  vertexShader: `
@@ -257,8 +238,8 @@ export const gaussBlurShader = new ShaderMaterial({
257
238
  gl_FragColor.a *= opacity;
258
239
  }
259
240
  `,
260
- blending: NoBlending, // 渲染时不与背景融合计算
241
+ blending: NoBlending,
261
242
  depthTest: false,
262
243
  depthWrite: false,
263
244
  transparent: true
264
- });
245
+ });
@@ -4,121 +4,81 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2023-03-08 02:05:25
6
6
  */
7
-
8
-
9
-
10
-
11
-
12
- import { Sprite, CanvasTexture, Vector2, Raycaster, Intersection } from "three";
7
+ import { Sprite, CanvasTexture, Vector2 } from "three";
13
8
  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
9
  // sprit弹窗1
27
10
  export default class SpritModal1 extends Sprite {
28
-
29
- constructor(config: SpritModal1Config = {}) {
11
+ constructor(config = {}) {
30
12
  super();
31
13
  this.updata(config);
32
14
  this.material.map = this.texture;
15
+ this.material.transparent = true;
16
+ this.material.alphaTest = 0.01;
33
17
  }
34
-
18
+ renderOrder = 99;
35
19
  // 背景图
36
20
  static img = (() => {
37
21
  const img = new Image();
38
22
  img.src = spriteModal1PNG;
39
23
  return img;
40
24
  })();
41
-
42
25
  canvas = (() => {
43
26
  const canvas = document.createElement("canvas");
44
27
  canvas.width = 1024;
45
28
  canvas.height = 1024;
46
29
  return canvas;
47
30
  })();
48
-
49
- context = this.canvas.getContext("2d")!;
50
-
31
+ context = this.canvas.getContext("2d");
51
32
  texture = new CanvasTexture(this.canvas);
52
-
53
33
  // 配置
54
- _config: {
55
- size: number,
56
- title: string,
57
- titleColor: string,
58
- texts: Array<{
59
- text: string,
60
- color: string,
61
- size: number
62
- }>
63
- } = {
64
- size: 10,
65
- title: "SpritModal1",
66
- titleColor: "#ffffff",
67
- texts: []
68
- // [
69
- // {
70
- // text: "1",
71
- // color: "#ffff00",
72
- // size: 40
73
- // },
74
- // {
75
- // text: "2",
76
- // color: "#ff00ff",
77
- // size: 40
78
- // },
79
- // ]
80
- }
81
-
82
- async updata(config: SpritModal1Config) {
83
-
84
- Object.assign(this._config, config)
85
-
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);
86
54
  //绘制背景
87
55
  this.context.clearRect(0, 0, 1024, 1024);
88
-
89
56
  while (!SpritModal1.img.complete) {
90
57
  await new Promise(resolve => setTimeout(resolve, 100));
91
58
  }
92
-
93
59
  // 设置大小
94
60
  this.scale.set(this._config.size, this._config.size, this._config.size);
95
-
96
61
  // this.context.fillStyle = "#00000088";
97
62
  // this.context.fillRect(0, 0, 1024, 1024);
98
-
99
63
  //绘制背景
100
64
  this.context.drawImage(SpritModal1.img, 186, 0);
101
-
102
65
  // 绘制标题
103
66
  this.context.fillStyle = this._config.titleColor;
104
- this.context.font = '40px serif';// 设置字体大小
67
+ this.context.font = '40px serif'; // 设置字体大小
105
68
  this.context.textAlign = "left";
106
69
  this.context.textBaseline = "top";
107
70
  this.context.fillText(this._config.title, 250, 72);
108
-
109
71
  let textPos = new Vector2(250, 150);
110
72
  let maxWidth = 530;
111
73
  // 绘制内容
112
74
  this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
113
75
  this.context.fillStyle = color;
114
- this.context.font = `${size}px serif`;// 设置字体大小
76
+ this.context.font = `${size}px serif`; // 设置字体大小
115
77
  this.context.textAlign = "left";
116
78
  this.context.textBaseline = "top";
117
-
118
79
  // 字符分隔为数组
119
80
  var arrText = text.split('');
120
81
  var line = '';
121
-
122
82
  // 文字自动换行计算
123
83
  for (var n = 0; n < arrText.length; n++) {
124
84
  var metrics = this.context.measureText(line + arrText[n]);
@@ -127,30 +87,23 @@ export default class SpritModal1 extends Sprite {
127
87
  this.context.fillText(line, textPos.x, textPos.y);
128
88
  line = "";
129
89
  textPos.y += size;
130
- } else {
90
+ }
91
+ else {
131
92
  line += arrText[n];
132
93
  }
133
94
  }
134
-
135
95
  this.context.fillText(line, textPos.x, textPos.y);
136
96
  textPos.y += size;
137
97
  });
138
-
139
98
  this.texture.needsUpdate = true;
140
-
141
99
  }
142
-
143
100
  //鼠标拾取计算
144
- raycast(raycaster: Raycaster, intersects: Intersection[]) {
145
-
146
- let intersect: Intersection[] = [];
101
+ raycast(raycaster, intersects) {
102
+ let intersect = [];
147
103
  super.raycast(raycaster, intersect);
148
104
  let inte = intersect[0];
149
- if (inte && (inte.uv!.x > 0.22 && inte.uv!.x < 0.78) && (inte.uv!.y > 0.54 && inte.uv!.y < 0.94)) {
105
+ if (inte && (inte.uv.x > 0.22 && inte.uv.x < 0.78) && (inte.uv.y > 0.54 && inte.uv.y < 0.94)) {
150
106
  intersects.push(inte);
151
107
  }
152
-
153
108
  }
154
-
155
109
  }
156
-
@@ -1,17 +1,15 @@
1
1
  /*
2
- * @Author: xiaosihan
3
- * @Date: 2022-04-07 16:42:26
2
+ * @Author: xiaosihan
3
+ * @Date: 2022-04-07 16:42:26
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2023-03-30 10:52:27
6
6
  */
7
-
8
- import { DefaultLoadingManager, EventDispatcher, RepeatWrapping, Texture, TextureLoader, VideoTexture } from "three";
7
+ import { DefaultLoadingManager, EventDispatcher, RepeatWrapping, TextureLoader, VideoTexture } from "three";
9
8
  import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
10
9
  import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
11
10
  import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
12
11
  import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
13
12
  import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
14
-
15
13
  // 引入静态资源
16
14
  //@ts-ignore
17
15
  import dracoWasmWrapperJS from "./draco/draco_wasm_wrapper.js?url";
@@ -19,46 +17,35 @@ import dracoWasmWrapperJS from "./draco/draco_wasm_wrapper.js?url";
19
17
  import dracoDecoderJS from "./draco/draco_decoder.js?url";
20
18
  //@ts-ignore
21
19
  import dracoDecoderWASM from "./draco/draco_decoder.wasm?url";
22
-
23
20
  // 加载器
24
21
  class ThreeLoader extends EventDispatcher {
25
-
26
22
  constructor() {
27
23
  super();
28
-
29
24
  DefaultLoadingManager.onStart = () => {
30
25
  this.onload = false;
31
- }
32
-
26
+ };
33
27
  // 有资源加载完成时通知渲染器
34
28
  DefaultLoadingManager.onProgress = () => {
35
29
  this.dispatchEvent({ type: "progress" });
36
- }
37
-
30
+ };
38
31
  DefaultLoadingManager.onLoad = () => {
39
32
  this.onload = true;
40
- }
33
+ };
41
34
  }
42
-
43
35
  // 各向异性
44
36
  anisotropy = 1;
45
-
46
37
  // 设置各向异性 由渲染器来调用并设置
47
- setAnisotropy(v: number) {
38
+ setAnisotropy(v) {
48
39
  this.anisotropy = v;
49
- };
50
-
40
+ }
41
+ ;
51
42
  // 纹理对向缓存
52
- textureMap = new Map() as Map<string, Texture>;
53
-
43
+ textureMap = new Map();
54
44
  // 纹理加载器
55
45
  textureLoader = new TextureLoader();
56
-
57
46
  // 获取地址对应的单例纹理对象
58
- getTexture(src: string) {
59
-
47
+ getTexture(src) {
60
48
  let texture = this.textureMap.get(src);
61
-
62
49
  if (!texture) {
63
50
  if (/\.mp4$/.test(src)) {
64
51
  const videoDom = document.createElement("video");
@@ -73,38 +60,30 @@ class ThreeLoader extends EventDispatcher {
73
60
  videoDom.play();
74
61
  });
75
62
  texture = new VideoTexture(videoDom);
76
- } else {
77
-
63
+ }
64
+ else {
78
65
  texture = this.textureLoader.load(src, tex => {
79
66
  tex.image.crossOrigin = "anonymous";
80
67
  });
81
68
  }
82
-
83
69
  this.textureMap.set(src, texture);
84
70
  }
85
-
86
71
  texture.wrapS = texture.wrapT = RepeatWrapping;
87
-
88
72
  texture.anisotropy = this.anisotropy;
89
-
90
- return texture as Texture;
91
- };
92
-
73
+ return texture;
74
+ }
75
+ ;
93
76
  // fbx模型加载器
94
77
  fbxLoader = new FBXLoader();
95
-
96
78
  //obj 加载器
97
79
  objLoader = new OBJLoader();
98
-
99
80
  // 材质加载器
100
81
  mtlLoader = new MTLLoader();
101
-
102
82
  // gltf 加载器
103
83
  gltfLoader = (() => {
104
84
  const loader = new GLTFLoader();
105
85
  const dracoLoader = new class ThreeBaseDRACOLoader extends DRACOLoader {
106
-
107
- _loadLibrary(url: string, responseType: string) {
86
+ _loadLibrary(url, responseType) {
108
87
  //@ts-ignore
109
88
  let urlConf = (process.env.NODE_ENV === "development") ? {
110
89
  "draco_decoder.js": "draco_decoder.js",
@@ -114,23 +93,18 @@ class ThreeLoader extends EventDispatcher {
114
93
  "draco_decoder.js": dracoWasmWrapperJS,
115
94
  "draco_wasm_wrapper.js": dracoDecoderJS,
116
95
  "draco_decoder.wasm": dracoDecoderWASM
117
- }
96
+ };
118
97
  //@ts-ignore
119
98
  return super._loadLibrary(urlConf[url], responseType);
120
99
  }
121
-
122
100
  }();
123
101
  //@ts-ignore
124
102
  dracoLoader.setDecoderPath((process.env.NODE_ENV === "development") ? '/node_modules/three/examples/js/libs/draco/' : '');
125
103
  loader.setDRACOLoader(dracoLoader);
126
104
  return loader;
127
- })()
128
-
105
+ })();
129
106
  // 是否加载完成
130
107
  onload = true;
131
-
132
108
  }
133
-
134
109
  const threeLoader = new ThreeLoader();
135
110
  export default threeLoader;
136
-