three-base 1.129.1 → 1.129.4

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 (54) hide show
  1. package/index.js +34 -0
  2. package/index.ts +5 -1
  3. package/lib/ApngTexture.d.ts +13 -0
  4. package/lib/{ApngTexture.ts → ApngTexture.js} +11 -41
  5. package/lib/ApngTextureManage.d.ts +18 -0
  6. package/lib/{ApngTextureManage.ts → ApngTextureManage.js} +13 -56
  7. package/lib/EventMesh.d.ts +18 -0
  8. package/lib/EventMesh.js +59 -0
  9. package/lib/ExtrudeMesh.d.ts +111 -0
  10. package/lib/{ExtrudeMesh.ts → ExtrudeMesh.js} +77 -284
  11. package/lib/FPScontrol.d.ts +44 -0
  12. package/lib/{FPScontrol.ts → FPScontrol.js} +25 -64
  13. package/lib/InstancedGroupMesh.d.ts +10 -0
  14. package/lib/InstancedGroupMesh.js +63 -0
  15. package/lib/KeyFrameAnimation.d.ts +25 -0
  16. package/lib/{KeyFrameAnimation.ts → KeyFrameAnimation.js} +19 -63
  17. package/lib/PlaneText.d.ts +37 -0
  18. package/lib/{PlaneText.ts → PlaneText.js} +5 -34
  19. package/lib/PointLight.d.ts +13 -0
  20. package/lib/{PointLight.ts → PointLight.js} +4 -18
  21. package/lib/Sky/Sky.d.ts +13 -0
  22. package/lib/Sky/{Sky.ts → Sky.js} +4 -12
  23. package/lib/Text3D/Text3D.d.ts +20 -0
  24. package/lib/Text3D/Text3D.js +60 -0
  25. package/lib/Text3D/fontController.d.ts +59 -0
  26. package/lib/Text3D/fontController.js +200 -0
  27. package/lib/Text3D/gentilis.json +811 -0
  28. package/lib/ThreeBase.d.ts +59 -0
  29. package/lib/{ThreeBase.ts → ThreeBase.js} +75 -131
  30. package/lib/ThreeMouse.d.ts +39 -0
  31. package/lib/{ThreeMouse.ts → ThreeMouse.js} +61 -168
  32. package/lib/Transition.d.ts +45 -0
  33. package/lib/{Transition.ts → Transition.js} +30 -101
  34. package/lib/index.d.ts +22 -0
  35. package/lib/keyContorls.d.ts +25 -0
  36. package/lib/{keyContorls.ts → keyContorls.js} +11 -40
  37. package/lib/planeModal1/PlaneModal1.d.ts +32 -0
  38. package/lib/planeModal1/{PlaneModal1.ts → PlaneModal1.js} +33 -77
  39. package/lib/shaders.d.ts +17 -0
  40. package/lib/{shaders.ts → shaders.js} +19 -38
  41. package/lib/spriteModal1/SpriteModal1.d.ts +31 -0
  42. package/lib/spriteModal1/{SpriteModal1.ts → SpriteModal1.js} +33 -80
  43. package/lib/threeLoader.d.ts +20 -0
  44. package/lib/{threeLoader.ts → threeLoader.js} +19 -45
  45. package/lib/threeUtils.d.ts +41 -0
  46. package/lib/{threeUtils.ts → threeUtils.js} +81 -82
  47. package/lib/type.d.ts +0 -0
  48. package/lib/{type.ts → type.js} +1 -4
  49. package/package.json +7 -6
  50. package/declare.d.ts +0 -5
  51. package/lib/EventMesh.ts +0 -79
  52. package/lib/InstancedGroupMesh.ts +0 -80
  53. package/lib/text/Text2D.ts +0 -41
  54. package/lib/text/Text3D.ts +0 -20
@@ -4,61 +4,49 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2023-03-16 14:34:49
6
6
  */
7
-
8
7
  import { Box3, BufferGeometry, Clock, EventDispatcher, Object3D, Vector3 } from "three";
