three-base 1.0.29 → 1.0.31

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/lib/ThreeBase.ts CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  import elementResizeEvent from "element-resize-event";
9
9
  import { round } from "lodash";
10
- import { AxesHelper, EventDispatcher, GridHelper, LinearFilter, NoBlending, NormalBlending, Object3D, PerspectiveCamera, RGBAFormat, Scene, Texture, Vector2, Vector3, WebGLRenderer, WebGLRenderTarget } from "three";
10
+ import { AxesHelper, EventDispatcher, GridHelper, LinearFilter, MOUSE, NoBlending, NormalBlending, Object3D, PerspectiveCamera, RGBAFormat, Scene, Texture, TOUCH, Vector2, Vector3, WebGLRenderer, WebGLRenderTarget } from "three";
11
11
  import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
12
12
  import { generateUUID } from "three/src/math/MathUtils";
13
13
  import { clearShader, coptyShader, fullScreenMesh, gaussBlurShader, strokeShader } from "./shaders";
@@ -176,7 +176,9 @@ export default class ThreeBase extends EventDispatcher {
176
176
 
177
177
  // 停止控制器的惯性
178
178
  this.controls.enableDamping = false;
179
+ this.controls.saveState();
179
180
  this.controls.update();
181
+ this.controls.reset();
180
182
  this.controls.enableDamping = true;
181
183
 
182
184
  position && this.controlsPosition.reset({ x: position.x, y: position.y, z: position.z });
@@ -189,7 +191,9 @@ export default class ThreeBase extends EventDispatcher {
189
191
 
190
192
  // 停止控制器的惯性
191
193
  this.controls.enableDamping = false;
194
+ this.controls.saveState();
192
195
  this.controls.update();
196
+ this.controls.reset();
193
197
  this.controls.enableDamping = true;
194
198
 
195
199
  let currentPosition = this.camera.position.clone();
@@ -247,6 +251,31 @@ export default class ThreeBase extends EventDispatcher {
247
251
  v3.z = 0;
248
252
  }
249
253
 
254
+ // 控制器类型
255
+ controlType: "OrbitControls" | "MapControls" = "OrbitControls";
256
+
257
+ // 记录一下空间平移方式
258
+ originScreenSpacePanning = false;
259
+
260
+ //改变控制器的类型
261
+ setControlType(controlType: "OrbitControls" | "MapControls") {
262
+
263
+ if (controlType === "OrbitControls") {
264
+ this.controls.screenSpacePanning = this.originScreenSpacePanning;
265
+ this.controls.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
266
+ this.controls.touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN };
267
+ } else if (controlType === "MapControls") {
268
+ this.originScreenSpacePanning = this.controls.screenSpacePanning;
269
+ // pan orthogonal to world-space direction camera.up
270
+ this.controls.screenSpacePanning = false;
271
+ this.controls.mouseButtons.LEFT = MOUSE.PAN;
272
+ this.controls.mouseButtons.RIGHT = MOUSE.ROTATE;
273
+ this.controls.touches.ONE = TOUCH.PAN;
274
+ this.controls.touches.TWO = TOUCH.DOLLY_ROTATE;
275
+ }
276
+
277
+ }
278
+
250
279
  // 寻找最顶层的父元素
251
280
  _findRoot(dom: ParentNode): ParentNode | undefined {
252
281
  if (dom.parentNode) {