lythreeframe 1.2.8 → 1.2.10

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.
@@ -3164,6 +3164,19 @@ class FirstPerson extends Pawn {
3164
3164
  }
3165
3165
  }
3166
3166
 
3167
+ function debounce(func, delay) {
3168
+ let timeoutId = null;
3169
+ return (...args) => {
3170
+ if (timeoutId) {
3171
+ clearTimeout(timeoutId);
3172
+ }
3173
+ timeoutId = setTimeout(() => {
3174
+ func(...args);
3175
+ timeoutId = null;
3176
+ }, delay);
3177
+ };
3178
+ }
3179
+
3167
3180
  class TransformGizmo extends Pawn {
3168
3181
  get control() {
3169
3182
  if (!this._control) {
@@ -3241,26 +3254,56 @@ class TransformGizmo extends Pawn {
3241
3254
  }
3242
3255
  }
3243
3256
  onObjectChanged() {
3244
- if (this.primaryTarget) {
3245
- //const TA1 = this.primaryTarget.getMatrixInWorld();
3246
- this.helperObject.updateMatrixWorld(true);
3247
- const TA2 = this.helperObject.matrixWorld.clone();
3248
- this.primaryTarget.onTransforming(TA2);
3249
- // const TA1Inverse = TA1.clone().invert();
3250
- //const transformMatrix = new Matrix4().multiplyMatrices(TA2, TA1Inverse);
3251
- this.targets.forEach((tar) => {
3252
- if (tar !== this.primaryTarget) {
3253
- let t = this.targetMatrixMap.get(tar);
3254
- if (t) {
3255
- let TB2 = new webgpu.Matrix4().multiplyMatrices(TA2, t); // B
3256
- tar.onTransforming(TB2);
3257
- }
3257
+ const de = debounce(() => {
3258
+ if (this.primaryTarget) {
3259
+ //const TA1 = this.primaryTarget.getMatrixInWorld();
3260
+ this.helperObject.updateMatrixWorld(true);
3261
+ const TA2 = this.helperObject.matrixWorld.clone();
3262
+ let p1 = new webgpu.Vector3();
3263
+ let q1 = new webgpu.Quaternion();
3264
+ let s1 = new webgpu.Vector3();
3265
+ TA2.decompose(p1, q1, s1);
3266
+ let mode = this.getMode();
3267
+ if (mode === "translate") {
3268
+ this.primaryTarget.onTranslating(p1);
3258
3269
  }
3259
- });
3260
- }
3261
- if (this.onUpdateFunction) {
3262
- this.onUpdateFunction();
3263
- }
3270
+ else if (mode === "rotate") {
3271
+ this.primaryTarget.onRotating(q1);
3272
+ }
3273
+ else if (mode === "scale") {
3274
+ this.primaryTarget.onScaling(s1);
3275
+ }
3276
+ // this.primaryTarget.onTransforming(TA2);
3277
+ // const TA1Inverse = TA1.clone().invert();
3278
+ //const transformMatrix = new Matrix4().multiplyMatrices(TA2, TA1Inverse);
3279
+ this.targets.forEach((tar) => {
3280
+ if (tar !== this.primaryTarget) {
3281
+ let t = this.targetMatrixMap.get(tar);
3282
+ if (t) {
3283
+ let p2 = new webgpu.Vector3();
3284
+ let q2 = new webgpu.Quaternion();
3285
+ let s2 = new webgpu.Vector3();
3286
+ let TB2 = new webgpu.Matrix4().multiplyMatrices(TA2, t); // B
3287
+ TB2.decompose(p2, q2, s2);
3288
+ if (mode === "translate") {
3289
+ tar.onTranslating(p2);
3290
+ }
3291
+ else if (mode === "rotate") {
3292
+ tar.onRotating(q2);
3293
+ }
3294
+ else if (mode === "scale") {
3295
+ tar.onScaling(s2);
3296
+ }
3297
+ // tar.onTransforming(TB2);
3298
+ }
3299
+ }
3300
+ });
3301
+ }
3302
+ if (this.onUpdateFunction) {
3303
+ this.onUpdateFunction();
3304
+ }
3305
+ }, 50);
3306
+ de();
3264
3307
  }
3265
3308
  set enable(newEnable) {
3266
3309
  this.control.enabled = newEnable;
@@ -3162,6 +3162,19 @@ class FirstPerson extends Pawn {
3162
3162
  }
3163
3163
  }
3164
3164
 
3165
+ function debounce(func, delay) {
3166
+ let timeoutId = null;
3167
+ return (...args) => {
3168
+ if (timeoutId) {
3169
+ clearTimeout(timeoutId);
3170
+ }
3171
+ timeoutId = setTimeout(() => {
3172
+ func(...args);
3173
+ timeoutId = null;
3174
+ }, delay);
3175
+ };
3176
+ }
3177
+
3165
3178
  class TransformGizmo extends Pawn {
3166
3179
  get control() {
3167
3180
  if (!this._control) {
@@ -3239,26 +3252,56 @@ class TransformGizmo extends Pawn {
3239
3252
  }
3240
3253
  }
3241
3254
  onObjectChanged() {
3242
- if (this.primaryTarget) {
3243
- //const TA1 = this.primaryTarget.getMatrixInWorld();
3244
- this.helperObject.updateMatrixWorld(true);
3245
- const TA2 = this.helperObject.matrixWorld.clone();
3246
- this.primaryTarget.onTransforming(TA2);
3247
- // const TA1Inverse = TA1.clone().invert();
3248
- //const transformMatrix = new Matrix4().multiplyMatrices(TA2, TA1Inverse);
3249
- this.targets.forEach((tar) => {
3250
- if (tar !== this.primaryTarget) {
3251
- let t = this.targetMatrixMap.get(tar);
3252
- if (t) {
3253
- let TB2 = new Matrix4().multiplyMatrices(TA2, t); // B
3254
- tar.onTransforming(TB2);
3255
- }
3255
+ const de = debounce(() => {
3256
+ if (this.primaryTarget) {
3257
+ //const TA1 = this.primaryTarget.getMatrixInWorld();
3258
+ this.helperObject.updateMatrixWorld(true);
3259
+ const TA2 = this.helperObject.matrixWorld.clone();
3260
+ let p1 = new Vector3();
3261
+ let q1 = new Quaternion();
3262
+ let s1 = new Vector3();
3263
+ TA2.decompose(p1, q1, s1);
3264
+ let mode = this.getMode();
3265
+ if (mode === "translate") {
3266
+ this.primaryTarget.onTranslating(p1);
3256
3267
  }
3257
- });
3258
- }
3259
- if (this.onUpdateFunction) {
3260
- this.onUpdateFunction();
3261
- }
3268
+ else if (mode === "rotate") {
3269
+ this.primaryTarget.onRotating(q1);
3270
+ }
3271
+ else if (mode === "scale") {
3272
+ this.primaryTarget.onScaling(s1);
3273
+ }
3274
+ // this.primaryTarget.onTransforming(TA2);
3275
+ // const TA1Inverse = TA1.clone().invert();
3276
+ //const transformMatrix = new Matrix4().multiplyMatrices(TA2, TA1Inverse);
3277
+ this.targets.forEach((tar) => {
3278
+ if (tar !== this.primaryTarget) {
3279
+ let t = this.targetMatrixMap.get(tar);
3280
+ if (t) {
3281
+ let p2 = new Vector3();
3282
+ let q2 = new Quaternion();
3283
+ let s2 = new Vector3();
3284
+ let TB2 = new Matrix4().multiplyMatrices(TA2, t); // B
3285
+ TB2.decompose(p2, q2, s2);
3286
+ if (mode === "translate") {
3287
+ tar.onTranslating(p2);
3288
+ }
3289
+ else if (mode === "rotate") {
3290
+ tar.onRotating(q2);
3291
+ }
3292
+ else if (mode === "scale") {
3293
+ tar.onScaling(s2);
3294
+ }
3295
+ // tar.onTransforming(TB2);
3296
+ }
3297
+ }
3298
+ });
3299
+ }
3300
+ if (this.onUpdateFunction) {
3301
+ this.onUpdateFunction();
3302
+ }
3303
+ }, 50);
3304
+ de();
3262
3305
  }
3263
3306
  set enable(newEnable) {
3264
3307
  this.control.enabled = newEnable;
@@ -0,0 +1 @@
1
+ export declare function debounce<T extends (...args: any[]) => any>(func: T, delay: number): (...args: Parameters<T>) => void;
@@ -1,5 +1,5 @@
1
1
  import { Pawn } from "./Pawn";
2
- import { Matrix4 } from "three/webgpu";
2
+ import { Matrix4, Quaternion, Vector3 } from "three/webgpu";
3
3
  import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
4
4
  import { Controller } from "../../Frame/Controller";
5
5
  export interface TransformType {
@@ -10,6 +10,9 @@ export interface TransformType {
10
10
  export interface ITransforming {
11
11
  isTransformAllowed(): boolean;
12
12
  onTransforming(worldMatrix: Matrix4): void;
13
+ onTranslating(worldPos: Vector3): void;
14
+ onRotating(worldQuat: Quaternion): void;
15
+ onScaling(worldScale: Vector3): void;
13
16
  getMatrixInWorld(): Matrix4;
14
17
  getAllowedTransformType(): TransformType;
15
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lythreeframe",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "description": "Three.js 封装",
5
5
  "main": "dist/bundle.cjs.js",
6
6
  "module": "dist/bundle.esm.js",