This commit is contained in:
HF 2024-01-23 14:57:24 +01:00
parent 9abd199821
commit dabda64c35

View File

@ -122,10 +122,11 @@ class VoxelPainterControls {
storeViewInStateTime = Date.now();
prevTime = Date.now();
offset = new Vector3();
direction = new Vector3();
velocity = new Vector3();
vec = new Vector3();
// force full update next tick
forceNextUpdate = true;
// forcing next update
forceNextUpdate = false;
constructor(renderer, camera, target, domElement, store) {
this.renderer = renderer;
@ -178,12 +179,10 @@ class VoxelPainterControls {
rotateLeft(angle) {
this.sphericalDelta.theta -= angle;
this.forceNextUpdate = true;
}
rotateUp(angle) {
this.sphericalDelta.phi -= angle;
this.forceNextUpdate = true;
}
// deltaX and deltaY are in pixels; right and down are positive
@ -212,7 +211,6 @@ class VoxelPainterControls {
}
v.multiplyScalar(distance);
this.panOffset.add(v);
this.forceNextUpdate = true;
}
//
@ -385,7 +383,6 @@ class VoxelPainterControls {
dollyDelta.set(0, (dollyEnd.y / dollyStart.y) ** zoomSpeed);
this.scale /= dollyDelta.y;
dollyStart.copy(dollyEnd);
this.forceNextUpdate = true;
}
handleTouchMoveDollyPan(event) {
@ -617,20 +614,23 @@ class VoxelPainterControls {
return false;
}
this.forceNextUpdate = false;
const delta = (time - this.prevTime) / 1000.0;
this.prevTime = time;
const {
camera,
target,
velocity,
direction,
offset,
vec,
spherical,
panOffset,
sphericalDelta,
} = this;
if (isMoving) {
const {
velocity,
vec,
} = this;
const delta = (time - this.prevTime) / 1000.0;
velocity.set(-moveU, moveW, moveV)
.normalize()
.multiplyScalar(1000.0 * delta);
@ -645,13 +645,6 @@ class VoxelPainterControls {
panOffset.add(vec);
}
const {
target,
offset,
spherical,
sphericalDelta,
} = this;
offset.copy(camera.position).sub(target);
// rotate offset to "y-axis-is-up" space
@ -689,13 +682,23 @@ class VoxelPainterControls {
panOffset.set(0, 0, 0);
}
target.add(panOffset);
/*
if (scope.target.y < 10.0) {
scope.target.y = 10.0;
}
*/
// clamp to boundaries
const bound = state.canvas.canvasSize / 2;
target.clamp(
{ x: -bound, y: 0, z: -bound },
{ x: bound, y: THREE_CANVAS_HEIGHT, z: bound },
);
target.clamp({
x: -bound,
y: 0,
z: -bound,
}, {
x: bound,
y: THREE_CANVAS_HEIGHT,
z: bound,
});
offset.setFromSpherical(spherical);