Use some names from the Mozilla Monument in the 3D demo

This commit is contained in:
Patrick Walton 2017-09-06 22:50:07 -07:00
parent 7de664e4a9
commit 6cbc7dc082
3 changed files with 36336 additions and 8 deletions

View File

@ -23,12 +23,9 @@ import {PathfinderDemoView, Timings} from "./view";
import SSAAStrategy from "./ssaa-strategy";
import * as _ from "lodash";
const WIDTH: number = 40000;
const WIDTH: number = 150000;
const TEXT: string[][] = [
[ "Lorem ipsum", "dolor sit amet" ],
[ "consectetur adipiscing elit." ],
];
const TEXT_DATA_URI: string = "/data/mozmonument.json";
const FONT: string = 'open-sans';
@ -38,7 +35,7 @@ const FOV: number = 45.0;
const NEAR_CLIP_PLANE: number = 0.01;
const FAR_CLIP_PLANE: number = 10000.0;
const SCALE: glmatrix.vec3 = glmatrix.vec3.fromValues(1.0 / 50.0, 1.0 / 50.0, 1.0);
const SCALE: glmatrix.vec3 = glmatrix.vec3.fromValues(1.0 / 200.0, 1.0 / 200.0, 1.0);
const ANTIALIASING_STRATEGIES: AntialiasingStrategyTable = {
none: NoAAStrategy,
@ -50,21 +47,55 @@ interface AntialiasingStrategyTable {
ssaa: typeof SSAAStrategy;
}
interface Panels {
upper: string[][];
lower: string[][];
}
class ThreeDController extends DemoAppController<ThreeDView> {
start() {
super.start();
this.textPromise = window.fetch(TEXT_DATA_URI)
.then(response => response.json())
.then(textData => this.parseTextData(textData));
this.loadInitialFile();
}
private parseTextData(textData: any): string[][] {
const panels = {
upper: [],
lower: [],
};
for (const nameData of textData.monument) {
if (nameData.side !== '1')
continue;
const row = parseInt(nameData.row) - 1, number = parseInt(nameData.number) - 1;
const panel: string[][] = panels[nameData.panel as ('upper' | 'lower')];
if (panel[row] == null)
panel[row] = [];
panel[row][number] = nameData.name;
}
return panels.upper.concat(panels.lower);
}
protected fileLoaded(): void {
const font = opentype.parse(this.fileData);
assert(font.isSupported(), "The font type is unsupported!");
this.textPromise.then(text => this.layoutText(font, text));
}
private layoutText(font: opentype.Font, text: string[][]) {
const createGlyph = (glyph: opentype.Glyph) => new ThreeDGlyph(glyph);
let textRuns = [];
for (let lineNumber = 0; lineNumber < TEXT.length; lineNumber++) {
const line = TEXT[lineNumber];
for (let lineNumber = 0; lineNumber < text.length; lineNumber++) {
const line = text[lineNumber];
const lineY = -lineNumber * font.lineHeight();
const lineGlyphs = line.map(string => {
@ -114,6 +145,8 @@ class ThreeDController extends DemoAppController<ThreeDView> {
private baseMeshes: PathfinderMeshData;
private expandedMeshes: PathfinderMeshData;
private textPromise: Promise<string[][]>;
}
class ThreeDView extends PathfinderDemoView {

View File

@ -54,6 +54,7 @@ static STATIC_JS_POPPER_JS_PATH: &'static str = "../client/node_modules/popper.j
static STATIC_JS_PATHFINDER_PATH: &'static str = "../client";
static STATIC_SVG_OCTICONS_PATH: &'static str = "../client/node_modules/octicons/build/svg";
static STATIC_GLSL_PATH: &'static str = "../../shaders";
static STATIC_DATA_PATH: &'static str = "../../resources/data";
static STATIC_DOC_API_INDEX_URI: &'static str = "/doc/api/pathfinder_font_renderer/index.html";
@ -610,6 +611,10 @@ fn static_svg_demo(svg_name: String) -> Option<NamedFile> {
.next()
.and_then(|&(_, path)| NamedFile::open(Path::new(path)).ok())
}
#[get("/data/<file..>")]
fn static_data(file: PathBuf) -> Option<NamedFile> {
NamedFile::open(Path::new(STATIC_DATA_PATH).join(file)).ok()
}
struct Shader {
file: File,
@ -653,5 +658,6 @@ fn main() {
static_glsl,
static_otf_demo,
static_svg_demo,
static_data,
]).launch();
}

File diff suppressed because it is too large Load Diff