Fix networking, mesh import

This commit is contained in:
Alan O'Cull 2023-12-05 18:58:43 -05:00
parent 5646c84a89
commit 05fca4e2e1
6 changed files with 31 additions and 13 deletions

4
buildwin.cmd Normal file
View File

@ -0,0 +1,4 @@
@REM rmdir dist\
@REM mkdir dist\public
@REM xcopy .\assets .\dist\public /e /h /y /f
tsc && webpack --config .\webpack\development.js

View File

@ -16,7 +16,8 @@
"build": "tsc && webpack --config ./webpack/development.js",
"rebuild": "npm run clean && npm run build",
"server": "node ./build/server/server.js",
"debug": "node ./build/server/server.js -debug"
"debug": "node ./build/server/server.js -debug",
"winserver": "node .\\build\\server\\server.js"
},
"repository": {
"type": "git",

View File

@ -19,10 +19,10 @@ const request_mesh = (filename: string) => {
request_mesh_listeners(request);
request.onreadystatechange = function() {
if (request.readyState == XMLHttpRequest.DONE) {
alert(request.responseText);
console.log(request.responseText);
const mesh = MeshImport.parse(request.responseText);
console.log(`Got mesh array at ${mesh.name}`);
console.log(mesh.shells);
console.log(mesh);
}
}
request.open('GET', `http://localhost:${3000}/mesh/${filename}`, true);
@ -30,7 +30,8 @@ const request_mesh = (filename: string) => {
return request;
}
document.onload = function() {
// Wait for page load before executing code
window.addEventListener('load', function() {
console.log('PAGE LOADED');
const req = request_mesh('clover.obj');
}
})

View File

@ -1,6 +1,6 @@
import Vector2 from './vector';
const EPSILON = 0.0001;
const EPSILON = 0.000001;
class Triangle {
public uvs: Vector2[];

View File

@ -22,7 +22,10 @@ const parse_tri = (line: string) => {
let nums: number[] = [];
for (let i = 1; i < 4 && i < vals.length; i++) {
nums[i-1] = parseFloat(vals[i]);
const idx = (i-1) * 2;
const face_corner = vals[i].split('/');
nums[idx] = parseInt(face_corner[0], 10);
nums[idx+1] = parseInt(face_corner[1], 10);
}
return nums;
}
@ -50,6 +53,8 @@ class MeshImport {
}
});
console.log(`# VERTs: ${verts.length / 3}\t# UVs ${uvs.length}\t# TRIs: ${tris.length / 6}`);
// Construct triangles
let t: Triangle[] = [];
for (let i = 0; i < tris.length; i += 6) {
@ -65,6 +70,8 @@ class MeshImport {
t.push(new Triangle(v, uv, uvi));
}
console.log('IMPORT: Total triangles found', t.length);
// Create an initial shell
let shells: Shell[] = [];
// Initialize shells by sorting triangles roughly int othem
@ -85,6 +92,8 @@ class MeshImport {
}
}
console.log('IMPORT: Total shells initial', shells.length);
// Now, combine shells
for (let i = 0; i < shells.length; i++) {
const a = shells[i];
@ -93,7 +102,7 @@ class MeshImport {
if (a.connected_shell(b)) {
a.merge(b);
shells = shells.splice(j, 1);
shells.splice(j, 1);
j--;
}
}

View File

@ -8,19 +8,22 @@ dotenv.config();
const app: Express = express();
const port = process.env.PORT;
const dir = `${process.cwd()}/dist/public`;
app.use('/', express.static(dir));
app.get('/mesh/*', (req: Request, res: Response) => {
console.log('Got MESH request ', req.url);
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
app.use(express.static('dist/public/objects/hard'));
res.sendFile(`${dir}/objects/hard/clover.obj`);
});
app.get('/', (req: Request, res: Response) => {
console.log('Got MAIN request ', req.url);
app.use(express.static('dist' + '/public'));
console.log('Got MAIN request ', req.url.length);
res.sendFile(`${dir}/index.html`);
});
app.listen(port, () => {
console.log(`Server is running on localhost:${port}`);
console.log(`Server is running on localhost:${port}, working in ${dir}`);
});