From 473deda2fb9be952c4fdcee529d82eb482e51f7f Mon Sep 17 00:00:00 2001 From: Giga Date: Mon, 4 Sep 2023 14:12:21 +1200 Subject: [PATCH 01/14] Create Hysteresis utility class Provides a simple rolling average hysteresis. --- src/modules/utility/hysteresis.ts | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/modules/utility/hysteresis.ts diff --git a/src/modules/utility/hysteresis.ts b/src/modules/utility/hysteresis.ts new file mode 100644 index 00000000..77bafbaf --- /dev/null +++ b/src/modules/utility/hysteresis.ts @@ -0,0 +1,51 @@ +/** + * The default number of points to sample from. + */ +const defaultLength = 10; + +/** + * A rolling average hysteresis. + * @param getter A function to retrieve new values. + * @param length `(Optional)` The number of points to sample the rolling average from. + * @param threshold `(Optional)` The snapping threshold. New values with a delta greater than this threshold will cause the output to snap to said new value. + */ +export class Hysteresis { + private getter; + private history; + private length; + private threshold; + + constructor(getter: () => number, length = defaultLength, threshold?: number) { + this.getter = getter; + this.history = new Array(); + this.length = length; + this.threshold = threshold; + + const value = getter(); + for (let i = 0; i < this.length; i++) { + this.history.push(value); + } + } + + /** + * @returns The value from the getter with hysteresis smoothing applied. + */ + public get(): number { + const value = this.getter(); + this.history.shift(); + this.history.push(value); + const average = this.history.reduce((a, b) => a + b) / this.length; + if (typeof this.threshold === "number" && Math.abs(value - this.history[this.history.length - 2]) > this.threshold) { + this.history = this.history.fill(value); + return value; + } + return average; + } + + /** + * @returns The value from the getter **without** hysteresis smoothing applied. + */ + public getInstant(): number { + return this.getter(); + } +} From 1833ff9fa4c058b4380dcdb53579ce07e93b601d Mon Sep 17 00:00:00 2001 From: Giga Date: Mon, 4 Sep 2023 14:13:50 +1200 Subject: [PATCH 02/14] Provide easier access to the active SceneController instance --- src/modules/avatar/controller/inputController.ts | 12 ++++-------- .../avatar/controller/inputs/keyboardInput.ts | 9 ++------- src/modules/scene/vscene.ts | 4 ++++ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/modules/avatar/controller/inputController.ts b/src/modules/avatar/controller/inputController.ts index 764b28d4..04854544 100644 --- a/src/modules/avatar/controller/inputController.ts +++ b/src/modules/avatar/controller/inputController.ts @@ -33,7 +33,7 @@ import { IInputHandler } from "./inputs/inputHandler"; import { KeyboardInput } from "./inputs/keyboardInput"; import { VirtualJoystickInput } from "./inputs/virtualJoystickInput"; import { applicationStore, userStore } from "@Stores/index"; -import type { SceneController } from "@Modules/scene/controllers"; +import { Renderer } from "@Base/modules/scene"; import { MouseSettingsController } from "@Base/modules/avatar/controller/inputs/mouseSettings"; // Custom camera controls. @@ -496,9 +496,7 @@ export class InputController extends ScriptComponent { return; } this._avatarState.state = State.Idle; - const sceneManager = this._scene.rootNodes.find((node) => node.id === "SceneManager") as GameObject; - const sceneController = sceneManager.components.get("SceneController") as SceneController | undefined; - sceneController?.applyGravity(); + Renderer.getScene().sceneController?.applyGravity(); } } @@ -550,15 +548,13 @@ export class InputController extends ScriptComponent { return; } - // Reset the avatar's rotation (so that it is standing up). + // Reset the avatar's rotation (so that it is standing upright). if (this._gameObject && this._gameObject.rotationQuaternion) { this._gameObject.rotationQuaternion.x = 0; this._gameObject.rotationQuaternion.z = 0; } - const sceneManager = this._scene.rootNodes.find((node) => node.id === "SceneManager") as GameObject; - const sceneController = sceneManager.components.get("SceneController") as SceneController | undefined; - sceneController?.applyGravity(); + Renderer.getScene().sceneController?.applyGravity(); this._avatarState.duration += delta; diff --git a/src/modules/avatar/controller/inputs/keyboardInput.ts b/src/modules/avatar/controller/inputs/keyboardInput.ts index e2f6c7b6..a8a3a9a7 100644 --- a/src/modules/avatar/controller/inputs/keyboardInput.ts +++ b/src/modules/avatar/controller/inputs/keyboardInput.ts @@ -33,8 +33,6 @@ import { InputState, CameraMode, InputMode } from "../inputState"; import { applicationStore, userStore } from "@Stores/index"; import { AudioManager as AudioMgr } from "@Modules/scene/audio"; import { Renderer } from "@Modules/scene"; -import type { GameObject } from "@Modules/object"; -import type { SceneController } from "@Modules/scene/controllers"; export class KeyboardInput implements IInputHandler { @@ -162,8 +160,7 @@ export class KeyboardInput implements IInputHandler { // Fly. if (sourceEvent.code === userStore.controls.keyboard.movement.fly?.keycode) { - const sceneManager = this._scene.rootNodes.find((node) => node.id === "SceneManager") as GameObject; - const sceneController = sceneManager.components.get("SceneController") as SceneController | undefined; + const sceneController = Renderer.getScene().sceneController; if (this._state.state === State.Fly) { this._state.action = Action.Jump; @@ -233,9 +230,7 @@ export class KeyboardInput implements IInputHandler { this._state.action = animation; // Remove gravity. - const sceneManager = this._scene.rootNodes.find((node) => node.id === "SceneManager") as GameObject; - const sceneController = sceneManager.components.get("SceneController") as SceneController | undefined; - sceneController?.removeGravity(); + Renderer.getScene().sceneController?.removeGravity(); // Snap to the sittable object. avatarMesh.setAbsolutePosition(selectedSitObject[0].getAbsolutePosition()); diff --git a/src/modules/scene/vscene.ts b/src/modules/scene/vscene.ts index af1c000c..dfdbe721 100644 --- a/src/modules/scene/vscene.ts +++ b/src/modules/scene/vscene.ts @@ -109,6 +109,10 @@ export class VScene { return this._css3DRenderer; } + public get sceneController(): Nullable { + return this._sceneController; + } + public render(): void { this._scene.render(); From e7f313a1d6cf0bd737c7d6ff9c305b87e2ce0808 Mon Sep 17 00:00:00 2001 From: Giga Date: Mon, 4 Sep 2023 14:16:59 +1200 Subject: [PATCH 03/14] Update the local avatar's nametag position with the hip bone position Allows the nametag to move up/down along with animations. Related to #142. --- src/modules/entity/entities/NametagEntity.ts | 20 +++++++++++++++++--- src/modules/scene/vscene.ts | 5 +++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/modules/entity/entities/NametagEntity.ts b/src/modules/entity/entities/NametagEntity.ts index 813e65b0..f42d94e0 100644 --- a/src/modules/entity/entities/NametagEntity.ts +++ b/src/modules/entity/entities/NametagEntity.ts @@ -12,7 +12,7 @@ /* eslint-disable @typescript-eslint/no-magic-numbers */ /* eslint-disable new-cap */ -import { AbstractMesh, +import { type AbstractMesh, Color3, DynamicTexture, Matrix, @@ -25,6 +25,7 @@ import { AbstractMesh, import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { Renderer } from "@Modules/scene"; import { userStore } from "@Stores/index"; +import { Hysteresis } from "@Modules/utility/hysteresis"; /** * Contains all of the memoized nametag meshes within the scene. @@ -119,7 +120,7 @@ export class NametagEntity { */ public static create( object: Mesh | AbstractMesh | TransformNode, - height: number, + height: number | (() => number), name: string, icon = false, color?: Color3, @@ -310,7 +311,15 @@ export class NametagEntity { // Position the nametag above the center of the object. const positionOffset = new Vector3(0, 0.15, 0); - mesh.position = new Vector3(positionOffset.x, height + positionOffset.y, positionOffset.z); + let h = 0; + let heightHysteresis: Nullable = null; + if (typeof height === "number") { + h = height + positionOffset.y; + } else { + h = height() + positionOffset.y; + heightHysteresis = new Hysteresis(() => height() + positionOffset.y, 100, positionOffset.y); + } + mesh.position = new Vector3(positionOffset.x, h, positionOffset.z); const scaleAdjustmentFactorX = object.scaling.x > 0 ? 1 / object.scaling.x : 1; const scaleAdjustmentFactorY = object.scaling.y > 0 ? 1 / object.scaling.y : 1; @@ -331,6 +340,11 @@ export class NametagEntity { if (!mesh) { return; } + // Update the nametag's position. + if (heightHysteresis) { + mesh.position.y = heightHysteresis.get(); + } + // Update the nametag's opacity. const avatar = Renderer.getScene()?.getMyAvatar(); if (avatar) { const avatarPosition = avatar.getAbsolutePosition().clone(); diff --git a/src/modules/scene/vscene.ts b/src/modules/scene/vscene.ts index dfdbe721..914ce850 100644 --- a/src/modules/scene/vscene.ts +++ b/src/modules/scene/vscene.ts @@ -323,7 +323,8 @@ export class VScene { } const avatarHeight = boundingVectors.max.y - boundingVectors.min.y; - const hipPosition = result.skeleton?.bones.find((bone) => bone.name === "Hips")?.position; + const hipBone = result.skeleton?.bones.find((bone) => bone.name === "Hips"); + const hipPosition = hipBone?.position; // Reload the avatar animations file in case the new avatar is a different size than the previous one. // The browser cache will prevent this from being fetched over the network if the avatar is switched frequently. @@ -380,7 +381,7 @@ export class VScene { let nametagColor = userStore.account.isAdmin ? Color3.FromHexString(applicationStore.theme.colors.primary) : undefined; NametagEntity.create( this._myAvatar, - avatarHeight, + () => (hipBone?.position.y ?? avatarHeight / 2) + avatarHeight / 2, userStore.avatar.displayName, false, nametagColor From a943334ba0bf13bf3ba8c0f2b3d8c7ae58737c25 Mon Sep 17 00:00:00 2001 From: Giga Date: Tue, 5 Sep 2023 13:46:35 +1200 Subject: [PATCH 04/14] Merge Places module into the Metaverse module To consolidate metaverse API methods. --- src/components/overlays/explore/Explore.vue | 7 +-- src/modules/metaverse/API.ts | 33 +++++++++++- src/modules/metaverse/APIPlaces.ts | 8 +++ src/modules/places/index.ts | 56 --------------------- src/pages/FirstTimeSetup.vue | 7 +-- 5 files changed, 48 insertions(+), 63 deletions(-) delete mode 100644 src/modules/places/index.ts diff --git a/src/components/overlays/explore/Explore.vue b/src/components/overlays/explore/Explore.vue index 3ca2f7d5..9073fd74 100644 --- a/src/components/overlays/explore/Explore.vue +++ b/src/components/overlays/explore/Explore.vue @@ -479,7 +479,8 @@ import { Vector3, Vector4 } from "@babylonjs/core"; import { applicationStore, userStore } from "@Stores/index"; import { Utility } from "@Modules/utility"; import { Location } from "@Modules/domain/location"; -import { Places, PlaceEntry } from "@Modules/places"; +import { API } from "@Modules/metaverse/API"; +import type { PlaceEntry } from "@Modules/metaverse/APIPlaces"; import { Renderer } from "@Modules/scene"; import Log from "@Modules/debugging/log"; import OverlayShell from "../OverlayShell.vue"; @@ -515,7 +516,7 @@ export default defineComponent({ data() { return { - placesList: [] as PlaceEntry[], + placesList: new Array(), loading: false, filterText: "", locationInput: "", @@ -598,7 +599,7 @@ export default defineComponent({ methods: { async loadPlacesList(): Promise { this.loading = true; - this.placesList = await Places.getActiveList(); + this.placesList = await API.getActivePlaceList(); this.loading = false; }, diff --git a/src/modules/metaverse/API.ts b/src/modules/metaverse/API.ts index 16e2efe0..cd5e0a66 100644 --- a/src/modules/metaverse/API.ts +++ b/src/modules/metaverse/API.ts @@ -13,8 +13,9 @@ import { MetaverseManager } from "@Modules/metaverse"; import { Account } from "../account"; import { GetAccountAPI, PostUsersAPI } from "@Modules/metaverse/APIAccount"; import { MetaverseInfoAPI } from "@Modules/metaverse/APIInfo"; -import { GetPlacesAPI } from "@Modules/metaverse/APIPlaces"; +import { GetPlacesAPI, type GetPlacesResponse, type PlaceEntry } from "@Modules/metaverse/APIPlaces"; import { OAuthTokenAPI } from "@Modules/metaverse/APIToken"; +import Log, { findErrorMessage } from "@Modules/debugging/log"; /** * Standard response from Metaverse server API requests. @@ -124,4 +125,34 @@ export class API { } throw new Error(`Vircadia API POST request to ${path} failed: ${response.status}: ${response.statusText}`); } + + /** + * @returns A list of the places (worlds) available in the connected Metaverse. + */ + public static async getActivePlaceList(): Promise { + const places: PlaceEntry[] = []; + + if (!MetaverseManager.activeMetaverse?.isConnected) { + Log.error(Log.types.PLACES, "Attempted to get places when not connected to a Metaverse server."); + } + + try { + const placesResponse = await this.get(this.endpoints.places + "?status=online") as GetPlacesResponse; + + for (const place of placesResponse.places) { + places.push({ + name: place.name, + placeId: place.placeId, + address: place.address, + description: place.description, + thumbnail: place.thumbnail ?? "", + currentAttendance: place.current_attendance ?? 0 + }); + } + } catch (error) { + Log.error(Log.types.PLACES, `Exception while attempting to get places: ${findErrorMessage(error)}`); + } + + return places; + } } diff --git a/src/modules/metaverse/APIPlaces.ts b/src/modules/metaverse/APIPlaces.ts index 3009a41a..c1259cdb 100644 --- a/src/modules/metaverse/APIPlaces.ts +++ b/src/modules/metaverse/APIPlaces.ts @@ -18,3 +18,11 @@ export interface GetPlacesResponse { "places": PlaceInfo[], "maturity-categories": string[] } +export interface PlaceEntry { + name: string; + placeId: string; + address: string; + description: string; + thumbnail: string; + currentAttendance: number; +} diff --git a/src/modules/places/index.ts b/src/modules/places/index.ts deleted file mode 100644 index 75e08e70..00000000 --- a/src/modules/places/index.ts +++ /dev/null @@ -1,56 +0,0 @@ -// -// Copyright 2021 Vircadia contributors. -// Copyright 2022 DigiSomni LLC. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -import { MetaverseManager } from "@Modules/metaverse"; -import { API } from "@Modules/metaverse/API"; -import type { GetPlacesResponse } from "@Modules/metaverse/APIPlaces"; -import Log, { findErrorMessage } from "@Modules/debugging/log"; - -export interface PlaceEntry { - name: string; - placeId: string; - address: string; - description: string; - thumbnail: string; - currentAttendance: number; -} - -/** - * Static methods for interacting with places/worlds in the connected Metaverse. - */ -export class Places { - /** - * @returns A list of the places (worlds) available in the connected Metaverse. - */ - public static async getActiveList(): Promise { - const places: PlaceEntry[] = []; - - if (!MetaverseManager.activeMetaverse?.isConnected) { - Log.error(Log.types.PLACES, "Attempted to get places when not connected to a Metaverse server."); - } - - try { - const placesResponse = await API.get(API.endpoints.places + "?status=online") as GetPlacesResponse; - - for (const place of placesResponse.places) { - places.push({ - name: place.name, - placeId: place.placeId, - address: place.address, - description: place.description, - thumbnail: place.thumbnail ?? "", - currentAttendance: place.current_attendance ?? 0 - }); - } - } catch (error) { - Log.error(Log.types.PLACES, `Exception while attempting to get places: ${findErrorMessage(error)}`); - } - - return places; - } -} diff --git a/src/pages/FirstTimeSetup.vue b/src/pages/FirstTimeSetup.vue index 2619e597..be95ab1b 100644 --- a/src/pages/FirstTimeSetup.vue +++ b/src/pages/FirstTimeSetup.vue @@ -498,7 +498,8 @@ import { defineComponent } from "vue"; import { uniqueNamesGenerator, adjectives, colors, animals } from "unique-names-generator"; import { AvatarStoreInterface } from "@Modules/avatar/StoreInterface"; import { Utility } from "@Modules/utility"; -import { Places, PlaceEntry } from "@Modules/places"; +import { API } from "@Modules/metaverse/API"; +import type { PlaceEntry } from "@Modules/metaverse/APIPlaces"; export default defineComponent({ name: "FirstTimeSetup", @@ -509,7 +510,7 @@ export default defineComponent({ transition: false, step: 1, AvatarStoreInterface, - placesList: [] as PlaceEntry[], + placesList: new Array(), selectedPlace: {} as PlaceEntry }; }, @@ -629,7 +630,7 @@ export default defineComponent({ */ async loadPlaces(): Promise { await Utility.metaverseConnectionSetup(applicationStore.defaultConnectionConfig.DEFAULT_METAVERSE_URL ?? ""); - this.placesList = await Places.getActiveList(); + this.placesList = await API.getActivePlaceList(); }, /** * Register the first-time-setup process as complete, and redirect to any pending location. From 1beb5e86f4503c2714e0412cb16b33d8ce95439f Mon Sep 17 00:00:00 2001 From: Giga Date: Fri, 8 Sep 2023 12:48:49 +1200 Subject: [PATCH 05/14] Merge the Object module into the Entity module To consolidate entities and components. --- src/components/JitsiContainer.vue | 3 +-- src/components/overlays/jitsi/Jitsi.vue | 3 +-- .../avatar/controller/inputController.ts | 2 +- .../avatar/controller/myAvatarController.ts | 2 +- src/modules/entity/EntityBuilder.ts | 2 +- .../entity/builders/AbstractEntityBuilder.ts | 2 +- .../entity/builders/ImageEntityBuilder.ts | 2 +- .../entity/builders/LightEntityBuilder.ts | 2 +- .../entity/builders/ModelEntityBuilder.ts | 2 +- .../entity/builders/ShapeEntityBuilder.ts | 2 +- .../entity/builders/ZoneEntityBuilder.ts | 2 +- .../entity/builders/materialEntityBuilder.ts | 2 +- .../entity/builders/webEntityBuilder.ts | 2 +- .../components}/GameObject.ts | 0 .../components/colliders/box.ts} | 0 .../components/colliders/capsule.ts} | 0 .../components/colliders/collider.ts | 4 ++-- .../entity/components/colliders/index.ts | 15 +++++++++++++++ .../components/colliders/mesh.ts} | 0 .../{object => entity/components}/component.ts | 0 .../entity/components/components/KeyLight.ts | 2 +- .../entity/components/components/haze.ts | 2 +- .../entity/components/components/image.ts | 3 ++- .../entity/components/components/index.ts | 10 ++++++---- .../components}/components/light.ts | 0 .../components/components/lightComponent.ts | 2 +- .../components/components/materialComponent.ts | 2 +- .../components}/components/mesh.ts | 0 .../entity/components/components/model.ts | 3 ++- .../components/components/shapeComponent.ts | 3 ++- .../entity/components/components/skybox.ts | 3 ++- .../components/controllers/EntityController.ts | 4 ++-- .../controllers/ZoneEntityController.ts | 3 +-- .../controllers/webEntityController.ts | 5 +++-- src/modules/entity/components/index.ts | 6 +++++- .../components/scripts/TeleportController.ts | 2 +- src/modules/entity/entities/NametagEntity.ts | 2 +- src/modules/entity/index.ts | 5 ++++- src/modules/object/components/index.ts | 15 --------------- src/modules/object/index.ts | 18 ------------------ .../scene/controllers/domainController.ts | 3 +-- src/modules/scene/resource.ts | 2 +- src/modules/scene/vscene.ts | 4 ++-- src/modules/script/script.ts | 2 +- 44 files changed, 70 insertions(+), 78 deletions(-) rename src/modules/{object => entity/components}/GameObject.ts (100%) rename src/modules/{object/components/colliders/boxCollider.ts => entity/components/colliders/box.ts} (100%) rename src/modules/{object/components/colliders/capsuleCollider.ts => entity/components/colliders/capsule.ts} (100%) rename src/modules/{object => entity}/components/colliders/collider.ts (97%) create mode 100644 src/modules/entity/components/colliders/index.ts rename src/modules/{object/components/colliders/meshCollider.ts => entity/components/colliders/mesh.ts} (100%) rename src/modules/{object => entity/components}/component.ts (100%) rename src/modules/{object => entity/components}/components/light.ts (100%) rename src/modules/{object => entity/components}/components/mesh.ts (100%) delete mode 100644 src/modules/object/components/index.ts delete mode 100644 src/modules/object/index.ts diff --git a/src/components/JitsiContainer.vue b/src/components/JitsiContainer.vue index 1337a463..c0e84e09 100644 --- a/src/components/JitsiContainer.vue +++ b/src/components/JitsiContainer.vue @@ -40,8 +40,7 @@ import { defineComponent } from "vue"; import { applicationStore, userStore } from "@Stores/index"; import { type JitsiRoomInfo } from "@Stores/application-store"; -import { GameObject } from "@Modules/object"; -import { WebEntityController } from "@Modules/entity"; +import { GameObject, WebEntityController } from "@Modules/entity"; export default defineComponent({ name: "JitsiContainer", diff --git a/src/components/overlays/jitsi/Jitsi.vue b/src/components/overlays/jitsi/Jitsi.vue index c11035f9..c2e5e3bf 100644 --- a/src/components/overlays/jitsi/Jitsi.vue +++ b/src/components/overlays/jitsi/Jitsi.vue @@ -47,8 +47,7 @@ import { defineComponent } from "vue"; import { applicationStore } from "@Stores/index"; import { type JitsiRoomInfo } from "@Stores/application-store"; -import { GameObject } from "@Modules/object"; -import { WebEntityController } from "@Modules/entity"; +import { GameObject, WebEntityController } from "@Modules/entity"; import OverlayShell from "../OverlayShell.vue"; export default defineComponent({ diff --git a/src/modules/avatar/controller/inputController.ts b/src/modules/avatar/controller/inputController.ts index 04854544..7ae7379d 100644 --- a/src/modules/avatar/controller/inputController.ts +++ b/src/modules/avatar/controller/inputController.ts @@ -25,7 +25,7 @@ import { Tools } from "@babylonjs/core"; import { Animator } from "../animator"; -import { GameObject, MeshComponent } from "@Modules/object"; +import { GameObject, MeshComponent } from "@Modules/entity/components"; import { ScriptComponent, inspector, inspectorAccessor } from "@Modules/script"; import { AvatarState, Action, JumpSubState, State, AnimationMap } from "./avatarState"; import { InputState, CameraMode } from "./inputState"; diff --git a/src/modules/avatar/controller/myAvatarController.ts b/src/modules/avatar/controller/myAvatarController.ts index fa104d25..c8aad00f 100644 --- a/src/modules/avatar/controller/myAvatarController.ts +++ b/src/modules/avatar/controller/myAvatarController.ts @@ -15,7 +15,7 @@ import { ScriptComponent, inspectorAccessor } from "@Modules/script"; // Domain Modules import { MyAvatarInterface, SkeletonJoint } from "@vircadia/web-sdk"; -import { MeshComponent } from "../../object"; +import { MeshComponent } from "@Modules/entity/components"; export class MyAvatarController extends ScriptComponent { private _myAvatar: Nullable = null; diff --git a/src/modules/entity/EntityBuilder.ts b/src/modules/entity/EntityBuilder.ts index d1360ca9..728484ba 100644 --- a/src/modules/entity/EntityBuilder.ts +++ b/src/modules/entity/EntityBuilder.ts @@ -10,7 +10,7 @@ // import { Scene } from "@babylonjs/core"; -import { GameObject } from "@Modules/object"; +import { GameObject } from "@Modules/entity"; import { IEntity } from "./EntityInterfaces"; import { EntityType } from "./EntityProperties"; import { AbstractEntityBuilder, ShapeEntityBuilder, LightEntityBuilder, ZoneEntityBuilder, ModelEntityBuilder, diff --git a/src/modules/entity/builders/AbstractEntityBuilder.ts b/src/modules/entity/builders/AbstractEntityBuilder.ts index 5a97d9d5..ce6ed76c 100644 --- a/src/modules/entity/builders/AbstractEntityBuilder.ts +++ b/src/modules/entity/builders/AbstractEntityBuilder.ts @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -import { GameObject } from "@Modules/object"; +import { GameObject } from "@Modules/entity"; import { IEntity } from "../EntityInterfaces"; export abstract class AbstractEntityBuilder { diff --git a/src/modules/entity/builders/ImageEntityBuilder.ts b/src/modules/entity/builders/ImageEntityBuilder.ts index 1cdb2d7e..638c0c28 100644 --- a/src/modules/entity/builders/ImageEntityBuilder.ts +++ b/src/modules/entity/builders/ImageEntityBuilder.ts @@ -11,7 +11,7 @@ import { IEntity, IImageEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Base/modules/object"; +import { GameObject } from "@Modules/entity"; import { ImageEntityController } from "../components"; export class ImageEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/entity/builders/LightEntityBuilder.ts b/src/modules/entity/builders/LightEntityBuilder.ts index 4f127b68..d05bc15c 100644 --- a/src/modules/entity/builders/LightEntityBuilder.ts +++ b/src/modules/entity/builders/LightEntityBuilder.ts @@ -11,7 +11,7 @@ import { IEntity, ILightEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Base/modules/object"; +import { GameObject } from "@Modules/entity"; import { LightEntityController } from "../components"; export class LightEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/entity/builders/ModelEntityBuilder.ts b/src/modules/entity/builders/ModelEntityBuilder.ts index 511ed7d9..c9b19567 100644 --- a/src/modules/entity/builders/ModelEntityBuilder.ts +++ b/src/modules/entity/builders/ModelEntityBuilder.ts @@ -11,7 +11,7 @@ import { IEntity, IModelEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Base/modules/object"; +import { GameObject } from "@Modules/entity"; import { ModelEntityController } from "../components"; export class ModelEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/entity/builders/ShapeEntityBuilder.ts b/src/modules/entity/builders/ShapeEntityBuilder.ts index cf3385c7..4231dad7 100644 --- a/src/modules/entity/builders/ShapeEntityBuilder.ts +++ b/src/modules/entity/builders/ShapeEntityBuilder.ts @@ -12,7 +12,7 @@ import { IEntity, IShapeEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Base/modules/object"; +import { GameObject } from "@Modules/entity"; import { ShapeEntityController } from "../components"; export class ShapeEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/entity/builders/ZoneEntityBuilder.ts b/src/modules/entity/builders/ZoneEntityBuilder.ts index 72a9b1b9..34fe312d 100644 --- a/src/modules/entity/builders/ZoneEntityBuilder.ts +++ b/src/modules/entity/builders/ZoneEntityBuilder.ts @@ -10,7 +10,7 @@ // import { IEntity, IZoneEntity } from "../EntityInterfaces"; -import { GameObject } from "@Base/modules/object"; +import { GameObject } from "@Modules/entity"; import { ZoneEntityController } from "../components"; export class ZoneEntityBuilder { diff --git a/src/modules/entity/builders/materialEntityBuilder.ts b/src/modules/entity/builders/materialEntityBuilder.ts index b1e6155c..2696070c 100644 --- a/src/modules/entity/builders/materialEntityBuilder.ts +++ b/src/modules/entity/builders/materialEntityBuilder.ts @@ -11,7 +11,7 @@ import { IEntity, IMaterialEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Base/modules/object"; +import { GameObject } from "@Modules/entity"; import { MaterialEntityController } from "../components"; export class MaterialEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/entity/builders/webEntityBuilder.ts b/src/modules/entity/builders/webEntityBuilder.ts index b7bd72de..b2520f79 100644 --- a/src/modules/entity/builders/webEntityBuilder.ts +++ b/src/modules/entity/builders/webEntityBuilder.ts @@ -11,7 +11,7 @@ import { IEntity, IWebEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Base/modules/object"; +import { GameObject } from "@Modules/entity"; import { WebEntityController } from "../components"; export class WebEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/object/GameObject.ts b/src/modules/entity/components/GameObject.ts similarity index 100% rename from src/modules/object/GameObject.ts rename to src/modules/entity/components/GameObject.ts diff --git a/src/modules/object/components/colliders/boxCollider.ts b/src/modules/entity/components/colliders/box.ts similarity index 100% rename from src/modules/object/components/colliders/boxCollider.ts rename to src/modules/entity/components/colliders/box.ts diff --git a/src/modules/object/components/colliders/capsuleCollider.ts b/src/modules/entity/components/colliders/capsule.ts similarity index 100% rename from src/modules/object/components/colliders/capsuleCollider.ts rename to src/modules/entity/components/colliders/capsule.ts diff --git a/src/modules/object/components/colliders/collider.ts b/src/modules/entity/components/colliders/collider.ts similarity index 97% rename from src/modules/object/components/colliders/collider.ts rename to src/modules/entity/components/colliders/collider.ts index 45123cb3..868d7c11 100644 --- a/src/modules/object/components/colliders/collider.ts +++ b/src/modules/entity/components/colliders/collider.ts @@ -14,8 +14,8 @@ import { PhysicsImpostor, StandardMaterial, Vector3 } from "@babylonjs/core"; import type { AbstractMesh, Material, Nullable, Scene } from "@babylonjs/core"; -import { GenericNodeComponent } from "@Modules/object/component"; -import type { GameObject } from "@Modules/object/GameObject"; +import { GenericNodeComponent } from "@Modules/entity/components"; +import type { GameObject } from "@Modules/entity/components"; const DEFAULT_MASS = 1; const DEFAULT_FRICTION = 0.5; diff --git a/src/modules/entity/components/colliders/index.ts b/src/modules/entity/components/colliders/index.ts new file mode 100644 index 00000000..fb134ecd --- /dev/null +++ b/src/modules/entity/components/colliders/index.ts @@ -0,0 +1,15 @@ +// +// index.ts +// +// Created by Giga on 5 September 2023. +// Copyright 2023 Vircadia contributors. +// Copyright 2023 DigiSomni LLC. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +export { BoxColliderComponent } from "./box"; +export { MeshColliderComponent } from "./mesh"; +export { CapsuleColliderComponent } from "./capsule"; +export { ColliderComponent } from "./collider"; diff --git a/src/modules/object/components/colliders/meshCollider.ts b/src/modules/entity/components/colliders/mesh.ts similarity index 100% rename from src/modules/object/components/colliders/meshCollider.ts rename to src/modules/entity/components/colliders/mesh.ts diff --git a/src/modules/object/component.ts b/src/modules/entity/components/component.ts similarity index 100% rename from src/modules/object/component.ts rename to src/modules/entity/components/component.ts diff --git a/src/modules/entity/components/components/KeyLight.ts b/src/modules/entity/components/components/KeyLight.ts index 20f028fd..9ced23a7 100644 --- a/src/modules/entity/components/components/KeyLight.ts +++ b/src/modules/entity/components/components/KeyLight.ts @@ -12,8 +12,8 @@ /* eslint-disable new-cap */ -import { GenericNodeComponent } from "@Modules/object"; import { DirectionalLight, Scene, Vector3 } from "@babylonjs/core"; +import { GenericNodeComponent } from "@Modules/entity/components"; import { IKeyLightProperty } from "../../EntityProperties"; import { EntityMapper } from "../../package"; diff --git a/src/modules/entity/components/components/haze.ts b/src/modules/entity/components/components/haze.ts index 8a84a262..8fc325c3 100644 --- a/src/modules/entity/components/components/haze.ts +++ b/src/modules/entity/components/components/haze.ts @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -import { GenericNodeComponent } from "@Modules/object"; import { Scene, TransformNode } from "@babylonjs/core"; +import { GenericNodeComponent } from "@Modules/entity/components"; import { IHazeProperty } from "../../EntityProperties"; import { EntityMapper } from "../../package"; diff --git a/src/modules/entity/components/components/image.ts b/src/modules/entity/components/components/image.ts index c30bfb84..bbea336b 100644 --- a/src/modules/entity/components/components/image.ts +++ b/src/modules/entity/components/components/image.ts @@ -12,8 +12,9 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ -import { MeshComponent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { MeshBuilder, Mesh, Texture, VideoTexture, StandardMaterial } from "@babylonjs/core"; +import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; +import { MeshComponent } from "./mesh"; import { IImageEntity } from "../../EntityInterfaces"; import { EntityMapper } from "../../package"; import { AssetUrl } from "../../builders/asset"; diff --git a/src/modules/entity/components/components/index.ts b/src/modules/entity/components/components/index.ts index 76181b63..d7b52703 100644 --- a/src/modules/entity/components/components/index.ts +++ b/src/modules/entity/components/components/index.ts @@ -9,11 +9,13 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -export { KeyLightComponent } from "./KeyLight"; export { HazeComponent } from "./haze"; -export { SkyboxComponent } from "./skybox"; -export { ModelComponent } from "./model"; export { ImageComponent } from "./image"; +export { KeyLightComponent } from "./KeyLight"; +export { AmbientLightComponent, LightComponent } from "./light"; +export { LightEntityComponent } from "./lightComponent"; export { MaterialComponent } from "./materialComponent"; +export { MeshComponent } from "./mesh"; +export { ModelComponent } from "./model"; export { ShapeComponent } from "./shapeComponent"; -export { LightEntityComponent } from "./lightComponent"; +export { SkyboxComponent } from "./skybox"; diff --git a/src/modules/object/components/light.ts b/src/modules/entity/components/components/light.ts similarity index 100% rename from src/modules/object/components/light.ts rename to src/modules/entity/components/components/light.ts diff --git a/src/modules/entity/components/components/lightComponent.ts b/src/modules/entity/components/components/lightComponent.ts index c5334d5e..b75b5b45 100644 --- a/src/modules/entity/components/components/lightComponent.ts +++ b/src/modules/entity/components/components/lightComponent.ts @@ -12,8 +12,8 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ -import { LightComponent } from "@Modules/object"; import { PointLight, SpotLight, Light, Vector3, Scene } from "@babylonjs/core"; +import { LightComponent } from "@Modules/entity/components"; import { ILightEntity } from "../../EntityInterfaces"; import { EntityMapper } from "../../package"; diff --git a/src/modules/entity/components/components/materialComponent.ts b/src/modules/entity/components/components/materialComponent.ts index 34e29c8a..2152c064 100644 --- a/src/modules/entity/components/components/materialComponent.ts +++ b/src/modules/entity/components/components/materialComponent.ts @@ -12,8 +12,8 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ -import { GenericNodeComponent, GameObject, MeshComponent, IComponent } from "@Modules/object"; import { Node, Material, StandardMaterial, AbstractMesh, Nullable, Observer } from "@babylonjs/core"; +import { GenericNodeComponent, GameObject, MeshComponent, IComponent } from "@Modules/entity/components"; import { IMaterialEntity } from "../../EntityInterfaces"; export class MaterialComponent extends GenericNodeComponent { diff --git a/src/modules/object/components/mesh.ts b/src/modules/entity/components/components/mesh.ts similarity index 100% rename from src/modules/object/components/mesh.ts rename to src/modules/entity/components/components/mesh.ts diff --git a/src/modules/entity/components/components/model.ts b/src/modules/entity/components/components/model.ts index 65b8fe30..b009e599 100644 --- a/src/modules/entity/components/components/model.ts +++ b/src/modules/entity/components/components/model.ts @@ -12,8 +12,9 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ -import { MeshComponent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { SceneLoader, PhysicsImpostor, AbstractMesh, TransformNode, Node } from "@babylonjs/core"; +import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; +import { MeshComponent } from "./mesh"; import { IModelEntity } from "../../EntityInterfaces"; import { NametagEntity } from "@Modules/entity/entities"; import { updateContentLoadingProgress } from "@Modules/scene/LoadingScreen"; diff --git a/src/modules/entity/components/components/shapeComponent.ts b/src/modules/entity/components/components/shapeComponent.ts index f22a8b24..9edc13c7 100644 --- a/src/modules/entity/components/components/shapeComponent.ts +++ b/src/modules/entity/components/components/shapeComponent.ts @@ -12,8 +12,9 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ -import { MeshComponent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { StandardMaterial, Mesh, MeshBuilder, PhysicsImpostor } from "@babylonjs/core"; +import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; +import { MeshComponent } from "./mesh"; import { IShapeEntity } from "../../EntityInterfaces"; import { EntityMapper } from "../../package"; diff --git a/src/modules/entity/components/components/skybox.ts b/src/modules/entity/components/components/skybox.ts index 39b06094..ba917a1f 100644 --- a/src/modules/entity/components/components/skybox.ts +++ b/src/modules/entity/components/components/skybox.ts @@ -12,8 +12,9 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ -import { MeshComponent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { Scene, MeshBuilder, StandardMaterial, Texture, CubeTexture, EquiRectangularCubeTexture, BaseTexture } from "@babylonjs/core"; +import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; +import { MeshComponent } from "./mesh"; import { ISkyboxProperty, IVector3Property } from "../../EntityProperties"; import { EntityMapper } from "../../package"; import { AssetUrl } from "../../builders/asset"; diff --git a/src/modules/entity/components/controllers/EntityController.ts b/src/modules/entity/components/controllers/EntityController.ts index 9f7115a3..59e6d723 100644 --- a/src/modules/entity/components/controllers/EntityController.ts +++ b/src/modules/entity/components/controllers/EntityController.ts @@ -10,15 +10,15 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +import { Nullable, Observer } from "@babylonjs/core"; // General Modules import Log from "@Modules/debugging/log"; // Domain Modules import { ScriptComponent } from "@Modules/script"; import { IEntity } from "../../EntityInterfaces"; import { EntityMapper } from "../../package"; -import { GameObject, MeshComponent } from "@Modules/object"; +import { GameObject, MeshComponent } from "@Modules/entity/components"; import { EntityScriptManager } from "../scripts"; -import { Nullable, Observer } from "@babylonjs/core"; export abstract class EntityController extends ScriptComponent { // domain properties diff --git a/src/modules/entity/components/controllers/ZoneEntityController.ts b/src/modules/entity/components/controllers/ZoneEntityController.ts index 91e9edd9..63bd458f 100644 --- a/src/modules/entity/components/controllers/ZoneEntityController.ts +++ b/src/modules/entity/components/controllers/ZoneEntityController.ts @@ -15,8 +15,7 @@ import { watch } from "vue"; import { EntityController } from "./EntityController"; import { IZoneEntity } from "../../EntityInterfaces"; -import { SkyboxComponent, KeyLightComponent, HazeComponent } from "../components"; -import { AmbientLightComponent } from "@Modules/object"; +import { AmbientLightComponent, SkyboxComponent, KeyLightComponent, HazeComponent } from "../components"; import { AssetUrl } from "../../builders"; import { HemisphericLight, Vector3, DefaultRenderingPipeline, CubeTexture, HDRCubeTexture, diff --git a/src/modules/entity/components/controllers/webEntityController.ts b/src/modules/entity/components/controllers/webEntityController.ts index 405984db..cda3c04a 100644 --- a/src/modules/entity/components/controllers/webEntityController.ts +++ b/src/modules/entity/components/controllers/webEntityController.ts @@ -12,11 +12,12 @@ /* eslint-disable new-cap */ /* eslint-disable @typescript-eslint/no-magic-numbers */ +import { MeshBuilder, Mesh, StandardMaterial, type Nullable } from "@babylonjs/core"; import { EntityController } from "./EntityController"; import { type IWebEntity, WebExtensions } from "../../EntityInterfaces"; -import { MeshComponent, MASK_MESH_RENDER_GROUP_ID } from "@Base/modules/object"; +import { MASK_MESH_RENDER_GROUP_ID } from "@Modules/entity"; +import { MeshComponent } from "@Modules/entity/components"; import { EntityMapper } from "../../package"; -import { MeshBuilder, Mesh, StandardMaterial, type Nullable } from "@babylonjs/core"; import { applicationStore } from "@Stores/index"; import { CSS3DObject } from "@Modules/scene/css3DRenderer"; import { Renderer } from "@Modules/scene"; diff --git a/src/modules/entity/components/index.ts b/src/modules/entity/components/index.ts index bb207c00..2237b8a0 100644 --- a/src/modules/entity/components/index.ts +++ b/src/modules/entity/components/index.ts @@ -9,7 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +export { BoxColliderComponent, MeshColliderComponent, CapsuleColliderComponent, ColliderComponent } from "./colliders"; +export { AbstractComponent, GenericNodeComponent, type IComponent } from "./component"; +export { AmbientLightComponent, LightComponent, KeyLightComponent, HazeComponent, + SkyboxComponent, ModelComponent, MeshComponent, MaterialComponent } from "./components"; export { EntityController, ShapeEntityController, ModelEntityController, LightEntityController, ZoneEntityController, ImageEntityController, MaterialEntityController, WebEntityController } from "./controllers"; -export { KeyLightComponent, HazeComponent, SkyboxComponent, ModelComponent, MaterialComponent } from "./components"; +export { GameObject } from "./GameObject"; diff --git a/src/modules/entity/components/scripts/TeleportController.ts b/src/modules/entity/components/scripts/TeleportController.ts index 25f28cb6..9ec5449f 100644 --- a/src/modules/entity/components/scripts/TeleportController.ts +++ b/src/modules/entity/components/scripts/TeleportController.ts @@ -17,7 +17,7 @@ import { inspector } from "@Modules/script"; import { Renderer, VScene } from "@Modules/scene"; import { EntityScriptComponent } from "./EntityScript"; import { Utility } from "@Modules/utility"; -import { GameObject } from "@Modules/object"; +import { GameObject } from "@Modules/entity"; import { InputController } from "@Modules/avatar"; diff --git a/src/modules/entity/entities/NametagEntity.ts b/src/modules/entity/entities/NametagEntity.ts index f42d94e0..f62819d0 100644 --- a/src/modules/entity/entities/NametagEntity.ts +++ b/src/modules/entity/entities/NametagEntity.ts @@ -22,7 +22,7 @@ import { type AbstractMesh, StandardMaterial, TransformNode, Vector3 } from "@babylonjs/core"; -import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; +import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; import { Renderer } from "@Modules/scene"; import { userStore } from "@Stores/index"; import { Hysteresis } from "@Modules/utility/hysteresis"; diff --git a/src/modules/entity/index.ts b/src/modules/entity/index.ts index 9778e5ba..41fc355c 100644 --- a/src/modules/entity/index.ts +++ b/src/modules/entity/index.ts @@ -20,4 +20,7 @@ export { EntityBuilder } from "./EntityBuilder"; export { EntityManager } from "./EntityManager"; export { EntityMapper } from "./package"; export { EntityEvent, EntityEventType } from "./entityEvent"; -export { WebEntityController } from "./components/controllers"; +export { GameObject, WebEntityController } from "./components"; + +export const MASK_MESH_RENDER_GROUP_ID = 0; +export const DEFAULT_MESH_RENDER_GROUP_ID = 1; diff --git a/src/modules/object/components/index.ts b/src/modules/object/components/index.ts deleted file mode 100644 index 59a4060e..00000000 --- a/src/modules/object/components/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -// -// index.ts -// -// Created by Nolan Huang on 30 Sep 2022. -// Copyright 2022 Vircadia contributors. -// Copyright 2022 DigiSomni LLC. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html - -export { MeshComponent } from "./mesh"; -export { LightComponent, AmbientLightComponent } from "./light"; -export { BoxColliderComponent } from "./colliders/boxCollider"; -export { MeshColliderComponent } from "./colliders/meshCollider"; -export { CapsuleColliderComponent } from "./colliders/capsuleCollider"; diff --git a/src/modules/object/index.ts b/src/modules/object/index.ts deleted file mode 100644 index e5d30a29..00000000 --- a/src/modules/object/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -// -// index.ts -// -// Created by Nolan Huang on 4 Aug 2022. -// Copyright 2022 Vircadia contributors. -// Copyright 2022 DigiSomni LLC. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html - -export { GameObject } from "./GameObject"; -export type { IComponent } from "./component"; -export { AbstractComponent, GenericNodeComponent } from "./component"; -export { MeshComponent, MeshColliderComponent, BoxColliderComponent, CapsuleColliderComponent, - LightComponent, AmbientLightComponent } from "./components"; - -export const MASK_MESH_RENDER_GROUP_ID = 0; -export const DEFAULT_MESH_RENDER_GROUP_ID = 1; diff --git a/src/modules/scene/controllers/domainController.ts b/src/modules/scene/controllers/domainController.ts index 76f629d7..989de5fa 100644 --- a/src/modules/scene/controllers/domainController.ts +++ b/src/modules/scene/controllers/domainController.ts @@ -18,8 +18,7 @@ import { MyAvatarController } from "@Modules/avatar"; import { DomainManager } from "@Modules/domain"; import { AssignmentClientState, Client } from "@Modules/domain/client"; import { ConnectionState, Domain } from "@Modules/domain/domain"; -import { EntityManager, type IEntity, EntityMapper } from "@Modules/entity"; -import { GameObject } from "@Modules/object"; +import { EntityManager, type IEntity, EntityMapper, GameObject } from "@Modules/entity"; import type { VScene } from "@Modules/scene/vscene"; import { ScriptComponent, inspectorAccessor, inspector } from "@Modules/script"; import Log from "@Modules/debugging/log"; diff --git a/src/modules/scene/resource.ts b/src/modules/scene/resource.ts index fb9a0e59..1b5260e8 100644 --- a/src/modules/scene/resource.ts +++ b/src/modules/scene/resource.ts @@ -14,7 +14,7 @@ import { AnimationGroup, Scene, SceneLoader, AssetsManager, AbstractMesh, Vector3, Quaternion, MeshBuilder, StandardMaterial, Color3, Skeleton } from "@babylonjs/core"; -import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; +import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; import { updateContentLoadingProgress } from "@Modules/scene/LoadingScreen"; import { Uuid } from "@vircadia/web-sdk"; import Log from "@Modules/debugging/log"; diff --git a/src/modules/scene/vscene.ts b/src/modules/scene/vscene.ts index 914ce850..4f6e8810 100644 --- a/src/modules/scene/vscene.ts +++ b/src/modules/scene/vscene.ts @@ -21,10 +21,10 @@ import { watch } from "vue"; import { DomainController, SceneController } from "./controllers"; import { CSS3DRenderer } from "./css3DRenderer"; import { ResourceManager } from "./resource"; -import { GameObject, MeshComponent, CapsuleColliderComponent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { ScriptComponent, requireScript, requireScripts } from "@Modules/script"; import { InputController, MyAvatarController, ScriptAvatarController, AvatarMapper } from "@Modules/avatar"; -import { IEntity, IEntityDescription, EntityBuilder, EntityEvent } from "@Modules/entity"; +import { IEntity, IEntityDescription, EntityBuilder, EntityEvent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; +import { GameObject, MeshComponent, CapsuleColliderComponent } from "@Modules/entity/components"; import { NametagEntity } from "@Modules/entity/entities"; import { DomainManager } from "@Modules/domain"; import { Location } from "@Modules/domain/location"; diff --git a/src/modules/script/script.ts b/src/modules/script/script.ts index d6e0b355..e85d3fe8 100644 --- a/src/modules/script/script.ts +++ b/src/modules/script/script.ts @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -import { IComponent, GameObject, MeshComponent } from "@Modules/object"; +import { IComponent, GameObject, MeshComponent } from "@Modules/entity/components"; import { inspectorAccessor } from "./decorators"; import { From 8b41fbb11b661890d7ad532da21ecc5dfcbf0c69 Mon Sep 17 00:00:00 2001 From: Giga Date: Thu, 14 Sep 2023 11:09:02 +1200 Subject: [PATCH 06/14] Revert "Merge the Object module into the Entity module" This reverts commit 1beb5e86f4503c2714e0412cb16b33d8ce95439f. This commit introduced a circular dependency that prevented the app from starting. I'm reverting it because I could not fix it via conventional changes --- src/components/JitsiContainer.vue | 3 ++- src/components/overlays/jitsi/Jitsi.vue | 3 ++- .../avatar/controller/inputController.ts | 2 +- .../avatar/controller/myAvatarController.ts | 2 +- src/modules/entity/EntityBuilder.ts | 2 +- .../entity/builders/AbstractEntityBuilder.ts | 2 +- .../entity/builders/ImageEntityBuilder.ts | 2 +- .../entity/builders/LightEntityBuilder.ts | 2 +- .../entity/builders/ModelEntityBuilder.ts | 2 +- .../entity/builders/ShapeEntityBuilder.ts | 2 +- .../entity/builders/ZoneEntityBuilder.ts | 2 +- .../entity/builders/materialEntityBuilder.ts | 2 +- .../entity/builders/webEntityBuilder.ts | 2 +- .../entity/components/colliders/index.ts | 15 --------------- .../entity/components/components/KeyLight.ts | 2 +- .../entity/components/components/haze.ts | 2 +- .../entity/components/components/image.ts | 3 +-- .../entity/components/components/index.ts | 10 ++++------ .../components/components/lightComponent.ts | 2 +- .../components/components/materialComponent.ts | 2 +- .../entity/components/components/model.ts | 3 +-- .../components/components/shapeComponent.ts | 3 +-- .../entity/components/components/skybox.ts | 3 +-- .../components/controllers/EntityController.ts | 4 ++-- .../controllers/ZoneEntityController.ts | 3 ++- .../controllers/webEntityController.ts | 5 ++--- src/modules/entity/components/index.ts | 6 +----- .../components/scripts/TeleportController.ts | 2 +- src/modules/entity/entities/NametagEntity.ts | 2 +- src/modules/entity/index.ts | 5 +---- .../components => object}/GameObject.ts | 0 .../{entity/components => object}/component.ts | 0 .../components/colliders/boxCollider.ts} | 0 .../components/colliders/capsuleCollider.ts} | 0 .../components/colliders/collider.ts | 4 ++-- .../components/colliders/meshCollider.ts} | 0 src/modules/object/components/index.ts | 15 +++++++++++++++ .../components => object}/components/light.ts | 0 .../components => object}/components/mesh.ts | 0 src/modules/object/index.ts | 18 ++++++++++++++++++ .../scene/controllers/domainController.ts | 3 ++- src/modules/scene/resource.ts | 2 +- src/modules/scene/vscene.ts | 4 ++-- src/modules/script/script.ts | 2 +- 44 files changed, 78 insertions(+), 70 deletions(-) delete mode 100644 src/modules/entity/components/colliders/index.ts rename src/modules/{entity/components => object}/GameObject.ts (100%) rename src/modules/{entity/components => object}/component.ts (100%) rename src/modules/{entity/components/colliders/box.ts => object/components/colliders/boxCollider.ts} (100%) rename src/modules/{entity/components/colliders/capsule.ts => object/components/colliders/capsuleCollider.ts} (100%) rename src/modules/{entity => object}/components/colliders/collider.ts (97%) rename src/modules/{entity/components/colliders/mesh.ts => object/components/colliders/meshCollider.ts} (100%) create mode 100644 src/modules/object/components/index.ts rename src/modules/{entity/components => object}/components/light.ts (100%) rename src/modules/{entity/components => object}/components/mesh.ts (100%) create mode 100644 src/modules/object/index.ts diff --git a/src/components/JitsiContainer.vue b/src/components/JitsiContainer.vue index c0e84e09..1337a463 100644 --- a/src/components/JitsiContainer.vue +++ b/src/components/JitsiContainer.vue @@ -40,7 +40,8 @@ import { defineComponent } from "vue"; import { applicationStore, userStore } from "@Stores/index"; import { type JitsiRoomInfo } from "@Stores/application-store"; -import { GameObject, WebEntityController } from "@Modules/entity"; +import { GameObject } from "@Modules/object"; +import { WebEntityController } from "@Modules/entity"; export default defineComponent({ name: "JitsiContainer", diff --git a/src/components/overlays/jitsi/Jitsi.vue b/src/components/overlays/jitsi/Jitsi.vue index c2e5e3bf..c11035f9 100644 --- a/src/components/overlays/jitsi/Jitsi.vue +++ b/src/components/overlays/jitsi/Jitsi.vue @@ -47,7 +47,8 @@ import { defineComponent } from "vue"; import { applicationStore } from "@Stores/index"; import { type JitsiRoomInfo } from "@Stores/application-store"; -import { GameObject, WebEntityController } from "@Modules/entity"; +import { GameObject } from "@Modules/object"; +import { WebEntityController } from "@Modules/entity"; import OverlayShell from "../OverlayShell.vue"; export default defineComponent({ diff --git a/src/modules/avatar/controller/inputController.ts b/src/modules/avatar/controller/inputController.ts index 7ae7379d..04854544 100644 --- a/src/modules/avatar/controller/inputController.ts +++ b/src/modules/avatar/controller/inputController.ts @@ -25,7 +25,7 @@ import { Tools } from "@babylonjs/core"; import { Animator } from "../animator"; -import { GameObject, MeshComponent } from "@Modules/entity/components"; +import { GameObject, MeshComponent } from "@Modules/object"; import { ScriptComponent, inspector, inspectorAccessor } from "@Modules/script"; import { AvatarState, Action, JumpSubState, State, AnimationMap } from "./avatarState"; import { InputState, CameraMode } from "./inputState"; diff --git a/src/modules/avatar/controller/myAvatarController.ts b/src/modules/avatar/controller/myAvatarController.ts index c8aad00f..fa104d25 100644 --- a/src/modules/avatar/controller/myAvatarController.ts +++ b/src/modules/avatar/controller/myAvatarController.ts @@ -15,7 +15,7 @@ import { ScriptComponent, inspectorAccessor } from "@Modules/script"; // Domain Modules import { MyAvatarInterface, SkeletonJoint } from "@vircadia/web-sdk"; -import { MeshComponent } from "@Modules/entity/components"; +import { MeshComponent } from "../../object"; export class MyAvatarController extends ScriptComponent { private _myAvatar: Nullable = null; diff --git a/src/modules/entity/EntityBuilder.ts b/src/modules/entity/EntityBuilder.ts index 728484ba..d1360ca9 100644 --- a/src/modules/entity/EntityBuilder.ts +++ b/src/modules/entity/EntityBuilder.ts @@ -10,7 +10,7 @@ // import { Scene } from "@babylonjs/core"; -import { GameObject } from "@Modules/entity"; +import { GameObject } from "@Modules/object"; import { IEntity } from "./EntityInterfaces"; import { EntityType } from "./EntityProperties"; import { AbstractEntityBuilder, ShapeEntityBuilder, LightEntityBuilder, ZoneEntityBuilder, ModelEntityBuilder, diff --git a/src/modules/entity/builders/AbstractEntityBuilder.ts b/src/modules/entity/builders/AbstractEntityBuilder.ts index ce6ed76c..5a97d9d5 100644 --- a/src/modules/entity/builders/AbstractEntityBuilder.ts +++ b/src/modules/entity/builders/AbstractEntityBuilder.ts @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -import { GameObject } from "@Modules/entity"; +import { GameObject } from "@Modules/object"; import { IEntity } from "../EntityInterfaces"; export abstract class AbstractEntityBuilder { diff --git a/src/modules/entity/builders/ImageEntityBuilder.ts b/src/modules/entity/builders/ImageEntityBuilder.ts index 638c0c28..1cdb2d7e 100644 --- a/src/modules/entity/builders/ImageEntityBuilder.ts +++ b/src/modules/entity/builders/ImageEntityBuilder.ts @@ -11,7 +11,7 @@ import { IEntity, IImageEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Modules/entity"; +import { GameObject } from "@Base/modules/object"; import { ImageEntityController } from "../components"; export class ImageEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/entity/builders/LightEntityBuilder.ts b/src/modules/entity/builders/LightEntityBuilder.ts index d05bc15c..4f127b68 100644 --- a/src/modules/entity/builders/LightEntityBuilder.ts +++ b/src/modules/entity/builders/LightEntityBuilder.ts @@ -11,7 +11,7 @@ import { IEntity, ILightEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Modules/entity"; +import { GameObject } from "@Base/modules/object"; import { LightEntityController } from "../components"; export class LightEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/entity/builders/ModelEntityBuilder.ts b/src/modules/entity/builders/ModelEntityBuilder.ts index c9b19567..511ed7d9 100644 --- a/src/modules/entity/builders/ModelEntityBuilder.ts +++ b/src/modules/entity/builders/ModelEntityBuilder.ts @@ -11,7 +11,7 @@ import { IEntity, IModelEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Modules/entity"; +import { GameObject } from "@Base/modules/object"; import { ModelEntityController } from "../components"; export class ModelEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/entity/builders/ShapeEntityBuilder.ts b/src/modules/entity/builders/ShapeEntityBuilder.ts index 4231dad7..cf3385c7 100644 --- a/src/modules/entity/builders/ShapeEntityBuilder.ts +++ b/src/modules/entity/builders/ShapeEntityBuilder.ts @@ -12,7 +12,7 @@ import { IEntity, IShapeEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Modules/entity"; +import { GameObject } from "@Base/modules/object"; import { ShapeEntityController } from "../components"; export class ShapeEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/entity/builders/ZoneEntityBuilder.ts b/src/modules/entity/builders/ZoneEntityBuilder.ts index 34fe312d..72a9b1b9 100644 --- a/src/modules/entity/builders/ZoneEntityBuilder.ts +++ b/src/modules/entity/builders/ZoneEntityBuilder.ts @@ -10,7 +10,7 @@ // import { IEntity, IZoneEntity } from "../EntityInterfaces"; -import { GameObject } from "@Modules/entity"; +import { GameObject } from "@Base/modules/object"; import { ZoneEntityController } from "../components"; export class ZoneEntityBuilder { diff --git a/src/modules/entity/builders/materialEntityBuilder.ts b/src/modules/entity/builders/materialEntityBuilder.ts index 2696070c..b1e6155c 100644 --- a/src/modules/entity/builders/materialEntityBuilder.ts +++ b/src/modules/entity/builders/materialEntityBuilder.ts @@ -11,7 +11,7 @@ import { IEntity, IMaterialEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Modules/entity"; +import { GameObject } from "@Base/modules/object"; import { MaterialEntityController } from "../components"; export class MaterialEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/entity/builders/webEntityBuilder.ts b/src/modules/entity/builders/webEntityBuilder.ts index b2520f79..b7bd72de 100644 --- a/src/modules/entity/builders/webEntityBuilder.ts +++ b/src/modules/entity/builders/webEntityBuilder.ts @@ -11,7 +11,7 @@ import { IEntity, IWebEntity } from "../EntityInterfaces"; import { AbstractEntityBuilder } from "./AbstractEntityBuilder"; -import { GameObject } from "@Modules/entity"; +import { GameObject } from "@Base/modules/object"; import { WebEntityController } from "../components"; export class WebEntityBuilder extends AbstractEntityBuilder { diff --git a/src/modules/entity/components/colliders/index.ts b/src/modules/entity/components/colliders/index.ts deleted file mode 100644 index fb134ecd..00000000 --- a/src/modules/entity/components/colliders/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -// -// index.ts -// -// Created by Giga on 5 September 2023. -// Copyright 2023 Vircadia contributors. -// Copyright 2023 DigiSomni LLC. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -export { BoxColliderComponent } from "./box"; -export { MeshColliderComponent } from "./mesh"; -export { CapsuleColliderComponent } from "./capsule"; -export { ColliderComponent } from "./collider"; diff --git a/src/modules/entity/components/components/KeyLight.ts b/src/modules/entity/components/components/KeyLight.ts index 9ced23a7..20f028fd 100644 --- a/src/modules/entity/components/components/KeyLight.ts +++ b/src/modules/entity/components/components/KeyLight.ts @@ -12,8 +12,8 @@ /* eslint-disable new-cap */ +import { GenericNodeComponent } from "@Modules/object"; import { DirectionalLight, Scene, Vector3 } from "@babylonjs/core"; -import { GenericNodeComponent } from "@Modules/entity/components"; import { IKeyLightProperty } from "../../EntityProperties"; import { EntityMapper } from "../../package"; diff --git a/src/modules/entity/components/components/haze.ts b/src/modules/entity/components/components/haze.ts index 8fc325c3..8a84a262 100644 --- a/src/modules/entity/components/components/haze.ts +++ b/src/modules/entity/components/components/haze.ts @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +import { GenericNodeComponent } from "@Modules/object"; import { Scene, TransformNode } from "@babylonjs/core"; -import { GenericNodeComponent } from "@Modules/entity/components"; import { IHazeProperty } from "../../EntityProperties"; import { EntityMapper } from "../../package"; diff --git a/src/modules/entity/components/components/image.ts b/src/modules/entity/components/components/image.ts index bbea336b..c30bfb84 100644 --- a/src/modules/entity/components/components/image.ts +++ b/src/modules/entity/components/components/image.ts @@ -12,9 +12,8 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ +import { MeshComponent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { MeshBuilder, Mesh, Texture, VideoTexture, StandardMaterial } from "@babylonjs/core"; -import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; -import { MeshComponent } from "./mesh"; import { IImageEntity } from "../../EntityInterfaces"; import { EntityMapper } from "../../package"; import { AssetUrl } from "../../builders/asset"; diff --git a/src/modules/entity/components/components/index.ts b/src/modules/entity/components/components/index.ts index d7b52703..76181b63 100644 --- a/src/modules/entity/components/components/index.ts +++ b/src/modules/entity/components/components/index.ts @@ -9,13 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +export { KeyLightComponent } from "./KeyLight"; export { HazeComponent } from "./haze"; +export { SkyboxComponent } from "./skybox"; +export { ModelComponent } from "./model"; export { ImageComponent } from "./image"; -export { KeyLightComponent } from "./KeyLight"; -export { AmbientLightComponent, LightComponent } from "./light"; -export { LightEntityComponent } from "./lightComponent"; export { MaterialComponent } from "./materialComponent"; -export { MeshComponent } from "./mesh"; -export { ModelComponent } from "./model"; export { ShapeComponent } from "./shapeComponent"; -export { SkyboxComponent } from "./skybox"; +export { LightEntityComponent } from "./lightComponent"; diff --git a/src/modules/entity/components/components/lightComponent.ts b/src/modules/entity/components/components/lightComponent.ts index b75b5b45..c5334d5e 100644 --- a/src/modules/entity/components/components/lightComponent.ts +++ b/src/modules/entity/components/components/lightComponent.ts @@ -12,8 +12,8 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ +import { LightComponent } from "@Modules/object"; import { PointLight, SpotLight, Light, Vector3, Scene } from "@babylonjs/core"; -import { LightComponent } from "@Modules/entity/components"; import { ILightEntity } from "../../EntityInterfaces"; import { EntityMapper } from "../../package"; diff --git a/src/modules/entity/components/components/materialComponent.ts b/src/modules/entity/components/components/materialComponent.ts index 2152c064..34e29c8a 100644 --- a/src/modules/entity/components/components/materialComponent.ts +++ b/src/modules/entity/components/components/materialComponent.ts @@ -12,8 +12,8 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ +import { GenericNodeComponent, GameObject, MeshComponent, IComponent } from "@Modules/object"; import { Node, Material, StandardMaterial, AbstractMesh, Nullable, Observer } from "@babylonjs/core"; -import { GenericNodeComponent, GameObject, MeshComponent, IComponent } from "@Modules/entity/components"; import { IMaterialEntity } from "../../EntityInterfaces"; export class MaterialComponent extends GenericNodeComponent { diff --git a/src/modules/entity/components/components/model.ts b/src/modules/entity/components/components/model.ts index b009e599..65b8fe30 100644 --- a/src/modules/entity/components/components/model.ts +++ b/src/modules/entity/components/components/model.ts @@ -12,9 +12,8 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ +import { MeshComponent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { SceneLoader, PhysicsImpostor, AbstractMesh, TransformNode, Node } from "@babylonjs/core"; -import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; -import { MeshComponent } from "./mesh"; import { IModelEntity } from "../../EntityInterfaces"; import { NametagEntity } from "@Modules/entity/entities"; import { updateContentLoadingProgress } from "@Modules/scene/LoadingScreen"; diff --git a/src/modules/entity/components/components/shapeComponent.ts b/src/modules/entity/components/components/shapeComponent.ts index 9edc13c7..f22a8b24 100644 --- a/src/modules/entity/components/components/shapeComponent.ts +++ b/src/modules/entity/components/components/shapeComponent.ts @@ -12,9 +12,8 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ +import { MeshComponent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { StandardMaterial, Mesh, MeshBuilder, PhysicsImpostor } from "@babylonjs/core"; -import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; -import { MeshComponent } from "./mesh"; import { IShapeEntity } from "../../EntityInterfaces"; import { EntityMapper } from "../../package"; diff --git a/src/modules/entity/components/components/skybox.ts b/src/modules/entity/components/components/skybox.ts index ba917a1f..39b06094 100644 --- a/src/modules/entity/components/components/skybox.ts +++ b/src/modules/entity/components/components/skybox.ts @@ -12,9 +12,8 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable new-cap */ +import { MeshComponent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { Scene, MeshBuilder, StandardMaterial, Texture, CubeTexture, EquiRectangularCubeTexture, BaseTexture } from "@babylonjs/core"; -import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; -import { MeshComponent } from "./mesh"; import { ISkyboxProperty, IVector3Property } from "../../EntityProperties"; import { EntityMapper } from "../../package"; import { AssetUrl } from "../../builders/asset"; diff --git a/src/modules/entity/components/controllers/EntityController.ts b/src/modules/entity/components/controllers/EntityController.ts index 59e6d723..9f7115a3 100644 --- a/src/modules/entity/components/controllers/EntityController.ts +++ b/src/modules/entity/components/controllers/EntityController.ts @@ -10,15 +10,15 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -import { Nullable, Observer } from "@babylonjs/core"; // General Modules import Log from "@Modules/debugging/log"; // Domain Modules import { ScriptComponent } from "@Modules/script"; import { IEntity } from "../../EntityInterfaces"; import { EntityMapper } from "../../package"; -import { GameObject, MeshComponent } from "@Modules/entity/components"; +import { GameObject, MeshComponent } from "@Modules/object"; import { EntityScriptManager } from "../scripts"; +import { Nullable, Observer } from "@babylonjs/core"; export abstract class EntityController extends ScriptComponent { // domain properties diff --git a/src/modules/entity/components/controllers/ZoneEntityController.ts b/src/modules/entity/components/controllers/ZoneEntityController.ts index 63bd458f..91e9edd9 100644 --- a/src/modules/entity/components/controllers/ZoneEntityController.ts +++ b/src/modules/entity/components/controllers/ZoneEntityController.ts @@ -15,7 +15,8 @@ import { watch } from "vue"; import { EntityController } from "./EntityController"; import { IZoneEntity } from "../../EntityInterfaces"; -import { AmbientLightComponent, SkyboxComponent, KeyLightComponent, HazeComponent } from "../components"; +import { SkyboxComponent, KeyLightComponent, HazeComponent } from "../components"; +import { AmbientLightComponent } from "@Modules/object"; import { AssetUrl } from "../../builders"; import { HemisphericLight, Vector3, DefaultRenderingPipeline, CubeTexture, HDRCubeTexture, diff --git a/src/modules/entity/components/controllers/webEntityController.ts b/src/modules/entity/components/controllers/webEntityController.ts index cda3c04a..405984db 100644 --- a/src/modules/entity/components/controllers/webEntityController.ts +++ b/src/modules/entity/components/controllers/webEntityController.ts @@ -12,12 +12,11 @@ /* eslint-disable new-cap */ /* eslint-disable @typescript-eslint/no-magic-numbers */ -import { MeshBuilder, Mesh, StandardMaterial, type Nullable } from "@babylonjs/core"; import { EntityController } from "./EntityController"; import { type IWebEntity, WebExtensions } from "../../EntityInterfaces"; -import { MASK_MESH_RENDER_GROUP_ID } from "@Modules/entity"; -import { MeshComponent } from "@Modules/entity/components"; +import { MeshComponent, MASK_MESH_RENDER_GROUP_ID } from "@Base/modules/object"; import { EntityMapper } from "../../package"; +import { MeshBuilder, Mesh, StandardMaterial, type Nullable } from "@babylonjs/core"; import { applicationStore } from "@Stores/index"; import { CSS3DObject } from "@Modules/scene/css3DRenderer"; import { Renderer } from "@Modules/scene"; diff --git a/src/modules/entity/components/index.ts b/src/modules/entity/components/index.ts index 2237b8a0..bb207c00 100644 --- a/src/modules/entity/components/index.ts +++ b/src/modules/entity/components/index.ts @@ -9,11 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -export { BoxColliderComponent, MeshColliderComponent, CapsuleColliderComponent, ColliderComponent } from "./colliders"; -export { AbstractComponent, GenericNodeComponent, type IComponent } from "./component"; -export { AmbientLightComponent, LightComponent, KeyLightComponent, HazeComponent, - SkyboxComponent, ModelComponent, MeshComponent, MaterialComponent } from "./components"; export { EntityController, ShapeEntityController, ModelEntityController, LightEntityController, ZoneEntityController, ImageEntityController, MaterialEntityController, WebEntityController } from "./controllers"; -export { GameObject } from "./GameObject"; +export { KeyLightComponent, HazeComponent, SkyboxComponent, ModelComponent, MaterialComponent } from "./components"; diff --git a/src/modules/entity/components/scripts/TeleportController.ts b/src/modules/entity/components/scripts/TeleportController.ts index 9ec5449f..25f28cb6 100644 --- a/src/modules/entity/components/scripts/TeleportController.ts +++ b/src/modules/entity/components/scripts/TeleportController.ts @@ -17,7 +17,7 @@ import { inspector } from "@Modules/script"; import { Renderer, VScene } from "@Modules/scene"; import { EntityScriptComponent } from "./EntityScript"; import { Utility } from "@Modules/utility"; -import { GameObject } from "@Modules/entity"; +import { GameObject } from "@Modules/object"; import { InputController } from "@Modules/avatar"; diff --git a/src/modules/entity/entities/NametagEntity.ts b/src/modules/entity/entities/NametagEntity.ts index f62819d0..f42d94e0 100644 --- a/src/modules/entity/entities/NametagEntity.ts +++ b/src/modules/entity/entities/NametagEntity.ts @@ -22,7 +22,7 @@ import { type AbstractMesh, StandardMaterial, TransformNode, Vector3 } from "@babylonjs/core"; -import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; +import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { Renderer } from "@Modules/scene"; import { userStore } from "@Stores/index"; import { Hysteresis } from "@Modules/utility/hysteresis"; diff --git a/src/modules/entity/index.ts b/src/modules/entity/index.ts index 41fc355c..9778e5ba 100644 --- a/src/modules/entity/index.ts +++ b/src/modules/entity/index.ts @@ -20,7 +20,4 @@ export { EntityBuilder } from "./EntityBuilder"; export { EntityManager } from "./EntityManager"; export { EntityMapper } from "./package"; export { EntityEvent, EntityEventType } from "./entityEvent"; -export { GameObject, WebEntityController } from "./components"; - -export const MASK_MESH_RENDER_GROUP_ID = 0; -export const DEFAULT_MESH_RENDER_GROUP_ID = 1; +export { WebEntityController } from "./components/controllers"; diff --git a/src/modules/entity/components/GameObject.ts b/src/modules/object/GameObject.ts similarity index 100% rename from src/modules/entity/components/GameObject.ts rename to src/modules/object/GameObject.ts diff --git a/src/modules/entity/components/component.ts b/src/modules/object/component.ts similarity index 100% rename from src/modules/entity/components/component.ts rename to src/modules/object/component.ts diff --git a/src/modules/entity/components/colliders/box.ts b/src/modules/object/components/colliders/boxCollider.ts similarity index 100% rename from src/modules/entity/components/colliders/box.ts rename to src/modules/object/components/colliders/boxCollider.ts diff --git a/src/modules/entity/components/colliders/capsule.ts b/src/modules/object/components/colliders/capsuleCollider.ts similarity index 100% rename from src/modules/entity/components/colliders/capsule.ts rename to src/modules/object/components/colliders/capsuleCollider.ts diff --git a/src/modules/entity/components/colliders/collider.ts b/src/modules/object/components/colliders/collider.ts similarity index 97% rename from src/modules/entity/components/colliders/collider.ts rename to src/modules/object/components/colliders/collider.ts index 868d7c11..45123cb3 100644 --- a/src/modules/entity/components/colliders/collider.ts +++ b/src/modules/object/components/colliders/collider.ts @@ -14,8 +14,8 @@ import { PhysicsImpostor, StandardMaterial, Vector3 } from "@babylonjs/core"; import type { AbstractMesh, Material, Nullable, Scene } from "@babylonjs/core"; -import { GenericNodeComponent } from "@Modules/entity/components"; -import type { GameObject } from "@Modules/entity/components"; +import { GenericNodeComponent } from "@Modules/object/component"; +import type { GameObject } from "@Modules/object/GameObject"; const DEFAULT_MASS = 1; const DEFAULT_FRICTION = 0.5; diff --git a/src/modules/entity/components/colliders/mesh.ts b/src/modules/object/components/colliders/meshCollider.ts similarity index 100% rename from src/modules/entity/components/colliders/mesh.ts rename to src/modules/object/components/colliders/meshCollider.ts diff --git a/src/modules/object/components/index.ts b/src/modules/object/components/index.ts new file mode 100644 index 00000000..59a4060e --- /dev/null +++ b/src/modules/object/components/index.ts @@ -0,0 +1,15 @@ +// +// index.ts +// +// Created by Nolan Huang on 30 Sep 2022. +// Copyright 2022 Vircadia contributors. +// Copyright 2022 DigiSomni LLC. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + +export { MeshComponent } from "./mesh"; +export { LightComponent, AmbientLightComponent } from "./light"; +export { BoxColliderComponent } from "./colliders/boxCollider"; +export { MeshColliderComponent } from "./colliders/meshCollider"; +export { CapsuleColliderComponent } from "./colliders/capsuleCollider"; diff --git a/src/modules/entity/components/components/light.ts b/src/modules/object/components/light.ts similarity index 100% rename from src/modules/entity/components/components/light.ts rename to src/modules/object/components/light.ts diff --git a/src/modules/entity/components/components/mesh.ts b/src/modules/object/components/mesh.ts similarity index 100% rename from src/modules/entity/components/components/mesh.ts rename to src/modules/object/components/mesh.ts diff --git a/src/modules/object/index.ts b/src/modules/object/index.ts new file mode 100644 index 00000000..e5d30a29 --- /dev/null +++ b/src/modules/object/index.ts @@ -0,0 +1,18 @@ +// +// index.ts +// +// Created by Nolan Huang on 4 Aug 2022. +// Copyright 2022 Vircadia contributors. +// Copyright 2022 DigiSomni LLC. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + +export { GameObject } from "./GameObject"; +export type { IComponent } from "./component"; +export { AbstractComponent, GenericNodeComponent } from "./component"; +export { MeshComponent, MeshColliderComponent, BoxColliderComponent, CapsuleColliderComponent, + LightComponent, AmbientLightComponent } from "./components"; + +export const MASK_MESH_RENDER_GROUP_ID = 0; +export const DEFAULT_MESH_RENDER_GROUP_ID = 1; diff --git a/src/modules/scene/controllers/domainController.ts b/src/modules/scene/controllers/domainController.ts index 989de5fa..76f629d7 100644 --- a/src/modules/scene/controllers/domainController.ts +++ b/src/modules/scene/controllers/domainController.ts @@ -18,7 +18,8 @@ import { MyAvatarController } from "@Modules/avatar"; import { DomainManager } from "@Modules/domain"; import { AssignmentClientState, Client } from "@Modules/domain/client"; import { ConnectionState, Domain } from "@Modules/domain/domain"; -import { EntityManager, type IEntity, EntityMapper, GameObject } from "@Modules/entity"; +import { EntityManager, type IEntity, EntityMapper } from "@Modules/entity"; +import { GameObject } from "@Modules/object"; import type { VScene } from "@Modules/scene/vscene"; import { ScriptComponent, inspectorAccessor, inspector } from "@Modules/script"; import Log from "@Modules/debugging/log"; diff --git a/src/modules/scene/resource.ts b/src/modules/scene/resource.ts index 1b5260e8..fb9a0e59 100644 --- a/src/modules/scene/resource.ts +++ b/src/modules/scene/resource.ts @@ -14,7 +14,7 @@ import { AnimationGroup, Scene, SceneLoader, AssetsManager, AbstractMesh, Vector3, Quaternion, MeshBuilder, StandardMaterial, Color3, Skeleton } from "@babylonjs/core"; -import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; +import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { updateContentLoadingProgress } from "@Modules/scene/LoadingScreen"; import { Uuid } from "@vircadia/web-sdk"; import Log from "@Modules/debugging/log"; diff --git a/src/modules/scene/vscene.ts b/src/modules/scene/vscene.ts index 4f6e8810..914ce850 100644 --- a/src/modules/scene/vscene.ts +++ b/src/modules/scene/vscene.ts @@ -21,10 +21,10 @@ import { watch } from "vue"; import { DomainController, SceneController } from "./controllers"; import { CSS3DRenderer } from "./css3DRenderer"; import { ResourceManager } from "./resource"; +import { GameObject, MeshComponent, CapsuleColliderComponent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object"; import { ScriptComponent, requireScript, requireScripts } from "@Modules/script"; import { InputController, MyAvatarController, ScriptAvatarController, AvatarMapper } from "@Modules/avatar"; -import { IEntity, IEntityDescription, EntityBuilder, EntityEvent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/entity"; -import { GameObject, MeshComponent, CapsuleColliderComponent } from "@Modules/entity/components"; +import { IEntity, IEntityDescription, EntityBuilder, EntityEvent } from "@Modules/entity"; import { NametagEntity } from "@Modules/entity/entities"; import { DomainManager } from "@Modules/domain"; import { Location } from "@Modules/domain/location"; diff --git a/src/modules/script/script.ts b/src/modules/script/script.ts index e85d3fe8..d6e0b355 100644 --- a/src/modules/script/script.ts +++ b/src/modules/script/script.ts @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -import { IComponent, GameObject, MeshComponent } from "@Modules/entity/components"; +import { IComponent, GameObject, MeshComponent } from "@Modules/object"; import { inspectorAccessor } from "./decorators"; import { From 87198efc4d6ccb5ae3435c32c6fbf3591b22d9ea Mon Sep 17 00:00:00 2001 From: Giga Date: Thu, 14 Sep 2023 12:15:44 +1200 Subject: [PATCH 07/14] Reduce the use of type assertions In favour of runtime type checking with `instanceof`. --- src/components/JitsiContainer.vue | 5 ++-- src/components/overlays/avatar/Avatar.vue | 4 +-- src/components/overlays/jitsi/Jitsi.vue | 5 ++-- .../avatar/controller/inputController.ts | 30 +++++++++---------- .../avatar/controller/myAvatarController.ts | 10 +++---- .../components/scripts/TeleportController.ts | 4 +-- src/modules/entity/entities/NametagEntity.ts | 8 ++--- .../scene/controllers/domainController.ts | 14 ++++----- src/modules/scene/vscene.ts | 12 ++++---- 9 files changed, 43 insertions(+), 49 deletions(-) diff --git a/src/components/JitsiContainer.vue b/src/components/JitsiContainer.vue index 1337a463..8b934bdb 100644 --- a/src/components/JitsiContainer.vue +++ b/src/components/JitsiContainer.vue @@ -70,10 +70,9 @@ export default defineComponent({ }, setupWebEntity(room: JitsiRoomInfo, element: HTMLElement): void { const gameObject = GameObject.getGameObjectByID(room.entity.id); - const controller = gameObject?.getComponent(WebEntityController.typeName) as WebEntityController; - if (controller) { + const controller = gameObject?.getComponent(WebEntityController.typeName); + if (controller instanceof WebEntityController) { controller.externalElement = element; - } } } diff --git a/src/components/overlays/avatar/Avatar.vue b/src/components/overlays/avatar/Avatar.vue index 81f532cc..09273367 100644 --- a/src/components/overlays/avatar/Avatar.vue +++ b/src/components/overlays/avatar/Avatar.vue @@ -515,8 +515,8 @@ export default defineComponent({ set: function(pVal: string): void { Log.debug(Log.types.AVATAR, `Avatar.vue: set displayNameStore. inputInfo=${pVal}`); const scene = Renderer.getScene(); - const avatarController = scene._myAvatar?.getComponent(MyAvatarController.typeName) as MyAvatarController; - if (avatarController) { + const avatarController = scene._myAvatar?.getComponent(MyAvatarController.typeName); + if (avatarController instanceof MyAvatarController) { avatarController.displayName = pVal; } this.userStore.avatar.displayName = pVal; diff --git a/src/components/overlays/jitsi/Jitsi.vue b/src/components/overlays/jitsi/Jitsi.vue index c11035f9..3fffd234 100644 --- a/src/components/overlays/jitsi/Jitsi.vue +++ b/src/components/overlays/jitsi/Jitsi.vue @@ -71,9 +71,10 @@ export default defineComponent({ }, methods: { - getWebEntityController() : WebEntityController { + getWebEntityController(): WebEntityController | undefined { const gameObject = GameObject.getGameObjectByID(this.room.entity.id); - return gameObject?.getComponent(WebEntityController.typeName) as WebEntityController; + const component = gameObject?.getComponent(WebEntityController.typeName); + return component instanceof WebEntityController ? component : undefined; } }, diff --git a/src/modules/avatar/controller/inputController.ts b/src/modules/avatar/controller/inputController.ts index 04854544..23317e84 100644 --- a/src/modules/avatar/controller/inputController.ts +++ b/src/modules/avatar/controller/inputController.ts @@ -41,7 +41,7 @@ class ArcRotateCameraCustomInput implements ICameraInput { className = "ArcRotateCameraCustomInput"; simpleName = "customKeyboardRotate"; camera: ArcRotateCamera; - _keysPressed = [] as string[]; + _keysPressed = new Array(); sensibility = 0.01; _preventDefault = false; @@ -68,9 +68,11 @@ class ArcRotateCameraCustomInput implements ICameraInput { attachControl(preventDefault: boolean): void { this._preventDefault = preventDefault; const engine = this.camera.getEngine(); - const element = engine.getInputElement() as HTMLElement; + const element = engine.getInputElement(); if (!this._onKeyDown || !this._onKeyUp) { - element.tabIndex = 1; + if (element) { + element.tabIndex = 1; + } // Define the keydown event handler. this._onKeyDown = (event: KeyboardEvent) => { if (this._preventDefault) { @@ -82,7 +84,7 @@ class ArcRotateCameraCustomInput implements ICameraInput { this._keysPressed.push(event.code); } }; - element.addEventListener("keydown", (event) => { + element?.addEventListener("keydown", (event) => { if (this._onKeyDown) { this._onKeyDown(event); } @@ -98,7 +100,7 @@ class ArcRotateCameraCustomInput implements ICameraInput { this._keysPressed.splice(index, 1); } }; - element.addEventListener("keyup", (event) => { + element?.addEventListener("keyup", (event) => { if (this._onKeyUp) { this._onKeyUp(event); } @@ -114,16 +116,16 @@ class ArcRotateCameraCustomInput implements ICameraInput { detachControl(): void { const engine = this.camera.getEngine(); - const element = engine.getInputElement() as HTMLElement; + const element = engine.getInputElement(); if (this._onKeyDown || this._onKeyUp) { // Remove all event listeners. - element.removeEventListener("keydown", (event) => { + element?.removeEventListener("keydown", (event) => { if (this._onKeyDown) { this._onKeyDown(event); } }); this._onKeyDown = undefined; - element.removeEventListener("keyup", (event) => { + element?.removeEventListener("keyup", (event) => { if (this._onKeyUp) { this._onKeyUp(event); } @@ -172,7 +174,7 @@ export class InputController extends ScriptComponent { private _cameraSkin = 0.1; private _cameraElastic = true; private _cameraViewTransitionThreshold = 1.5; - private _animGroups: Nullable> = null; + private _animGroups = new Array(); private _animator: Nullable = null; private _avatarState: AvatarState = new AvatarState(); private _avatarHeight = 0; @@ -342,9 +344,7 @@ export class InputController extends ScriptComponent { public onInitialize(): void { - this._animator = new Animator( - this._gameObject as GameObject, - this._animGroups as AnimationGroup[]); + this._animator = new Animator(this._gameObject as GameObject, this._animGroups); // Jump animation-end handler. const jumpAnim = this._animator.getAnimationGroup("jump_standing_land_settle_all"); @@ -885,9 +885,9 @@ export class InputController extends ScriptComponent { } // Set the visibility of the avatar's mesh. - const meshComp = this._gameObject.getComponent(MeshComponent.typeName) as MeshComponent; - if (meshComp) { - meshComp.visible = visible; + const meshComponent = this._gameObject.getComponent("Mesh"); + if (meshComponent instanceof MeshComponent) { + meshComponent.visible = visible; } } } diff --git a/src/modules/avatar/controller/myAvatarController.ts b/src/modules/avatar/controller/myAvatarController.ts index fa104d25..64c9228a 100644 --- a/src/modules/avatar/controller/myAvatarController.ts +++ b/src/modules/avatar/controller/myAvatarController.ts @@ -105,21 +105,21 @@ export class MyAvatarController extends ScriptComponent { const skeleton = new Array(); this._skeletonNodes.clear(); - const comp = this._gameObject.getComponent(MeshComponent.typeName) as MeshComponent; + const component = this._gameObject.getComponent(MeshComponent.typeName); - if (!comp || !comp.mesh) { + if (!(component instanceof MeshComponent) || !component.mesh) { return; } // Collect the names of the bones in the skeleton. const bones: string[] = []; - if (comp.skeleton) { - for (const bone of comp.skeleton.bones) { + if (component.skeleton) { + for (const bone of component.skeleton.bones) { bones.push(bone.name); } } - const nodes = comp.mesh.getChildren((node) => node.getClassName() === "TransformNode", false); + const nodes = component.mesh.getChildren((node) => node.getClassName() === "TransformNode", false); nodes?.forEach((node) => { this._skeletonNodes.set(node.name, node as TransformNode); }); diff --git a/src/modules/entity/components/scripts/TeleportController.ts b/src/modules/entity/components/scripts/TeleportController.ts index 25f28cb6..b0a67dee 100644 --- a/src/modules/entity/components/scripts/TeleportController.ts +++ b/src/modules/entity/components/scripts/TeleportController.ts @@ -77,9 +77,9 @@ export class TeleportController extends EntityScriptComponent { return; } - const controller = avatar.getComponent(InputController.typeName) as InputController; + const controller = avatar.getComponent(InputController.typeName); - if (controller && !controller.isTeleported) { + if (controller instanceof InputController && !controller.isTeleported) { void Utility.connectionSetup(this._destination); } } diff --git a/src/modules/entity/entities/NametagEntity.ts b/src/modules/entity/entities/NametagEntity.ts index f42d94e0..cd536868 100644 --- a/src/modules/entity/entities/NametagEntity.ts +++ b/src/modules/entity/entities/NametagEntity.ts @@ -61,7 +61,7 @@ function createSector(name: string, vector1: Vector3, vector2: Vector3, radius = const segmentAngle = sectorAngle / segments; // Create points to connect each segment. - const points = [] as Vector3[]; + const points = new Array(); for (let i = 0; i < segments; i++) { const matrix = Matrix.RotationAxis(Vector3.Cross(vector1, vector2), segmentAngle * i); const rotated = Vector3.TransformCoordinates(firstPoint, matrix); @@ -70,7 +70,7 @@ function createSector(name: string, vector1: Vector3, vector2: Vector3, radius = points.push(lastPoint.add(origin)); // Connect each segment point back to the origin. - const originPoints = [] as Vector3[]; + const originPoints = new Array(); points.forEach(() => { originPoints.push(origin); }); @@ -225,7 +225,7 @@ export class NametagEntity { plane.material = foregroundMaterial; // Rounded corners. - const corners = [] as Mesh[]; + const corners = new Array(); const cornerPositions = [ new Vector3(-tagWidth / 2, tagHeight / 2 - tagCornerRadius, 0), new Vector3(tagWidth / 2, tagHeight / 2 - tagCornerRadius, 0), @@ -252,7 +252,7 @@ export class NametagEntity { } // Left and right edges. - const edges = [] as Mesh[]; + const edges = new Array(); const edgeOptions = { width: tagCornerRadius, height: tagHeight - tagCornerRadius * 2, diff --git a/src/modules/scene/controllers/domainController.ts b/src/modules/scene/controllers/domainController.ts index 76f629d7..009092e7 100644 --- a/src/modules/scene/controllers/domainController.ts +++ b/src/modules/scene/controllers/domainController.ts @@ -108,12 +108,9 @@ export class DomainController extends ScriptComponent { } else if (state === ConnectionState.DISCONNECTED) { this._vscene?.unloadAllAvatars(); - if (this._vscene && this._vscene._myAvatar) { - const myAvatarController = this._vscene._myAvatar.getComponent( - MyAvatarController.typeName) as MyAvatarController; - if (myAvatarController) { - myAvatarController.myAvatar = null; - } + const myAvatarController = this._vscene?._myAvatar?.getComponent(MyAvatarController.typeName); + if (myAvatarController instanceof MyAvatarController) { + myAvatarController.myAvatar = null; } const avatarList = this._avatarMixer?.avatarList; @@ -157,9 +154,8 @@ export class DomainController extends ScriptComponent { myAvatarInterface.skeletonModelURL = this._vscene.myAvatarModelURL; } - const gameObject = this._vscene._myAvatar; - if (gameObject) { - const myAvatarController = gameObject.getComponent(MyAvatarController.typeName) as MyAvatarController; + const myAvatarController = this._vscene._myAvatar?.getComponent(MyAvatarController.typeName); + if (myAvatarController instanceof MyAvatarController) { myAvatarController.myAvatar = myAvatarInterface; } } diff --git a/src/modules/scene/vscene.ts b/src/modules/scene/vscene.ts index 914ce850..a6e5feff 100644 --- a/src/modules/scene/vscene.ts +++ b/src/modules/scene/vscene.ts @@ -210,11 +210,9 @@ export class VScene { } public stopMyAvatar(): void { - if (this._myAvatar) { - const controller = this._myAvatar.getComponent(InputController.typeName) as InputController; - if (controller) { - controller.isStopped = true; - } + const controller = this._myAvatar?.getComponent(InputController.typeName); + if (controller instanceof InputController) { + controller.isStopped = true; } } @@ -231,8 +229,8 @@ export class VScene { this._myAvatar.rotationQuaternion = rotation; } - const controller = this._myAvatar.getComponent(InputController.typeName) as InputController; - if (controller) { + const controller = this._myAvatar.getComponent(InputController.typeName); + if (controller instanceof InputController) { controller.isTeleported = true; } } From 569e707427667b7bb754e0f6004700e0f343f90d Mon Sep 17 00:00:00 2001 From: Giga Date: Thu, 14 Sep 2023 12:16:27 +1200 Subject: [PATCH 08/14] Update attribution --- src/modules/utility/hysteresis.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/modules/utility/hysteresis.ts b/src/modules/utility/hysteresis.ts index 77bafbaf..e3666bf3 100644 --- a/src/modules/utility/hysteresis.ts +++ b/src/modules/utility/hysteresis.ts @@ -1,3 +1,14 @@ +// +// hysteresis.ts +// +// Created by Giga on 4 September 2023. +// Copyright 2023 Vircadia contributors. +// Copyright 2023 DigiSomni LLC. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + /** * The default number of points to sample from. */ From b0af5bd0db65c343c0bf388e39dbe294412eadc8 Mon Sep 17 00:00:00 2001 From: Giga Date: Thu, 14 Sep 2023 15:50:55 +1200 Subject: [PATCH 09/14] Update other players' nametag positions with their avatar's hip bone position --- src/modules/scene/vscene.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/scene/vscene.ts b/src/modules/scene/vscene.ts index a6e5feff..2bbea14a 100644 --- a/src/modules/scene/vscene.ts +++ b/src/modules/scene/vscene.ts @@ -447,20 +447,24 @@ export class VScene { avatar.addComponent(meshComponent); avatar.addComponent(new ScriptAvatarController(domain)); + const hipBone = meshComponent.skeleton?.bones.find((bone) => bone.name === "Hips"); + const hipPosition = hipBone?.position; + const nametagHeight = () => (hipPosition?.y ?? avatarHeight / 2) + avatarHeight / 2; + this._avatarList.set(stringId, avatar); // Add a nametag to the avatar. let nametagColor = applicationStore.avatars.avatarsInfo.get(id)?.isAdmin ? Color3.FromHexString(applicationStore.theme.colors.primary) : undefined; - NametagEntity.create(avatar, avatarHeight, domain.displayName, false, nametagColor); + NametagEntity.create(avatar, nametagHeight, domain.displayName, false, nametagColor); // Update the nametag color when the player's admin state is changed. watch(() => Boolean(applicationStore.avatars.avatarsInfo.get(id)?.isAdmin), (value: boolean) => { nametagColor = value ? Color3.FromHexString(applicationStore.theme.colors.primary) : undefined; const nametagAvatar = this._avatarList.get(stringId); NametagEntity.removeAll(nametagAvatar); if (nametagAvatar) { - NametagEntity.create(nametagAvatar, avatarHeight, domain.displayName, false, nametagColor); + NametagEntity.create(nametagAvatar, nametagHeight, domain.displayName, false, nametagColor); } }); // Update the nametag when the displayName is changed. @@ -468,7 +472,7 @@ export class VScene { const nametagAvatar = this._avatarList.get(stringId); NametagEntity.removeAll(nametagAvatar); if (nametagAvatar) { - NametagEntity.create(nametagAvatar, avatarHeight, domain.displayName, false, nametagColor); + NametagEntity.create(nametagAvatar, nametagHeight, domain.displayName, false, nametagColor); } }); } From 89598c2de2e08eb4eeb1bc2e562615d12c18a52a Mon Sep 17 00:00:00 2001 From: Giga Date: Thu, 14 Sep 2023 15:56:38 +1200 Subject: [PATCH 10/14] Update the camera's position with the avatar's hip bone position Allows the camera to move up/down along with animations. --- .../avatar/controller/inputController.ts | 39 +++++++++++++++---- .../avatar/controller/myAvatarController.ts | 38 ++++++++++-------- src/modules/scene/vscene.ts | 17 +++----- 3 files changed, 58 insertions(+), 36 deletions(-) diff --git a/src/modules/avatar/controller/inputController.ts b/src/modules/avatar/controller/inputController.ts index 23317e84..0208a26f 100644 --- a/src/modules/avatar/controller/inputController.ts +++ b/src/modules/avatar/controller/inputController.ts @@ -33,8 +33,9 @@ import { IInputHandler } from "./inputs/inputHandler"; import { KeyboardInput } from "./inputs/keyboardInput"; import { VirtualJoystickInput } from "./inputs/virtualJoystickInput"; import { applicationStore, userStore } from "@Stores/index"; -import { Renderer } from "@Base/modules/scene"; -import { MouseSettingsController } from "@Base/modules/avatar/controller/inputs/mouseSettings"; +import { Renderer } from "@Modules/scene"; +import { MouseSettingsController } from "@Modules/avatar/controller/inputs/mouseSettings"; +import { Hysteresis } from "@Modules/utility/hysteresis"; // Custom camera controls. class ArcRotateCameraCustomInput implements ICameraInput { @@ -174,11 +175,13 @@ export class InputController extends ScriptComponent { private _cameraSkin = 0.1; private _cameraElastic = true; private _cameraViewTransitionThreshold = 1.5; + private _cameraHeightHysteresis: Nullable = null; private _animGroups = new Array(); private _animator: Nullable = null; - private _avatarState: AvatarState = new AvatarState(); + private _avatarState = new AvatarState(); private _avatarHeight = 0; - private _inputState: InputState = new InputState(); + private _avatarRoot: Nullable = null; + private _inputState = new InputState(); private _input: Nullable = null; private _isMobile = false; @@ -200,10 +203,20 @@ export class InputController extends ScriptComponent { this._animGroups = value; } + /** + * The height of the avatar model. + */ public set avatarHeight(value: number) { this._avatarHeight = value; } + /** + * The root vector of the avatar model. + */ + public set avatarRoot(value: Vector3) { + this._avatarRoot = value; + } + public set camera(value: Nullable) { this._camera = value; @@ -230,6 +243,12 @@ export class InputController extends ScriptComponent { } }); + this._cameraHeightHysteresis = new Hysteresis( + () => (this._avatarRoot?.y ?? this._avatarHeight / 2) + this._avatarHeight / 2, + 100, + 0.1 + ); + // Remove the default camera controls. this._camera.inputs.removeByType("ArcRotateCameraKeyboardMoveInput"); @@ -726,8 +745,15 @@ export class InputController extends ScriptComponent { return; } + const cameraMode = this._camera.radius <= this._cameraViewTransitionThreshold + ? CameraMode.FirstPerson + : CameraMode.ThirdPerson; + // Make the camera follow the avatar. - this._defaultCameraTarget.y = this._avatarHeight; + const smoothHeight = cameraMode === CameraMode.FirstPerson && userStore.graphics.cameraBobbing + ? this._cameraHeightHysteresis?.getInstant() + : this._cameraHeightHysteresis?.get(); + this._defaultCameraTarget.y = smoothHeight ?? this._avatarHeight; this._gameObject.position.addToRef(this._defaultCameraTarget, this._camera.target); // Update the FOV. @@ -738,9 +764,6 @@ export class InputController extends ScriptComponent { this._snapCamera(delta); } - const cameraMode = this._camera.radius <= this._cameraViewTransitionThreshold - ? CameraMode.FirstPerson - : CameraMode.ThirdPerson; if (cameraMode === CameraMode.FirstPerson) { this._cameraViewTransitionThreshold = this._camera.lowerRadiusLimit; this._camera.wheelDeltaPercentage = MouseSettingsController.sensitivityComponents.wheelDeltaMultiplier; diff --git a/src/modules/avatar/controller/myAvatarController.ts b/src/modules/avatar/controller/myAvatarController.ts index 64c9228a..0e6d5ee4 100644 --- a/src/modules/avatar/controller/myAvatarController.ts +++ b/src/modules/avatar/controller/myAvatarController.ts @@ -9,7 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -import { TransformNode } from "@babylonjs/core"; +/* eslint-disable new-cap */ + +import { TransformNode, Vector3 } from "@babylonjs/core"; import { AvatarMapper, BoneType } from "../AvatarMapper"; import { ScriptComponent, inspectorAccessor } from "@Modules/script"; @@ -21,6 +23,7 @@ export class MyAvatarController extends ScriptComponent { private _myAvatar: Nullable = null; private _skeletonNodes: Map = new Map(); private _modelURL: string | undefined; + public skeletonRootPosition = Vector3.Zero(); constructor() { super(MyAvatarController.typeName); @@ -170,27 +173,28 @@ export class MyAvatarController extends ScriptComponent { } this._myAvatar.skeleton.forEach((joint) => { - if (!this._myAvatar) { + const node = this._skeletonNodes.get(joint.jointName); + if (!this._myAvatar || !node) { return; } - const node = this._skeletonNodes.get(joint.jointName); - if (node) { - this._myAvatar.jointTranslations[joint.jointIndex] - = AvatarMapper.mapToDomainJointTranslation(node.position); - - let rotation = node.rotationQuaternion; - if (rotation) { - if (joint.parentIndex >= 0) { - const q = this._myAvatar.jointRotations[joint.parentIndex]; - if (q) { - const parentRotation = AvatarMapper.mapToLocalJointRotation(q); - rotation = parentRotation.multiply(rotation); - } - } + this._myAvatar.jointTranslations[joint.jointIndex] = AvatarMapper.mapToDomainJointTranslation(node.position); - this._myAvatar.jointRotations[joint.jointIndex] = AvatarMapper.mapToDomainJointRotation(rotation); + if (joint.jointName === "Hips") { + this.skeletonRootPosition.copyFrom(node.position); + } + + let rotation = node.rotationQuaternion; + if (rotation) { + if (joint.parentIndex >= 0) { + const q = this._myAvatar.jointRotations[joint.parentIndex]; + if (q) { + const parentRotation = AvatarMapper.mapToLocalJointRotation(q); + rotation = parentRotation.multiply(rotation); + } } + + this._myAvatar.jointRotations[joint.jointIndex] = AvatarMapper.mapToDomainJointRotation(rotation); } }); } diff --git a/src/modules/scene/vscene.ts b/src/modules/scene/vscene.ts index 2bbea14a..b14f6506 100644 --- a/src/modules/scene/vscene.ts +++ b/src/modules/scene/vscene.ts @@ -360,13 +360,14 @@ export class VScene { } this._myAvatar.addComponent(capsuleCollider); + const myAvatarController = new MyAvatarController(); const avatarController = new InputController(); avatarController.animGroups = this._avatarAnimationGroups; avatarController.avatarHeight = avatarHeight; + avatarController.avatarRoot = myAvatarController.skeletonRootPosition; avatarController.camera = this._camera as ArcRotateCamera; + const nametagHeightGetter = () => myAvatarController.skeletonRootPosition.y + avatarHeight / 2; this._myAvatar.addComponent(avatarController); - - const myAvatarController = new MyAvatarController(); this._myAvatar.addComponent(myAvatarController); if (DomainManager.ActiveDomain && DomainManager.ActiveDomain.AvatarClient?.MyAvatar) { myAvatarController.myAvatar = DomainManager.ActiveDomain.AvatarClient?.MyAvatar; @@ -377,26 +378,20 @@ export class VScene { // Add a nametag to the avatar. let nametagColor = userStore.account.isAdmin ? Color3.FromHexString(applicationStore.theme.colors.primary) : undefined; - NametagEntity.create( - this._myAvatar, - () => (hipBone?.position.y ?? avatarHeight / 2) + avatarHeight / 2, - userStore.avatar.displayName, - false, - nametagColor - ); + NametagEntity.create(this._myAvatar, nametagHeightGetter, userStore.avatar.displayName, false, nametagColor); // Update the nametag color when the player's admin state is changed in the Store. watch(() => userStore.account.isAdmin, (value: boolean) => { nametagColor = value ? Color3.FromHexString(applicationStore.theme.colors.primary) : undefined; NametagEntity.removeAll(this._myAvatar); if (this._myAvatar) { - NametagEntity.create(this._myAvatar, avatarHeight, userStore.avatar.displayName, false, nametagColor); + NametagEntity.create(this._myAvatar, nametagHeightGetter, userStore.avatar.displayName, false, nametagColor); } }); // Update the nametag when the displayName is changed in the Store. watch(() => userStore.avatar.displayName, (value: string) => { NametagEntity.removeAll(this._myAvatar); if (this._myAvatar) { - NametagEntity.create(this._myAvatar, avatarHeight, value, false, nametagColor); + NametagEntity.create(this._myAvatar, nametagHeightGetter, value, false, nametagColor); } }); From 8b8606c8a2bf4c7b5c30070361052438164c7e08 Mon Sep 17 00:00:00 2001 From: Giga Date: Thu, 14 Sep 2023 16:00:07 +1200 Subject: [PATCH 11/14] Remove unused logic, blank lines Method was retrieving `avatarController` and not using it. --- src/modules/entity/EntityBuilder.ts | 1 - .../components/controllers/EntityController.ts | 1 - src/modules/scene/controllers/sceneController.ts | 12 ++---------- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/modules/entity/EntityBuilder.ts b/src/modules/entity/EntityBuilder.ts index d1360ca9..1f89b3ef 100644 --- a/src/modules/entity/EntityBuilder.ts +++ b/src/modules/entity/EntityBuilder.ts @@ -32,7 +32,6 @@ class EntityGameObjectBuilder { this._builders.set("Image", new ImageEntityBuilder()); this._builders.set("Material", new MaterialEntityBuilder()); this._builders.set("Web", new WebEntityBuilder()); - } public createEntity(entity: IEntity, scene: Nullable): Nullable { diff --git a/src/modules/entity/components/controllers/EntityController.ts b/src/modules/entity/components/controllers/EntityController.ts index 9f7115a3..695556a3 100644 --- a/src/modules/entity/components/controllers/EntityController.ts +++ b/src/modules/entity/components/controllers/EntityController.ts @@ -30,7 +30,6 @@ export abstract class EntityController extends ScriptComponent { this._entity = entity; } - public onInitialize(): void { this._entity.onCommonPropertiesChanged?.add(this._updateCommonProperties.bind(this)); this._entity.onRenderModeChanged?.add(this._updateRenderModeProperties.bind(this)); diff --git a/src/modules/scene/controllers/sceneController.ts b/src/modules/scene/controllers/sceneController.ts index 75e167f0..411e31a5 100644 --- a/src/modules/scene/controllers/sceneController.ts +++ b/src/modules/scene/controllers/sceneController.ts @@ -16,7 +16,6 @@ import { Vector3, Ray } from "@babylonjs/core"; import { ScriptComponent } from "@Modules/script"; import type { VScene } from "@Modules/scene/vscene"; -import { InputController } from "@Modules/avatar"; import Log from "@Modules/debugging/log"; const DEFAULT_GRAVITY = 9.81; @@ -74,15 +73,8 @@ export class SceneController extends ScriptComponent { } public onUpdate(): void { - if (this._scene.isReady()) { - const avatar = this._vscene.getMyAvatar(); - const avatarController = avatar?.getComponent(InputController.typeName) as InputController | null; - if (!avatarController) { - return; - } - if (!this.isGravityApplied && this._detectGround()) { - this.applyGravity(); - } + if (this._scene.isReady() && !this.isGravityApplied && this._detectGround()) { + this.applyGravity(); } } From 6f9103cde877829a1c7794f0c762d15ed13a8c15 Mon Sep 17 00:00:00 2001 From: Giga Date: Thu, 14 Sep 2023 16:07:13 +1200 Subject: [PATCH 12/14] Add camera bobbing setting to the Graphics menu --- src/components/overlays/settings/Graphics.vue | 16 ++++++++++++++++ src/stores/user-store.ts | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/overlays/settings/Graphics.vue b/src/components/overlays/settings/Graphics.vue index b19380a3..a397793d 100644 --- a/src/components/overlays/settings/Graphics.vue +++ b/src/components/overlays/settings/Graphics.vue @@ -63,6 +63,22 @@ {{ fieldOfView }} + + + Camera Bobbing + + + + + + {{ userStore.graphics.cameraBobbing ? `On` : `Off` }} + + Date: Fri, 15 Sep 2023 16:47:26 +1200 Subject: [PATCH 13/14] Update comment --- src/modules/utility/hysteresis.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/utility/hysteresis.ts b/src/modules/utility/hysteresis.ts index e3666bf3..dd0d1179 100644 --- a/src/modules/utility/hysteresis.ts +++ b/src/modules/utility/hysteresis.ts @@ -17,7 +17,7 @@ const defaultLength = 10; /** * A rolling average hysteresis. * @param getter A function to retrieve new values. - * @param length `(Optional)` The number of points to sample the rolling average from. + * @param length `(Optional)` The number of points to sample the rolling average from. (Increasing this number makes the output smoother.) * @param threshold `(Optional)` The snapping threshold. New values with a delta greater than this threshold will cause the output to snap to said new value. */ export class Hysteresis { From 20dd0c79720bed9fbf94669b968962770edda620 Mon Sep 17 00:00:00 2001 From: Giga Date: Sun, 17 Sep 2023 12:32:24 +1200 Subject: [PATCH 14/14] Add camera bobbing setting to the Controls menu --- src/components/overlays/settings/Controls.vue | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/components/overlays/settings/Controls.vue b/src/components/overlays/settings/Controls.vue index 69ab4bc9..01aa6d76 100644 --- a/src/components/overlays/settings/Controls.vue +++ b/src/components/overlays/settings/Controls.vue @@ -52,6 +52,9 @@ kbd { Keyboard + + Camera + + + + + + + + Camera Bobbing + + + + + + {{ userStore.graphics.cameraBobbing ? `On` : `Off` }} + + + + +