move assets to visualizer package

This commit is contained in:
Ilion Beyst 2021-12-29 22:54:30 +01:00
parent 0c6d978442
commit 71ee6c99e9
22 changed files with 66 additions and 15 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

View file

@ -22,5 +22,9 @@ export default defineConfig({
"/api/": "http://localhost:5000", "/api/": "http://localhost:5000",
"/ws": "ws://localhost:5000/ws", "/ws": "ws://localhost:5000/ws",
}, },
fs: {
// Allow serving files from one level up to the project root
allow: ['..']
}
}, },
}) })

View file

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View file

Before

Width:  |  Height:  |  Size: 912 B

After

Width:  |  Height:  |  Size: 912 B

View file

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View file

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View file

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View file

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View file

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View file

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -7,7 +7,7 @@
"build": "vite build", "build": "vite build",
"build-wasm": "wasm-pack build ../planetwars-rs --target web" "build-wasm": "wasm-pack build ../planetwars-rs --target web"
}, },
"files": ["src"], "files": ["src", "assets"],
"main": "src/index.ts", "main": "src/index.ts",
"devDependencies": { "devDependencies": {
"@originjs/vite-plugin-commonjs": "^1.0.1", "@originjs/vite-plugin-commonjs": "^1.0.1",

View file

@ -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;
}

View file

@ -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";

View file

@ -27,6 +27,7 @@ import { VertexBuffer, IndexBuffer } from "./webgl/buffer";
import { VertexBufferLayout, VertexArray } from "./webgl/vertexBufferLayout"; import { VertexBufferLayout, VertexArray } from "./webgl/vertexBufferLayout";
import { defaultLabelFactory, LabelFactory, Align, Label } from "./webgl/text"; import { defaultLabelFactory, LabelFactory, Align, Label } from "./webgl/text";
import { VoronoiBuilder } from "./voronoi/voronoi"; import { VoronoiBuilder } from "./voronoi/voronoi";
import * as assets from "./assets";
// svg-mesh requires global to exist // svg-mesh requires global to exist
(window as any).global = window; (window as any).global = window;
@ -585,34 +586,38 @@ var meshes: Mesh[];
var shaders: Dictionary<ShaderFactory>; var shaders: Dictionary<ShaderFactory>;
export async function set_instance(source: string): Promise<GameInstance> { export async function set_instance(source: string): Promise<GameInstance> {
// TODO: embed shader programs
if (!meshes || !shaders) { if (!meshes || !shaders) {
const mesh_promises = ["ship.svg", "earth.svg", "mars.svg", "venus.svg"] const mesh_promises = [
.map((name) => "/static/res/assets/" + name) assets.shipSvg,
.map(url_to_mesh); assets.earthSvg,
assets.marsSvg,
assets.venusSvg,
].map(url_to_mesh);
const shader_promies = [ const shader_promies = [
(async () => (async () =>
<[string, ShaderFactory]>[ <[string, ShaderFactory]>[
"normal", "normal",
await ShaderFactory.create_factory( await ShaderFactory.create_factory(
"/static/shaders/frag/simple.glsl", assets.simpleFragmentShader,
"/static/shaders/vert/simple.glsl" assets.simpleVertexShader,
), ),
])(), ])(),
(async () => (async () =>
<[string, ShaderFactory]>[ <[string, ShaderFactory]>[
"vor", "vor",
await ShaderFactory.create_factory( await ShaderFactory.create_factory(
"/static/shaders/frag/vor.glsl", assets.vorFragmentShader,
"/static/shaders/vert/vor.glsl" assets.vorVertexShader,
), ),
])(), ])(),
(async () => (async () =>
<[string, ShaderFactory]>[ <[string, ShaderFactory]>[
"image", "image",
await ShaderFactory.create_factory( await ShaderFactory.create_factory(
"/static/shaders/frag/image.glsl", assets.imageFragmentShader,
"/static/shaders/vert/simple.glsl" assets.simpleVertexShader,
), ),
])(), ])(),
]; ];

View file

@ -4,15 +4,22 @@ import { VertexBuffer, IndexBuffer } from './buffer';
import { VertexArray, VertexBufferLayout } from './vertexBufferLayout'; import { VertexArray, VertexBufferLayout } from './vertexBufferLayout';
import { Renderer } from './renderer'; import { Renderer } from './renderer';
import { Texture } from './texture'; import { Texture } from './texture';
import * as assets from "../assets";
const URL = window.location.origin+window.location.pathname; // const URL = window.location.origin+window.location.pathname;
const LOCATION = URL.substring(0, URL.lastIndexOf("/") + 1); // 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> { async function create_texture_from_svg(gl: WebGLRenderingContext, name: string, path: string, width: number, height: number): Promise<Texture> {
const [mesh, factory] = await Promise.all([ const [mesh, factory] = await Promise.all([
url_to_mesh(path), 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); const program = factory.create_shader(gl);
@ -54,7 +61,7 @@ async function main() {
console.log(Math.max(...mesh.positions), Math.min(...mesh.positions)); console.log(Math.max(...mesh.positions), Math.min(...mesh.positions));
const renderer = new Renderer(); 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); const program = factory.create_shader(gl);
var positionBuffer = new VertexBuffer(gl, mesh.positions); var positionBuffer = new VertexBuffer(gl, mesh.positions);

View file

@ -4,6 +4,7 @@ import { Texture } from "./texture";
import { DefaultRenderable } from "./renderer"; import { DefaultRenderable } from "./renderer";
import { IndexBuffer, VertexBuffer } from "./buffer"; import { IndexBuffer, VertexBuffer } from "./buffer";
import { VertexBufferLayout, VertexArray } from "./vertexBufferLayout"; import { VertexBufferLayout, VertexArray } from "./vertexBufferLayout";
import { fontPng } from "../assets";
export enum Align { 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);
} }