9
-
10
8
  class ThreeUtils extends EventDispatcher {
11
-
12
9
  constructor() {
13
10
  super();
14
-
15
11
  this.requestAnimationFrame();
16
12
  }
17
13
  //@ts-ignore
18
- isProd = process.env.NODE_ENV === "production";
19
-
14
+ isProd = (process.env.NODE_ENV === "production");
20
15
  //@ts-ignore
21
- isDev = process.env.NODE_ENV === "development";
22
-
23
- timeTemp = performance.now();
24
-
25
- accumulate = 0;// 事件分发次数
26
-
27
- box3 = new Box3();
28
- size = new Vector3();
29
- center = new Vector3();
30
-
31
- clock = new Clock();
32
-
16
+ isDev = (process.env.NODE_ENV === "development");
17
+ _timeTemp = performance.now();
18
+ _accumulate = 0; // 事件分发次数
19
+ _box3 = new Box3();
20
+ _size = new Vector3();
21
+ _center = new Vector3();
22
+ _clock = new Clock();
33
23
  requestAnimationFrame() {
34
- this.accumulate += 1;
35
- const timeTemp = this.timeTemp = performance.now();
24
+ this._accumulate += 1;
25
+ const timeTemp = this._timeTemp = performance.now();
36
26
  this.dispatchEvent({
37
27
  type: "requestAnimationFrame",
38
28
  timeTemp,
39
- accumulate: this.accumulate
29
+ accumulate: this._accumulate
40
30
  });
41
-
42
31
  this._computerDomZoom();
43
-
32
+ //执行一个计划任务
33
+ let work = this.workList.splice(0, 1)[0];
34
+ work && work();
44
35
  setTimeout(() => {
45
36
  this.requestAnimationFrame();
46
- }, 45 - this.clock.getDelta());
37
+ }, 45 - this._clock.getDelta());
47
38
  }
48
-
49
39
  // 需要保持宽高比的元素列表
50
- private _keepZoomDoms: Array<{ dom: HTMLElement, width: number, height: number }> = [];
51
-
40
+ _keepZoomDoms = [];
52
41
  /**
53
42
  *计算需要保持比例的元素
54
43
  */
55
- private _computerDomZoom() {
44
+ _computerDomZoom() {
56
45
  //1. 踢除没有出现在页面上的 dom 元素
57
46
  this._keepZoomDoms = this._keepZoomDoms.filter(l => this.inDocument(l.dom));
58
-
59
47
  //2.设置dom的缩放值样式
60
48
  this._keepZoomDoms.map((item, i) => {
61
- let parentRact = window.getComputedStyle(item.dom.parentNode as Element);
49
+ let parentRact = window.getComputedStyle(item.dom.parentNode);
62
50
  let width = parseInt(parentRact.width);
63
51
  let height = parseInt(parentRact.height);
64
52
  let scale = Math.min(width / item.width, height / item.height);
@@ -70,111 +58,122 @@ class ThreeUtils extends EventDispatcher {
70
58
  width: `${item.width}px`,
71
59
  height: `${item.height}px`
72
60
  });
73
-
74
61
  });
75
62
  }
76
-
77
63
  /**
78
64
  * dom元素保持比例
79
65
  */
