three-base 2.0.70 → 2.0.72

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.
@@ -18,15 +18,15 @@ export default class InstancedMeshBase extends MeshBase {
18
18
  instanceColor: InstancedBufferAttribute;
19
19
  loadModel(url: string, filename?: string): Promise<void>;
20
20
  computeBoundingSphere: import("lodash").DebouncedFunc<() => void>;
21
- setCount(count?: number): void;
22
- setMatrixAt(index: number, matrix: Matrix4): void;
21
+ setCount(count?: number): Promise<void>;
22
+ setMatrixAt(index: number, matrix: Matrix4): Promise<void>;
23
23
  setTRS(index: number, { position, rotation, scale }: {
24
24
  position?: Vector3;
25
25
  rotation?: Euler;
26
26
  scale?: Vector3;
27
- }): void;
28
- setColorAt(index: number, color: (instancedMesh: InstancedMesh) => Color | undefined): void;
27
+ }): Promise<void>;
28
+ setColorAt(index: number, color: (instancedMesh: InstancedMesh) => Color | undefined): Promise<void>;
29
29
  updateMatrixWorld(force?: boolean): void;
30
- addEventListener(name: string, callback: (e: any) => void): void;
30
+ addEventListener(name: string, callback: (e: any) => void): Promise<void>;
31
31
  removeEventListener(name: string, callback: (e: any) => void): void;
32
32
  }
