three-base 1.0.24 → 1.0.26

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/lib/ThreeBase.ts CHANGED
@@ -214,10 +214,7 @@ export default class ThreeBase extends EventDispatcher {
214
214
  }
215
215
 
216
216
  // 等待动画执行完成
217
- while (!this.controlsCenter.isDone() || !this.controlsPosition.isDone()) {
218
- await new Promise(resolve => setTimeout(resolve, 100));
219
- }
220
-
217
+ await new Promise(resolve => setTimeout(resolve, Math.max(this.controlsCenter._duration, this.controlsPosition._duration)));
221
218
  }
222
219
 
223
220
  // 获取控制的位置和朝向 保留3位小数
package/lib/Transition.ts CHANGED
@@ -186,9 +186,7 @@ export default class Transition {
186
186
  }
187
187
  threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
188
188
 
189
- while (!this._isDone) {
190
- await new Promise(resolve => setTimeout(resolve, 50));
191
- }
189
+ await new Promise(resolve => setTimeout(resolve, this._duration));
192
190
 
193
191
  return this;
194
192
  }
package/lib/threeUtils.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @Last Modified time: 2022-06-21 16:45:33
6
6
  */
7
7
 
8
- import { Box3, Clock, EventDispatcher, Object3D, Vector3 } from "three";
8
+ import { Box3, BufferGeometry, Clock, EventDispatcher, Object3D, Vector3 } from "three";
9
9
 
10
10
  class ThreeUtils extends EventDispatcher {
11
11
 
@@ -16,7 +16,7 @@ class ThreeUtils extends EventDispatcher {
16
16
  }
17
17
  //@ts-ignore
18
18
  isProd = process.env.NODE_ENV === "production";
19
-
19
+
20
20
  //@ts-ignore
21
21
  isDev = process.env.NODE_ENV === "development";
22
22
 
@@ -45,37 +45,60 @@ class ThreeUtils extends EventDispatcher {
45
45
  }
46
46
 
47
47
  // 获取模型大小
48
- getSize(object3d: Object3D) {
49
- this.box3.setFromObject(object3d);
50
- this.box3.getSize(this.size);
48
+ getSize(object3d: Object3D | BufferGeometry) {
49
+
50
+ if (object3d instanceof Object3D) {
51
+ this.box3.setFromObject(object3d);
52
+ this.box3.getSize(this.size);
53
+ } else if (object3d instanceof BufferGeometry) {
54
+ object3d.computeBoundingBox();
55
+ object3d.boundingBox!.getSize(this.size);
56
+ }
57
+
51
58
  return this.size;
52
59
  }
53
60
 
54
61
  // 模型对齐底面
55
- alignButton(object3d: Object3D, y = 0) {
56
- this.box3.setFromObject(object3d);
57
- this.box3.getCenter(this.center);
58
- this.box3.getSize(this.size);
59
- object3d.position.y -= (this.center.y - (this.size.y * 0.5));
60
- object3d.position.y += y;
61
- object3d.updateMatrixWorld(true);
62
+ alignBotton(object3d: Object3D | BufferGeometry, y = 0) {
63
+
64
+ if (object3d instanceof Object3D) {
65
+ this.box3.setFromObject(object3d);
66
+ this.box3.getCenter(this.center);
67
+ this.box3.getSize(this.size);
68
+ object3d.position.y -= (this.center.y - (this.size.y * 0.5));
69
+ object3d.position.y += y;
70
+ object3d.updateMatrixWorld(true);
71
+ } else if (object3d instanceof BufferGeometry) {
72
+ object3d.computeBoundingBox();
73
+ object3d.translate(0, -object3d.boundingBox!.min.y, 0);
74
+ }
62
75
  }
63
76
 
64
77
  // 居中对象
65
- centerObject3D(object3d: Object3D) {
66
- this.box3.setFromObject(object3d);
67
- this.box3.getCenter(this.center);
68
- object3d.position.sub(this.center);
69
- object3d.updateMatrixWorld(true);
78
+ centerObject3D(object3d: Object3D | BufferGeometry) {
79
+ if (object3d instanceof Object3D) {
80
+ this.box3.setFromObject(object3d);
81
+ this.box3.getCenter(this.center);
82
+ object3d.position.sub(this.center);
83
+ object3d.updateMatrixWorld(true);
84
+ } else if (object3d instanceof BufferGeometry) {
85
+ object3d.center();
86
+ }
70
87
  }
71
88
 
72
89
  //缩放至指定大小
73
- scaleTo(object3d: Object3D, size: number = 1) {
74
- this.box3.setFromObject(object3d);
75
- this.box3.getSize(this.size);
76
- const scale = size / Math.max(this.size.x, this.size.y, this.size.z);
77
- object3d.scale.multiplyScalar(scale);
78
- object3d.updateMatrixWorld(true);
90
+ scaleTo(object3d: Object3D | BufferGeometry, size: number = 1) {
91
+ if (object3d instanceof Object3D) {
92
+ this.box3.setFromObject(object3d);
93
+ this.box3.getSize(this.size);
94
+ const scale = size / Math.max(this.size.x, this.size.y, this.size.z);
95
+ object3d.scale.multiplyScalar(scale);
96
+ object3d.updateMatrixWorld(true);
97
+ } else if (object3d instanceof BufferGeometry) {
98
+ const originSize = this.getSize(object3d);
99
+ const scale = size / Math.max(originSize.x, originSize.y, originSize.z);
100
+ object3d.scale(scale, scale, scale);
101
+ }
79
102
  }
80
103
 
81
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-base",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "three 3d three-base",
5
5
  "keywords": [
6
6
  "three",