80
- keepZoom(dom: HTMLElement | null, width: number = 1920, height: number = 1080) {
66
+ keepZoom(dom, width = 1920, height = 1080) {
81
67
  if (dom) {
82
68
  // 去掉相同的dom存储的信息
83
69
  this._keepZoomDoms = this._keepZoomDoms.filter(l => l.dom !== dom);
84
-
85
70
  // 把配置加入到列表中
86
71
  this._keepZoomDoms.push({ dom, width, height });
87
-
88
72
  dom.dataset.a = "这个元素缩放比例由 threeUtils.keepZoom 方法设置";
89
73
  }
90
74
  }
91
-
75
+ workList = [];
76
+ // 时钟对象
77
+ clock = new Clock();
78
+ // 按照任务队列依次执行计划任务 性能优化
79
+ /**
80
+ * @param {() => void} [callback]
81
+ * @param {boolean} [first=true] 需要优先执行
82
+ */
83
+ addWork(work, first = false) {
84
+ // 加入任务队列
85
+ if (work && !this.workList.includes(work)) {
86
+ if (first) {
87
+ this.workList.splice(1, 0, work); // 优先执行的任务回调
88
+ }
89
+ else {
90
+ this.workList.push(work);
91
+ }
92
+ }
93
+ }
92
94
  /**
93
95
  *判断一个元素是否在页面上
94
96
  */
95
- inDocument(dom: ParentNode | null): boolean {
97
+ inDocument(dom) {
96
98
  if (dom === null) {
97
99
  return false;
98
- } else if (dom.parentNode === null) {
100
+ }
101
+ else if (dom.parentNode === null) {
99
102
  return false;
100
- } else if (dom.parentNode === document) {
103
+ }
104
+ else if (dom.parentNode === document) {
101
105
  return true;
102
- } else {
106
+ }
107
+ else {
103
108
  return this.inDocument(dom.parentNode);
104
109
  }
105
110
  }
106
-
107
111
  // 获取中心点
108
- getCenter(object3d: Object3D | BufferGeometry) {
112
+ getCenter(object3d) {
109
113
  if (object3d instanceof Object3D) {
110
- this.box3.setFromObject(object3d);
111
- this.box3.getCenter(this.center);
112
- } else if (object3d instanceof BufferGeometry) {
114
+ this._box3.setFromObject(object3d);
115
+ this._box3.getCenter(this._center);
116
+ }
117
+ else if (object3d instanceof BufferGeometry) {
113
118
  object3d.computeBoundingBox();
114
- object3d.boundingBox!.getCenter(this.center);
119
+ object3d.boundingBox.getCenter(this._center);
115
120
  }
116
-
117
- return this.center;
121
+ return this._center;
118
122
  }
119
-
120
123
  // 获取模型大小
121
- getSize(object3d: Object3D | BufferGeometry) {
124
+ getSize(object3d) {
122
125
  if (object3d instanceof Object3D) {
123
- this.box3.setFromObject(object3d);
124
- this.box3.getSize(this.size);
125
- } else if (object3d instanceof BufferGeometry) {
126
+ this._box3.setFromObject(object3d);
127
+ this._box3.getSize(this._size);
128
+ }
129
+ else if (object3d instanceof BufferGeometry) {
126
130
  object3d.computeBoundingBox();
127
- object3d.boundingBox!.getSize(this.size);
131
+ object3d.boundingBox.getSize(this._size);
128
132
  }
129
-
130
- return this.size;
133
+ return this._size;
131
134
  }
132
-
133
135
  // 模型对齐底面
134
- alignBottom(object3d: Object3D | BufferGeometry, y = 0) {
136
+ alignBottom(object3d, y = 0) {
135
137
  if (object3d instanceof Object3D) {
136
- this.box3.setFromObject(object3d);
137
- this.box3.getCenter(this.center);
138
- this.box3.getSize(this.size);
139
- object3d.position.y -= (this.center.y - (this.size.y * 0.5));
138
+ this._box3.setFromObject(object3d);
139
+ this._box3.getCenter(this._center);
140
+ this._box3.getSize(this._size);
141
+ object3d.position.y -= (this._center.y - (this._size.y * 0.5));
140
142
  object3d.position.y += y;
141
143
  object3d.updateMatrixWorld(true);
142
- } else if (object3d instanceof BufferGeometry) {
144
+ }
145
+ else if (object3d instanceof BufferGeometry) {
143
146
  object3d.computeBoundingBox();
144
- object3d.translate(0, -object3d.boundingBox!.min.y, 0);
147
+ object3d.translate(0, -object3d.boundingBox.min.y + y, 0);
145
148
  }
146
149
  }
147
-
148
150
  // 居中对象
149
- centerObject3D(object3d: Object3D | BufferGeometry) {
151
+ centerObject3D(object3d) {
150
152
  if (object3d instanceof Object3D) {
151
- this.box3.setFromObject(object3d);
152
- this.box3.getCenter(this.center);
153
- object3d.position.sub(this.center);
153
+ this._box3.setFromObject(object3d);
154
+ this._box3.getCenter(this._center);
155
+ object3d.position.sub(this._center);
154
156
  object3d.updateMatrixWorld(true);
155
- } else if (object3d instanceof BufferGeometry) {
157
+ }
158
+ else if (object3d instanceof BufferGeometry) {
156
159
  object3d.center();
157
160
  }
158
161
  }
159
-
162
+ //居中对象
163
+ center(object3d) {
164
+ this.centerObject3D(object3d);
165
+ }
160
166
  //缩放至指定大小
161
- scaleTo(object3d: Object3D | BufferGeometry, size: number = 1) {
167
+ scaleTo(object3d, size = 1) {
162
168
  const originSize = this.getSize(object3d);
163
169
  const scale = size / Math.max(originSize.x, originSize.y, originSize.z);
164
170
  if (object3d instanceof Object3D) {
165
171
  object3d.scale.multiplyScalar(scale);
166
- } else if (object3d instanceof BufferGeometry) {
172
+ }
173
+ else if (object3d instanceof BufferGeometry) {
167
174
  object3d.scale(scale, scale, scale);
168
175
  }
169
176
  }
170
-
171
- //TODO 导出gltf文件
172
- // exportGltf(object3d: Object3D) {
173
-
174
- // }
175
-
176
177
  }
177
-
178
178
  const threeUtils = new ThreeUtils();
179
-
180
- export default threeUtils;
179
+ export default threeUtils;
package/lib/type.d.ts ADDED
File without changes
@@ -4,10 +4,7 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2022-01-05 14:21:42
6
6
  */
7
-
8
-
9
-
10
7
  // declare module '*?url' {
11
8
  // const src: string
12
9
  // export default src
13
- // }
10
+ // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-base",
3
- "version": "1.129.1",
3
+ "version": "1.129.4",
4
4
  "description": "three 3d three-base",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,15 +12,15 @@
12
12
  "three-base",
13
13
  "three-spritetext"
14
14
  ],
15
- "main": "index.ts",
16
- "module": "index.ts",
17
- "types": "index.ts",
15
+ "main": "index.js",
16
+ "module": "index.js",
17
+ "types": "",
18
18
  "files": [
19
19
  "index.ts",
20
20
  "declare.d.ts",
21
21
  "lib/*.js",
22
- "lib/*.ts",
23
- "lib/**/*.ts",
22
+ "lib/*.d.ts",
23
+ "lib/**/*.d.ts",
24
24
  "lib/**/*.js",
25
25
  "lib/**/*.tsx",
26
26
  "lib/**/*.css",
@@ -41,6 +41,7 @@
41
41
  "apng-js": "^1",
42
42
  "element-resize-event": "^3",
43
43
  "lodash": "^4",
44
+ "dexie": "^3",
44
45
  "three": "0.129.0",
45
46
  "vite": "^4",
46
47
  "three-spritetext": "^1",
package/declare.d.ts DELETED
@@ -1,5 +0,0 @@
1
-
2
- // 声明模块
3
-
4
- declare interface Window {
5
- }
package/lib/EventMesh.ts DELETED
@@ -1,79 +0,0 @@
1
- /*
2
- * @Author: xiaosihan
3
- * @Date: 2022-03-20 12:55:37
4
- * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2023-02-07 11:19:56
6
- */
7
-
8
- import { BoxGeometry, BufferGeometry, CylinderGeometry, DoubleSide, FrontSide, Material, Mesh, MeshBasicMaterial, MeshNormalMaterial } from "three";
9
- import threeUtils from "./threeUtils";
10
-
11
- // 碰撞的形状
12
- export enum CollisionShaere {
13
- cube = "cube", // 正方体
14
- cylinder = "cylinder" // 圆柱体
15
- }
16
-
17
- /**
18
- * 碰撞检测用的模型
19
- */
20
- export default class EventMesh extends Mesh<BufferGeometry, Material> {
21
-
22
- constructor(type: CollisionShaere = CollisionShaere.cube) {
23
- super();
24
-
25
- this.material = EventMesh.material;
26
-
27
- this.setType(type);
28
-
29
- // 生产环境 不用渲染
30
- if (threeUtils.isProd) {
31
- this.material = new MeshBasicMaterial({
32
- side: DoubleSide,
33
- transparent: true,
34
- opacity: 0.25,
35
- alphaTest: 1
36
- });
37
- }
38
- }
39
-
40
- static type = CollisionShaere;
41
-
42
- static material = new MeshNormalMaterial({
43
- side: DoubleSide,
44
- transparent: true,
45
- opacity: 0.3,
46
- });
47
-
48
- renderOrder = 99;
49
-
50
- // 正方体 网格模型
51
- static cubeGeo = new BoxGeometry(1, 1, 1, 1, 1, 1);
52
-
53
- // 圆柱体 网格模型
54
- static cylinderGeo = new CylinderGeometry(1, 1, 1, 50, 1, false, 0, Math.PI * 2);
55
-
56
- // 是否是碰撞检测专用的模型
57
- isEventMesh = true;
58
-
59
- setType(type: CollisionShaere) {
60
-
61
- switch (type) {
62
- case EventMesh.type.cube:
63
- this.geometry = EventMesh.cubeGeo;
64
- break;
65
-
66
- case EventMesh.type.cylinder:
67
- this.geometry = EventMesh.cylinderGeo;
68
- break;
69
-
70
- default:
71
- break;
72
- }
73
-
74
- this.geometry.computeVertexNormals();
75
-
76
-
77
- }
78
-
79
- }
@@ -1,80 +0,0 @@
1
- /*
2
- * @Author: xiaosihan
3
- * @Date: 2023-02-21 09:55:52
4
- * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2023-02-26 14:42:21
6
- */
7
-
8
- import * as THREE from 'three'
9
-
10
- // 模型组转成 实例对象
11
- export default class InstancedGroupMesh extends THREE.Mesh {
12
- isInstancedGroupMesh = true
13
-
14
- count: number = 0
15
-
16
- meshCollect: Record<string, THREE.Mesh[]> = {}
17
-
18
- instanceCollect: Record<string, THREE.InstancedMesh> = {}
19
-
20
- static matrix = new THREE.Matrix4()
21
-
22
- constructor(group: THREE.Group, count: number) {
23
- super()
24
-
25
- this.count = count
26
-
27
- const { meshCollect, instanceCollect } = this
28
-
29
- group.updateMatrixWorld(true);
30
-
31
- // collect all mesh counts, in case there are more than one copy of the same mesh in this group
32
- group.traverse((obj) => {
33
- const mesh = obj as THREE.Mesh
34
- if (mesh.isMesh) {
35
-
36
- mesh.matrixWorld.decompose(mesh.position, mesh.quaternion, mesh.scale);
37
- mesh.rotation.setFromQuaternion(mesh.quaternion);
38
- mesh.updateMatrix();
39
-
40
- // same geometry and same material consider as the same mesh
41
- const uuid = mesh.geometry.uuid + '/' + (mesh.material as THREE.Material).uuid
42
-
43
- if (meshCollect[uuid]) {
44
- meshCollect[uuid].push(mesh)
45
- } else {
46
- meshCollect[uuid] = [mesh]
47
- }
48
- } else {
49
- obj.position.set(0, 0, 0);
50
- obj.scale.set(1, 1, 1);
51
- obj.rotation.set(0, 0, 0);
52
- }
53
-
54
- })
55
-
56
- // create all instances
57
- Object.keys(meshCollect).forEach(uuid => {
58
- const meshes = meshCollect[uuid]
59
- const mesh = meshes[0]
60
-
61
- const instancedMesh = new THREE.InstancedMesh(mesh.geometry, mesh.material, meshes.length * count)
62
- instanceCollect[uuid] = instancedMesh
63
- this.add(instancedMesh)
64
- })
65
- }
66
-
67
- setMatrixAt(index: number, matrix: THREE.Matrix4) {
68
- Object.keys(this.meshCollect).forEach(uuid => {
69
- const instancedMesh = this.instanceCollect[uuid]
70
- const collect = this.meshCollect[uuid]
71
- collect.forEach((mesh: THREE.Mesh, i: number) => {
72
- InstancedGroupMesh.matrix.copy(mesh.matrix)
73
- InstancedGroupMesh.matrix.premultiply(matrix)
74
-
75
- instancedMesh.setMatrixAt(collect.length * index + i, InstancedGroupMesh.matrix);
76
- instancedMesh.instanceMatrix.needsUpdate = true;
77
- })
78
- })
79
- }
80
- }
@@ -1,41 +0,0 @@
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();
39
- }
40
-
41
- }
@@ -1,20 +0,0 @@
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(text: string = "Text2D") {
14
- super();
15
- }
16
-
17
-
18
-
19
-
20
- }