archivable, fix deltatime

This commit is contained in:
Evert Prants 2023-06-18 09:58:58 +03:00
parent d40e2073ee
commit 84c320faa2
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
9 changed files with 22 additions and 28 deletions

View File

@ -40,6 +40,7 @@ import FileUploadSvg from '../../icons/file-upload.svg.vue';
import Menu from '../menu/Menu.vue';
import { readFileToString } from '../../utils/read-file';
import { Asset, assetManager } from '@freeblox/engine';
import { NearestFilter } from 'three';
const props = defineProps<{
editor: Editor;

View File

@ -20,7 +20,7 @@ class CameraControls extends EventDispatcher {
public pointerSpeed = 1.5;
public panSpeed = 1;
public movementSpeed = 0.025;
public movementSpeed = 16;
public shiftMultiplier = 0.45;
public zoomScale = 100;
public screenSpacePanning = true;
@ -148,9 +148,9 @@ class CameraControls extends EventDispatcher {
private onScroll(event: WheelEvent) {
if (event.deltaY < 0) {
this.moveForward(this.movementSpeed * this.zoomScale);
this.moveForward(this.movementSpeed * 0.002 * this.zoomScale);
} else if (event.deltaY > 0) {
this.moveForward(-this.movementSpeed * this.zoomScale);
this.moveForward(-this.movementSpeed * 0.002 * this.zoomScale);
}
}

View File

@ -7,13 +7,11 @@ import {
Renderer,
LevelComponent,
WorldFile,
instanceCharacterObject,
Humanoid,
} from '@freeblox/engine';
import { EditorEvents } from '../types/events';
import { WorkspaceComponent } from './workspace';
import { HistoryComponent } from './history';
import { ShotcutsComponent } from './shortcuts';
import { ShortcutsComponent } from './shortcuts';
export class Editor extends GameRunner {
public lastTick = performance.now();
@ -23,14 +21,12 @@ export class Editor extends GameRunner {
public viewport!: ViewportComponent;
public workspace!: WorkspaceComponent;
public history!: HistoryComponent;
public shortcuts!: ShotcutsComponent;
public shortcuts!: ShortcutsComponent;
public mouse!: MouseComponent;
public environment!: EnvironmentComponent;
public level!: LevelComponent;
public running = false;
private test!: Humanoid;
override mount(element: HTMLElement) {
this.element = element;
this.render = new Renderer(element);
@ -45,7 +41,7 @@ export class Editor extends GameRunner {
this.history = new HistoryComponent(this.render, this.events);
this.history.initialize();
this.shortcuts = new ShotcutsComponent(this.render, this.events);
this.shortcuts = new ShortcutsComponent(this.render, this.events);
this.shortcuts.initialize();
this.mouse = new MouseComponent(this.render, this.events);
@ -59,16 +55,10 @@ export class Editor extends GameRunner {
this.viewport.setSizeFromViewport();
this.start();
instanceCharacterObject().then((obj) => {
this.workspace.world.add(obj);
this.test = obj.getObjectByName('Humanoid');
this.test.initialize();
});
}
override loop(now: DOMHighResTimeStamp) {
const delta = now - this.lastTick;
const delta = (now - this.lastTick) / 1000;
this.lastTick = now;
this.running && requestAnimationFrame((ts) => this.loop(ts));
@ -76,7 +66,6 @@ export class Editor extends GameRunner {
this.viewport.update(delta);
this.workspace.update(delta);
this.mouse.update(delta);
this.test?.tick(delta);
this.render.render();
this.workspace.render();

View File

@ -4,7 +4,7 @@ import { EditorEvents } from '..';
/**
* Provides editing shortcuts for the editor.
*/
export class ShotcutsComponent extends EngineComponent {
export class ShortcutsComponent extends EngineComponent {
public cleanUpEvents?: Function;
constructor(

View File

@ -10,6 +10,7 @@ import { GameObject } from '../types/game-object';
import { Ticking } from '../types/ticking';
import { EditorProperty } from '../decorators/property';
import { MeshPart } from './mesh.object';
import { clamp } from 'three/src/math/MathUtils.js';
export type HumanoidBodyPart =
| 'Head'
@ -54,7 +55,7 @@ export class Humanoid extends GameObject implements Ticking {
return this._health;
}
set health(value: number) {
const health = Math.max(Math.min(Math.floor(value), this.maxHealth), 0);
const health = clamp(Math.floor(value), 0, this.maxHealth);
if (health === 0) this.die();
this.health = health;
}
@ -101,14 +102,14 @@ export class Humanoid extends GameObject implements Ticking {
this.mixer = new AnimationMixer(this.parent);
this.ready = true;
const clip = AnimationClip.findByName(this.parent.animations, 'Walk');
const clip = AnimationClip.findByName(this.parent.animations, 'Idle');
const action = this.mixer.clipAction(clip);
action.play();
}
tick(dt: number): void {
if (!this.ready) return;
this.mixer.update(dt / 1000);
this.mixer.update(dt);
}
detach(bodyPart?: HumanoidBodyPart) {

View File

@ -16,6 +16,9 @@ export class GameObject extends Object3D {
@EditorProperty({ type: Boolean })
public override visible: boolean = true;
@EditorProperty({ type: Boolean })
public archivable: boolean = true;
constructor() {
super();
this.name = this.objectType;
@ -42,7 +45,9 @@ export class GameObject extends Object3D {
name: this.name,
objectType: this.objectType,
children: this.children
.filter((entry) => entry instanceof GameObject)
.filter(
(entry) => entry instanceof GameObject && entry.archivable !== false
)
.map((entry) => (entry as GameObject).serialize()),
visible: this.visible,
};

View File

@ -72,13 +72,15 @@ export const instanceCharacterObject = async () => {
baseObject.animations = base.clips;
baseObject.add(bone as Bone);
baseObject.archivable = false;
convertedBodyParts.forEach((object) => baseObject.add(object));
convertedBodyParts.forEach((object) => (object.archivable = false));
head.texture = base.faceTexture;
const controller = new Humanoid();
controller.archivable = false;
baseObject.add(controller);
console.log(baseObject);
return baseObject;
};

View File

@ -1,3 +0,0 @@
export function clamp(x: number, min: number, max: number): number {
return Math.min(Math.max(x, min), max);
}

View File

@ -1,4 +1,3 @@
export * from './clamp';
export * from './debounce';
export * from './events';
export * from './read-metadata';