Only load navmesh for environments + cleanup

This commit is contained in:
netpro2k 2022-02-22 16:23:51 -08:00
Родитель 4fe2529a9a
Коммит 80b7a23b8e
7 изменённых файлов: 21 добавлений и 41 удалений

Просмотреть файл

@ -23,7 +23,6 @@
- [environment](#components/environment)
- [hide-when-quality](#components/environment/hide-when-quality)
- [layers](#components/environment/layers)
- [nav-mesh-helper](#components/environment/nav-mesh-helper)
- [scene-shadow](#components/environment/scene-shadow)
- [spawn-point](#components/environment/spawn-point)
- [gltf](#components/gltf)
@ -372,14 +371,6 @@ Sets layer flags on the underlying Object3D
`src/components/layers.js`
<a name="components/environment/nav-mesh-helper"></a>
#### nav-mesh-helper
Initializes teleporters when the environment bundle has loaded.
`src/components/nav-mesh-helper.js`
<a name="components/environment/scene-shadow"></a>
#### scene-shadow

Просмотреть файл

@ -1,15 +0,0 @@
/**
* Initializes teleporters when the environment bundle has loaded.
* @namespace environment
* @component nav-mesh-helper
*/
AFRAME.registerComponent("nav-mesh-helper", {
init: function() {
this.el.addEventListener("model-loaded", () => {
const teleporters = document.querySelectorAll("[teleporter]");
for (let i = 0; i < teleporters.length; i++) {
teleporters[i].components["teleporter"].queryCollisionEntities();
}
});
}
});

Просмотреть файл

@ -120,20 +120,8 @@ AFRAME.GLTFModelPlus.registerComponent("spawn-point", "spawn-point", el => {
willMaintainWorldUp: true
});
});
AFRAME.GLTFModelPlus.registerComponent("nav-mesh", "nav-mesh", (el, _componentName, componentData) => {
const nav = AFRAME.scenes[0].systems.nav;
const zone = componentData.zone || "character";
let found = false;
el.object3D.traverse(node => {
if (node.isMesh && !found) {
found = true;
nav.loadMesh(node, zone);
}
});
// There isn't actually an a-frame nav-mesh component, but we want to tag this el as a nav-mesh since
// nav-mesh-helper will query for it later.
el.setAttribute("nav-mesh");
});
AFRAME.GLTFModelPlus.registerComponent("nav-mesh", "nav-mesh");
AFRAME.GLTFModelPlus.registerComponent("pinnable", "pinnable");

Просмотреть файл

@ -1292,7 +1292,6 @@
<a-entity
id="environment-root"
body-helper="type: static; mass: 0; collisionFilterGroup: 2; collisionFilterMask: 1;"
nav-mesh-helper
>
<a-entity id="environment-scene"></a-entity>
</a-entity>

Просмотреть файл

@ -231,8 +231,6 @@ import "./components/set-yxz-order";
import "./components/cursor-controller";
import "./components/nav-mesh-helper";
import "./components/tools/pen";
import "./components/tools/pen-laser";
import "./components/tools/networked-drawing";

Просмотреть файл

@ -89,6 +89,8 @@ export class EnvironmentSystem {
updateEnvironment(envEl) {
const envSettingsEl = envEl.querySelector("[environment-settings]");
const skyboxEl = envEl.querySelector("[skybox]");
const navmeshEl = envEl.querySelector("[nav-mesh]");
const envSettings = {
...defaultEnvSettings,
skybox: skyboxEl?.components["skybox"]
@ -98,6 +100,11 @@ export class EnvironmentSystem {
Object.assign(envSettings, envSettingsEl.components["environment-settings"].data);
}
const navMesh = navmeshEl?.object3D.getObjectByProperty("isMesh", true);
if (navMesh) {
AFRAME.scenes[0].systems.nav.loadMesh(navMesh, navmeshEl.components["nav-mesh"].data.zone);
}
// TODO animated objects should not be static
envEl.object3D.traverse(o => {
if (o.isMesh) {
@ -194,6 +201,12 @@ export class EnvironmentSystem {
}
}
AFRAME.registerComponent("nav-mesh", {
schema: {
zone: { default: "character" }
}
});
AFRAME.registerComponent("environment-settings", {
schema: {
toneMapping: { default: defaultEnvSettings.toneMapping, oneOf: Object.values(toneMappingOptions) },

Просмотреть файл

@ -19,6 +19,12 @@ AFRAME.registerSystem("nav", {
geometry.applyMatrix4(mesh.matrixWorld);
this.pathfinder.setZoneData(zone, Pathfinding.createZone(geometry));
this.mesh = mesh;
const teleporters = document.querySelectorAll("[teleporter]");
for (let i = 0; i < teleporters.length; i++) {
teleporters[i].components["teleporter"].queryCollisionEntities();
}
this.el.sceneEl.emit("nav-mesh-loaded");
if (qsTruthy("debugNavmesh")) {