Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to update dependencies and code for 2023. #47

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<meta charset="utf-8">
<title>A-Frame Inspector Recast Plugin • Example</title>
<script src="//aframe.io/releases/0.8.2/aframe.min.js"></script>
<script src="//cdn.rawgit.com/donmccurdy/aframe-extras/v4.1.2/dist/aframe-extras.js"></script>
<script src="https://rawgit.com/feiss/aframe-environment-component/master/dist/aframe-environment-component.min.js"></script>
<script src="../bundle.js"></script>
</head>
Expand All @@ -19,15 +18,8 @@
<a-cursor nav-debug-pointer raycaster="objects: [nav-mesh];"></a-cursor>
</a-entity>
</a-entity>
<!-- <a-box color="red" position="0 0.5 -5" id="box"></a-box> -->
<!-- <a-box color="darkgreen" height="0.1" depth="20" width="20" id="ground"></a-box> -->
<!-- <a-entity scaleDIS="0.5 2 1" obj-model="obj: assets/nav_test.obj" color="#ccc" id="nav_test"></a-entity> -->
<a-entity obj-model="obj: assets/dungeon.obj" color="#ccc" id="dungeon"></a-entity>
<!-- <a-entity gltf-model="assets/tmp/medieval_fantasy_book/scene.gltf" id="fantasy_book"></a-entity> -->
<!-- <a-entity obj-model="obj: assets/tmp/medieval_fantasy_book/medieval_fantasy_book.obj" id="fantasy_book"></a-entity> -->
<!-- <a-entity gltf-model="assets/tmp/medieval_castle_with_village/scene.gltf" id="castle_village"></a-entity> -->
<a-entity id="navmesh" nav-mesh></a-entity>
<!-- <a-sky scaleDIS="0.001 0.001 0.001" color="red"></a-sky> -->
</a-scene>
</body>
</html>
44 changes: 37 additions & 7 deletions function.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const express = require('express');
const multer = require('multer');
const assert = require('fluent-assert');
const recast = require('@donmccurdy/recast');
const Recast = require('recast-detour');
const RecastConfig = require('./src/recast-config');

const PORT = process.env.PORT || 3000;
Expand All @@ -15,6 +15,14 @@ const upload = multer({ storage: multer.memoryStorage(), limits: {fileSize: '50m

// ---------------------------------------- //

let recast;

async function init() {
recast = await Recast();
}

// ---------------------------------------- //

app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
Expand All @@ -23,23 +31,33 @@ app.use(function(req, res, next) {

// ---------------------------------------- //

app.post('*', upload, (req, res) => {
app.post('*', upload, async (req, res) => {

await init();

const files = req.files || {};
if (!files.position || !files.index) return res.sendStatus(400);

let config;
const config = new recast.rcConfig();

// Validate configuration.
try {

config = RecastConfig.map((param) => {
// Reference:
// - https://github.com/BabylonJS/Babylon.js/blob/eba84f474c7e1bc1d331e76c0e13a8ccbc772a34/packages/dev/core/src/Navigation/Plugins/recastJSPlugin.ts

config.borderSize = 0;
config.tileSize = 0;

RecastConfig.forEach((param) => {
assert.ok(param.name, req.query[param.name]);
const value = Number(req.query[param.name]);
assert.number(param.name, value).range(param.min, param.max);
return value;
config[param.recastName] = value;
});

console.log(config);

} catch (e) {

console.error(e);
Expand All @@ -48,6 +66,8 @@ app.post('*', upload, (req, res) => {

}

let navmesh;

// Load input.
try {

Expand All @@ -73,7 +93,14 @@ app.post('*', upload, (req, res) => {
}

console.time('recast::load');
recast.load(position, index);
navmesh = new recast.NavMesh();
navmesh.build(
Array.from(position),
position.length / 3,
Array.from(index),
index.length,
config
);
console.timeEnd('recast::load');

} catch (e) {
Expand All @@ -88,7 +115,10 @@ app.post('*', upload, (req, res) => {
try {

console.time('recast::build');
const output = recast.build.apply(recast, config).replace(/@/g, '\n');
const debug = navmesh.getDebugNavMesh();
const triangles = debug.getTriangleCount();
console.log({triangles, debug});
// TODO: extract navmesh data
console.timeEnd('recast::build');

if (output.indexOf('v') === -1) {
Expand Down
Loading