three-base 2.0.71 → 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.
- package/InstancedMeshBase.d.ts +5 -5
- package/InstancedMeshBase.js +12 -9
- package/InstancedMeshBase.ts +17 -11
- package/package.json +1 -1
package/InstancedMeshBase.d.ts
CHANGED
|
@@ -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
|
}
|
package/InstancedMeshBase.js
CHANGED
|
@@ -111,14 +111,13 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
111
111
|
}
|
|
112
112
|
// 更新包围盒
|
|
113
113
|
computeBoundingSphere = throttle(() => {
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
m.computeBoundingSphere();
|
|
117
|
-
}
|
|
114
|
+
this.children.map(instancedMesh => {
|
|
115
|
+
instancedMesh.computeBoundingSphere();
|
|
118
116
|
});
|
|
119
117
|
}, 1000);
|
|
120
118
|
//初始实例矩阵的数量
|
|
121
|
-
setCount(count = 0) {
|
|
119
|
+
async setCount(count = 0) {
|
|
120
|
+
await this.awaitLoaded();
|
|
122
121
|
const instanceMatrix = new InstancedBufferAttribute(new Float32Array(count * 16), 16);
|
|
123
122
|
const instanceColor = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3);
|
|
124
123
|
for (let i = 0; i < this.count; i++) {
|
|
@@ -141,7 +140,8 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
141
140
|
});
|
|
142
141
|
}
|
|
143
142
|
// 设置矩阵
|
|
144
|
-
setMatrixAt(index, matrix) {
|
|
143
|
+
async setMatrixAt(index, matrix) {
|
|
144
|
+
await this.awaitLoaded();
|
|
145
145
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
146
146
|
const instancedMesh = this.instanceCollect[uuid];
|
|
147
147
|
const collect = this.meshCollect[uuid];
|
|
@@ -155,7 +155,8 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
155
155
|
this.computeBoundingSphere();
|
|
156
156
|
}
|
|
157
157
|
//设置移动旋转缩放
|
|
158
|
-
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();
|
|
159
160
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
160
161
|
const instancedMesh = this.instanceCollect[uuid];
|
|
161
162
|
const collect = this.meshCollect[uuid];
|
|
@@ -178,7 +179,8 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
178
179
|
this.computeBoundingSphere();
|
|
179
180
|
}
|
|
180
181
|
// 设置颜色
|
|
181
|
-
setColorAt(index, color) {
|
|
182
|
+
async setColorAt(index, color) {
|
|
183
|
+
await this.awaitLoaded();
|
|
182
184
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
183
185
|
const instancedMesh = this.instanceCollect[uuid];
|
|
184
186
|
const collect = this.meshCollect[uuid];
|
|
@@ -200,7 +202,8 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
200
202
|
});
|
|
201
203
|
}
|
|
202
204
|
// 事件监听
|
|
203
|
-
addEventListener(name, callback) {
|
|
205
|
+
async addEventListener(name, callback) {
|
|
206
|
+
await this.awaitLoaded();
|
|
204
207
|
super.addEventListener(name, callback);
|
|
205
208
|
this.children.map(mesh => {
|
|
206
209
|
mesh.addEventListener(name, callback);
|
package/InstancedMeshBase.ts
CHANGED
|
@@ -146,18 +146,16 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
146
146
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
|
|
150
149
|
// 更新包围盒
|
|
151
150
|
computeBoundingSphere = throttle(() => {
|
|
152
|
-
this.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
})
|
|
151
|
+
this.children.map(instancedMesh => {
|
|
152
|
+
instancedMesh.computeBoundingSphere();
|
|
153
|
+
});
|
|
157
154
|
}, 1000)
|
|
158
155
|
|
|
159
156
|
//初始实例矩阵的数量
|
|
160
|
-
setCount(count: number = 0) {
|
|
157
|
+
async setCount(count: number = 0) {
|
|
158
|
+
await this.awaitLoaded();
|
|
161
159
|
|
|
162
160
|
const instanceMatrix = new InstancedBufferAttribute(new Float32Array(count * 16), 16);
|
|
163
161
|
const instanceColor = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3);
|
|
@@ -189,7 +187,9 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
189
187
|
}
|
|
190
188
|
|
|
191
189
|
// 设置矩阵
|
|
192
|
-
setMatrixAt(index: number, matrix: Matrix4) {
|
|
190
|
+
async setMatrixAt(index: number, matrix: Matrix4) {
|
|
191
|
+
await this.awaitLoaded();
|
|
192
|
+
|
|
193
193
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
194
194
|
const instancedMesh = this.instanceCollect[uuid]
|
|
195
195
|
const collect = this.meshCollect[uuid]
|
|
@@ -206,7 +206,7 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
//设置移动旋转缩放
|
|
209
|
-
setTRS(
|
|
209
|
+
async setTRS(
|
|
210
210
|
index: number,
|
|
211
211
|
{
|
|
212
212
|
position = InstancedMeshBase._position,
|
|
@@ -218,6 +218,8 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
218
218
|
scale?: Vector3
|
|
219
219
|
}
|
|
220
220
|
) {
|
|
221
|
+
await this.awaitLoaded();
|
|
222
|
+
|
|
221
223
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
222
224
|
const instancedMesh = this.instanceCollect[uuid]
|
|
223
225
|
const collect = this.meshCollect[uuid]
|
|
@@ -256,7 +258,9 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
256
258
|
}
|
|
257
259
|
|
|
258
260
|
// 设置颜色
|
|
259
|
-
setColorAt(index: number, color: (instancedMesh: InstancedMesh) => Color | undefined) {
|
|
261
|
+
async setColorAt(index: number, color: (instancedMesh: InstancedMesh) => Color | undefined) {
|
|
262
|
+
await this.awaitLoaded();
|
|
263
|
+
|
|
260
264
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
261
265
|
const instancedMesh = this.instanceCollect[uuid]
|
|
262
266
|
const collect = this.meshCollect[uuid]
|
|
@@ -280,7 +284,9 @@ export default class InstancedMeshBase extends MeshBase {
|
|
|
280
284
|
}
|
|
281
285
|
|
|
282
286
|
// 事件监听
|
|
283
|
-
addEventListener(name: string, callback: (e: any) => void) {
|
|
287
|
+
async addEventListener(name: string, callback: (e: any) => void) {
|
|
288
|
+
await this.awaitLoaded();
|
|
289
|
+
|
|
284
290
|
super.addEventListener(name, callback);
|
|
285
291
|
this.children.map(mesh => {
|
|
286
292
|
mesh.addEventListener(name, callback);
|