three-base 2.0.76 → 2.0.77

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.
@@ -19,7 +19,7 @@ export default class InstancedMeshBase extends MeshBase {
19
19
  loadModel(url: string, filename?: string): Promise<void>;
20
20
  computeBoundingSphere: import("lodash").DebouncedFunc<() => void>;
21
21
  setCount(count?: number): Promise<void>;
22
- setMatrixAt(index: number, matrix: Matrix4): 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;
@@ -149,15 +149,14 @@ export default class InstancedMeshBase extends MeshBase {
149
149
  });
150
150
  }
151
151
  // 设置矩阵
152
- async setMatrixAt(index, matrix) {
153
- const new_matrix = matrix.clone();
152
+ async setMatrixAt(index, matrix = new Matrix4().identity()) {
154
153
  await this.awaitLoaded();
155
154
  Object.keys(this.meshCollect).forEach(uuid => {
156
155
  const instancedMesh = this.instanceCollect[uuid];
157
156
  const collect = this.meshCollect[uuid];
158
157
  collect.forEach((mesh, i) => {
159
158
  InstancedMeshBase._matrix.copy(mesh.matrix);
160
- InstancedMeshBase._matrix.premultiply(new_matrix);
159
+ InstancedMeshBase._matrix.premultiply(matrix);
161
160
  instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
162
161
  instancedMesh.instanceMatrix.needsUpdate = true;
163
162
  });
@@ -165,12 +164,8 @@ export default class InstancedMeshBase extends MeshBase {
165
164
  this.computeBoundingSphere();
166
165
  }
167
166
  //设置移动旋转缩放
168
- async setTRS(index, { position = InstancedMeshBase._position, rotation = InstancedMeshBase._rotation, scale = InstancedMeshBase._scale }) {
169
- const new_position = position.clone();
170
- const new_rotation = rotation.clone();
171
- const new_scale = scale.clone();
167
+ async setTRS(index, { position, rotation, scale }) {
172
168
  await this.awaitLoaded();
173
- console.log("setTRS", index);
174
169
  Object.keys(this.meshCollect).forEach(uuid => {
175
170
  const instancedMesh = this.instanceCollect[uuid];
176
171
  const collect = this.meshCollect[uuid];
@@ -180,9 +175,9 @@ export default class InstancedMeshBase extends MeshBase {
180
175
  InstancedMeshBase._matrix.premultiply(mesh.matrix.clone().invert());
181
176
  InstancedMeshBase._matrix.decompose(InstancedMeshBase._position, InstancedMeshBase._Quaternion, InstancedMeshBase._scale);
182
177
  InstancedMeshBase._rotation.setFromQuaternion(InstancedMeshBase._Quaternion);
183
- InstancedMeshBase._position.copy(new_position);
184
- InstancedMeshBase._rotation.copy(new_rotation);
185
- InstancedMeshBase._scale.copy(new_scale);
178
+ position && InstancedMeshBase._position.copy(position);
179
+ rotation && InstancedMeshBase._rotation.copy(rotation);
180
+ scale && InstancedMeshBase._scale.copy(scale);
186
181
  InstancedMeshBase._Quaternion.setFromEuler(InstancedMeshBase._rotation);
187
182
  InstancedMeshBase._matrix.compose(InstancedMeshBase._position, InstancedMeshBase._Quaternion, InstancedMeshBase._scale);
188
183
  InstancedMeshBase._matrix.premultiply(mesh.matrix);
@@ -175,7 +175,6 @@ export default class InstancedMeshBase extends MeshBase {
175
175
  this.count = count;
176
176
 
177
177
  this.children.map((instanceMesh: InstancedMesh) => {
178
-
179
178
  const instanceMatrix = new InstancedBufferAttribute(new Float32Array(count * 16), 16);
180
179
  const instanceColor = new InstancedBufferAttribute(new Float32Array(count * 3).fill(1), 3);
181
180
 
@@ -197,15 +196,14 @@ export default class InstancedMeshBase extends MeshBase {
197
196
  }
198
197
 
199
198
  // 设置矩阵
200
- async setMatrixAt(index: number, matrix: Matrix4) {
201
- const new_matrix = matrix.clone();
199
+ async setMatrixAt(index: number, matrix: Matrix4 = new Matrix4().identity()) {
202
200
  await this.awaitLoaded();
203
201
  Object.keys(this.meshCollect).forEach(uuid => {
204
- const instancedMesh = this.instanceCollect[uuid]
202
+ const instancedMesh = this.instanceCollect[uuid];
205
203
  const collect = this.meshCollect[uuid]
206
204
  collect.forEach((mesh: Mesh, i: number) => {
207
- InstancedMeshBase._matrix.copy(mesh.matrix)
208
- InstancedMeshBase._matrix.premultiply(new_matrix);
205
+ InstancedMeshBase._matrix.copy(mesh.matrix);
206
+ InstancedMeshBase._matrix.premultiply(matrix);
209
207
 
210
208
  instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
211
209
  instancedMesh.instanceMatrix.needsUpdate = true;
@@ -219,20 +217,17 @@ export default class InstancedMeshBase extends MeshBase {
219
217
  async setTRS(
220
218
  index: number,
221
219
  {
222
- position = InstancedMeshBase._position,
223
- rotation = InstancedMeshBase._rotation,
224
- scale = InstancedMeshBase._scale
220
+ position,
221
+ rotation,
222
+ scale
225
223
  }: {
226
224
  position?: Vector3;
227
225
  rotation?: Euler;
228
226
  scale?: Vector3
229
227
  }
230
228
  ) {
231
- const new_position = position.clone();
232
- const new_rotation = rotation.clone();
233
- const new_scale = scale.clone();
234
229
  await this.awaitLoaded();
235
- console.log("setTRS", index);
230
+
236
231
  Object.keys(this.meshCollect).forEach(uuid => {
237
232
  const instancedMesh = this.instanceCollect[uuid]
238
233
  const collect = this.meshCollect[uuid]
@@ -240,7 +235,6 @@ export default class InstancedMeshBase extends MeshBase {
240
235
 
241
236
  //获取对应的模型的矩阵
242
237
  instancedMesh.getMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
243
-
244
238
  InstancedMeshBase._matrix.premultiply(mesh.matrix.clone().invert());
245
239
 
246
240
  InstancedMeshBase._matrix.decompose(
@@ -249,9 +243,9 @@ export default class InstancedMeshBase extends MeshBase {
249
243
  InstancedMeshBase._scale
250
244
  );
251
245
  InstancedMeshBase._rotation.setFromQuaternion(InstancedMeshBase._Quaternion);
252
- InstancedMeshBase._position.copy(new_position);
253
- InstancedMeshBase._rotation.copy(new_rotation);
254
- InstancedMeshBase._scale.copy(new_scale);
246
+ position && InstancedMeshBase._position.copy(position);
247
+ rotation && InstancedMeshBase._rotation.copy(rotation);
248
+ scale && InstancedMeshBase._scale.copy(scale);
255
249
  InstancedMeshBase._Quaternion.setFromEuler(InstancedMeshBase._rotation);
256
250
 
257
251
  InstancedMeshBase._matrix.compose(
@@ -261,7 +255,6 @@ export default class InstancedMeshBase extends MeshBase {
261
255
  );
262
256
 
263
257
  InstancedMeshBase._matrix.premultiply(mesh.matrix);
264
-
265
258
  instancedMesh.setMatrixAt(collect.length * index + i, InstancedMeshBase._matrix);
266
259
  instancedMesh.instanceMatrix.needsUpdate = true;
267
260
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-base",
3
- "version": "2.0.76",
3
+ "version": "2.0.77",
4
4
  "description": "three 3d three-base",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"