Fix Editor npm dependencies

This commit is contained in:
Lucas Dower 2023-10-10 20:59:30 +01:00
parent 16cc8290c9
commit 243595c39d
19 changed files with 9716 additions and 91 deletions

2
.gitignore vendored
View File

@ -10,7 +10,7 @@
/Editor/node_modules
/Editor/.firebase
/Editor/.firebaserc
/Editor/webpack/
/Editor/build
# Sandbox
/Sandbox/node_modules

View File

@ -1,40 +0,0 @@
import fs from 'fs';
import path from 'path';
import { PNG } from 'pngjs';
import { decode as jpegDecode } from 'jpeg-js';
import { OtS_Texture } from 'Core/src/ots_texture';
export function createReadableStream(p: fs.PathLike) {
return new ReadableStream({
async start(controller) {
const readStream = fs.createReadStream(p);
readStream.on('data', (chunk) => {
controller.enqueue(chunk);
});
readStream.on('end', () => {
controller.close();
});
readStream.on('error', (err) => {
throw err;
});
},
});
}
export function createOtSTexture(p: fs.PathLike) {
const ext = path.extname(p.toString());
switch (ext) {
case '.jpg':
case '.jpeg': {
var jpegData = fs.readFileSync(p);
const jpeg = jpegDecode(jpegData, {
maxMemoryUsageInMB: undefined,
formatAsRGBA: true,
});
return new OtS_Texture(Uint8ClampedArray.from(jpeg.data), jpeg.width, jpeg.width, 'nearest', 'repeat');
}
}
}

9651
Editor/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,11 +4,9 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "tests"
},
"scripts": {
"build": "echo \"Nothing to build\" && exit 0",
"start": "webpack serve --config ./webpack.dev.js",
"build": "webpack --config ./webpack.prod.js",
"test": "echo \"No tests\" && exit 0"
},
"keywords": [],
@ -16,5 +14,26 @@
"license": "ISC",
"dependencies": {
"ots-core": "file:../Core"
},
"devDependencies": {
"@types/pngjs": "^6.0.2",
"copy-webpack-plugin": "^11.0.0",
"file-loader": "^6.2.0",
"ga-gtag": "^1.1.7",
"html-webpack-plugin": "^5.5.3",
"i18next": "^23.5.1",
"jpeg-js": "^0.4.4",
"jszip": "^3.10.1",
"node-polyfill-webpack-plugin": "^2.0.1",
"pngjs": "^7.0.0",
"raw-loader": "^4.0.2",
"split.js": "^1.6.5",
"ts-loader": "^9.5.0",
"twgl.js": "^5.5.3",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-merge": "^5.9.0",
"worker-loader": "^3.0.8"
}
}

View File

@ -1,4 +1,4 @@
import ATLAS_VANILLA from '../../res/atlases/vanilla.atlas';
import ATLAS_VANILLA from '../res/atlases/vanilla.atlas';
import { AppAnalytics } from './analytics';
import { FallableBehaviour } from '../../Core/src/block_mesh';

View File

