From c023121a86fb2661c5ee1a989d4ddd432d2a9246 Mon Sep 17 00:00:00 2001 From: Aitolda <21160271+Aitolda@users.noreply.github.com> Date: Mon, 14 Oct 2024 09:01:13 -0500 Subject: [PATCH] Custom compound mesh for zones now working -you can now enter a compound URL (glb) and use this to control the shape of your zone. --- .gitignore | 2 ++ quasar.config.js | 4 ++-- .../components/controllers/ZoneEntityController.ts | 14 +++++++------- src/modules/scene/ZoneManager.ts | 12 +++++++++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index cf87bcaa..3e8ca0a2 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ src/modules/directory_structure.txt public/local-assets/Skybox2k.png public/local-assets/Reflections4.hdr public/local-assets/monkey.glb +public/local-assets/Cylinder.glb +public/local-assets/Meters.glb diff --git a/quasar.config.js b/quasar.config.js index 74e3986f..6ffbd420 100644 --- a/quasar.config.js +++ b/quasar.config.js @@ -192,7 +192,7 @@ module.exports = configure(function (ctx) { image: "/assets/models/avatars/sara-cropped-small.webp", file: "/assets/models/avatars/sara.glb", scale: 1, - starred: true, + starred: false, }, KLM23NOP: { name: "Mark", @@ -391,7 +391,7 @@ module.exports = configure(function (ctx) { image: "/assets/models/avatars/Maria-small.webp", file: "/assets/models/avatars/Maria.glb", scale: 1, - starred: false, + starred: true, }), }, }, diff --git a/src/modules/entity/components/controllers/ZoneEntityController.ts b/src/modules/entity/components/controllers/ZoneEntityController.ts index 3925f134..35cf8485 100644 --- a/src/modules/entity/components/controllers/ZoneEntityController.ts +++ b/src/modules/entity/components/controllers/ZoneEntityController.ts @@ -76,7 +76,7 @@ export class ZoneEntityController extends EntityController { private _haze: Nullable = null; private _vls: Nullable = null; private _watchingGraphicsSettings = false; - private _zoneMesh: Mesh | AbstractMesh | null = null; + private _zoneMesh: AbstractMesh | null = null; constructor(entity: IZoneEntity) { // Extract a unique identifier from the zone's ID @@ -387,7 +387,7 @@ export class ZoneEntityController extends EntityController { // Find the mesh that represents the compound shape const compoundMesh = meshes.find(mesh => mesh.name !== "__root__") || meshes[0]; - if (compoundMesh instanceof Mesh) { + if (compoundMesh instanceof AbstractMesh) { this._zoneMesh = compoundMesh; this._zoneMesh.name = meshName; this._zoneMesh.id = meshName; // Set the ID to match the name @@ -395,18 +395,18 @@ export class ZoneEntityController extends EntityController { // Remove any parent-child relationships this._zoneMesh.parent = null; this._zoneMesh.getChildMeshes().forEach(child => { - if (child instanceof Mesh) { - child.parent = null; + if (child instanceof AbstractMesh) { + child.parent = this._zoneMesh; } }); } else { - console.warn(`Compound mesh for zone ${zoneId} is not a Mesh instance`); + console.warn(`Compound mesh for zone ${zoneId} is not an AbstractMesh instance`); return; } // Dispose of all other imported meshes meshes.forEach(mesh => { - if (mesh !== this._zoneMesh) { + if (mesh !== this._zoneMesh && this._zoneMesh && !mesh.isDescendantOf(this._zoneMesh)) { mesh.dispose(); } }); @@ -458,7 +458,7 @@ export class ZoneEntityController extends EntityController { // but remove any skybox-specific code } - public get zoneMesh(): Mesh | AbstractMesh | null { + public get zoneMesh(): AbstractMesh | null { return this._zoneMesh; } diff --git a/src/modules/scene/ZoneManager.ts b/src/modules/scene/ZoneManager.ts index 6ace3819..ac259806 100644 --- a/src/modules/scene/ZoneManager.ts +++ b/src/modules/scene/ZoneManager.ts @@ -1,4 +1,4 @@ -import { Scene, Vector3 } from "@babylonjs/core"; +import { Scene, Vector3, AbstractMesh } from "@babylonjs/core"; import { ZoneEntityController } from "../entity/components/controllers/ZoneEntityController"; import Log from "@Modules/debugging/log"; @@ -54,11 +54,17 @@ export class ZoneManager { const zoneMesh = zoneController.zoneMesh; if (!zoneMesh) return false; + // Check if the zoneMesh is a compound shape (has child meshes) if (zoneMesh.getChildMeshes().length > 0) { // For compound shapes, check if the point is inside any child mesh - return zoneMesh.getChildMeshes().some(childMesh => childMesh.intersectsPoint(point)); + return zoneMesh.getChildMeshes().some(childMesh => { + if (childMesh instanceof AbstractMesh) { + return childMesh.intersectsPoint(point); + } + return false; + }); } else { - // For simple shapes, use the existing check + // For simple shapes or single mesh compounds, use intersectsPoint return zoneMesh.intersectsPoint(point); } }