three-base 2.0.126 → 2.0.128

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.
@@ -26,7 +26,13 @@ export default class InstancedMeshBase extends MeshBase {
26
26
  rotation?: Euler;
27
27
  scale?: Vector3;
28
28
  }): Promise<void>;
29
+ getTRS(index?: number): Promise<{
30
+ position: Vector3;
31
+ rotation: Euler;
32
+ scale: Vector3;
33
+ }>;
29
34
  setColorAt(index: number, color: (instancedMesh: InstancedMesh) => Color | undefined): Promise<void>;
35
+ getColorAt(index?: number): Promise<Color>;
30
36
  updateMatrixWorld(force?: boolean): void;
31
37
  addEventListener(name: string, callback: (e: any) => void): Promise<void>;
32
38
  removeEventListener(name: string, callback: (e: any) => void): void;
@@ -4,8 +4,8 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2024-06-07 22:14:53
6
6
  */
7
- import { isString, throttle } from "lodash";
8
- import { Euler, InstancedBufferAttribute, InstancedMesh, Matrix4, Quaternion, Vector3, } from "three";
7
+ import { first, isString, throttle } from "lodash";
8
+ import { Color, Euler, InstancedBufferAttribute, InstancedMesh, Matrix4, Quaternion, Vector3, } from "three";
9
9
  import MeshBase from "./MeshBase";
10
10
  import threeUtils from "./threeUtils";
11
11
  import threeLoader from "./threeLoader";
@@ -225,6 +225,21 @@ export default class InstancedMeshBase extends MeshBase {
225
225
  });
226
226
  this.computeBoundingSphere();
227
227
  }
228
+ //获取指定位置的移动旋转缩放
229
+ async getTRS(index = 0) {
230
+ await this.awaitLoaded();
231
+ const position = new Vector3();
232
+ const rotation = new Euler();
233
+ const scale = new Vector3();
234
+ const uuid = first(Object.keys(this.instanceCollect));
235
+ const instancedMesh = this.instanceCollect[uuid];
236
+ if (instancedMesh) {
237
+ instancedMesh.getMatrixAt(index, InstancedMeshBase._matrix);
238
+ InstancedMeshBase._matrix.decompose(position, InstancedMeshBase._Quaternion, scale);
239
+ rotation.setFromQuaternion(InstancedMeshBase._Quaternion);
240
+ }
241
+ return { position, rotation, scale };
242
+ }
228
243
  // 设置颜色
229
244
  async setColorAt(index, color) {
230
245
  await this.awaitLoaded();
@@ -240,6 +255,17 @@ export default class InstancedMeshBase extends MeshBase {
240
255
  });
241
256
  });
242
257
  }
258
+ // 获取颜色
259
+ async getColorAt(index = 0) {
260
+ await this.awaitLoaded();
261
+ const color = new Color();
262
+ const uuid = first(Object.keys(this.instanceCollect));
263
+ const instancedMesh = this.instanceCollect[uuid];
264
+ if (instancedMesh) {
265
+ instancedMesh.getColorAt(index, color);
266
+ }
267
+ return color;
268
+ }
243
269
  // 同步属性
244
270
  updateMatrixWorld(force) {
245
271
  super.updateMatrixWorld(force);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-base",
3
- "version": "2.0.126",
3
+ "version": "2.0.128",
4
4
  "description": "three 3d three-base",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"