@inweb/viewer-three 27.2.2 → 27.2.4
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/dist/viewer-three.js +2 -30
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +1 -1
- package/dist/viewer-three.module.js +3 -31
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/controls/WalkControls.d.ts +0 -8
- package/package.json +5 -5
- package/src/Viewer/controls/WalkControls.ts +3 -41
|
@@ -19,14 +19,8 @@ export declare class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
19
19
|
movementSpeed: number;
|
|
20
20
|
multiplier: number;
|
|
21
21
|
private groundFollowingSkippedFrames;
|
|
22
|
-
readonly GROUND_BOX_HALF_SIZE = 20;
|
|
23
|
-
readonly GROUND_BOX_REFRESH_THRESHOLD = 0.3;
|
|
24
22
|
private raycaster;
|
|
25
23
|
private groundObjects;
|
|
26
|
-
private _groundObjectBoxes;
|
|
27
|
-
private _activeGroundObjects;
|
|
28
|
-
private _groundBox;
|
|
29
|
-
private _groundBoxCenter;
|
|
30
24
|
private moveKeys;
|
|
31
25
|
private moveWheel;
|
|
32
26
|
private moveClock;
|
|
@@ -47,8 +41,6 @@ export declare class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
47
41
|
onWheel: (event: WheelEvent) => void;
|
|
48
42
|
onKeyDown: (event: KeyboardEvent) => void;
|
|
49
43
|
onKeyUp: (event: KeyboardEvent) => void;
|
|
50
|
-
private _rebuildGroundBox;
|
|
51
|
-
private _needsGroundBoxRebuild;
|
|
52
44
|
private updateGroundFollowing;
|
|
53
45
|
update(): void;
|
|
54
46
|
rotateCamera(delta: Vector2): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-three",
|
|
3
|
-
"version": "27.2.
|
|
3
|
+
"version": "27.2.4",
|
|
4
4
|
"description": "JavaScript library for rendering CAD and BIM files in a browser using Three.js",
|
|
5
5
|
"homepage": "https://cloud.opendesign.com/docs/index.html",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"docs": "typedoc"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@inweb/client": "~27.2.
|
|
39
|
-
"@inweb/eventemitter2": "~27.2.
|
|
40
|
-
"@inweb/markup": "~27.2.
|
|
41
|
-
"@inweb/viewer-core": "~27.2.
|
|
38
|
+
"@inweb/client": "~27.2.4",
|
|
39
|
+
"@inweb/eventemitter2": "~27.2.4",
|
|
40
|
+
"@inweb/markup": "~27.2.4",
|
|
41
|
+
"@inweb/viewer-core": "~27.2.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@streamparser/json": "^0.0.22",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { Clock, Camera, Controls, Quaternion, Vector2, Vector3, Raycaster, Object3D, MathUtils } from "three";
|
|
25
25
|
|
|
26
26
|
interface WalkControlsEventMap {
|
|
27
27
|
change: { type: "change" };
|
|
@@ -41,15 +41,8 @@ export class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
41
41
|
public multiplier = 3;
|
|
42
42
|
private groundFollowingSkippedFrames = 0;
|
|
43
43
|
|
|
44
|
-
readonly GROUND_BOX_HALF_SIZE = 20;
|
|
45
|
-
readonly GROUND_BOX_REFRESH_THRESHOLD = 0.3; // fraction of half-size
|
|
46
|
-
|
|
47
44
|
private raycaster: Raycaster;
|
|
48
45
|
private groundObjects: Object3D[];
|
|
49
|
-
private _groundObjectBoxes = new Map<Object3D, Box3>();
|
|
50
|
-
private _activeGroundObjects: Object3D[] = [];
|
|
51
|
-
private _groundBox = new Box3();
|
|
52
|
-
private _groundBoxCenter = new Vector3();
|
|
53
46
|
|
|
54
47
|
private moveKeys: Set<string>;
|
|
55
48
|
private moveWheel = 0;
|
|
@@ -71,9 +64,6 @@ export class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
71
64
|
this.camera = camera;
|
|
72
65
|
|
|
73
66
|
this.groundObjects = groundObjects;
|
|
74
|
-
for (const obj of groundObjects) {
|
|
75
|
-
this._groundObjectBoxes.set(obj, new Box3().setFromObject(obj));
|
|
76
|
-
}
|
|
77
67
|
this.raycaster = new Raycaster();
|
|
78
68
|
this.raycaster.near = 0;
|
|
79
69
|
this.raycaster.far = this.EYE_HEIGHT + this.FAILING_DISTANCE;
|
|
@@ -188,39 +178,11 @@ export class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
188
178
|
if (this.moveKeys.delete(event.code)) this.update();
|
|
189
179
|
};
|
|
190
180
|
|
|
191
|
-
private _rebuildGroundBox(center: Vector3) {
|
|
192
|
-
const h = this.GROUND_BOX_HALF_SIZE;
|
|
193
|
-
this._groundBoxCenter.copy(center);
|
|
194
|
-
this._groundBox.set(
|
|
195
|
-
new Vector3(center.x - h, center.y - h * 4, center.z - h),
|
|
196
|
-
new Vector3(center.x + h, center.y + h * 4, center.z + h)
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
this._activeGroundObjects = this.groundObjects.filter((obj) => {
|
|
200
|
-
const objectBox = this._groundObjectBoxes.get(obj);
|
|
201
|
-
return objectBox !== undefined && this._groundBox.intersectsBox(objectBox);
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
private _needsGroundBoxRebuild(pos: Vector3): boolean {
|
|
206
|
-
if (this._activeGroundObjects.length === 0 && this.groundObjects.length > 0) return true;
|
|
207
|
-
const threshold = this.GROUND_BOX_HALF_SIZE * this.GROUND_BOX_REFRESH_THRESHOLD;
|
|
208
|
-
return (
|
|
209
|
-
Math.abs(pos.x - this._groundBoxCenter.x) > threshold || Math.abs(pos.z - this._groundBoxCenter.z) > threshold
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
181
|
private updateGroundFollowing() {
|
|
214
|
-
const pos = this.object.position;
|
|
215
|
-
|
|
216
|
-
if (this._needsGroundBoxRebuild(pos)) {
|
|
217
|
-
this._rebuildGroundBox(pos);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
182
|
this._up.copy(this.camera.up).negate();
|
|
221
|
-
this.raycaster.set(
|
|
183
|
+
this.raycaster.set(this.object.position, this._up);
|
|
222
184
|
|
|
223
|
-
const intersects = this.raycaster.intersectObjects(this.
|
|
185
|
+
const intersects = this.raycaster.intersectObjects(this.groundObjects, false);
|
|
224
186
|
if (intersects.length > 0) {
|
|
225
187
|
const groundY = intersects[0].point.y;
|
|
226
188
|
const targetY = groundY + this.EYE_HEIGHT;
|