@@ -29,6 +29,7 @@ export default class InstancedMeshBase extends MeshBase {
29
29
  instanceColor = new InstancedBufferAttribute(new Float32Array(0 * 3), 3);
30
30
  // 重构加载模型的方法
31
31
  async loadModel(url, filename = "") {
32
+ this.url = url;
32
33
  if (!url) {
33
34
  this.clear();
34
35
  return;
@@ -110,14 +111,13 @@ export default class InstancedMeshBase extends MeshBase {
110
111
  }
111
112
  // 更新包围盒
112
113
  computeBoundingSphere = throttle(() => {
113
- this.traverse(m => {
114
- if (m !== this) {
115
- m.computeBoundingSphere();
116
- }
114
+ this.children.map(instancedMesh => {
115
+ instancedMesh.computeBoundingSphere();
117
116
  });
118
117
  }, 1000);
119
118
  //初始实例矩阵的数量
120
- setCount(count = 0) {
119
+ async setCount(count = 0) {
120
+ await this.awaitLoaded();
121
121
  const instanceMatrix = new InstancedBufferAttribute(new Float32Array(count * 16), 16);
122
122
  const instanceColor = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3);
123
123
  for (let i = 0; i < this.count; i++) {
@@ -140,7 +140,8 @@ export default class InstancedMeshBase extends MeshBase {
140
140
  });
141
141
  }
142
142
  // 设置矩阵
143
- setMatrixAt(index, matrix) {
143
+ async setMatrixAt(index, matrix) {
144
+ await this.awaitLoaded();
144
145
  Object.keys(this.meshCollect).forEach(uuid => {
145
146
  const instancedMesh = this.instanceCollect[uuid];
146
147
  const collect = this.meshCollect[uuid];
@@ -154,7 +155,8 @@ export default class InstancedMeshBase extends MeshBase {
154
155
  this.computeBoundingSphere();
155
156
  }
156
157
  //设置移动旋转缩放
157
- setTRS(index, { position = InstancedMeshBase._position, rotation = InstancedMeshBase._rotation, scale = InstancedMeshBase._scale }) {
158
+ async setTRS(index, { position = InstancedMeshBase._position, rotation = InstancedMeshBase._rotation, scale = InstancedMeshBase._scale }) {
159
+ await this.awaitLoaded();
158
160
  Object.keys(this.meshCollect).forEach(uuid => {
159
161
  const instancedMesh = this.instanceCollect[uuid];
160
162
  const collect = this.meshCollect[uuid];
@@ -177,7 +179,8 @@ export default class InstancedMeshBase extends MeshBase {
177
179
  this.computeBoundingSphere();
178
180
  }
179
181
  // 设置颜色
180
- setColorAt(index, color) {
182
+ async setColorAt(index, color) {
183
+ await this.awaitLoaded();
181
184
  Object.keys(this.meshCollect).forEach(uuid => {
182
185
  const instancedMesh = this.instanceCollect[uuid];
183
186
  const collect = this.meshCollect[uuid];
@@ -199,7 +202,8 @@ export default class InstancedMeshBase extends MeshBase {
199
202
  });
200
203
  }
201
204
  // 事件监听
202
- addEventListener(name, callback) {
205
+ async addEventListener(name, callback) {
206
+ await this.awaitLoaded();
203
207
  super.addEventListener(name, callback);
204
208
  this.children.map(mesh => {
205
209
  mesh.addEventListener(name, callback);
@@ -43,6 +43,9 @@ export default class InstancedMeshBase extends MeshBase {
43
43
 
44
44
  // 重构加载模型的方法
45
45
  async loadModel(url: string, filename: string = "") {
46
+
47
+ this.url = url;
48
+
46
49
  if (!url) {
47
50
  this.clear();
48
51
  return;
@@ -143,18 +146,16 @@ export default class InstancedMeshBase extends MeshBase {
143
146
 
144
147
  }
145
148
 
146
-
147
149
  // 更新包围盒
148
150
  computeBoundingSphere = throttle(() => {
149
- this.traverse(m => {
150
- if (m !== this) {
151
- (m as InstancedMesh).computeBoundingSphere();
152
- }
153
- })
151
+ this.children.map(instancedMesh => {
152
+ instancedMesh.computeBoundingSphere();
153
+ });
154
154
  }, 1000)
155
155
 
156
156
  //初始实例矩阵的数量
157
- setCount(count: number = 0) {
157
+ async setCount(count: number = 0) {
158
+ await this.awaitLoaded();
158
159
 
159
160
  const instanceMatrix = new InstancedBufferAttribute(new Float32Array(count * 16), 16);
160
161
  const instanceColor = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3);
@@ -186,7 +187,9 @@ export default class InstancedMeshBase extends MeshBase {
186
187
  }
187
188
 
188
189
  // 设置矩阵
189
- setMatrixAt(index: number, matrix: Matrix4) {
190
+ async setMatrixAt(index: number, matrix: Matrix4) {
191
+ await this.awaitLoaded();
192
+
190
193
  Object.keys(this.meshCollect).forEach(uuid => {
191
194
  const instancedMesh = this.instanceCollect[uuid]
192
195
  const collect = this.meshCollect[uuid]
@@ -203,7 +206,7 @@ export default class InstancedMeshBase extends MeshBase {
203
206
  }
204
207
 
205
208
  //设置移动旋转缩放
206
- setTRS(
209
+ async setTRS(
207
210
  index: number,
208
211
  {
209
212
  position = InstancedMeshBase._position,
@@ -215,6 +218,8 @@ export default class InstancedMeshBase extends MeshBase {
215
218
  scale?: Vector3
216
219
  }
217
220
  ) {
221
+ await this.awaitLoaded();
222
+
218
223
  Object.keys(this.meshCollect).forEach(uuid => {
219
224
  const instancedMesh = this.instanceCollect[uuid]
220
225
  const collect = this.meshCollect[uuid]
@@ -253,7 +258,9 @@ export default class InstancedMeshBase extends MeshBase {
253
258
  }
254
259
 
255
260
  // 设置颜色
256
- setColorAt(index: number, color: (instancedMesh: InstancedMesh) => Color | undefined) {
261
+ async setColorAt(index: number, color: (instancedMesh: InstancedMesh) => Color | undefined) {
262
+ await this.awaitLoaded();
263
+
257
264
  Object.keys(this.meshCollect).forEach(uuid => {
258
265
  const instancedMesh = this.instanceCollect[uuid]
259
266
  const collect = this.meshCollect[uuid]
@@ -277,7 +284,9 @@ export default class InstancedMeshBase extends MeshBase {
277
284
  }
278
285
 
279
286
  // 事件监听
280
- addEventListener(name: string, callback: (e: any) => void) {
287
+ async addEventListener(name: string, callback: (e: any) => void) {
288
+ await this.awaitLoaded();
289
+
281
290
  super.addEventListener(name, callback);
282
291
  this.children.map(mesh => {
283
292
  mesh.addEventListener(name, callback);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-base",
3
- "version": "2.0.70",
3
+ "version": "2.0.72",
4
4
  "description": "three 3d three-base",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"