diff options
-rw-r--r-- | web/pw-frontend/public/static/res/assets/leaves.jpg | bin | 36902 -> 0 bytes | |||
-rw-r--r-- | web/pw-frontend/vite.config.js | 4 | ||||
-rw-r--r-- | web/pw-visualizer/assets/res/earth.svg (renamed from web/pw-frontend/public/static/res/assets/earth.svg) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/res/font.png (renamed from web/pw-frontend/public/static/res/assets/font.png) | bin | 912 -> 912 bytes | |||
-rw-r--r-- | web/pw-visualizer/assets/res/jupiter.svg (renamed from web/pw-frontend/public/static/res/assets/jupiter.svg) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/res/mars.svg (renamed from web/pw-frontend/public/static/res/assets/mars.svg) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/res/neptune.svg (renamed from web/pw-frontend/public/static/res/assets/neptune.svg) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/res/ship.svg (renamed from web/pw-frontend/public/static/res/assets/ship.svg) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/res/uranus.svg (renamed from web/pw-frontend/public/static/res/assets/uranus.svg) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/res/venus.svg (renamed from web/pw-frontend/public/static/res/assets/venus.svg) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/shaders/frag/image.glsl (renamed from web/pw-frontend/public/static/shaders/frag/image.glsl) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/shaders/frag/simple.glsl (renamed from web/pw-frontend/public/static/shaders/frag/simple.glsl) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/shaders/frag/vor.glsl (renamed from web/pw-frontend/public/static/shaders/frag/vor.glsl) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/shaders/vert/image.glsl (renamed from web/pw-frontend/public/static/shaders/vert/image.glsl) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/shaders/vert/simple.glsl (renamed from web/pw-frontend/public/static/shaders/vert/simple.glsl) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/assets/shaders/vert/vor.glsl (renamed from web/pw-frontend/public/static/shaders/vert/vor.glsl) | 0 | ||||
-rw-r--r-- | web/pw-visualizer/package.json | 2 | ||||
-rw-r--r-- | web/pw-visualizer/src/asset_files.ts | 19 | ||||
-rw-r--r-- | web/pw-visualizer/src/assets.ts | 15 | ||||
-rw-r--r-- | web/pw-visualizer/src/index.ts | 23 | ||||
-rw-r--r-- | web/pw-visualizer/src/webgl/index.ts | 15 | ||||
-rw-r--r-- | web/pw-visualizer/src/webgl/text.ts | 3 |
22 files changed, 66 insertions, 15 deletions
diff --git a/web/pw-frontend/public/static/res/assets/leaves.jpg b/web/pw-frontend/public/static/res/assets/leaves.jpg Binary files differdeleted file mode 100644 index 529b94e..0000000 --- a/web/pw-frontend/public/static/res/assets/leaves.jpg +++ /dev/null diff --git a/web/pw-frontend/vite.config.js b/web/pw-frontend/vite.config.js index 84889ec..68e02e2 100644 --- a/web/pw-frontend/vite.config.js +++ b/web/pw-frontend/vite.config.js @@ -22,5 +22,9 @@ export default defineConfig({ "/api/": "http://localhost:5000", "/ws": "ws://localhost:5000/ws", }, + fs: { + // Allow serving files from one level up to the project root + allow: ['..'] + } }, }) diff --git a/web/pw-frontend/public/static/res/assets/earth.svg b/web/pw-visualizer/assets/res/earth.svg index f1be561..f1be561 100644 --- a/web/pw-frontend/public/static/res/assets/earth.svg +++ b/web/pw-visualizer/assets/res/earth.svg diff --git a/web/pw-frontend/public/static/res/assets/font.png b/web/pw-visualizer/assets/res/font.png Binary files differindex 1724e0d..1724e0d 100644 --- a/web/pw-frontend/public/static/res/assets/font.png +++ b/web/pw-visualizer/assets/res/font.png diff --git a/web/pw-frontend/public/static/res/assets/jupiter.svg b/web/pw-visualizer/assets/res/jupiter.svg index e5fcd0f..e5fcd0f 100644 --- a/web/pw-frontend/public/static/res/assets/jupiter.svg +++ b/web/pw-visualizer/assets/res/jupiter.svg diff --git a/web/pw-frontend/public/static/res/assets/mars.svg b/web/pw-visualizer/assets/res/mars.svg index d92851d..d92851d 100644 --- a/web/pw-frontend/public/static/res/assets/mars.svg +++ b/web/pw-visualizer/assets/res/mars.svg diff --git a/web/pw-frontend/public/static/res/assets/neptune.svg b/web/pw-visualizer/assets/res/neptune.svg index 995d440..995d440 100644 --- a/web/pw-frontend/public/static/res/assets/neptune.svg +++ b/web/pw-visualizer/assets/res/neptune.svg diff --git a/web/pw-frontend/public/static/res/assets/ship.svg b/web/pw-visualizer/assets/res/ship.svg index ee202ff..ee202ff 100644 --- a/web/pw-frontend/public/static/res/assets/ship.svg +++ b/web/pw-visualizer/assets/res/ship.svg diff --git a/web/pw-frontend/public/static/res/assets/uranus.svg b/web/pw-visualizer/assets/res/uranus.svg index fb192a4..fb192a4 100644 --- a/web/pw-frontend/public/static/res/assets/uranus.svg +++ b/web/pw-visualizer/assets/res/uranus.svg diff --git a/web/pw-frontend/public/static/res/assets/venus.svg b/web/pw-visualizer/assets/res/venus.svg index 3bebb10..3bebb10 100644 --- a/web/pw-frontend/public/static/res/assets/venus.svg +++ b/web/pw-visualizer/assets/res/venus.svg diff --git a/web/pw-frontend/public/static/shaders/frag/image.glsl b/web/pw-visualizer/assets/shaders/frag/image.glsl index 69c8b91..69c8b91 100644 --- a/web/pw-frontend/public/static/shaders/frag/image.glsl +++ b/web/pw-visualizer/assets/shaders/frag/image.glsl diff --git a/web/pw-frontend/public/static/shaders/frag/simple.glsl b/web/pw-visualizer/assets/shaders/frag/simple.glsl index 1292569..1292569 100644 --- a/web/pw-frontend/public/static/shaders/frag/simple.glsl +++ b/web/pw-visualizer/assets/shaders/frag/simple.glsl diff --git a/web/pw-frontend/public/static/shaders/frag/vor.glsl b/web/pw-visualizer/assets/shaders/frag/vor.glsl index faaa68f..faaa68f 100644 --- a/web/pw-frontend/public/static/shaders/frag/vor.glsl +++ b/web/pw-visualizer/assets/shaders/frag/vor.glsl diff --git a/web/pw-frontend/public/static/shaders/vert/image.glsl b/web/pw-visualizer/assets/shaders/vert/image.glsl index 5dd3f56..5dd3f56 100644 --- a/web/pw-frontend/public/static/shaders/vert/image.glsl +++ b/web/pw-visualizer/assets/shaders/vert/image.glsl diff --git a/web/pw-frontend/public/static/shaders/vert/simple.glsl b/web/pw-visualizer/assets/shaders/vert/simple.glsl index 935decf..935decf 100644 --- a/web/pw-frontend/public/static/shaders/vert/simple.glsl +++ b/web/pw-visualizer/assets/shaders/vert/simple.glsl diff --git a/web/pw-frontend/public/static/shaders/vert/vor.glsl b/web/pw-visualizer/assets/shaders/vert/vor.glsl index 75747c4..75747c4 100644 --- a/web/pw-frontend/public/static/shaders/vert/vor.glsl +++ b/web/pw-visualizer/assets/shaders/vert/vor.glsl diff --git a/web/pw-visualizer/package.json b/web/pw-visualizer/package.json index bbeb6d2..8f48c74 100644 --- a/web/pw-visualizer/package.json +++ b/web/pw-visualizer/package.json @@ -7,7 +7,7 @@ "build": "vite build", "build-wasm": "wasm-pack build ../planetwars-rs --target web" }, - "files": ["src"], + "files": ["src", "assets"], "main": "src/index.ts", "devDependencies": { "@originjs/vite-plugin-commonjs": "^1.0.1", diff --git a/web/pw-visualizer/src/asset_files.ts b/web/pw-visualizer/src/asset_files.ts new file mode 100644 index 0000000..dfd222c --- /dev/null +++ b/web/pw-visualizer/src/asset_files.ts @@ -0,0 +1,19 @@ +declare module "*.svg" { + const url: string; + export default url; +} + +declare module "*.png" { + const url: string; + export default url; +} + +declare module "*.glsl" { + const url: string; + export default url; +} + +declare module "*.glsl?url" { + const url: string; + export default url; +}
\ No newline at end of file diff --git a/web/pw-visualizer/src/assets.ts b/web/pw-visualizer/src/assets.ts new file mode 100644 index 0000000..e04f2c1 --- /dev/null +++ b/web/pw-visualizer/src/assets.ts @@ -0,0 +1,15 @@ +export {default as shipSvg} from "../assets/res/ship.svg"; + +export {default as earthSvg} from "../assets/res/earth.svg"; +export {default as marsSvg} from "../assets/res/mars.svg"; +export {default as venusSvg} from "../assets/res/venus.svg"; + +export {default as fontPng} from "../assets/res/font.png"; + +export {default as imageFragmentShader} from "../assets/shaders/frag/image.glsl?url"; +export {default as simpleFragmentShader} from "../assets/shaders/frag/simple.glsl?url"; +export {default as vorFragmentShader} from "../assets/shaders/frag/vor.glsl?url"; + +export {default as imageVertexShader} from "../assets/shaders/vert/image.glsl?url"; +export {default as simpleVertexShader} from "../assets/shaders/vert/simple.glsl?url"; +export {default as vorVertexShader} from "../assets/shaders/vert/vor.glsl?url";
\ No newline at end of file diff --git a/web/pw-visualizer/src/index.ts b/web/pw-visualizer/src/index.ts index 363a1c5..df2c3c2 100644 --- a/web/pw-visualizer/src/index.ts +++ b/web/pw-visualizer/src/index.ts @@ -27,6 +27,7 @@ import { VertexBuffer, IndexBuffer } from "./webgl/buffer"; import { VertexBufferLayout, VertexArray } from "./webgl/vertexBufferLayout"; import { defaultLabelFactory, LabelFactory, Align, Label } from "./webgl/text"; import { VoronoiBuilder } from "./voronoi/voronoi"; +import * as assets from "./assets"; // svg-mesh requires global to exist (window as any).global = window; @@ -585,34 +586,38 @@ var meshes: Mesh[]; var shaders: Dictionary<ShaderFactory>; export async function set_instance(source: string): Promise<GameInstance> { + // TODO: embed shader programs if (!meshes || !shaders) { - const mesh_promises = ["ship.svg", "earth.svg", "mars.svg", "venus.svg"] - .map((name) => "/static/res/assets/" + name) - .map(url_to_mesh); + const mesh_promises = [ + assets.shipSvg, + assets.earthSvg, + assets.marsSvg, + assets.venusSvg, + ].map(url_to_mesh); const shader_promies = [ (async () => <[string, ShaderFactory]>[ "normal", await ShaderFactory.create_factory( - "/static/shaders/frag/simple.glsl", - "/static/shaders/vert/simple.glsl" + assets.simpleFragmentShader, + assets.simpleVertexShader, ), ])(), (async () => <[string, ShaderFactory]>[ "vor", await ShaderFactory.create_factory( - "/static/shaders/frag/vor.glsl", - "/static/shaders/vert/vor.glsl" + assets.vorFragmentShader, + assets.vorVertexShader, ), ])(), (async () => <[string, ShaderFactory]>[ "image", await ShaderFactory.create_factory( - "/static/shaders/frag/image.glsl", - "/static/shaders/vert/simple.glsl" + assets.imageFragmentShader, + assets.simpleVertexShader, ), ])(), ]; diff --git a/web/pw-visualizer/src/webgl/index.ts b/web/pw-visualizer/src/webgl/index.ts index fdb7886..1742713 100644 --- a/web/pw-visualizer/src/webgl/index.ts +++ b/web/pw-visualizer/src/webgl/index.ts @@ -4,15 +4,22 @@ import { VertexBuffer, IndexBuffer } from './buffer'; import { VertexArray, VertexBufferLayout } from './vertexBufferLayout'; import { Renderer } from './renderer'; import { Texture } from './texture'; +import * as assets from "../assets"; -const URL = window.location.origin+window.location.pathname; -const LOCATION = URL.substring(0, URL.lastIndexOf("/") + 1); +// const URL = window.location.origin+window.location.pathname; +// const LOCATION = URL.substring(0, URL.lastIndexOf("/") + 1); async function create_texture_from_svg(gl: WebGLRenderingContext, name: string, path: string, width: number, height: number): Promise<Texture> { const [mesh, factory] = await Promise.all([ url_to_mesh(path), - ShaderFactory.create_factory(LOCATION + "static/shaders/frag/static_color.glsl", LOCATION + "static/shaders/vert/svg.glsl") + ShaderFactory.create_factory( + // assets.simpleFragmentShader, + // assets.simpleVertexShader, + // TODO: previously: this was the old code, which was not working. + // what is the correct shader here? + "static/shaders/frag/static_color.glsl", "static/shaders/vert/svg.glsl" + ) ]); const program = factory.create_shader(gl); @@ -54,7 +61,7 @@ async function main() { console.log(Math.max(...mesh.positions), Math.min(...mesh.positions)); const renderer = new Renderer(); - const factory = await ShaderFactory.create_factory(LOCATION + "static/shaders/frag/static_color.glsl", LOCATION + "static/shaders/vert/simple.glsl"); + const factory = await ShaderFactory.create_factory(assets.simpleFragmentShader, assets.simpleVertexShader); const program = factory.create_shader(gl); var positionBuffer = new VertexBuffer(gl, mesh.positions); diff --git a/web/pw-visualizer/src/webgl/text.ts b/web/pw-visualizer/src/webgl/text.ts index 3f1cec6..fdfbc55 100644 --- a/web/pw-visualizer/src/webgl/text.ts +++ b/web/pw-visualizer/src/webgl/text.ts @@ -4,6 +4,7 @@ import { Texture } from "./texture"; import { DefaultRenderable } from "./renderer"; import { IndexBuffer, VertexBuffer } from "./buffer"; import { VertexBufferLayout, VertexArray } from "./vertexBufferLayout"; +import { fontPng } from "../assets"; export enum Align { @@ -188,5 +189,5 @@ export function defaultLabelFactory(gl: WebGLRenderingContext, shader: Shader): }, }; - return new LabelFactory(gl, '/static/res/assets/font.png', fontInfo, shader); + return new LabelFactory(gl, fontPng, fontInfo, shader); } |