From 26d964637d4ac6ccba58a1ddcbe5e8d2d0e0a616 Mon Sep 17 00:00:00 2001 From: ajuvercr Date: Thu, 19 Sep 2019 17:52:48 +0200 Subject: [PATCH] better planets --- frontend/package-lock.json | 3 + frontend/www/index.ts | 92 +- frontend/www/package-lock.json | 877 ++++++++++++++++++- frontend/www/package.json | 5 +- frontend/www/static/res/assets/earth.svg | 114 +++ frontend/www/static/res/assets/jupiter.svg | 118 +++ frontend/www/static/res/assets/mars.svg | 114 +++ frontend/www/static/res/assets/neptune.svg | 186 ++++ frontend/www/static/res/assets/uranus.svg | 150 ++++ frontend/www/static/res/assets/venus.svg | 114 +++ frontend/www/static/shaders/frag/simple.glsl | 27 +- frontend/www/static/shaders/vert/simple.glsl | 16 +- frontend/www/webgl/index.ts | 89 +- frontend/www/webgl/renderer.ts | 32 +- frontend/www/webgl/shader.ts | 11 + frontend/www/webgl/texture.ts | 66 +- frontend/www/webgl/util.ts | 33 +- 17 files changed, 1895 insertions(+), 152 deletions(-) create mode 100644 frontend/package-lock.json create mode 100644 frontend/www/static/res/assets/earth.svg create mode 100644 frontend/www/static/res/assets/jupiter.svg create mode 100644 frontend/www/static/res/assets/mars.svg create mode 100644 frontend/www/static/res/assets/neptune.svg create mode 100644 frontend/www/static/res/assets/uranus.svg create mode 100644 frontend/www/static/res/assets/venus.svg diff --git a/frontend/package-lock.json b/frontend/package-lock.json new file mode 100644 index 0000000..48e341a --- /dev/null +++ b/frontend/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +} diff --git a/frontend/www/index.ts b/frontend/www/index.ts index e70ad6c..09aacaf 100644 --- a/frontend/www/index.ts +++ b/frontend/www/index.ts @@ -1,7 +1,7 @@ import { Game } from "planetwars"; import { memory } from "planetwars/plantwars_bg"; -import { Resizer, resizeCanvasToDisplaySize, FPSCounter } from "./webgl/util"; -import { Shader, Uniform4f, Uniform2fv, Uniform3fv, Uniform1i, Uniform1f, Uniform2f, ShaderFactory } from './webgl/shader'; +import { Resizer, resizeCanvasToDisplaySize, FPSCounter, url_to_mesh, Mesh } from "./webgl/util"; +import { Shader, Uniform4f, Uniform2fv, Uniform3fv, Uniform1i, Uniform1f, Uniform2f, ShaderFactory, Uniform3f, UniformMatrix3fv } from './webgl/shader'; import { Renderer } from "./webgl/renderer"; import { VertexBuffer, IndexBuffer } from "./webgl/buffer"; import { VertexBufferLayout, VertexArray } from "./webgl/vertexBufferLayout"; @@ -34,6 +34,8 @@ const CANVAS = document.getElementById("c"); const RESOLUTION = [CANVAS.width, CANVAS.height]; const GL = CANVAS.getContext("webgl"); + + resizeCanvasToDisplaySize(GL.canvas); GL.viewport(0, 0, GL.canvas.width, GL.canvas.height); @@ -43,23 +45,6 @@ GL.clear(GL.COLOR_BUFFER_BIT); GL.enable(GL.BLEND); GL.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA); -const positionBuffer = new VertexBuffer(GL, [ - -1, -1, - -1, 1, - 1, -1, - 1, 1, -]); - -const layout = new VertexBufferLayout(); -layout.push(GL.FLOAT, 2, 4, "a_position"); -const vao = new VertexArray(); -vao.addBuffer(positionBuffer, layout); - -const indexBuffer = new IndexBuffer(GL, [ - 0, 1, 2, - 1, 2, 3, -]); - var SHADERFACOTRY: ShaderFactory; ShaderFactory.create_factory( LOCATION + "static/shaders/frag/simple.glsl", LOCATION + "static/shaders/vert/simple.glsl" @@ -75,13 +60,53 @@ class GameInstance { last_time = 0; frame = -1; - constructor(game: Game) { + constructor(game: Game, meshes: Mesh[]) { this.game = game; this.planet_count = this.game.get_planet_count(); this.shader = SHADERFACOTRY.create_shader(GL, {"MAX_CIRCLES": ''+this.planet_count}); this.resizer = new Resizer(CANVAS, [...f32v(game.get_viewbox(), 4)], true); this.renderer = new Renderer(); - this.renderer.addToDraw(indexBuffer, vao, this.shader); + // this.renderer.addToDraw(indexBuffer, vao, this.shader); + this.game.update_turn(10); + + const planets = f32v(game.get_planets(), this.planet_count * 3); + const colours = f32v(game.get_planet_colors(), this.planet_count * 3); + + console.log(planets.length); + console.log(colours.length); + + + console.log(this.planet_count); + for(let i=0; i < this.planet_count; i++){ + const colour = new Uniform3f(colours[i*3], colours[i*3 + 1], colours[i*3 + 2]); + + console.log(colour); + + const transform = new UniformMatrix3fv([ + 1, 0, 0, + 0, 1, 0, + planets[i*3], planets[i*3+1], 1, + ]); + + const indexBuffer = new IndexBuffer(GL, meshes[i % meshes.length].cells); + + const positionBuffer = new VertexBuffer(GL, meshes[i % meshes.length].positions); + + const layout = new VertexBufferLayout(); + layout.push(GL.FLOAT, 3, 4, "a_position"); + const vao = new VertexArray(); + vao.addBuffer(positionBuffer, layout); + + this.renderer.addToDraw( + indexBuffer, + vao, + this.shader, + { + "u_color": colour, + "u_trans": transform, + } + ) + } // this.game.update_turn(this.frame); @@ -94,27 +119,38 @@ class GameInstance { this.last_time = time; this.frame ++; this.game.update_turn(this.frame); - } - this.shader.uniform(GL, "u_circle_count", new Uniform1i(this.planet_count)); + const colours = f32v(this.game.get_planet_colors(), this.planet_count * 3); + for(let i=0; i < this.planet_count; i++){ + const u = new Uniform3f(colours[i*3], colours[i*3 + 1], colours[i*3 + 2]); + this.renderer.updateUniform(i, (us) => us["u_color"] = u); + } + } + GL.bindFramebuffer(GL.FRAMEBUFFER, null); + GL.viewport(0, 0, GL.canvas.width, GL.canvas.height); + GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); this.shader.uniform(GL, "u_time", new Uniform1f(time * 0.001)); this.shader.uniform(GL, "u_mouse", new Uniform2f(this.resizer.get_mouse_pos())); this.shader.uniform(GL, "u_viewbox", new Uniform4f(this.resizer.get_viewbox())); this.shader.uniform(GL, "u_resolution", new Uniform2f(RESOLUTION)); - this.shader.uniform(GL, "u_circles", new Uniform3fv(f32v(this.game.get_planets(), 3 * this.planet_count))); - this.shader.uniform(GL, "u_colors", new Uniform3fv(f32v(this.game.get_planet_colors(), 3 * this.planet_count))); - this.renderer.render(GL); + COUNTER.frame(time); } } var game_instance: GameInstance; -export function set_instance(game: Game) { - game_instance = new GameInstance(game); +export async function set_instance(game: Game) { + const meshes = await Promise.all( + ["earth.svg", "jupiter.svg", "mars.svg"].map( + (name) => "static/res/assets/" + name + ).map(url_to_mesh) + ); + console.log(meshes[0]); + game_instance = new GameInstance(game, meshes); console.log(game.turn_count()); diff --git a/frontend/www/package-lock.json b/frontend/www/package-lock.json index 19fdad9..3ec94ae 100644 --- a/frontend/www/package-lock.json +++ b/frontend/www/package-lock.json @@ -221,6 +221,25 @@ "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==", "dev": true }, + "CSSselect": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/CSSselect/-/CSSselect-0.4.1.tgz", + "integrity": "sha1-+Kt+H4QYzmPNput713ioXX7EkrI=", + "requires": { + "CSSwhat": "0.4", + "domutils": "1.4" + } + }, + "CSSwhat": { + "version": "0.4.7", + "resolved": "https://registry.npmjs.org/CSSwhat/-/CSSwhat-0.4.7.tgz", + "integrity": "sha1-hn2g/zn3eGEyQsRM/qg/CqTr35s=" + }, + "abs-svg-path": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/abs-svg-path/-/abs-svg-path-0.1.1.tgz", + "integrity": "sha1-32Acjo0roQ1KdtYl4japo5wnI78=" + }, "accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -237,6 +256,11 @@ "integrity": "sha512-/czfa8BwS88b9gWQVhc8eknunSA2DoJpJyTQkhheIf5E48u1N0R4q/YxxsAeqRrmK9TQ/uYfgLDfZo91UlANIA==", "dev": true }, + "adaptive-bezier-curve": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/adaptive-bezier-curve/-/adaptive-bezier-curve-1.0.3.tgz", + "integrity": "sha1-R3V3q+h9coDUbKQWSfbCJkb+gic=" + }, "ajv": { "version": "6.5.3", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.3.tgz", @@ -261,6 +285,12 @@ "integrity": "sha1-6GuBnGAs+IIa1jdBNpjx3sAhhHo=", "dev": true }, + "amdefine": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", + "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=", + "optional": true + }, "ansi-colors": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.3.tgz", @@ -490,6 +520,16 @@ "integrity": "sha1-3DQxT05nkxgJP8dgJyUl+UvyXBY=", "dev": true }, + "big-rat": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/big-rat/-/big-rat-1.0.4.tgz", + "integrity": "sha1-do0JO7V5MN0Y7Vdcf8on3FORreo=", + "requires": { + "bit-twiddle": "^1.0.2", + "bn.js": "^4.11.6", + "double-bits": "^1.1.1" + } + }, "big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -502,6 +542,16 @@ "integrity": "sha1-RqoXUftqL5PuXmibsQh9SxTGwgU=", "dev": true }, + "binary-search-bounds": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/binary-search-bounds/-/binary-search-bounds-2.0.4.tgz", + "integrity": "sha512-2hg5kgdKql5ClF2ErBcSx0U5bnl5hgS4v7wMnLFodyR47yMtj2w+UAZB+0CiqyHct2q543i7Bi4/aMIegorCCg==" + }, + "bit-twiddle": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bit-twiddle/-/bit-twiddle-1.0.2.tgz", + "integrity": "sha1-DGwfq+KyPRcXPZpht7cJPrnhdp4=" + }, "bluebird": { "version": "3.5.5", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", @@ -511,8 +561,7 @@ "bn.js": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", - "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==", - "dev": true + "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==" }, "body-parser": { "version": "1.19.0", @@ -563,6 +612,20 @@ "multicast-dns-service-types": "^1.1.0" } }, + "bound-points": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/bound-points/-/bound-points-1.0.0.tgz", + "integrity": "sha1-fhY5uFMYRRlLfKCYIGmADvR0Mqc=" + }, + "box-intersect": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/box-intersect/-/box-intersect-1.0.2.tgz", + "integrity": "sha512-yJeMwlmFPG1gIa7Rs/cGXeI6iOj6Qz5MG5PE61xLKpElUGzmJ4abm+qsLpzxKJFpsSDq742BQEocr8dI2t8Nxw==", + "requires": { + "bit-twiddle": "^1.0.2", + "typedarray-pool": "^1.1.0" + } + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -693,8 +756,7 @@ "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", - "dev": true + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" }, "buffer-indexof": { "version": "1.1.1", @@ -797,6 +859,16 @@ "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", "dev": true }, + "cdt2d": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/cdt2d/-/cdt2d-1.0.0.tgz", + "integrity": "sha1-TyEkNLzWe9s9aLj+9KzcLFRBUUE=", + "requires": { + "binary-search-bounds": "^2.0.3", + "robust-in-sphere": "^1.1.3", + "robust-orientation": "^1.1.3" + } + }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -819,6 +891,25 @@ } } }, + "cheerio": { + "version": "0.17.0", + "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-0.17.0.tgz", + "integrity": "sha1-+lrkLMYBIRM9KW0LRtmDIV9yaOo=", + "requires": { + "CSSselect": "~0.4.0", + "dom-serializer": "~0.0.0", + "entities": "~1.1.1", + "htmlparser2": "~3.7.2", + "lodash": "~2.4.1" + }, + "dependencies": { + "lodash": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", + "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=" + } + } + }, "chokidar": { "version": "2.1.6", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.6.tgz", @@ -895,6 +986,20 @@ } } }, + "clean-pslg": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/clean-pslg/-/clean-pslg-1.1.2.tgz", + "integrity": "sha1-vTXHRgt+irWp92Gl7VF5aqPIbBE=", + "requires": { + "big-rat": "^1.0.3", + "box-intersect": "^1.0.1", + "nextafter": "^1.0.0", + "rat-vec": "^1.1.1", + "robust-segment-intersect": "^1.0.1", + "union-find": "^1.0.2", + "uniq": "^1.0.1" + } + }, "cliui": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", @@ -1017,7 +1122,6 @@ "version": "1.6.2", "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", - "dev": true, "requires": { "buffer-from": "^1.0.0", "inherits": "^2.0.3", @@ -1213,8 +1317,7 @@ "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "create-ecdh": { "version": "4.0.3", @@ -1342,6 +1445,14 @@ "ip-regex": "^2.1.0" } }, + "define-properties": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", + "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "requires": { + "object-keys": "^1.0.12" + } + }, "define-property": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/define-property/-/define-property-2.0.2.tgz", @@ -1508,12 +1619,95 @@ "buffer-indexof": "^1.0.0" } }, + "dom-serializer": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.0.1.tgz", + "integrity": "sha1-lYmCfx4y0iw3yCmtq9WbMkevjq8=", + "requires": { + "domelementtype": "~1.1.1", + "entities": "~1.1.1" + }, + "dependencies": { + "domelementtype": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz", + "integrity": "sha1-vSh3PiZCiBrsUVRJJCmcXNgiGFs=" + } + } + }, + "dom-walk": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.1.tgz", + "integrity": "sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg=" + }, "domain-browser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/domain-browser/-/domain-browser-1.2.0.tgz", "integrity": "sha512-jnjyiM6eRyZl2H+W8Q/zLMA481hzi0eszAaBUzIVnmYVDBbnLxVNnfu1HgEBvCbL+71FrxMl3E6lpKH7Ge3OXA==", "dev": true }, + "domelementtype": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz", + "integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==" + }, + "domhandler": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.2.1.tgz", + "integrity": "sha1-Wd+dzSJ+gIs2Wuc+H2aErD2Ub8I=", + "requires": { + "domelementtype": "1" + } + }, + "domutils": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.4.3.tgz", + "integrity": "sha1-CGVRN5bGswYDGFDhdVFrr4C3Km8=", + "requires": { + "domelementtype": "1" + } + }, + "double-bits": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/double-bits/-/double-bits-1.1.1.tgz", + "integrity": "sha1-WKu6RUlNpND6Nrc60RoobJGEscY=" + }, + "dup": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/dup/-/dup-1.0.0.tgz", + "integrity": "sha1-UfxaxoX4GWRp3wuQXpNLIK9bQCk=" + }, + "duplexer2": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.0.2.tgz", + "integrity": "sha1-xhTc9n4vsUmVqRcR5aYX6KYKMds=", + "requires": { + "readable-stream": "~1.1.9" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + } + } + }, "duplexify": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-3.6.0.tgz", @@ -1585,6 +1779,11 @@ "tapable": "^1.0.0" } }, + "entities": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==" + }, "errno": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz", @@ -1594,6 +1793,40 @@ "prr": "~1.0.1" } }, + "es-abstract": { + "version": "1.14.2", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.14.2.tgz", + "integrity": "sha512-DgoQmbpFNOofkjJtKwr87Ma5EW4Dc8fWhD0R+ndq7Oc456ivUfGOOP6oAZTTKl5/CcNMP+EN+e3/iUzgE0veZg==", + "requires": { + "es-to-primitive": "^1.2.0", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.0", + "is-callable": "^1.1.4", + "is-regex": "^1.0.4", + "object-inspect": "^1.6.0", + "object-keys": "^1.1.1", + "string.prototype.trimleft": "^2.0.0", + "string.prototype.trimright": "^2.0.0" + }, + "dependencies": { + "object-inspect": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.6.0.tgz", + "integrity": "sha512-GJzfBZ6DgDAmnuaM3104jR4s1Myxr3Y3zfIyN4z3UdqN69oSRacNK8UhnobDdC+7J2AHCjGwxQubNJfE70SXXQ==" + } + } + }, + "es-to-primitive": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz", + "integrity": "sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==", + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -1606,6 +1839,33 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "escodegen": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.3.3.tgz", + "integrity": "sha1-8CQBb1qI4Eb9EgBQVek5gC5sXyM=", + "requires": { + "esprima": "~1.1.1", + "estraverse": "~1.5.0", + "esutils": "~1.0.0", + "source-map": "~0.1.33" + }, + "dependencies": { + "estraverse": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-1.5.1.tgz", + "integrity": "sha1-hno+jlip+EYYr7bC3bzZFrfLr3E=" + }, + "source-map": { + "version": "0.1.43", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz", + "integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=", + "optional": true, + "requires": { + "amdefine": ">=0.0.4" + } + } + } + }, "eslint-scope": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz", @@ -1616,6 +1876,11 @@ "estraverse": "^4.1.1" } }, + "esprima": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-1.1.1.tgz", + "integrity": "sha1-W28VR/TRAuZw4UDFCb5ncdautUk=" + }, "esrecurse": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", @@ -1631,6 +1896,11 @@ "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true }, + "esutils": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-1.0.0.tgz", + "integrity": "sha1-gVHTWOIMisx/t0XnRywAJf5JZXA=" + }, "etag": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", @@ -1877,6 +2147,42 @@ } } }, + "extract-svg-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/extract-svg-path/-/extract-svg-path-2.1.0.tgz", + "integrity": "sha1-YGKkpLuA/qit8JfY9MKZuIxTrSg=", + "requires": { + "cheerio": "^0.17.0", + "jsesc": "^0.5.0", + "object-assign": "^4.0.1", + "static-module": "^1.1.3", + "through2": "^2.0.0", + "xml-parse-from-string": "^1.0.0" + } + }, + "falafel": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/falafel/-/falafel-2.1.0.tgz", + "integrity": "sha1-lrsXdh2rqU9G0AFzizzt86Z/4Gw=", + "requires": { + "acorn": "^5.0.0", + "foreach": "^2.0.5", + "isarray": "0.0.1", + "object-keys": "^1.0.6" + }, + "dependencies": { + "acorn": { + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", + "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==" + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + } + } + }, "fast-deep-equal": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", @@ -2021,12 +2327,25 @@ } } }, + "for-each": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", + "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", + "requires": { + "is-callable": "^1.1.3" + } + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", "integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=", "dev": true }, + "foreach": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", + "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=" + }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -2631,6 +2950,11 @@ } } }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, "get-caller-file": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", @@ -2699,6 +3023,22 @@ } } }, + "global": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/global/-/global-4.3.2.tgz", + "integrity": "sha1-52mJJopsdMOJCLEwWxD8DjlOnQ8=", + "requires": { + "min-document": "^2.19.0", + "process": "~0.5.1" + }, + "dependencies": { + "process": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/process/-/process-0.5.2.tgz", + "integrity": "sha1-FjjYqONML0QKkduVq5rrZ3/Bhc8=" + } + } + }, "global-modules": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/global-modules/-/global-modules-2.0.0.tgz", @@ -2767,12 +3107,25 @@ "integrity": "sha512-d4sze1JNC454Wdo2fkuyzCr6aHcbL6PGGuFAz0Li/NcOm1tCHGnWDRmJP85dh9IhQErTc2svWFEX5xHIOo//kQ==", "dev": true }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "requires": { + "function-bind": "^1.1.1" + } + }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "dev": true }, + "has-symbols": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz", + "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=" + }, "has-value": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/has-value/-/has-value-1.0.0.tgz", @@ -2863,6 +3216,55 @@ "integrity": "sha1-DfKTUfByEWNRXfueVUPl9u7VFi8=", "dev": true }, + "htmlparser2": { + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.7.3.tgz", + "integrity": "sha1-amTHdjfAjG8w7CqBV6UzM758sF4=", + "requires": { + "domelementtype": "1", + "domhandler": "2.2", + "domutils": "1.5", + "entities": "1.0", + "readable-stream": "1.1" + }, + "dependencies": { + "domutils": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", + "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", + "requires": { + "dom-serializer": "0", + "domelementtype": "1" + } + }, + "entities": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz", + "integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=" + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + } + } + }, "http-deceiver": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/http-deceiver/-/http-deceiver-1.2.7.tgz", @@ -3033,8 +3435,7 @@ "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "ini": { "version": "1.3.5", @@ -3123,6 +3524,11 @@ "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", "dev": true }, + "is-callable": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", + "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==" + }, "is-data-descriptor": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz", @@ -3143,6 +3549,11 @@ } } }, + "is-date-object": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", + "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=" + }, "is-descriptor": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/is-descriptor/-/is-descriptor-0.1.6.tgz", @@ -3242,12 +3653,28 @@ "isobject": "^3.0.1" } }, + "is-regex": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", + "integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=", + "requires": { + "has": "^1.0.1" + } + }, "is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", "dev": true }, + "is-symbol": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz", + "integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==", + "requires": { + "has-symbols": "^1.0.0" + } + }, "is-windows": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz", @@ -3263,8 +3690,7 @@ "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, "isexe": { "version": "2.0.0", @@ -3278,6 +3704,11 @@ "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", "dev": true }, + "jsesc": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", + "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=" + }, "json-parse-better-errors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", @@ -3334,6 +3765,14 @@ "invert-kv": "^2.0.0" } }, + "load-svg": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/load-svg/-/load-svg-1.0.0.tgz", + "integrity": "sha1-f4uhBgIyJykgLn5Eh5mqA5PxTn4=", + "requires": { + "xhr": "^1.16.0" + } + }, "loader-runner": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-2.4.0.tgz", @@ -3544,6 +3983,14 @@ "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", "dev": true }, + "min-document": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/min-document/-/min-document-2.19.0.tgz", + "integrity": "sha1-e9KC4/WELtKVu3SM3Z8f+iyCRoU=", + "requires": { + "dom-walk": "^0.1.0" + } + }, "minimalistic-assert": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", @@ -3568,8 +4015,7 @@ "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" }, "mississippi": { "version": "3.0.0", @@ -3698,6 +4144,14 @@ "integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==", "dev": true }, + "nextafter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/nextafter/-/nextafter-1.0.0.tgz", + "integrity": "sha1-t9d7U1MQ4+CX5gJauwqQNHfsGjo=", + "requires": { + "double-bits": "^1.1.0" + } + }, "nice-try": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.4.tgz", @@ -3758,6 +4212,20 @@ "remove-trailing-separator": "^1.0.1" } }, + "normalize-path-scale": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/normalize-path-scale/-/normalize-path-scale-2.0.0.tgz", + "integrity": "sha1-2LHMVcAI8XrCijb/N1O3JXvwu7M=", + "requires": { + "bound-points": "^1.0.0", + "unlerp": "^1.0.1" + } + }, + "normalize-svg-path": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/normalize-svg-path/-/normalize-svg-path-0.1.0.tgz", + "integrity": "sha1-RWNg5g7Odfvve11+FgSA5//Rb+U=" + }, "npm-run-path": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", @@ -3776,8 +4244,7 @@ "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" }, "object-copy": { "version": "0.1.0", @@ -3810,6 +4277,16 @@ } } }, + "object-inspect": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-0.4.0.tgz", + "integrity": "sha1-9RV8EWwUVbJDsG7pdwM5LFrYn+w=" + }, + "object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==" + }, "object-visit": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/object-visit/-/object-visit-1.0.1.tgz", @@ -3981,12 +4458,26 @@ "safe-buffer": "^5.1.1" } }, + "parse-headers": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/parse-headers/-/parse-headers-2.0.2.tgz", + "integrity": "sha512-/LypJhzFmyBIDYP9aDVgeyEb5sQfbfY5mnDq4hVhlQ69js87wXfmEI5V3xI6vvXasqebp0oCytYFLxsBVfCzSg==", + "requires": { + "for-each": "^0.3.3", + "string.prototype.trim": "^1.1.2" + } + }, "parse-passwd": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/parse-passwd/-/parse-passwd-1.0.0.tgz", "integrity": "sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=", "dev": true }, + "parse-svg-path": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/parse-svg-path/-/parse-svg-path-0.1.2.tgz", + "integrity": "sha1-en7A0esG+lMlx9PgCbhZoJtdSes=" + }, "parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -4139,8 +4630,7 @@ "process-nextick-args": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", - "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", - "dev": true + "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" }, "promise-inflight": { "version": "1.0.1", @@ -4229,6 +4719,65 @@ "integrity": "sha512-w7fLxIRCRT7U8Qu53jQnJyPkYZIaR4n5151KMfcJlO/A9397Wxb1amJvROTK6TOnp7PfoAmg/qXiNHI+08jRfA==", "dev": true }, + "quote-stream": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/quote-stream/-/quote-stream-0.0.0.tgz", + "integrity": "sha1-zeKelMQJsW4Z3HCYuJtmWPlyHTs=", + "requires": { + "minimist": "0.0.8", + "through2": "~0.4.1" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "object-keys": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-0.4.0.tgz", + "integrity": "sha1-KKaq50KN0sOpLz2V8hM13SBOAzY=" + }, + "readable-stream": { + "version": "1.0.34", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", + "integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + }, + "through2": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/through2/-/through2-0.4.2.tgz", + "integrity": "sha1-2/WGYDEVHsg1K7bE22SiKSqEC5s=", + "requires": { + "readable-stream": "~1.0.17", + "xtend": "~2.1.1" + } + }, + "xtend": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-2.1.2.tgz", + "integrity": "sha1-bv7MKk2tjmlixJAbM3znuoe10os=", + "requires": { + "object-keys": "~0.4.0" + } + } + } + }, + "random-float": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/random-float/-/random-float-1.0.0.tgz", + "integrity": "sha1-Ookc1mNCEI/F9Gzfoyg44msHsJ4=" + }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -4254,6 +4803,14 @@ "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", "dev": true }, + "rat-vec": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/rat-vec/-/rat-vec-1.1.1.tgz", + "integrity": "sha1-Dd4rZrezS7G80qI4BerIBth/0X8=", + "requires": { + "big-rat": "^1.0.3" + } + }, "raw-body": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz", @@ -4278,7 +4835,6 @@ "version": "2.3.6", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", - "dev": true, "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -4421,6 +4977,55 @@ "inherits": "^2.0.1" } }, + "robust-in-sphere": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/robust-in-sphere/-/robust-in-sphere-1.1.3.tgz", + "integrity": "sha1-HFiD0WpOkjkpR27zSBmFe/Kpz3U=", + "requires": { + "robust-scale": "^1.0.0", + "robust-subtract": "^1.0.0", + "robust-sum": "^1.0.0", + "two-product": "^1.0.0" + } + }, + "robust-orientation": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/robust-orientation/-/robust-orientation-1.1.3.tgz", + "integrity": "sha1-2v9bANO+TmByLw6cAVbvln8cIEk=", + "requires": { + "robust-scale": "^1.0.2", + "robust-subtract": "^1.0.0", + "robust-sum": "^1.0.0", + "two-product": "^1.0.2" + } + }, + "robust-scale": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/robust-scale/-/robust-scale-1.0.2.tgz", + "integrity": "sha1-d1Ey7QlULQKOWLLMecBikLz3jDI=", + "requires": { + "two-product": "^1.0.2", + "two-sum": "^1.0.0" + } + }, + "robust-segment-intersect": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/robust-segment-intersect/-/robust-segment-intersect-1.0.1.tgz", + "integrity": "sha1-MlK2oPwboUreaRXMvgnLzpqrHBw=", + "requires": { + "robust-orientation": "^1.1.3" + } + }, + "robust-subtract": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/robust-subtract/-/robust-subtract-1.0.0.tgz", + "integrity": "sha1-4LFk4e2LpOOl3aRaEgODSNvtPpo=" + }, + "robust-sum": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/robust-sum/-/robust-sum-1.0.0.tgz", + "integrity": "sha1-FmRuUlKStNJdgnV6KGlV4Lv6U9k=" + }, "run-queue": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/run-queue/-/run-queue-1.0.3.tgz", @@ -4433,8 +5038,7 @@ "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "safe-regex": { "version": "1.1.0", @@ -4642,6 +5246,11 @@ "safe-buffer": "^5.0.1" } }, + "shallow-copy": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/shallow-copy/-/shallow-copy-0.0.1.tgz", + "integrity": "sha1-QV9CcC1z2BAzApLMXuhurhoRoXA=" + }, "shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", @@ -4663,6 +5272,11 @@ "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "dev": true }, + "simplify-path": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/simplify-path/-/simplify-path-1.1.0.tgz", + "integrity": "sha1-eRs50lJwsK/ANd51e6gm5vF2YQM=" + }, "slash": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz", @@ -4844,8 +5458,7 @@ "source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", - "dev": true + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=" }, "source-map-resolve": { "version": "0.5.2", @@ -4942,6 +5555,36 @@ "figgy-pudding": "^3.5.1" } }, + "static-eval": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/static-eval/-/static-eval-0.2.4.tgz", + "integrity": "sha1-t9NNg4k3uWn5ZBygfUj47eJj6ns=", + "requires": { + "escodegen": "~0.0.24" + }, + "dependencies": { + "escodegen": { + "version": "0.0.28", + "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-0.0.28.tgz", + "integrity": "sha1-Dk/xcV8yh3XWyrUaxEpAbNer/9M=", + "requires": { + "esprima": "~1.0.2", + "estraverse": "~1.3.0", + "source-map": ">= 0.1.2" + } + }, + "esprima": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-1.0.4.tgz", + "integrity": "sha1-n1V+CPw7TSbs6d00+Pv0drYlha0=" + }, + "estraverse": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-1.3.2.tgz", + "integrity": "sha1-N8K4k+8T1yPydth41g2FNRUqbEI=" + } + } + }, "static-extend": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz", @@ -4963,6 +5606,69 @@ } } }, + "static-module": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/static-module/-/static-module-1.5.0.tgz", + "integrity": "sha1-J9qYg8QajNCSNvhC8MHrxu32PYY=", + "requires": { + "concat-stream": "~1.6.0", + "duplexer2": "~0.0.2", + "escodegen": "~1.3.2", + "falafel": "^2.1.0", + "has": "^1.0.0", + "object-inspect": "~0.4.0", + "quote-stream": "~0.0.0", + "readable-stream": "~1.0.27-1", + "shallow-copy": "~0.0.1", + "static-eval": "~0.2.0", + "through2": "~0.4.1" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "object-keys": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-0.4.0.tgz", + "integrity": "sha1-KKaq50KN0sOpLz2V8hM13SBOAzY=" + }, + "readable-stream": { + "version": "1.0.34", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", + "integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + }, + "through2": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/through2/-/through2-0.4.2.tgz", + "integrity": "sha1-2/WGYDEVHsg1K7bE22SiKSqEC5s=", + "requires": { + "readable-stream": "~1.0.17", + "xtend": "~2.1.1" + } + }, + "xtend": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-2.1.2.tgz", + "integrity": "sha1-bv7MKk2tjmlixJAbM3znuoe10os=", + "requires": { + "object-keys": "~0.4.0" + } + } + } + }, "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", @@ -5035,11 +5741,38 @@ } } }, + "string.prototype.trim": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.2.0.tgz", + "integrity": "sha512-9EIjYD/WdlvLpn987+ctkLf0FfvBefOCuiEr2henD8X+7jfwPnyvTdmW8OJhj5p+M0/96mBdynLWkxUr+rHlpg==", + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.13.0", + "function-bind": "^1.1.1" + } + }, + "string.prototype.trimleft": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/string.prototype.trimleft/-/string.prototype.trimleft-2.1.0.tgz", + "integrity": "sha512-FJ6b7EgdKxxbDxc79cOlok6Afd++TTs5szo+zJTUyow3ycrRfJVE2pq3vcN53XexvKZu/DJMDfeI/qMiZTrjTw==", + "requires": { + "define-properties": "^1.1.3", + "function-bind": "^1.1.1" + } + }, + "string.prototype.trimright": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/string.prototype.trimright/-/string.prototype.trimright-2.1.0.tgz", + "integrity": "sha512-fXZTSV55dNBwv16uw+hh5jkghxSnc5oHq+5K/gXgizHwAvMetdAJlHqqoFC1FSDVPYWLkAKl2cxpUT41sV7nSg==", + "requires": { + "define-properties": "^1.1.3", + "function-bind": "^1.1.1" + } + }, "string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, "requires": { "safe-buffer": "~5.1.0" } @@ -5068,6 +5801,33 @@ "has-flag": "^3.0.0" } }, + "svg-mesh-3d": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/svg-mesh-3d/-/svg-mesh-3d-1.1.0.tgz", + "integrity": "sha1-WdFlGBLcu/xp+212K5M5ETgsFKU=", + "requires": { + "bound-points": "^1.0.0", + "cdt2d": "^1.0.0", + "clean-pslg": "^1.1.0", + "normalize-path-scale": "^2.0.0", + "object-assign": "^4.0.1", + "parse-svg-path": "^0.1.1", + "random-float": "^1.0.0", + "simplify-path": "^1.1.0", + "svg-path-contours": "^2.0.0" + } + }, + "svg-path-contours": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/svg-path-contours/-/svg-path-contours-2.0.0.tgz", + "integrity": "sha1-x2oSlCnbBette2Hk0cWNEUqJOKI=", + "requires": { + "abs-svg-path": "^0.1.1", + "adaptive-bezier-curve": "^1.0.3", + "normalize-svg-path": "^0.1.0", + "vec2-copy": "^1.0.0" + } + }, "tapable": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/tapable/-/tapable-1.0.0.tgz", @@ -5122,7 +5882,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.3.tgz", "integrity": "sha1-AARWmzfHx0ujnEPzzteNGtlBQL4=", - "dev": true, "requires": { "readable-stream": "^2.1.5", "xtend": "~4.0.1" @@ -5273,6 +6032,16 @@ "integrity": "sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=", "dev": true }, + "two-product": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/two-product/-/two-product-1.0.2.tgz", + "integrity": "sha1-Z9ldSyV6kh4stL16+VEfkIhSLqo=" + }, + "two-sum": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/two-sum/-/two-sum-1.0.0.tgz", + "integrity": "sha1-MdPzIjnk9zHsqd+RVeKyl/AIq2Q=" + }, "type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", @@ -5286,8 +6055,16 @@ "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", - "dev": true + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" + }, + "typedarray-pool": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/typedarray-pool/-/typedarray-pool-1.1.0.tgz", + "integrity": "sha1-0RT0hIAUifU+yrXoCIqiMET0mNk=", + "requires": { + "bit-twiddle": "^1.0.0", + "dup": "^1.0.0" + } }, "typescript": { "version": "3.6.3", @@ -5295,6 +6072,11 @@ "integrity": "sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==", "dev": true }, + "union-find": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/union-find/-/union-find-1.0.2.tgz", + "integrity": "sha1-KSusQV5q06iVNdI3AQ20pTYoTlg=" + }, "union-value": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", @@ -5307,6 +6089,11 @@ "set-value": "^2.0.1" } }, + "uniq": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz", + "integrity": "sha1-sxxa6CVIRKOoKBVBzisEuGWnNP8=" + }, "unique-filename": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz", @@ -5325,6 +6112,11 @@ "imurmurhash": "^0.1.4" } }, + "unlerp": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/unlerp/-/unlerp-1.0.1.tgz", + "integrity": "sha1-4oNR47C3f1Y5gCeu+LLk8UvTdvo=" + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -5438,8 +6230,7 @@ "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "utils-merge": { "version": "1.0.1", @@ -5465,6 +6256,11 @@ "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=", "dev": true }, + "vec2-copy": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/vec2-copy/-/vec2-copy-1.0.0.tgz", + "integrity": "sha1-xu7B2NrVRiUZTl9x+EM7YtLyCno=" + }, "vm-browserify": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-1.1.0.tgz", @@ -5843,11 +6639,32 @@ "async-limiter": "~1.0.0" } }, + "xhr": { + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/xhr/-/xhr-1.17.1.tgz", + "integrity": "sha1-BTM0nkp7uWfQvYeKlh2VBfkFLf8=", + "requires": { + "global": "~4.3.0", + "once": "~1.1.1", + "parse-headers": "^2.0.0" + }, + "dependencies": { + "once": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/once/-/once-1.1.1.tgz", + "integrity": "sha1-nbV0kzzLCMOnYU0VQDLAnqbzOec=" + } + } + }, + "xml-parse-from-string": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml-parse-from-string/-/xml-parse-from-string-1.0.1.tgz", + "integrity": "sha1-qQKekp09vN7RafPG4oI42VpdWig=" + }, "xtend": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=", - "dev": true + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" }, "y18n": { "version": "4.0.0", diff --git a/frontend/www/package.json b/frontend/www/package.json index 46e25a6..c7afb8f 100644 --- a/frontend/www/package.json +++ b/frontend/www/package.json @@ -20,7 +20,10 @@ "mozaic" ], "dependencies": { - "planetwars": "file:../pkg" + "planetwars": "file:../pkg", + "extract-svg-path": "^2.1.0", + "load-svg": "^1.0.0", + "svg-mesh-3d": "^1.1.0" }, "author": "Arthur Vercruysse ", "license": "(MIT OR Apache-2.0)", diff --git a/frontend/www/static/res/assets/earth.svg b/frontend/www/static/res/assets/earth.svg new file mode 100644 index 0000000..f1be561 --- /dev/null +++ b/frontend/www/static/res/assets/earth.svg @@ -0,0 +1,114 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/frontend/www/static/res/assets/jupiter.svg b/frontend/www/static/res/assets/jupiter.svg new file mode 100644 index 0000000..e5fcd0f --- /dev/null +++ b/frontend/www/static/res/assets/jupiter.svg @@ -0,0 +1,118 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/frontend/www/static/res/assets/mars.svg b/frontend/www/static/res/assets/mars.svg new file mode 100644 index 0000000..d92851d --- /dev/null +++ b/frontend/www/static/res/assets/mars.svg @@ -0,0 +1,114 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/frontend/www/static/res/assets/neptune.svg b/frontend/www/static/res/assets/neptune.svg new file mode 100644 index 0000000..995d440 --- /dev/null +++ b/frontend/www/static/res/assets/neptune.svg @@ -0,0 +1,186 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/frontend/www/static/res/assets/uranus.svg b/frontend/www/static/res/assets/uranus.svg new file mode 100644 index 0000000..fb192a4 --- /dev/null +++ b/frontend/www/static/res/assets/uranus.svg @@ -0,0 +1,150 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/frontend/www/static/res/assets/venus.svg b/frontend/www/static/res/assets/venus.svg new file mode 100644 index 0000000..3bebb10 --- /dev/null +++ b/frontend/www/static/res/assets/venus.svg @@ -0,0 +1,114 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/frontend/www/static/shaders/frag/simple.glsl b/frontend/www/static/shaders/frag/simple.glsl index 6b78958..cb8bc50 100644 --- a/frontend/www/static/shaders/frag/simple.glsl +++ b/frontend/www/static/shaders/frag/simple.glsl @@ -2,31 +2,8 @@ precision mediump float; #endif -uniform int u_circle_count; -uniform float u_time; -uniform vec2 u_mouse; -uniform vec4 u_viewbox; // [x, y, width, height] -uniform vec2 u_resolution; -uniform vec3 u_circles[$MAX_CIRCLES]; -uniform vec3 u_colors[$MAX_CIRCLES]; - -varying vec2 v_pos; +uniform vec3 u_color; void main() { - vec2 uv = v_pos; - - float alpha = 0.0; - vec3 color; - for (int i = 0; i < $MAX_CIRCLES; i++ ){ - if (i >= u_circle_count) { break; } - float d = distance(uv.xy, u_circles[i].xy); - float a = 1.0 - d/u_circles[i].z; - if (a > alpha) { - alpha = a; - color = u_colors[i]; - } - } - - gl_FragColor = vec4(color, alpha); - // gl_FragColor.w *= alpha; + gl_FragColor = vec4(u_color, 1.0); } diff --git a/frontend/www/static/shaders/vert/simple.glsl b/frontend/www/static/shaders/vert/simple.glsl index 1d74e16..e35e68b 100644 --- a/frontend/www/static/shaders/vert/simple.glsl +++ b/frontend/www/static/shaders/vert/simple.glsl @@ -6,17 +6,23 @@ attribute vec2 a_position; uniform vec4 u_viewbox; // [x, y, width, height] uniform vec2 u_resolution; +uniform mat3 u_trans; varying vec2 v_pos; void main() { + vec3 pos = vec3(a_position, 1.0); - vec2 uv = ( a_position.xy + 1.0 ) * 0.5; + pos = u_trans * pos; - uv *= u_viewbox.zw; - uv += u_viewbox.xy; + vec2 uv = pos.xy; - v_pos = uv.xy; + // Viewbox's center is top left, a_position's is in the center to the screen + // So translate and scale the viewbox** + uv -= u_viewbox.xy + (u_viewbox.zw * 0.5); + uv /= u_viewbox.zw * 0.5; - gl_Position = vec4(a_position.xy, 0.0, 1.0); + v_pos = (uv.xy + 1.0) * 0.5; + + gl_Position = vec4(uv.xy, 0.0, 1.0); } diff --git a/frontend/www/webgl/index.ts b/frontend/www/webgl/index.ts index 8a7c39f..7cca94e 100644 --- a/frontend/www/webgl/index.ts +++ b/frontend/www/webgl/index.ts @@ -1,45 +1,66 @@ - -import { Shader, Uniform4f, Uniform2fv, Uniform3fv, Uniform1i, Uniform1f, Uniform2f, ShaderFactory } from './shader'; -import { resizeCanvasToDisplaySize, FPSCounter, onload2promise, Resizer } from "./util"; +import { Shader, Uniform4f, Uniform2fv, Uniform3fv, Uniform1i, Uniform1f, Uniform2f, ShaderFactory, UniformMatrix3fv, Uniform3f } from './shader'; +import { resizeCanvasToDisplaySize, FPSCounter, onload2promise, Resizer, url_to_mesh } from "./util"; import { VertexBuffer, IndexBuffer } from './buffer'; import { VertexArray, VertexBufferLayout } from './vertexBufferLayout'; import { Renderer } from './renderer'; import { Texture } from './texture'; +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 { + + 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") + ]); + + const program = factory.create_shader(gl); + const renderer = new Renderer(); + + var positionBuffer = new VertexBuffer(gl, mesh.positions); + var layout = new VertexBufferLayout(); + layout.push(gl.FLOAT, 3, 4, "a_position"); + + const vao = new VertexArray(); + vao.addBuffer(positionBuffer, layout); + + program.bind(gl); + vao.bind(gl, program); + + var indexBuffer = new IndexBuffer(gl, mesh.cells); + indexBuffer.bind(gl); + + renderer.addToDraw(indexBuffer, vao, program, {}); + + return Texture.fromRenderer(gl, name, width, height, renderer); +} + async function main() { - const URL = window.location.origin+window.location.pathname; - const LOCATION = URL.substring(0, URL.lastIndexOf("/") + 1); - - // Get A WebGL context var canvas = document.getElementById("c"); const resolution = [canvas.width, canvas.height]; - const resizer = new Resizer(canvas, [-100, -10, 200, 20], true); + const resizer = new Resizer(canvas, [-10, -10, 20, 20], true); var gl = canvas.getContext("webgl"); if (!gl) { return; } + const mesh = await url_to_mesh("static/res/images/earth.svg"); + console.log(Math.max(...mesh.positions), Math.min(...mesh.positions)); const renderer = new Renderer(); - const factory = await ShaderFactory.create_factory(LOCATION + "static/shaders/frag/simple.glsl", LOCATION + "static/shaders/vert/simple.glsl"); - const program = factory.create_shader(gl, {"MAX_CIRCLES": "50"}); + const factory = await ShaderFactory.create_factory(LOCATION + "static/shaders/frag/static_color.glsl", LOCATION + "static/shaders/vert/simple.glsl"); + const program = factory.create_shader(gl); - var positions = [ - -1, -1, 0, 1, - -1, 1, 0, 0, - 1, -1, 1, 1, - 1, 1, 1, 0, - ]; - - var positionBuffer = new VertexBuffer(gl, positions); + var positionBuffer = new VertexBuffer(gl, mesh.positions); var layout = new VertexBufferLayout(); - layout.push(gl.FLOAT, 2, 4, "a_position"); - layout.push(gl.FLOAT, 2, 4, "a_tex"); + layout.push(gl.FLOAT, 3, 4, "a_position"); + // layout.push(gl.FLOAT, 2, 4, "a_tex"); const vao = new VertexArray(); vao.addBuffer(positionBuffer, layout); @@ -59,40 +80,23 @@ async function main() { program.bind(gl); vao.bind(gl, program); - var indices = [ - 0, 1, 2, - 1, 2, 3, - ]; - - var indexBuffer = new IndexBuffer(gl, indices); + var indexBuffer = new IndexBuffer(gl, mesh.cells); indexBuffer.bind(gl); - renderer.addToDraw(indexBuffer, vao, program); - - var blue = 1.0; - var inc = 0.05; + renderer.addToDraw(indexBuffer, vao, program, {}); const counter = new FPSCounter(); const step = function (time: number) { - blue += inc; - // if (blue > 1.0 || blue < 0.0) { - // inc = -1 * inc; - // blue += inc; - // } - program.uniform(gl, "u_circle_count", new Uniform1i(3)); + // console.log(resizer.get_viewbox()); program.uniform(gl, "u_time", new Uniform1f(time * 0.001)); program.uniform(gl, "u_mouse", new Uniform2f(resizer.get_mouse_pos())); program.uniform(gl, "u_viewbox", new Uniform4f(resizer.get_viewbox())); program.uniform(gl, "u_resolution", new Uniform2f(resolution)); - program.uniform(gl, "u_circles", new Uniform3fv([ - 0, 0, 3.5, - -2, -2, 2, - 5, 2, 4, - ])); - program.uniform(gl, "u_color", new Uniform4f([1, blue, 0, 1])); + program.uniform(gl, "u_trans", new UniformMatrix3fv([1, 0, 0, 0, 1, 0, 0, 0, 1])); + program.uniform(gl, "u_color", new Uniform3f(1.0, 0.5, 0.0)); renderer.render(gl); @@ -103,6 +107,7 @@ async function main() { requestAnimationFrame(step); } + main(); document.getElementById("loader").classList.remove("loading"); diff --git a/frontend/www/webgl/renderer.ts b/frontend/www/webgl/renderer.ts index 2c4f6fa..26ef696 100644 --- a/frontend/www/webgl/renderer.ts +++ b/frontend/www/webgl/renderer.ts @@ -1,8 +1,9 @@ import { IndexBuffer } from './buffer'; -import { Shader, Uniform1i } from './shader'; +import { Shader, Uniform1i, Uniform } from './shader'; import { VertexArray } from './vertexBufferLayout'; import { Texture } from './texture'; +import { Dictionary } from './util'; export interface Renderable { render(gl: WebGLRenderingContext): void; @@ -15,34 +16,49 @@ export class Renderer { vertexArrays: VertexArray[]; shaders: Shader[]; textures: Texture[]; + uniforms: Dictionary[]; constructor() { this.indexBuffers = []; this.vertexArrays = []; this.shaders = []; this.textures = []; + this.uniforms = []; + } + + updateUniform(i: number, f: (uniforms: Dictionary) => void) { + f(this.uniforms[i]); } addRenderable(item: Renderable) { this.renderables.push(item); } - addToDraw(indexBuffer: IndexBuffer, vertexArray: VertexArray, shader: Shader, texture?: Texture): number { + addToDraw(indexBuffer: IndexBuffer, vertexArray: VertexArray, shader: Shader, uniforms: Dictionary,texture?: Texture): number { this.indexBuffers.push(indexBuffer); this.vertexArrays.push(vertexArray); this.shaders.push(shader); this.textures.push(texture); + this.uniforms.push(uniforms); + + return this.indexBuffers.length - 1; } - render(gl: WebGLRenderingContext) { + render(gl: WebGLRenderingContext, frameBuffer?: WebGLFramebuffer, width?: number, height?: number) { + gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); + gl.viewport(0, 0, width || gl.canvas.width, height || gl.canvas.height); + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + const maxTextures = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS); let texLocation = 0; for(let i = 0; i < this.indexBuffers.length; i ++) { const indexBuffer = this.indexBuffers[i]; const vertexArray = this.vertexArrays[i]; + const uniforms = this.uniforms[i]; + const shader = this.shaders[i]; const texture = this.textures[i]; @@ -56,10 +72,14 @@ export class Renderer { console.error("Using too many textures, this is not supported yet\nUndefined behaviour!"); } } - - if (vertexArray && shader) { + + if (vertexArray && shader && uniforms) { + for(let key in uniforms) { + shader.uniform(gl, key, uniforms[key]); + } + vertexArray.bind(gl, shader); - + if (indexBuffer) { indexBuffer.bind(gl); gl.drawElements(gl.TRIANGLES, indexBuffer.getCount(), gl.UNSIGNED_SHORT, 0); diff --git a/frontend/www/webgl/shader.ts b/frontend/www/webgl/shader.ts index 6f99d3c..3f867e8 100644 --- a/frontend/www/webgl/shader.ts +++ b/frontend/www/webgl/shader.ts @@ -304,3 +304,14 @@ export class Uniform4f implements Uniform { gl.uniform4f(location, this.v0, this.v1, this.v2, this.v3); } } + +export class UniformMatrix3fv implements Uniform { + data: number[]; + constructor(data: number[]) { + this.data = data; + } + + setUniform(gl: WebGLRenderingContext, location: WebGLUniformLocation) { + gl.uniformMatrix3fv(location, false, this.data); + } +} diff --git a/frontend/www/webgl/texture.ts b/frontend/www/webgl/texture.ts index a9cbb39..04649c9 100644 --- a/frontend/www/webgl/texture.ts +++ b/frontend/www/webgl/texture.ts @@ -1,25 +1,62 @@ +import { Renderer } from "./renderer"; - -// TODO: fix texture locations, not use only 0 export class Texture { texture: WebGLTexture; - image: HTMLImageElement; + width: number; + height: number; loaded: boolean; name: string; - constructor( + static fromImage( gl: WebGLRenderingContext, path: string, name: string, + ): Texture { + const out = new Texture(gl, name); + + const image = new Image(); + image.onload = out.setImage.bind(out, gl, image); + image.onerror = error; + image.src = path; + + return out; + } + + static fromRenderer( + gl: WebGLRenderingContext, + name: string, + width: number, + height: number, + renderer: Renderer + ): Texture { + const out = new Texture(gl, name); + out.width = width; + out.height = height; + + gl.texImage2D( + gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, + gl.RGBA, gl.UNSIGNED_BYTE, null); + + const fb = gl.createFramebuffer(); + gl.bindFramebuffer(gl.FRAMEBUFFER, fb); + + const attachmentPoint = gl.COLOR_ATTACHMENT0; + gl.framebufferTexture2D(gl.FRAMEBUFFER, attachmentPoint, gl.TEXTURE_2D, out.texture, 0); + + renderer.render(gl, fb, width, height); + + out.loaded = true; + + return out; + } + + constructor( + gl: WebGLRenderingContext, + name: string, ) { this.loaded = false; this.name = name; - this.image = new Image(); - this.image.onload = () => this.handleImageLoaded(gl); - this.image.onerror = error; - this.image.src = path; - this.texture = gl.createTexture(); this.bind(gl); @@ -32,11 +69,12 @@ export class Texture { gl.UNSIGNED_BYTE, new Uint8Array([255, 0, 0, 255])); } - handleImageLoaded(gl: WebGLRenderingContext) { - console.log('handling image loaded'); + setImage(gl: WebGLRenderingContext, image: HTMLImageElement) { this.bind(gl); + this.width = image.width; + this.height = image.height; - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this.image); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); this.unbind(gl); @@ -54,11 +92,11 @@ export class Texture { getWidth(): number { - return this.image.width; + return this.width; } getHeight(): number { - return this.image.height; + return this.height; } } diff --git a/frontend/www/webgl/util.ts b/frontend/www/webgl/util.ts index fc6fc07..3cef7a8 100644 --- a/frontend/www/webgl/util.ts +++ b/frontend/www/webgl/util.ts @@ -1,3 +1,6 @@ +var loadSvg = require('load-svg') +var parsePath = require('extract-svg-path').parse +var svgMesh3d = require('svg-mesh-3d') export interface Dictionary { [Key: string]: T; @@ -159,10 +162,38 @@ export class Resizer { } get_viewbox(): number[] { - return this.viewbox; + return this.viewbox; + // return [this.viewbox[0] / this.orig_viewbox[0], this.viewbox[1] / this.orig_viewbox[1], this.viewbox[2] / this.orig_viewbox[2], this.viewbox[3] / this.orig_viewbox[3],]; } get_mouse_pos(): number[] { return this.mouse_pos; } } + +export class Mesh { + cells: number[]; + positions: number[]; + + constructor(mesh: any) { + this.cells = mesh.cells.flat(); + this.positions = mesh.positions.flat(); + } +} + +export async function url_to_mesh(url: string): Promise { + + return new Promise(function(resolve) { + loadSvg(url, function (err: any, svg: any) { + if (err) throw err; + + var svgPath = parsePath(svg); + var mesh = svgMesh3d(svgPath, { + delaunay: false, + scale: 10, + }); + + resolve(new Mesh(mesh)); + }); + }); +}