three-base 2.0.125 → 2.0.127

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
+ positon: 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 positon = 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(positon, InstancedMeshBase._Quaternion, scale);
239
+ rotation.setFromQuaternion(InstancedMeshBase._Quaternion);
240
+ }
241
+ return { positon, 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/ThreeBase.d.ts CHANGED
@@ -4,7 +4,7 @@ import ThreeMouse from "./ThreeMouse";
4
4
  import Transition from "./Transition";
5
5
  export default class ThreeBase extends EventDispatcher {
6
6
  constructor();
7
- devicePixelRatio: number;
7
+ minDevicePixelRatio: number;
8
8
  baseDepthTexture: DepthTexture;
9
9
  baseRenderTarget: WebGLRenderTarget<Texture>;
10
10
  renderTarget: WebGLRenderTarget<Texture>;
package/ThreeBase.js CHANGED
@@ -38,8 +38,8 @@ export default class ThreeBase extends EventDispatcher {
38
38
  });
39
39
  this.init();
40
40
  }
41
- // 设置分辨率
42
- devicePixelRatio = Math.max(window.devicePixelRatio, 2);
41
+ // 设置最小分辨率
42
+ minDevicePixelRatio = 1;
43
43
  // 基础深度纹理
44
44
  baseDepthTexture = (() => {
45
45
  const baseDepthTexture = new DepthTexture(4096, 4096);
@@ -101,8 +101,8 @@ export default class ThreeBase extends EventDispatcher {
101
101
  this.rendererLost = false;
102
102
  }, false);
103
103
  renderer.localClippingEnabled = true;
104
- renderer.setPixelRatio(this.devicePixelRatio);
105
- renderer.autoClear = false;
104
+ renderer.setPixelRatio(Math.max(window.devicePixelRatio, this.minDevicePixelRatio)),
105
+ renderer.autoClear = false;
106
106
  renderer.clear();
107
107
  renderer.outputColorSpace = SRGBColorSpace;
108
108
  // 缓解过暗或者过亮
@@ -194,14 +194,14 @@ export default class ThreeBase extends EventDispatcher {
194
194
  // this.orthographicCamera.bottom = -height / width;
195
195
  this.orthographicCamera.left = -width / height;
196
196
  this.orthographicCamera.right = width / height;
197
- this.renderer.setPixelRatio(this.devicePixelRatio);
198
- this.renderer.setSize(width, height);
197
+ this.renderer.setPixelRatio(Math.max(window.devicePixelRatio, this.minDevicePixelRatio)),
198
+ this.renderer.setSize(width, height);
199
199
  // 设置帧缓存区的尺寸
200
- this.baseRenderTarget.setSize(width * this.devicePixelRatio, height * this.devicePixelRatio);
200
+ this.baseRenderTarget.setSize(width * Math.max(window.devicePixelRatio, this.minDevicePixelRatio), height * Math.max(window.devicePixelRatio, this.minDevicePixelRatio));
201
201
  // 设置深度纹理的尺寸
202
- this.baseDepthTexture.image.width = width * this.devicePixelRatio;
203
- this.baseDepthTexture.image.height = height * this.devicePixelRatio;
204
- this.size.set(width, height);
202
+ this.baseDepthTexture.image.width = width * Math.max(window.devicePixelRatio, this.minDevicePixelRatio),
203
+ this.baseDepthTexture.image.height = height * Math.max(window.devicePixelRatio, this.minDevicePixelRatio),
204
+ this.size.set(width, height);
205
205
  setTimeout(() => {
206
206
  this.needRender = true;
207
207
  }, 100);
@@ -489,15 +489,15 @@ export default class ThreeBase extends EventDispatcher {
489
489
  this.renderer.render(this.scene, camera);
490
490
  // 后处理特效渲染(描边,发光,颜色覆盖,bloom,磨砂玻璃)
491
491
  this.scene.traverseVisible((obj) => {
492
- stroke_pass(this.renderer, camera, obj, this.baseDepthTexture, this.devicePixelRatio);
493
- glow_pass(this.renderer, camera, obj, this.baseDepthTexture, this.devicePixelRatio);
494
- bloom_pass(this.renderer, camera, obj, this.baseRenderTarget, this.baseDepthTexture, this.devicePixelRatio);
492
+ stroke_pass(this.renderer, camera, obj, this.baseDepthTexture, Math.max(window.devicePixelRatio, this.minDevicePixelRatio));
493
+ glow_pass(this.renderer, camera, obj, this.baseDepthTexture, Math.max(window.devicePixelRatio, this.minDevicePixelRatio));
494
+ bloom_pass(this.renderer, camera, obj, this.baseRenderTarget, this.baseDepthTexture, Math.max(window.devicePixelRatio, this.minDevicePixelRatio));
495
495
  });
496
496
  this.renderer.setRenderTarget(null);
497
497
  this.renderer.clear();
498
498
  this.renderRendererTarget(this.baseRenderTarget);
499
499
  this.scene.traverseVisible((obj) => {
500
- cover_pass(this.renderer, camera, obj, this.baseDepthTexture, this.devicePixelRatio);
500
+ cover_pass(this.renderer, camera, obj, this.baseDepthTexture, Math.max(window.devicePixelRatio, this.minDevicePixelRatio));
501
501
  });
502
502
  this.dispatchEvent({ type: "afterRender" });
503
503
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-base",
3
- "version": "2.0.125",
3
+ "version": "2.0.127",
4
4
  "description": "three 3d three-base",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"