three-base 2.0.124 → 2.0.126

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/FPScontrol.d.ts CHANGED
@@ -22,8 +22,11 @@ export default class FPScontrol extends EventDispatcher {
22
22
  addOctree(obj: Object3D): Octree;
23
23
  playerCollider: Capsule;
24
24
  clock: Clock;
25
+ prePlayerVelocity: Vector3;
25
26
  playerVelocity: Vector3;
27
+ jumping: boolean;
26
28
  playerDirection: Vector3;
29
+ prePlayerOnFloor: boolean;
27
30
  playerOnFloor: boolean;
28
31
  mouseTime: number;
29
32
  isMousedown: boolean;
package/FPScontrol.js CHANGED
@@ -69,8 +69,12 @@ export default class FPScontrol extends EventDispatcher {
69
69
  playerCollider = new Capsule(new Vector3(0, 0.35, 0), new Vector3(0, 1, 0), 0.35);
70
70
  // 时钟对象
71
71
  clock = new Clock();
72
+ prePlayerVelocity = new Vector3();
72
73
  playerVelocity = new Vector3();
74
+ // 起跳中
75
+ jumping = false;
73
76
  playerDirection = new Vector3();
77
+ prePlayerOnFloor = false;
74
78
  playerOnFloor = false;
75
79
  mouseTime = 0;
76
80
  isMousedown = false;
@@ -139,7 +143,8 @@ export default class FPScontrol extends EventDispatcher {
139
143
  !this.keyStates["KeyS"] &&
140
144
  !this.keyStates["KeyA"] &&
141
145
  !this.keyStates["KeyD"]) {
142
- if (!this.inertia) { // 关闭惯性时就大幅增加动能的衰减
146
+ if (!this.inertia) {
147
+ // 关闭惯性时就大幅增加动能的衰减
143
148
  this.playerVelocity.x *= 0.85;
144
149
  this.playerVelocity.z *= 0.85;
145
150
  }
@@ -147,6 +152,8 @@ export default class FPScontrol extends EventDispatcher {
147
152
  if (this.playerOnFloor) {
148
153
  if (this.keyStates["Space"]) {
149
154
  this.playerVelocity.y = 15;
155
+ this.jumping = true;
156
+ this.dispatchEvent({ type: "jump_start" });
150
157
  }
151
158
  }
152
159
  };
@@ -174,8 +181,23 @@ export default class FPScontrol extends EventDispatcher {
174
181
  if (!this.playerOnFloor) {
175
182
  this.playerVelocity.addScaledVector(result.normal, -result.normal.dot(this.playerVelocity));
176
183
  }
184
+ const { x: preX, y: preY, z: preZ } = this.prePlayerVelocity;
185
+ const { x, y, z } = this.playerVelocity;
186
+ if (Math.abs(preX + preZ) < 0.1 && Math.abs(x + z) > 0.1) {
187
+ this.dispatchEvent({ type: "move_start" });
188
+ }
189
+ else if (Math.abs(preX + preZ) > 0.1 && Math.abs(x + z) < 0.1) {
190
+ this.dispatchEvent({ type: "move_end" });
191
+ }
192
+ this.prePlayerVelocity.copy(this.playerVelocity);
177
193
  this.playerCollider.translate(result.normal.multiplyScalar(result.depth));
178
194
  }
195
+ if (this.jumping && !this.prePlayerOnFloor && this.playerOnFloor) {
196
+ // 分发落地事件
197
+ this.jumping = false;
198
+ this.dispatchEvent({ type: "jump_end" });
199
+ }
200
+ this.prePlayerOnFloor = this.playerOnFloor;
179
201
  }
180
202
  // 更新控制器的位置
181
203
  teleportPlayerIfOob = () => {
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.124",
3
+ "version": "2.0.126",
4
4
  "description": "three 3d three-base",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"