This commit is contained in:
Lucas Dower 2021-10-30 00:28:21 +01:00
parent 1bdaa3ec9a
commit c593fb1c3d
7 changed files with 39 additions and 47 deletions

View File

@ -7,6 +7,7 @@
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<div id="main">
<canvas id="c"></canvas>
<div class="toolbar-container">
@ -25,7 +26,7 @@
<div id="groupVoxel" class="input-group transparent">
<div class="input-group-item pill-left">Voxel size</div>
<input id="inputVoxelSize" type="number" class="input-group-item input-group-item-dominant text-field"
value="0.1" disabled>
value="0.25" min="0.01" step="0.01" disabled>
</input>
<button id="buttonVoxelise" class="input-group-item pill-right bg-primary cursor-pointer" disabled>
Voxelise
@ -60,15 +61,13 @@
</div>
</div>
</div>
</body>
</body>
<script src="./src/vendor/jquery-3.6.0.min.js"></script>
<script src="./src/vendor/jquery-3.3.1.slim.min.js"></script>
<script src="./src/vendor/popper.min.js"></script>
<script>
require("./dist/client.js");
</script>
<script src="./src/vendor/jquery-3.6.0.min.js"></script>
<script src="./src/vendor/jquery-3.3.1.slim.min.js"></script>
<script src="./src/vendor/popper.min.js"></script>
<script>
require("./dist/client.js");
</script>
</html>

View File

@ -22,7 +22,6 @@
},
"homepage": "https://github.com/LucasDower/ObjToSchematic#readme",
"devDependencies": {
"@types/bootstrap": "^5.1.1",
"@types/jquery": "^3.5.6",
"@types/pngjs": "^6.0.1",
"electron": "^13.1.4",
@ -32,7 +31,6 @@
},
"dependencies": {
"@popperjs/core": "^2.9.3",
"bootstrap": "^5.1.0",
"expand-vertex-data": "^1.1.2",
"jpeg-js": "^0.4.3",
"pngjs": "^6.0.0",

View File

@ -1,19 +1,13 @@
import { Schematic, Litematic, Exporter } from "./schematic";
import { Exporter } from "./schematic";
import { VoxelManager } from "./voxel_manager";
import { Renderer } from "./renderer";
import { Toast, ToastStyle } from "./ui/toast";
import { Modal } from "./ui/modal";
import { Mesh } from "./mesh";
import { remote } from 'electron';
import { remote } from "electron";
import path from "path";
enum ToastColour {
RED = "bg-danger",
ORANGE = "bg-warning",
GREEN = "bg-success"
}
export class AppContext {
@ -38,8 +32,17 @@ export class AppContext {
}
public load(files: Array<string>) {
if (files.length != 1) {
public load() {
const files = remote.dialog.showOpenDialogSync({
title: "Load Waveform .obj file",
buttonLabel: "Load",
filters: [{
name: 'Waveform obj file',
extensions: ['obj']
}]
});
if (!files || files.length != 1) {
return;
}
@ -54,7 +57,7 @@ export class AppContext {
try {
this._loadedMesh = new Mesh(file, this._gl);
} catch (err: any) {
console.log(err);
console.error(err);
Toast.show("Could not load mesh", ToastStyle.Failure);
return;
}
@ -91,12 +94,19 @@ export class AppContext {
this._voxelManager.clear();
this._voxelManager.setVoxelSize(this._voxelSize);
this._voxelManager.voxeliseMesh(this._loadedMesh);
} catch (err: any) {
console.error(err.message);
Toast.show("Could not voxelise mesh", ToastStyle.Failure);
return;
}
try {
this._renderer.clear();
this._renderer.registerVoxelMesh(this._voxelManager);
this._renderer.compile();
} catch (err: any) {
Toast.show(err.message, ToastStyle.Failure);
console.error(err.message);
Toast.show("Could not register voxel mesh", ToastStyle.Failure);
return;
}
@ -136,7 +146,6 @@ export class AppContext {
});
if (filePath === undefined) {
console.error("no path");
return;
}

View File

@ -1,31 +1,15 @@
import { AppContext } from "./app_context";
import { Schematic, Litematic } from "./schematic";
import { remote } from "electron";
const context = new AppContext();
function handleFileLoad() {
const files = remote.dialog.showOpenDialogSync({
title: "Load Waveform .obj file",
buttonLabel: "Load",
filters: [{
name: 'Waveform obj file',
extensions: ['obj']
}]
});
if (files) {
context.load(files);
}
}
$("#buttonChooseFile").on("click", () => {
handleFileLoad();
context.load();
});
$("#inputFile").on("click", () => {
handleFileLoad();
context.load();
});
$("#buttonVoxelise").on("click", () => {

View File

@ -30,7 +30,7 @@ export class Texture {
}
getRGBA(uv: UV): RGBA {
uv.v = 1 - uv.v;
//uv.v = 1 - uv.v;
const x = Math.floor(uv.u * this._image.width);
const y = Math.floor(uv.v * this._image.height);

View File

@ -7,12 +7,12 @@ export class Toast {
private static current: ToastStyle = ToastStyle.Success;
private static autoHideDelay: number = 4000;
private static timeout: NodeJS.Timeout;
public static show(text: string, style: ToastStyle) {
this._setText(text);
this._setStyle(style);
this._show();
setTimeout(() => { this._hide(); }, this.autoHideDelay);
}
private static _setText(text: string) {
@ -26,7 +26,9 @@ export class Toast {
}
private static _show() {
clearTimeout(this.timeout);
$("#toast").removeClass("hide");
this.timeout = setTimeout(() => { this._hide(); }, this.autoHideDelay);
}
private static _hide() {

View File

@ -3,7 +3,7 @@
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
"incremental": true, /* Enable incremental compilation */
"incremental": false, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
//"resolveJsonModule": true,