@ -1,7 +1,7 @@
import { ASSERT } from '../../Core/src/util/error_util';
import { OtS_Mesh } from '../../Core/src/ots_mesh';
import { Triangle } from '../../Core/src/triangle';
import { Material } from 'Core/src/materials';
import { Material } from 'ots-core/src/materials';
export type TMeshBuffer = {
position: { numComponents: 3, data: Float32Array },
@ -93,7 +93,7 @@ export class BufferGenerator {
}
// Normal
const normalArray = Triangle.GetNormal(triangle.v0.position, triangle.v1.position, triangle.v2.position).toArray();
const normalArray = Triangle.CalcNormal(triangle.v0.position, triangle.v1.position, triangle.v2.position).toArray();
{
materialBuffer.normal.data.set(normalArray, insertIndex * 9 + 0);
materialBuffer.normal.data.set(normalArray, insertIndex * 9 + 3);

View File

@ -3,28 +3,30 @@ import * as twgl from 'twgl.js';
import { Bounds } from '../../../Core/src/bounds';
import { RGBA } from '../../../Core/src/colour';
import { AttributeData, MergeAttributeData, RenderBuffer } from './render_buffer';
import { Triangle, UVTriangle } from '../../../Core/src/triangle';
import { Triangle } from '../../../Core/src/triangle';
import { ASSERT } from '../../../Core/src/util/error_util';
import { Vector3 } from '../../../Core/src/vector';
import { OtS_VoxelMesh } from '../../../Core/src/ots_voxel_mesh';
import { OtS_Triangle } from 'ots-core/src/ots_mesh';
import { OtS_Texture } from 'ots-core/src/ots_texture';
export class GeometryTemplates {
private static readonly _default_cube = twgl.primitives.createCubeVertices(1.0);
static getTriangleBufferData(triangle: UVTriangle): AttributeData {
const n = triangle.getNormal();
static getTriangleBufferData(triangle: OtS_Triangle): AttributeData {
const n = Triangle.CalcNormal(triangle.v0.position, triangle.v1.position, triangle.v2.position);
return {
custom: {
position: [
triangle.v0.x, triangle.v0.y, triangle.v0.z,
triangle.v1.x, triangle.v1.y, triangle.v1.z,
triangle.v2.x, triangle.v2.y, triangle.v2.z,
triangle.v0.position.x, triangle.v0.position.y, triangle.v0.position.z,
triangle.v1.position.x, triangle.v1.position.y, triangle.v1.position.z,
triangle.v2.position.x, triangle.v2.position.y, triangle.v2.position.z,
],
texcoord: [
triangle.uv0.u, triangle.uv0.v,
triangle.uv1.u, triangle.uv1.v,
triangle.uv2.u, triangle.uv2.v,
triangle.v0.texcoord.u, triangle.v0.texcoord.v,
triangle.v1.texcoord.u, triangle.v1.texcoord.v,
triangle.v2.texcoord.u, triangle.v2.texcoord.v,
],
normal: [
n.x, n.y, n.z,

View File

@ -1,7 +1,7 @@
import ATLAS_VANILLA from '../../../res/atlases/vanilla.atlas';
import ATLAS_VANILLA from '../../res/atlases/vanilla.atlas';
import * as twgl from 'twgl.js';
import VANILLA_TEXTURE from '../../../res/atlases/vanilla.png';
import VANILLA_TEXTURE from '../../res/atlases/vanilla.png';
import { Bounds } from '../../../Core/src/bounds';
import { ArcballCamera } from './camera';
import { RGBA, RGBAUtil } from '../../../Core/src/colour';

View File

@ -1,15 +1,15 @@
import * as twgl from 'twgl.js';
import FRAG_BLOCK from '../../../res/shaders/block_fragment.fs';
import VERT_BLOCK from '../../../res/shaders/block_vertex.vs';
import FRAG_DEBUG from '../../../res/shaders/debug_fragment.fs';
import VERT_DEBUG from '../../../res/shaders/debug_vertex.vs';
import FRAG_TRI_SOLID from '../../../res/shaders/solid_tri_fragment.fs';
import VERT_TRI_SOLID from '../../../res/shaders/solid_tri_vertex.vs';
import FRAG_TRI_TEXTURE from '../../../res/shaders/texture_tri_fragment.fs';
import VERT_TRI_TEXTURE from '../../../res/shaders/texture_tri_vertex.vs';
import FRAG_VOXEL from '../../../res/shaders/voxel_fragment.fs';
import VERT_VOXEL from '../../../res/shaders/voxel_vertex.vs';
import FRAG_BLOCK from '../../res/shaders/block_fragment.fs';
import VERT_BLOCK from '../../res/shaders/block_vertex.vs';
import FRAG_DEBUG from '../../res/shaders/debug_fragment.fs';
import VERT_DEBUG from '../../res/shaders/debug_vertex.vs';
import FRAG_TRI_SOLID from '../../res/shaders/solid_tri_fragment.fs';
import VERT_TRI_SOLID from '../../res/shaders/solid_tri_vertex.vs';
import FRAG_TRI_TEXTURE from '../../res/shaders/texture_tri_fragment.fs';
import VERT_TRI_TEXTURE from '../../res/shaders/texture_tri_vertex.vs';
import FRAG_VOXEL from '../../res/shaders/voxel_fragment.fs';
import VERT_VOXEL from '../../res/shaders/voxel_vertex.vs';
export class ShaderManager {
public textureTriProgram?: twgl.ProgramInfo;

View File

@ -1,5 +1,3 @@
import * as path from 'path';
import { ASSERT } from '../../../../Core/src/util/error_util';
import { UIUtil } from '../../util/ui_util';
import { ConfigComponent } from './config';
@ -65,8 +63,9 @@ export class FileComponent extends ConfigComponent<File, HTMLDivElement> {
protected override _updateStyles() {
if (this._loadedFilePath) {
const parsedPath = path.parse(this._loadedFilePath);
this._getElement().innerHTML = parsedPath.name + parsedPath.ext;
//const parsedPath = path.parse(this._loadedFilePath);
//this._getElement().innerHTML = parsedPath.name + parsedPath.ext;
this._getElement().innerHTML = this._loadedFilePath
} else {
this._getElement().innerHTML = `<i>${LOC('import.components.no_file_chosen')}</i>`;
}

View File

@ -1,4 +1,4 @@
import IMAGE_LOGO from '../../../../res/icon.png';
import IMAGE_LOGO from '../../../res/icon.png';
import { AppConfig } from '../../config';
import { LOC } from '../../localiser';

View File

@ -5,7 +5,7 @@ import { UIUtil } from '../../util/ui_util';
import { AppIcons } from '../icons';
import { ConfigComponent } from './config';
import { ToolbarItemComponent } from './toolbar_item';
import { TImageRawWrap } from 'Editor/src/texture_reader';
import { TImageRawWrap } from 'src/texture_reader';
export class ImageComponent extends ConfigComponent<Promise<TImageRawWrap>, HTMLImageElement> {
private _switchElement: ToolbarItemComponent;

View File

@ -1,4 +1,4 @@
import { UIUtil } from '../../../../Core/src/util/ui_util';
import { UIUtil } from 'src/util/ui_util';
import { ConfigComponent } from './config';
export class NumberComponent extends ConfigComponent<number, HTMLInputElement> {

View File

@ -9,7 +9,7 @@ import { AppIcons } from '../icons';
import { CheckboxComponent } from './checkbox';
import { ConfigComponent } from './config';
import { ToolbarItemComponent } from './toolbar_item';
import { BlockPalette } from 'Core/src/util/type_util';
import { BlockPalette } from '../../../../Core/src/util/type_util';
export class PaletteComponent extends ConfigComponent<BlockPalette, HTMLDivElement> {
private _checkboxes: { block: string, element: CheckboxComponent }[];

View File

@ -22,8 +22,6 @@ import { HeaderComponent } from './components/header';
import { PaletteComponent } from './components/palette';
import { PlaceholderComponent } from './components/placeholder';
import { SliderComponent } from './components/slider';
import { SolidMaterialComponent } from './components/solid_material';
import { TexturedMaterialComponent } from './components/textured_material';
import { ToolbarItemComponent } from './components/toolbar_item';
import { VectorComponent } from './components/vector';
import { AppConsole } from './console';
@ -31,9 +29,8 @@ import { AppIcons } from './icons';
import { HTMLBuilder, MiscComponents } from './misc';
import { AppConfig } from '../config';
import { OtS_ReplaceMode } from '../../../Core/src/ots_voxel_mesh';
import { Material, TexturedMaterial } from 'Core/src/materials';
import { OtS_Texture } from 'Core/src/ots_texture';
import { MaterialComponent } from './components/material';
import { Material } from 'ots-core/src/materials';
export type Group = {
id: string,

View File

@ -17,7 +17,7 @@ export function downloadAsZip(zipFilename: string, files: { content: any, filena
zip.file(file.filename, file.content);
});
zip.generateAsync({type:"blob"}).then(function(content) {
zip.generateAsync({type:"blob"}).then(function(content: any) {
download(content, zipFilename);
});
}

View File

@ -1,11 +1,9 @@
import path from 'path';
import { BlockMesh } from '../../../Core/src/block_mesh';
import { BufferGenerator } from '../buffer';
import { EAppEvent, EventManager } from '../event';
import { IExporter } from '../../../Core/src/exporters/base_exporter';
import { ExporterFactory } from '../../../Core/src/exporters/exporters';
import { ImporterFactor } from '../../../Core/src/importers/importers';
import { ImporterFactory } from '../../../Core/src/importers/importers';
import { LOC, Localiser } from '../localiser';
import { ProgressManager, TTaskHandle } from '../progress';
import { ASSERT } from '../../../Core/src/util/error_util';
@ -88,9 +86,10 @@ export class WorkerClient {
}
public async import(params: ImportParams.Input): Promise<ImportParams.Output> {
const parsed = path.parse(params.file.name);
//const parsed = path.parse(params.file.name);
const extension = params.file.name.split('.').findLast(() => true);
const importer = ImporterFactor.GetImporter(parsed.ext === '.obj' ? 'obj' : 'gltf');
const importer = ImporterFactory.GetImporter(extension === '.obj' ? 'obj' : 'gltf');
this._loadedMesh = await importer.import(params.file.stream());
this._loadedMesh.centre();

View File

@ -8,7 +8,7 @@ import { TAxis } from '../../../Core/src/util/type_util';
import { Vector3 } from '../../../Core/src/vector';
import { AppError } from '../util/editor_util';
import { OtS_ReplaceMode } from '../../../Core/src/ots_voxel_mesh';
import { Material } from 'Core/src/materials';
import { Material } from '../../../Core/src/materials';
export namespace InitParams {
export type Input = {

View File

@ -4,7 +4,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: './src/editor/main.ts',
entry: './src/main.ts',
plugins: [
new NodePolyfillPlugin(),
new HtmlWebpackPlugin({
@ -46,6 +46,6 @@ module.exports = {
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, './webpack'),
path: path.resolve(__dirname, './build'),
},
};