Skip to content

Commit

Permalink
Custom compound mesh for zones now working
Browse files Browse the repository at this point in the history
-you can now enter a compound URL (glb) and use this to control the shape of your zone.
  • Loading branch information
Aitolda committed Oct 14, 2024
1 parent 246e1db commit c023121
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions quasar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class ZoneEntityController extends EntityController {
private _haze: Nullable<HazeComponent> = null;
private _vls: Nullable<VolumetricLightScatteringPostProcess> = 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
Expand Down Expand Up @@ -387,26 +387,26 @@ 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

// 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();
}
});
Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 9 additions & 3 deletions src/modules/scene/ZoneManager.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit c023121

Please sign in to comment.