Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control Camera Speed #285

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class Camera extends Element {

sceneRadius = 5;

flySpeed = 5;

picker: Picker;

workRenderTarget: RenderTarget;
Expand Down
2 changes: 1 addition & 1 deletion src/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class PointerController {
const z = keys.ArrowDown - keys.ArrowUp;

if (x || z) {
const factor = deltaTime * camera.distance * camera.sceneRadius * 20;
const factor = deltaTime * camera.flySpeed;
const worldTransform = camera.entity.getWorldTransform();
const xAxis = worldTransform.getX().mulScalar(x * factor);
const zAxis = worldTransform.getZ().mulScalar(z * factor);
Expand Down
10 changes: 10 additions & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,16 @@ const registerEditorEvents = (events: Events, editHistory: EditHistory, scene: S
setSplatSize(value);
});

// camera fly speed

const setFlySpeed = (value: number) => {
scene.camera.flySpeed = value;
};

events.on('camera.setFlySpeed', (value: number) => {
setFlySpeed(value);
});

// outline selection

let outlineSelection = false;
Expand Down
6 changes: 6 additions & 0 deletions src/ui/localization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const localizeInit = () => {
'options.outline-selection': 'Umriss Selektion',
'options.show-grid': 'Raster anzeigen',
'options.show-bound': 'Objektbox anzeigen',
'options.camera-fly-speed': 'Kamera Geschwindigkeit',

// Camera panel
'camera': 'KAMERA POSEN',
Expand Down Expand Up @@ -224,6 +225,7 @@ const localizeInit = () => {
'options.outline-selection': 'Outline Selection',
'options.show-grid': 'Show Grid',
'options.show-bound': 'Show Bound',
'options.camera-fly-speed': 'Fly Speed',

// Camera panel
'camera': 'CAMERA POSES',
Expand Down Expand Up @@ -385,6 +387,7 @@ const localizeInit = () => {
'options.outline-selection': 'Contour de la sélection',
'options.show-grid': 'Afficher la grille',
'options.show-bound': 'Afficher limites',
'options.camera-fly-speed': 'Vitesse de vol',

// Camera panel
'camera': 'POSES DE LA CAMERA',
Expand Down Expand Up @@ -537,6 +540,7 @@ const localizeInit = () => {
'options.outline-selection': '選択のアウトライン',
'options.show-grid': 'グリッド',
'options.show-bound': 'バウンディングボックス',
'options.camera-fly-speed': 'カメラの移動速度',

// Camera panel
'camera': 'カメラポーズ',
Expand Down Expand Up @@ -689,6 +693,7 @@ const localizeInit = () => {
'options.outline-selection': '선택 윤곽선',
'options.show-grid': '그리드 표시',
'options.show-bound': '경계 표시',
'options.camera-fly-speed': '카메라 이동 속도',

// Camera panel
'camera': '카메라 포즈',
Expand Down Expand Up @@ -841,6 +846,7 @@ const localizeInit = () => {
'options.outline-selection': '轮廓选择',
'options.show-grid': '显示网格',
'options.show-bound': '显示边界',
'options.camera-fly-speed': '相机飞行速度',

// Camera panel
'camera': '相机姿势',
Expand Down
33 changes: 33 additions & 0 deletions src/ui/view-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ class ViewPanel extends Container {
centersSizeRow.append(centersSizeLabel);
centersSizeRow.append(centersSizeSlider);

// camera fly speed

const cameraFlySpeedRow = new Container({
class: 'view-panel-row'
});

const cameraFlySpeedLabel = new Label({
text: localize('options.camera-fly-speed'),
class: 'view-panel-row-label'
});

const cameraFlySpeedSlider = new SliderInput({
class: 'view-panel-row-slider',
min: 0.1,
max: 30,
precision: 1,
value: 5
});

cameraFlySpeedRow.append(cameraFlySpeedLabel);
cameraFlySpeedRow.append(cameraFlySpeedSlider);

// outline selection

const outlineSelectionRow = new Container({
Expand Down Expand Up @@ -219,6 +241,7 @@ class ViewPanel extends Container {
this.append(outlineSelectionRow);
this.append(showGridRow);
this.append(showBoundRow);
this.append(cameraFlySpeedRow);

// handle panel visibility

Expand Down Expand Up @@ -275,6 +298,16 @@ class ViewPanel extends Container {
events.fire('camera.setMode', 'centers');
});

// camera speed

events.on('camera.flySpeed', (value: number) => {
cameraFlySpeedSlider.value = value;
});

cameraFlySpeedSlider.on('change', (value: number) => {
events.fire('camera.setFlySpeed', value);
});

// outline selection

events.on('view.outlineSelection', (value: boolean) => {
Expand Down
Loading