diff --git a/demo/client/html/3d-demo.html.hbs b/demo/client/html/3d-demo.html.hbs index 864f0473..98de0b9b 100644 --- a/demo/client/html/3d-demo.html.hbs +++ b/demo/client/html/3d-demo.html.hbs @@ -1,7 +1,7 @@ - 3D — Pathfinder Demo + 3D Demo — Pathfinder {{>partials/header.html}} diff --git a/demo/client/html/mesh-debugger.html.hbs b/demo/client/html/mesh-debugger.html.hbs new file mode 100644 index 00000000..a1c4331f --- /dev/null +++ b/demo/client/html/mesh-debugger.html.hbs @@ -0,0 +1,13 @@ + + + + Mesh Debugger — Pathfinder + + {{>partials/header.html}} + + + + {{>partials/navbar.html}} + + + diff --git a/demo/client/html/svg-demo.html.hbs b/demo/client/html/svg-demo.html.hbs index b98dfbe7..614c1bc8 100644 --- a/demo/client/html/svg-demo.html.hbs +++ b/demo/client/html/svg-demo.html.hbs @@ -1,7 +1,7 @@ - SVG — Pathfinder Demo + SVG Demo — Pathfinder {{>partials/header.html}} diff --git a/demo/client/html/text-demo.html.hbs b/demo/client/html/text-demo.html.hbs index 96d856de..4ff2ae37 100644 --- a/demo/client/html/text-demo.html.hbs +++ b/demo/client/html/text-demo.html.hbs @@ -1,7 +1,7 @@ - Text — Pathfinder Demo + Text Demo — Pathfinder {{>partials/header.html}} diff --git a/demo/client/src/3d-demo.ts b/demo/client/src/3d-demo.ts index b4518d87..a8cd2d4a 100644 --- a/demo/client/src/3d-demo.ts +++ b/demo/client/src/3d-demo.ts @@ -11,13 +11,13 @@ import * as glmatrix from 'gl-matrix'; import {AntialiasingStrategy, AntialiasingStrategyName, NoAAStrategy} from "./aa-strategy"; +import {DemoAppController} from "./app-controller"; import {mat4, vec2} from "gl-matrix"; import {PathfinderMeshData} from "./meshes"; import {ShaderMap, ShaderProgramSource} from "./shader-loader"; import {BUILTIN_FONT_URI, TextLayout, PathfinderGlyph} from "./text"; -import {panic, PathfinderError} from "./utils"; +import {PathfinderError, panic, unwrapNull} from "./utils"; import {PathfinderView, Timings} from "./view"; -import AppController from "./app-controller"; import SSAAStrategy from "./ssaa-strategy"; const TEXT: string = "Lorem ipsum dolor sit amet"; @@ -36,7 +36,7 @@ interface AntialiasingStrategyTable { ssaa: typeof SSAAStrategy; } -class ThreeDController extends AppController { +class ThreeDController extends DemoAppController { start() { super.start(); @@ -55,11 +55,11 @@ class ThreeDController extends AppController { }); } - protected createView(canvas: HTMLCanvasElement, - commonShaderSource: string, - shaderSources: ShaderMap): - ThreeDView { - return new ThreeDView(this, canvas, commonShaderSource, shaderSources); + protected createView(): ThreeDView { + return new ThreeDView(this, + this.canvas, + unwrapNull(this.commonShaderSource), + unwrapNull(this.shaderSources)); } protected get builtinFileURI(): string { diff --git a/demo/client/src/app-controller.ts b/demo/client/src/app-controller.ts index af2b00ea..af01daaf 100644 --- a/demo/client/src/app-controller.ts +++ b/demo/client/src/app-controller.ts @@ -13,11 +13,41 @@ import {ShaderLoader, ShaderMap, ShaderProgramSource} from './shader-loader'; import {expectNotNull, unwrapUndef, unwrapNull} from './utils'; import {PathfinderView} from "./view"; -export default abstract class AppController { - constructor() {} - +export abstract class AppController { start() { const canvas = document.getElementById('pf-canvas') as HTMLCanvasElement; + } + + protected loadInitialFile() { + this.fetchFile(this.defaultFile); + } + + protected fetchFile(file: string) { + window.fetch(`${this.builtinFileURI}/${file}`) + .then(response => response.arrayBuffer()) + .then(data => { + this.fileData = data; + this.fileLoaded(); + }); + } + + protected canvas: HTMLCanvasElement; + + protected fileData: ArrayBuffer; + + protected abstract fileLoaded(): void; + + protected abstract get defaultFile(): string; + protected abstract get builtinFileURI(): string; +} + +export abstract class DemoAppController extends AppController { + constructor() { + super(); + } + + start() { + super.start(); this.settingsCard = document.getElementById('pf-settings') as HTMLElement; this.settingsButton = document.getElementById('pf-settings-button') as HTMLButtonElement; @@ -50,7 +80,9 @@ export default abstract class AppController { shaderLoader.load(); this.view = Promise.all([shaderLoader.common, shaderLoader.shaders]).then(allShaders => { - return this.createView(canvas, allShaders[0], allShaders[1]); + this.commonShaderSource = allShaders[0]; + this.shaderSources = allShaders[1]; + return this.createView(); }); this.aaLevelSelect = document.getElementById('pf-aa-level-select') as HTMLSelectElement; @@ -58,10 +90,6 @@ export default abstract class AppController { this.updateAALevel(); } - protected loadInitialFile() { - this.fetchFile(this.defaultFile); - } - private updateAALevel() { const selectedOption = this.aaLevelSelect.selectedOptions[0]; const aaValues = unwrapNull(/^([a-z-]+)(?:-([0-9]+))?$/.exec(selectedOption.value)); @@ -106,31 +134,15 @@ export default abstract class AppController { this.fetchFile(selectedOption.value); } - private fetchFile(file: string) { - window.fetch(`${this.builtinFileURI}/${file}`) - .then(response => response.arrayBuffer()) - .then(data => { - this.fileData = data; - this.fileLoaded(); - }); - } - - protected abstract fileLoaded(): void; - - protected abstract get builtinFileURI(): string; - - protected abstract get defaultFile(): string; - - protected abstract createView(canvas: HTMLCanvasElement, - commonShaderSource: string, - shaderSources: ShaderMap): View; + protected abstract createView(): View; view: Promise; - protected fileData: ArrayBuffer; - - protected canvas: HTMLCanvasElement; protected filePickerElement: HTMLInputElement | null; + + protected commonShaderSource: string | null; + protected shaderSources: ShaderMap | null; + private aaLevelSelect: HTMLSelectElement; private settingsCard: HTMLElement; private settingsButton: HTMLButtonElement; diff --git a/demo/client/src/mesh-debugger.ts b/demo/client/src/mesh-debugger.ts new file mode 100644 index 00000000..d5fac892 --- /dev/null +++ b/demo/client/src/mesh-debugger.ts @@ -0,0 +1,42 @@ +// pathfinder/client/src/mesh-debugger.ts +// +// Copyright © 2017 The Pathfinder Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +import {AppController} from "./app-controller"; +import {BUILTIN_FONT_URI} from "./text"; +import {unwrapNull} from "./utils"; + +const DEFAULT_FONT: string = 'nimbus-sans'; + +class MeshDebuggerAppController extends AppController { + start() { + super.start(); + + this.loadInitialFile(); + + } + protected fileLoaded(): void { + throw new Error("Method not implemented."); + } + + protected get defaultFile(): string { + return DEFAULT_FONT; + } + + protected get builtinFileURI(): string { + return BUILTIN_FONT_URI; + } +} + +function main() { + const appController = new MeshDebuggerAppController; + appController.start(); +} + +main(); diff --git a/demo/client/src/svg-demo.ts b/demo/client/src/svg-demo.ts index 1e4004f5..ffc1dd90 100644 --- a/demo/client/src/svg-demo.ts +++ b/demo/client/src/svg-demo.ts @@ -12,13 +12,13 @@ import * as glmatrix from 'gl-matrix'; import * as _ from 'lodash'; import 'path-data-polyfill.js'; +import {DemoAppController} from './app-controller'; import {AntialiasingStrategy, AntialiasingStrategyName, NoAAStrategy} from "./aa-strategy"; import {ECAAStrategy, ECAAMulticolorStrategy} from "./ecaa-strategy"; import {PathfinderMeshData} from "./meshes"; import {ShaderMap, ShaderProgramSource} from './shader-loader'; -import {panic} from './utils'; +import {panic, unwrapNull} from './utils'; import {PathfinderView, Timings} from './view'; -import AppController from './app-controller'; import SSAAStrategy from "./ssaa-strategy"; const parseColor = require('parse-color'); @@ -54,7 +54,7 @@ interface AntialiasingStrategyTable { ecaa: typeof ECAAStrategy; } -class SVGDemoController extends AppController { +class SVGDemoController extends DemoAppController { start() { super.start(); @@ -73,10 +73,11 @@ class SVGDemoController extends AppController { this.attachSVG(svgElement); } - protected createView(canvas: HTMLCanvasElement, - commonShaderSource: string, - shaderSources: ShaderMap) { - return new SVGDemoView(this, canvas, commonShaderSource, shaderSources); + protected createView() { + return new SVGDemoView(this, + this.canvas, + unwrapNull(this.commonShaderSource), + unwrapNull(this.shaderSources)); } private attachSVG(svgElement: SVGSVGElement) { diff --git a/demo/client/src/text-demo.ts b/demo/client/src/text-demo.ts index a3d80fc3..fa9e3ba5 100644 --- a/demo/client/src/text-demo.ts +++ b/demo/client/src/text-demo.ts @@ -15,6 +15,7 @@ import * as glmatrix from 'gl-matrix'; import * as opentype from 'opentype.js'; import {AntialiasingStrategy, AntialiasingStrategyName, NoAAStrategy} from './aa-strategy'; +import {DemoAppController} from './app-controller'; import {ECAAMonochromeStrategy, ECAAStrategy} from './ecaa-strategy'; import {createFramebuffer, createFramebufferColorTexture} from './gl-utils'; import {createFramebufferDepthTexture, QUAD_ELEMENTS, setTextureParameters} from './gl-utils'; @@ -24,7 +25,6 @@ import {PathfinderShaderProgram, ShaderMap, ShaderProgramSource} from './shader- import {BUILTIN_FONT_URI, PathfinderGlyph, TextLayout} from "./text"; import {PathfinderError, assert, expectNotNull, UINT32_SIZE, unwrapNull, panic} from './utils'; import {MonochromePathfinderView, Timings} from './view'; -import AppController from './app-controller'; import PathfinderBufferTexture from './buffer-texture'; import SSAAStrategy from './ssaa-strategy'; @@ -115,7 +115,7 @@ function rectsIntersect(a: glmatrix.vec4, b: glmatrix.vec4): boolean { return a[2] > b[0] && a[3] > b[1] && a[0] < b[2] && a[1] < b[3]; } -class TextDemoController extends AppController { +class TextDemoController extends DemoAppController { constructor() { super(); this.text = DEFAULT_TEXT; @@ -151,10 +151,11 @@ class TextDemoController extends AppController { window.jQuery(this.editTextModal).modal('hide'); } - protected createView(canvas: HTMLCanvasElement, - commonShaderSource: string, - shaderSources: ShaderMap) { - return new TextDemoView(this, canvas, commonShaderSource, shaderSources); + protected createView() { + return new TextDemoView(this, + this.canvas, + unwrapNull(this.commonShaderSource), + unwrapNull(this.shaderSources)); } protected fileLoaded() { diff --git a/demo/client/webpack.config.js b/demo/client/webpack.config.js index 2fef1036..f5e591d9 100644 --- a/demo/client/webpack.config.js +++ b/demo/client/webpack.config.js @@ -8,6 +8,7 @@ module.exports = { '3d-demo': "./src/3d-demo.ts", 'svg-demo': "./src/svg-demo.ts", 'text-demo': "./src/text-demo.ts", + 'mesh-debugger': "./src/mesh-debugger.ts", }, module: { rules: [ diff --git a/demo/server/src/main.rs b/demo/server/src/main.rs index baa4cbc4..51bc0fe4 100644 --- a/demo/server/src/main.rs +++ b/demo/server/src/main.rs @@ -42,6 +42,7 @@ static STATIC_INDEX_PATH: &'static str = "../client/index.html"; static STATIC_TEXT_DEMO_PATH: &'static str = "../client/text-demo.html"; static STATIC_SVG_DEMO_PATH: &'static str = "../client/svg-demo.html"; static STATIC_3D_DEMO_PATH: &'static str = "../client/3d-demo.html"; +static STATIC_MESH_DEBUGGER_PATH: &'static str = "../client/mesh-debugger.html"; static STATIC_DOC_API_PATH: &'static str = "../../font-renderer/target/doc"; static STATIC_CSS_BOOTSTRAP_PATH: &'static str = "../client/node_modules/bootstrap/dist/css"; static STATIC_CSS_OCTICONS_PATH: &'static str = "../client/node_modules/octicons/build"; @@ -532,6 +533,10 @@ fn static_demo_svg() -> io::Result { fn static_demo_3d() -> io::Result { NamedFile::open(STATIC_3D_DEMO_PATH) } +#[get("/debug/mesh")] +fn static_debug_mesh() -> io::Result { + NamedFile::open(STATIC_MESH_DEBUGGER_PATH) +} #[get("/doc/api")] fn static_doc_api_index() -> Redirect { Redirect::to(STATIC_DOC_API_INDEX_URI) @@ -617,6 +622,7 @@ fn main() { static_demo_text, static_demo_svg, static_demo_3d, + static_debug_mesh, static_doc_api_index, static_doc_api, static_css_bootstrap,