├── .editorconfig ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── code-of-conduct.md ├── dist ├── dan-shari-gl.es5.js ├── dan-shari-gl.es5.js.map ├── dan-shari-gl.umd.js ├── dan-shari-gl.umd.js.map ├── lib │ ├── camera │ │ ├── camera.js │ │ └── camera.js.map │ ├── dan-shari-gl.js │ ├── dan-shari-gl.js.map │ ├── extra │ │ ├── TexturePool.js │ │ ├── TexturePool.js.map │ │ ├── cameracontroller.js │ │ ├── cameracontroller.js.map │ │ ├── fbo.js │ │ ├── fbo.js.map │ │ ├── swapRenderer.js │ │ ├── swapRenderer.js.map │ │ ├── textLayout.js │ │ ├── textLayout.js.map │ │ ├── textRendering.js │ │ └── textRendering.js.map │ ├── interfaces │ │ ├── interface.js │ │ └── interface.js.map │ ├── math │ │ ├── math.js │ │ ├── math.js.map │ │ ├── ray.js │ │ └── ray.js.map │ └── utils │ │ ├── common │ │ ├── constants.js │ │ ├── constants.js.map │ │ ├── shaders.js │ │ └── shaders.js.map │ │ ├── functions │ │ ├── assets-functions.js │ │ ├── assets-functions.js.map │ │ ├── gl-functions.js │ │ ├── gl-functions.js.map │ │ ├── gl-textures.js │ │ └── gl-textures.js.map │ │ └── generate │ │ ├── generateGeometry.js │ │ ├── generateGeometry.js.map │ │ ├── generateSimpleGeometry.js │ │ └── generateSimpleGeometry.js.map └── types │ ├── camera │ └── camera.d.ts │ ├── dan-shari-gl.d.ts │ ├── extra │ ├── TexturePool.d.ts │ ├── cameracontroller.d.ts │ ├── fbo.d.ts │ ├── swapRenderer.d.ts │ ├── textLayout.d.ts │ └── textRendering.d.ts │ ├── interfaces │ └── interface.d.ts │ ├── math │ ├── math.d.ts │ └── ray.d.ts │ ├── src │ ├── camera │ │ └── camera.d.ts │ ├── extra │ │ ├── TexturePool.d.ts │ │ ├── cameracontroller.d.ts │ │ ├── fbo.d.ts │ │ ├── textLayout.d.ts │ │ └── textRendering.d.ts │ ├── math │ │ ├── math.d.ts │ │ └── ray.d.ts │ └── utils │ │ ├── common │ │ ├── constants.d.ts │ │ └── shaders.d.ts │ │ ├── functions │ │ ├── assets-functions.d.ts │ │ ├── gl-functions.d.ts │ │ └── gl-textures.d.ts │ │ └── generate │ │ ├── generateGeometry.d.ts │ │ └── generateSimpleGeometry.d.ts │ └── utils │ ├── common │ ├── constants.d.ts │ └── shaders.d.ts │ ├── functions │ ├── assets-functions.d.ts │ ├── gl-functions.d.ts │ └── gl-textures.d.ts │ └── generate │ ├── generateGeometry.d.ts │ └── generateSimpleGeometry.d.ts ├── package-lock.json ├── package.json ├── rollup.config.ts ├── site ├── documents │ ├── assets │ │ ├── css │ │ │ └── main.css │ │ ├── images │ │ │ ├── icons.png │ │ │ ├── icons@2x.png │ │ │ ├── widgets.png │ │ │ └── widgets@2x.png │ │ └── js │ │ │ ├── main.js │ │ │ └── search.js │ ├── classes │ │ ├── camera.html │ │ ├── cameracontroller.html │ │ ├── dampedaction.html │ │ ├── fbo.html │ │ ├── orthocamera.html │ │ ├── perspectivecamera.html │ │ ├── ray.html │ │ ├── swaprenderer.html │ │ ├── textlayout.html │ │ ├── textlines.html │ │ ├── textrendering.html │ │ └── texturepools.html │ ├── globals.html │ ├── index.html │ └── interfaces │ │ ├── box.html │ │ ├── iuniformobject.html │ │ └── vector3.html ├── examples │ ├── 00-sphere.html │ ├── 01-text.html │ ├── 02-shadow.html │ ├── 03-draco.html │ ├── 04-globe.html │ ├── 05-particles.html │ ├── 06-castMouse.html │ ├── 07-interaction.html │ ├── 08-particles.html │ ├── 09-posteffect.html │ ├── 10-fluid.html │ ├── 11-fluid.html │ ├── assets │ │ ├── draco │ │ │ └── dragon.drc │ │ ├── fonts │ │ │ ├── roboto.json │ │ │ └── roboto.png │ │ ├── images │ │ │ └── shari.jpg │ │ ├── json │ │ │ ├── 3dcoat-materialball.json │ │ │ ├── material-ball.json │ │ │ └── ne-110m.json │ │ ├── material-ball.json │ │ ├── obj │ │ │ ├── 3dcoat-materialball.obj │ │ │ └── bunny.obj │ │ └── robo-orb.json │ ├── index.html │ └── vendors │ │ ├── TweenMax.js │ │ ├── chroma.min.js │ │ ├── dat.gui.min.js │ │ ├── draco_decoder.js │ │ ├── gl-matrix.js │ │ ├── parser.js │ │ ├── perlin.js │ │ ├── simplex-noise.js │ │ └── stats.min.js ├── index.md ├── sketches │ └── index.html └── tutorials │ ├── 00-triangle.html │ └── index.html ├── src ├── camera │ └── camera.ts ├── dan-shari-gl.ts ├── extra │ ├── TexturePool.ts │ ├── cameracontroller.ts │ ├── fbo.ts │ ├── swapRenderer.ts │ ├── textLayout.ts │ └── textRendering.ts ├── interfaces │ └── interface.ts ├── math │ ├── math.ts │ └── ray.ts └── utils │ ├── common │ ├── constants.ts │ └── shaders.ts │ ├── functions │ ├── assets-functions.ts │ ├── gl-functions.ts │ └── gl-textures.ts │ └── generate │ ├── generateGeometry.ts │ └── generateSimpleGeometry.ts ├── tools ├── gh-pages-publish.ts └── semantic-release-prepare.ts ├── tsconfig.json ├── tslint.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | #root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | max_line_length = 100 10 | indent_size = 2 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .nyc_output 4 | .DS_Store 5 | *.log 6 | .vscode 7 | .idea 8 | compiled 9 | .awcache 10 | .rpt2_cache 11 | .history -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | cache: 3 | directories: 4 | - ~/.npm 5 | notifications: 6 | email: false 7 | node_js: 8 | - '10' 9 | - '11' 10 | - '8' 11 | - '6' 12 | script: 13 | - npm run test:prod && npm run build 14 | after_success: 15 | - npm run travis-deploy-once "npm run report-coverage" 16 | - if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then npm run travis-deploy-once "npm run deploy-docs"; fi 17 | - if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then npm run travis-deploy-once "npm run semantic-release"; fi 18 | branches: 19 | except: 20 | - /^v\d+\.\d+\.\d+$/ 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 kenji 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dan-shari-gl 2 | 3 | #### minimum webgl framework 4 | 5 | ### Install 6 | 7 | `npm i dan-shari-gl --save` 8 | 9 | [![NPM version][dan-shari-gl-npm-image]][dan-shari-gl-npm-url] 10 | 11 | 12 | ### API Documents 13 | 14 | [dan-shari-gl/documents/](https://kenjispecial.github.io/dan-shari-gl/site/documents/) 15 | 16 | ### Examples 17 | 18 | [dan-shari-gl/examples](https://kenjispecial.github.io/dan-shari-gl/site/examples) 19 | 20 | ### Tools 21 | 22 | - [dan-shari-gl-mesh-generator](https://github.com/kenjiSpecial/dan-shari-gl-mesh-generator) 23 | 24 | ##### this library is being developed with [alexjoverm/typescript-library-starter](https://github.com/alexjoverm/typescript-library-starter) 25 | 26 | [dan-shari-gl-npm-image]: https://img.shields.io/npm/v/dan-shari-gl.svg?style=flat-square 27 | [dan-shari-gl-npm-url]: https://www.npmjs.com/package/dan-shari-gl 28 | 29 | ### Useful Tools 30 | 31 | #### Color 32 | 33 | - [Hex to C# Colors Converter](http://kokizzu.blogspot.com/2018/11/hex-to-c-colors-converter.html) 34 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at alexjovermorales@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /dist/lib/camera/camera.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | }; 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | Object.defineProperty(exports, "__esModule", { value: true }); 16 | var gl_matrix_1 = require("gl-matrix"); 17 | var Camera = /** @class */ (function () { 18 | function Camera(type) { 19 | if (type === void 0) { type = 'camera'; } 20 | this.position = { x: 0, y: 0, z: 0 }; 21 | this.lookAtPosition = { x: 0, y: 0, z: 0 }; 22 | this.viewMatrix = gl_matrix_1.mat4.create(); 23 | this.viewMatrixInverse = gl_matrix_1.mat4.create(); 24 | this.projectionMatrix = gl_matrix_1.mat4.create(); 25 | this.projectionMatrixInverse = gl_matrix_1.mat4.create(); 26 | this.type = type; 27 | } 28 | Camera.prototype.updatePosition = function (xx, yy, zz) { 29 | if (xx === void 0) { xx = 0; } 30 | if (yy === void 0) { yy = 0; } 31 | if (zz === void 0) { zz = 0; } 32 | this.position.x = xx; 33 | this.position.y = yy; 34 | this.position.z = zz; 35 | }; 36 | Camera.prototype.updateLookAtPosition = function (xx, yy, zz) { 37 | if (xx === void 0) { xx = 0; } 38 | if (yy === void 0) { yy = 0; } 39 | if (zz === void 0) { zz = -100; } 40 | this.lookAtPosition.x = xx; 41 | this.lookAtPosition.y = yy; 42 | this.lookAtPosition.z = zz; 43 | }; 44 | Camera.prototype.updateViewMatrix = function () { 45 | gl_matrix_1.mat4.lookAt(this.viewMatrix, [this.position.x, this.position.y, this.position.z], [this.lookAtPosition.x, this.lookAtPosition.y, this.lookAtPosition.z], [0, 1, 0]); 46 | gl_matrix_1.mat4.invert(this.viewMatrixInverse, this.viewMatrix); 47 | }; 48 | return Camera; 49 | }()); 50 | exports.Camera = Camera; 51 | // --------------------- 52 | var PerspectiveCamera = /** @class */ (function (_super) { 53 | __extends(PerspectiveCamera, _super); 54 | function PerspectiveCamera(width, height, fov, near, far) { 55 | if (fov === void 0) { fov = 45; } 56 | if (near === void 0) { near = 0.1; } 57 | if (far === void 0) { far = 1000; } 58 | var _this = _super.call(this, 'perspective') || this; 59 | _this.width = width; 60 | _this.height = height; 61 | _this.fov = fov; 62 | _this.near = near; 63 | _this.far = far; 64 | _this.updatePerspective(); 65 | return _this; 66 | } 67 | PerspectiveCamera.prototype.updatePerspective = function () { 68 | gl_matrix_1.mat4.perspective(this.projectionMatrix, (this.fov / 180) * Math.PI, this.width / this.height, this.near, this.far); 69 | gl_matrix_1.mat4.invert(this.projectionMatrixInverse, this.projectionMatrix); 70 | }; 71 | PerspectiveCamera.prototype.updateSize = function (width, height) { 72 | this.width = width; 73 | this.height = height; 74 | this.updatePerspective(); 75 | }; 76 | PerspectiveCamera.prototype.updateFocus = function (near, far) { 77 | if (near) 78 | this.near = near; 79 | if (far) 80 | this.far = far; 81 | this.updatePerspective(); 82 | }; 83 | PerspectiveCamera.prototype.updatefov = function (angle) { 84 | this.fov = angle; 85 | this.updatePerspective(); 86 | }; 87 | return PerspectiveCamera; 88 | }(Camera)); 89 | exports.PerspectiveCamera = PerspectiveCamera; 90 | // --------------------- 91 | var OrthoCamera = /** @class */ (function (_super) { 92 | __extends(OrthoCamera, _super); 93 | function OrthoCamera(left, right, bottom, top, near, far) { 94 | var _this = _super.call(this, 'ortho') || this; 95 | _this.left = left; 96 | _this.right = right; 97 | _this.bottom = bottom; 98 | _this.top = top; 99 | _this.near = near; 100 | _this.far = far; 101 | _this.updatePerspective(); 102 | return _this; 103 | } 104 | OrthoCamera.prototype.updateSize = function (left, right, bottom, top) { 105 | this.left = left; 106 | this.right = right; 107 | this.bottom = bottom; 108 | this.top = top; 109 | this.updatePerspective(); 110 | }; 111 | OrthoCamera.prototype.updateFocus = function (near, far) { 112 | if (near) 113 | this.near = near; 114 | if (far) 115 | this.far = far; 116 | this.updatePerspective(); 117 | }; 118 | OrthoCamera.prototype.updatePerspective = function () { 119 | gl_matrix_1.mat4.ortho(this.projectionMatrix, this.left, this.right, this.bottom, this.top, this.near, this.far); 120 | gl_matrix_1.mat4.invert(this.projectionMatrixInverse, this.projectionMatrix); 121 | }; 122 | return OrthoCamera; 123 | }(Camera)); 124 | exports.OrthoCamera = OrthoCamera; 125 | //# sourceMappingURL=camera.js.map -------------------------------------------------------------------------------- /dist/lib/camera/camera.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"camera.js","sourceRoot":"","sources":["../../../src/camera/camera.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAiC;AAGjC;IASC,gBA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G,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAEf,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC1B,CAAC;IAEM,iCAAW,GAAlB,UAAmB,IAAY,EAAE,GAAW;QAC3C,IAAI,IAAI;YAAE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAC3B,IAAI,GAAG;YAAE,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAExB,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC1B,CAAC;IAEM,uCAAiB,GAAxB;QACC,gBAAI,CAAC,KAAK,CACT,IAAI,CAAC,gBAAgB,EACrB,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,GAAG,CACR,CAAC;QAEF,gBAAI,CAAC,MAAM,CAAC,IAAI,CAAC,uBAAuB,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAClE,CAAC;IACF,kBAAC;AAAD,CAAC,AAzDD,CAAiC,MAAM,GAyDtC;AAzDY,kCAAW"} -------------------------------------------------------------------------------- /dist/lib/dan-shari-gl.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function __export(m) { 3 | for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; 4 | } 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | __export(require("./utils/functions/gl-functions")); 7 | __export(require("./utils/functions/gl-textures")); 8 | __export(require("./utils/functions/assets-functions")); 9 | __export(require("./utils/generate/generateGeometry")); 10 | __export(require("./utils/generate/generateSimpleGeometry")); 11 | __export(require("./utils/common/constants")); 12 | __export(require("./utils/common/shaders")); 13 | __export(require("./math/math")); 14 | __export(require("./math/ray")); 15 | __export(require("./camera/camera")); 16 | // sub compoents 17 | __export(require("./extra/cameracontroller")); 18 | __export(require("./extra/textLayout")); 19 | __export(require("./extra/textRendering")); 20 | __export(require("./extra/TexturePool")); 21 | __export(require("./extra/swapRenderer")); 22 | __export(require("./extra/fbo")); 23 | //# sourceMappingURL=dan-shari-gl.js.map -------------------------------------------------------------------------------- /dist/lib/dan-shari-gl.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"dan-shari-gl.js","sourceRoot":"","sources":["../../src/dan-shari-gl.ts"],"names":[],"mappings":";;;;;AAAA,oDAA+C;AAC/C,mDAA8C;AAC9C,wDAAmD;AAEnD,uDAAkD;AAClD,6DAAwD;AAExD,8CAAyC;AACzC,4CAAuC;AAEvC,iCAA4B;AAC5B,gCAA2B;AAE3B,qCAAgC;AAEhC,gBAAgB;AAChB,8CAAyC;AACzC,wCAAmC;AACnC,2CAAsC;AACtC,yCAAoC;AACpC,0CAAqC;AACrC,iCAA4B"} -------------------------------------------------------------------------------- /dist/lib/extra/TexturePool.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var gl_textures_1 = require("../utils/functions/gl-textures"); 4 | var constants_1 = require("../utils/common/constants"); 5 | var TexturePools = /** @class */ (function () { 6 | function TexturePools() { 7 | this.textures = {}; 8 | } 9 | TexturePools.GET_INSTANCE = function () { 10 | if (!TexturePools.instance) { 11 | TexturePools.instance = new TexturePools(); 12 | // ... any one time initialization goes here ... 13 | } 14 | return TexturePools.instance; 15 | }; 16 | TexturePools.GET_TEXTURE = function (name) { 17 | return TexturePools.instance.textures[name]; 18 | }; 19 | TexturePools.prototype.setGL = function (gl) { 20 | this.gl = gl; 21 | this.setImage('empty', this.createEmptyCanvas()); 22 | }; 23 | TexturePools.prototype.setImage = function (name, element) { 24 | var texture = gl_textures_1.createImageTexture(this.gl, element); 25 | this.textures[name] = texture; 26 | }; 27 | TexturePools.prototype.createEmptyCanvas = function () { 28 | var canvas = document.createElement('canvas'); 29 | canvas.width = constants_1.EMPTY_CANVAS_SIZE; 30 | canvas.height = constants_1.EMPTY_CANVAS_SIZE; 31 | var ctx = canvas.getContext('2d'); 32 | ctx.fillStyle = '#ffffff'; 33 | ctx.fillRect(0, 0, constants_1.EMPTY_CANVAS_SIZE, constants_1.EMPTY_CANVAS_SIZE); 34 | ctx.fillStyle = constants_1.EMPTY_CANVAS_COLOR; 35 | var cnt = 0; 36 | var unitWidthSize = constants_1.EMPTY_CANVAS_SIZE / constants_1.COLOR_REPEAT; 37 | for (var xx = 0; xx < constants_1.COLOR_REPEAT; xx = xx + 1) { 38 | for (var yy = 0; yy < constants_1.COLOR_REPEAT; yy = yy + 1) { 39 | if (cnt % 2 === 0) { 40 | var xpos = xx * unitWidthSize; 41 | var ypos = yy * unitWidthSize; 42 | ctx.fillRect(xpos, ypos, unitWidthSize, unitWidthSize); 43 | } 44 | cnt = cnt + 1; 45 | } 46 | } 47 | return canvas; 48 | }; 49 | return TexturePools; 50 | }()); 51 | exports.TexturePools = TexturePools; 52 | //# sourceMappingURL=TexturePool.js.map -------------------------------------------------------------------------------- /dist/lib/extra/TexturePool.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"TexturePool.js","sourceRoot":"","sources":["../../../src/extra/TexturePool.ts"],"names":[],"mappings":";;AAAA,8DAAoE;AACpE,uDAAgG;AAEhG;IAIC;QAFO,aAAQ,GAAoC,EAAE,CAAC;IAE/B,CAAC;IAEV,yBAAY,GAA1B;QACC,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;YAC3B,YAAY,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;YAC3C,gDAAgD;SAChD;QAED,OAAO,YAAY,CAAC,QAAQ,CAAC;IAC9B,CAAC;IAEa,wBAAW,GAAzB,UAA0B,IAAY;QACrC,OAAO,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAEM,4BAAK,GAAZ,UAAa,EAAyB;QACrC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,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,CAAC;iBACvD;gBACD,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;aACd;SACD;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IACF,mBAAC;AAAD,CAAC,AApDD,IAoDC;AApDY,oCAAY"} -------------------------------------------------------------------------------- /dist/lib/extra/fbo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var gl_textures_1 = require("../utils/functions/gl-textures"); 4 | var FBO = /** @class */ (function () { 5 | function FBO(gl, width, height, texture, isDepthNeed) { 6 | if (isDepthNeed === void 0) { isDepthNeed = false; } 7 | this.gl = gl; 8 | this.width = width; 9 | this.height = height; 10 | this.texture = 11 | texture === undefined || texture === null 12 | ? gl_textures_1.createEmptyTexture(this.gl, width, height) 13 | : texture; 14 | this.buffer = this.gl.createFramebuffer(); 15 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.buffer); 16 | this.bindTex(); 17 | if (isDepthNeed) { 18 | this.createDepth(); 19 | this.updateDepth(); 20 | } 21 | } 22 | FBO.prototype.bindTex = function () { 23 | this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER, this.gl.COLOR_ATTACHMENT0, this.gl.TEXTURE_2D, this.texture, 0); 24 | }; 25 | FBO.prototype.createDepth = function () { 26 | this.depth = this.gl.createRenderbuffer(); 27 | }; 28 | FBO.prototype.updateDepth = function () { 29 | this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, this.depth); 30 | this.gl.renderbufferStorage(this.gl.RENDERBUFFER, this.gl.DEPTH_COMPONENT16, this.width, this.height); 31 | this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER, this.gl.DEPTH_ATTACHMENT, this.gl.RENDERBUFFER, this.depth); 32 | }; 33 | FBO.prototype.bind = function () { 34 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.buffer); 35 | }; 36 | FBO.prototype.unbind = function () { 37 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null); 38 | }; 39 | FBO.prototype.resize = function (width, height, texture) { 40 | this.width = width; 41 | this.height = height; 42 | this.bind(); 43 | gl_textures_1.updateEmptyImageTexture(this.gl, this.texture, width, height); 44 | this.bindTex(); 45 | this.updateDepth(); 46 | }; 47 | FBO.prototype.getTexture = function () { 48 | return this.texture; 49 | }; 50 | return FBO; 51 | }()); 52 | exports.FBO = FBO; 53 | //# sourceMappingURL=fbo.js.map -------------------------------------------------------------------------------- /dist/lib/extra/fbo.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"fbo.js","sourceRoot":"","sources":["../../../src/extra/fbo.ts"],"names":[],"mappings":";;AAAA,8DAIwC;AACxC;IAQC,aACC,EAAyB,EACzB,KAAa,EACb,MAAc,EACd,OAA6B,EAC7B,WAA4B;QAA5B,4BAAA,EAAA,mBAA4B;QAE5B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO;YACX,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI;gBACxC,CAAC,CAAC,gCAAkB,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC;gBAC5C,CAAC,CAAC,OAAO,CAAC;QAEZ,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC;QAC1C,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1D,IAAI,CAAC,OAAO,EAAE,CAAC;QAEf,IAAI,WAAW,EAAE;YAChB,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,IAAI,CAAC,WAAW,EAAE,CAAC;SACnB;IACF,CAAC;IAEO,qBAAO,GAAf;QACC,IAAI,CAAC,EAAE,CAAC,oBAAoB,CAC3B,IAAI,CAAC,EAAE,CA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,EAAE,IAAI,CAAC,OAAuB,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAC9E,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,CAAC,WAAW,EAAE,CAAC;IACpB,CAAC;IAEM,wBAAU,GAAjB;QACC,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IACF,UAAC;AAAD,CAAC,AArFD,IAqFC;AArFY,kBAAG"} -------------------------------------------------------------------------------- /dist/lib/extra/swapRenderer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var gl_functions_1 = require("../utils/functions/gl-functions"); 4 | var gl_textures_1 = require("../utils/functions/gl-textures"); 5 | var constants_1 = require("../utils/common/constants"); 6 | var generateSimpleGeometry_1 = require("../utils/generate/generateSimpleGeometry"); 7 | var SwapRenderer = /** @class */ (function () { 8 | function SwapRenderer(gl) { 9 | this.textures = {}; 10 | this.framebuffers = {}; 11 | this.programs = {}; 12 | this.positionVbos = {}; 13 | this.gl = gl; 14 | } 15 | SwapRenderer.prototype.setSize = function (width, height) { 16 | this.gl.viewport(0, 0, width, height); 17 | }; 18 | SwapRenderer.prototype.createProgram = function (programName, vertexShader, fragmentShader) { 19 | var program = gl_functions_1.createProgram(this.gl, vertexShader, fragmentShader); 20 | this.gl.useProgram(program); 21 | this.programs[programName] = { 22 | id: program, 23 | uniforms: {} 24 | }; 25 | }; 26 | SwapRenderer.prototype.initTexture = function (name, width, height, type) { 27 | var texture = gl_textures_1.createEmptyTexture(this.gl, width, height, constants_1.RGB, constants_1.LINEAR, constants_1.LINEAR, constants_1.CLAMP_TO_EDGE, constants_1.CLAMP_TO_EDGE, type); 28 | this.textures[name] = texture; 29 | }; 30 | SwapRenderer.prototype.initTextureWithImage = function (name, type, image) { 31 | var texture = gl_textures_1.createCustomTypeImageTexture(this.gl, image, this.gl.RGB, type, true); 32 | this.textures[name] = texture; 33 | }; 34 | SwapRenderer.prototype.initFramebufferForTexture = function (textureName) { 35 | var texture = this.textures[textureName]; 36 | var framebuffer = this.gl.createFramebuffer(); 37 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, framebuffer); 38 | this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER, this.gl.COLOR_ATTACHMENT0, this.gl.TEXTURE_2D, texture, 0); 39 | this.framebuffers[textureName] = framebuffer; 40 | }; 41 | SwapRenderer.prototype.initDepthTexture = function (width, height) { 42 | var depth = this.gl.createRenderbuffer(); 43 | this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, depth); 44 | this.gl.renderbufferStorage(this.gl.RENDERBUFFER, this.gl.DEPTH_COMPONENT16, width, height); 45 | }; 46 | SwapRenderer.prototype.setProgram = function (programName) { 47 | this.gl.useProgram(this.programs[programName].id); 48 | }; 49 | SwapRenderer.prototype.use = function (programName) { 50 | this.gl.useProgram(this.programs[programName].id); 51 | }; 52 | SwapRenderer.prototype.getProgram = function (programName) { 53 | return this.programs[programName].id; 54 | }; 55 | SwapRenderer.prototype.createPositionVBO = function (name, scaleX, scaleY) { 56 | if (scaleX === void 0) { scaleX = 1; } 57 | if (scaleY === void 0) { scaleY = 1; } 58 | var buffer = this.gl.createBuffer(); 59 | this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer); 60 | this.gl.bufferData(this.gl.ARRAY_BUFFER, generateSimpleGeometry_1.createSuperSimpleplane(scaleX, scaleY), this.gl.STATIC_DRAW); 61 | this.positionVbos[name] = buffer; 62 | }; 63 | SwapRenderer.prototype.usePositionVBO = function () { 64 | var location = 0; 65 | this.gl.enableVertexAttribArray(location); 66 | this.gl.vertexAttribPointer(location, 2, this.gl.FLOAT, false, 0, 0); 67 | }; 68 | SwapRenderer.prototype.updateVBO = function (name) { 69 | var buffer = this.positionVbos[name]; 70 | this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer); 71 | this.usePositionVBO(); 72 | }; 73 | SwapRenderer.prototype.run = function (programName, inputNameArr, outputName) { 74 | this.use(programName); 75 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.framebuffers[outputName]); 76 | for (var ii = 0; ii < inputNameArr.length; ii = ii + 1) { 77 | var inputName = inputNameArr[ii]; 78 | this.gl.activeTexture(this.gl.TEXTURE0 + ii); 79 | this.gl.bindTexture(this.gl.TEXTURE_2D, this.textures[inputName]); 80 | } 81 | this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, 4); 82 | }; 83 | SwapRenderer.prototype.swapTextures = function (texture1Name, texture2Name) { 84 | var tempTex = this.textures[texture1Name]; 85 | this.textures[texture1Name] = this.textures[texture2Name]; 86 | this.textures[texture2Name] = tempTex; 87 | var tempFBO = this.framebuffers[texture1Name]; 88 | this.framebuffers[texture1Name] = this.framebuffers[texture2Name]; 89 | this.framebuffers[texture2Name] = tempFBO; 90 | }; 91 | SwapRenderer.prototype.setUniform = function (programName, name, val, type) { 92 | var uniforms = this.programs[programName].uniforms; 93 | // console.log(this.programs[programName].uniforms); 94 | var location = uniforms[name]; 95 | if (!location) { 96 | location = this.gl.getUniformLocation(this.programs[programName].id, name); 97 | uniforms[name] = location; 98 | if (!location) { 99 | console.warn({ programName: programName, name: name }); 100 | } 101 | } 102 | if (type === constants_1.UNIFORM_1F) 103 | this.gl.uniform1f(location, val); 104 | else if (type === constants_1.UNIFORM_2F) { 105 | val = val; 106 | this.gl.uniform2f(location, val[0], val[1]); 107 | } 108 | else if (type === constants_1.UNIFORM_3F) { 109 | val = val; 110 | this.gl.uniform3f(location, val[0], val[1], val[2]); 111 | } 112 | else if (type === constants_1.UNIFORM_1I) { 113 | this.gl.uniform1i(location, val); 114 | } 115 | else if (type === constants_1.UNIFORM_MAT_4F) { 116 | this.gl.uniformMatrix4fv(location, false, val); 117 | } 118 | else { 119 | console.warn('no uniform for type ' + type); 120 | } 121 | }; 122 | SwapRenderer.prototype.reset = function () { 123 | this.programs = {}; 124 | this.framebuffers = {}; 125 | this.textures = {}; 126 | this.positionVbos = {}; 127 | }; 128 | return SwapRenderer; 129 | }()); 130 | exports.SwapRenderer = SwapRenderer; 131 | //# sourceMappingURL=swapRenderer.js.map -------------------------------------------------------------------------------- /dist/lib/extra/swapRenderer.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"swapRenderer.js","sourceRoot":"","sources":["../../../src/extra/swapRenderer.ts"],"names":[],"mappings":";;AAAA,gEAAgE;AAEhE,8DAIwC;AACxC,uDASmC;AACnC,mFAAkF;AAElF;IAsBC,sBAAY,EAAyB;QAnB7B,aAAQ,GAEZ,EAAE,CAAC;QAEC,iBAAY,GAEhB,EAAE,CAAC;QAEC,aAAQ,GAKZ,EAAE,CAAC;QAEC,iBAAY,GAEhB,EAAE,CAAC;QAGN,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACd,CAAC;IAEM,8BAAO,GAAd,UAAe,KAAa,EAAE,MAAc;QAC3C,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAEM,oCAAa,GAApB,UAAqB,WAAmB,EAAE,YAAoB,EAAE,cAAsB;QACrF,IAAM,OAAO,GAAG,4BAAa,CAAC,IAAI,CAAC,EAAE,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;QAErE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAE5B,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG;YAC5B,EAAE,EAAE,OAAO;YACX,QAAQ,EAAE,EAAE;SACZ,CAAC;IACH,CAAC;IAEM,kCAAW,GAAlB,UAAmB,IAAY,EAAE,KAAa,EAAE,MAAc,EAAE,IAAY;QAC3E,IAAM,OAAO,GAAG,gCAAkB,CACjC,IAAI,CAAC,EAAE,EACP,KAAK,EACL,MAAM,EACN,eAAG,EACH,kBAAM,EACN,kBAAM,EACN,yBAAa,EACb,yBAAa,EACb,IAAI,CACJ,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,IAAI,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AAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SACpD;aAAM,IAAI,IAAI,KAAK,sBAAU,EAAE;YAC/B,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAa,CAAC,CAAC;SAC3C;aAAM,IAAI,IAAI,KAAK,0BAAc,EAAE;YACnC,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAkB,CAAC,CAAC;SAC9D;aAAM;YACN,OAAO,CAAC,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;SAC5C;IACF,CAAC;IAEM,4BAAK,GAAZ;QACC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACxB,CAAC;IACF,mBAAC;AAAD,CAAC,AAtLD,IAsLC;AAtLY,oCAAY"} -------------------------------------------------------------------------------- /dist/lib/extra/textRendering.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var TextRendering = /** @class */ (function () { 4 | function TextRendering(gl, textLayout, bitmapImage) { 5 | var vertices = []; 6 | var uvs = []; 7 | var indices = []; 8 | var imageWidth = bitmapImage.width; 9 | var imageHeight = bitmapImage.height; 10 | textLayout.glyphs.forEach(function (glyph, index) { 11 | var bitmap = glyph.data; 12 | var _a = glyph.position, xx = _a[0], yy = _a[1]; 13 | var startX = xx + bitmap.xoffset - textLayout.width / 2; 14 | var endX = startX + bitmap.width; 15 | var startY = -1 * (yy + bitmap.yoffset + textLayout.height / 2); 16 | var endY = startY - bitmap.height; 17 | var startUVX = bitmap.x / imageWidth; 18 | var endUVX = startUVX + bitmap.width / imageWidth; 19 | var startUVY = 1 - bitmap.y / imageHeight; 20 | var endUVY = 1 - (bitmap.y + bitmap.height) / imageHeight; 21 | vertices.push(startX, startY, endX, startY, endX, endY, startX, endY); 22 | uvs.push(startUVX, startUVY, endUVX, startUVY, endUVX, endUVY, startUVX, endUVY); 23 | var lastIndex = 4 * index; 24 | indices.push(0 + lastIndex, 2 + lastIndex, 1 + lastIndex, 0 + lastIndex, 3 + lastIndex, 2 + lastIndex); 25 | }); 26 | this.vertices = new Float32Array(vertices); 27 | this.uvs = new Float32Array(uvs); 28 | this.indices = new Uint16Array(indices); 29 | } 30 | return TextRendering; 31 | }()); 32 | exports.TextRendering = TextRendering; 33 | //# sourceMappingURL=textRendering.js.map -------------------------------------------------------------------------------- /dist/lib/extra/textRendering.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"textRendering.js","sourceRoot":"","sources":["../../../src/extra/textRendering.ts"],"names":[],"mappings":";;AAAA;IAIC,uBAAY,EAAyB,EAAE,UAAe,EAAE,WAAgB;QACvE,IAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,IAAM,GAAG,GAAa,EAAE,CAAC;QACzB,IAAM,OAAO,GAAa,EAAE,CAAC;QAE7B,IAAI,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC;QACnC,IAAI,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC;QAErC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,UAAC,KAAU,EAAE,KAAU;YAChD,IAAI,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC;YACpB,IAAA,mBAAyB,EAAxB,UAAE,EAAE,UAAoB,CAAC;YAE9B,IAAI,MAAM,GAAG,EAAE,GAAG,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC;YACxD,IAAI,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;YACjC,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,OAAO,GAAG,UAAU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interface.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=interface.js.map -------------------------------------------------------------------------------- /dist/lib/interfaces/interface.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/interfaces/interface.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/lib/math/math.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | function clamp(value, min, max) { 4 | return Math.min(Math.max(value, min), max); 5 | } 6 | exports.clamp = clamp; 7 | function range(min, max) { 8 | return (max - min) * Math.random() + min; 9 | } 10 | exports.range = range; 11 | // https://stackoverflow.com/questions/32861804/how-to-calculate-the-centre-point-of-a-circle-given-three-points 12 | function calculateCircleCenter(A, B, C) { 13 | var yDeltaA = B.y - A.y; 14 | var xDeltaA = B.x - A.x; 15 | var yDeltaB = C.y - B.y; 16 | var xDeltaB = C.x - B.x; 17 | var center = { x: 0, y: 0, z: 0 }; 18 | var aSlope = yDeltaA / xDeltaA; 19 | var bSlope = yDeltaB / xDeltaB; 20 | center.x = 21 | (aSlope * bSlope * (A.y - C.y) + bSlope * (A.x + B.x) - aSlope * (B.x + C.x)) / 22 | (2 * (bSlope - aSlope)); 23 | center.y = (-1 * (center.x - (A.x + B.x) / 2)) / aSlope + (A.y + B.y) / 2; 24 | return center; 25 | } 26 | exports.calculateCircleCenter = calculateCircleCenter; 27 | function mix(x, y, a) { 28 | return x * (1 - a) + y * a; 29 | } 30 | exports.mix = mix; 31 | function degToRad(value) { 32 | // Math.PI / 180 = 0.017453292519943295 33 | return value * 0.017453292519943295; 34 | } 35 | exports.degToRad = degToRad; 36 | function radToDeg(value) { 37 | // 180 / Math.PI = 57.29577951308232 38 | return 57.29577951308232 * value; 39 | } 40 | exports.radToDeg = radToDeg; 41 | //# sourceMappingURL=math.js.map -------------------------------------------------------------------------------- /dist/lib/math/math.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"math.js","sourceRoot":"","sources":["../../../src/math/math.ts"],"names":[],"mappings":";;AACA,SAAgB,KAAK,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IAC5D,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC;AAFD,sBAEC;AAED,SAAgB,KAAK,CAAC,GAAW,EAAE,GAAW;IAC7C,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;AAC1C,CAAC;AAFD,sBAEC;AAED,gHAAgH;AAChH,SAAgB,qBAAqB,CAAC,CAAU,EAAE,CAAU,EAAE,CAAU;IACvE,IAAM,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAM,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAM,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAM,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAE1B,IAAI,MAAM,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAElC,IAAM,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IACjC,IAAM,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IAEjC,MAAM,CAAC,CAAC;QACP,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7E,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;IACzB,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAE1E,OAAO,MAAM,CAAC;AACf,CAAC;AAjBD,sDAiBC;AAED,SAAgB,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;IAClD,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAFD,kBAEC;AAED,SAAgB,QAAQ,CAAC,KAAa;IACrC,uCAAuC;IACvC,OAAO,KAAK,GAAG,oBAAoB,CAAC;AACrC,CAAC;AAHD,4BAGC;AAED,SAAgB,QAAQ,CAAC,KAAa;IACrC,oCAAoC;IACpC,OAAO,iBAAiB,GAAG,KAAK,CAAC;AAClC,CAAC;AAHD,4BAGC"} -------------------------------------------------------------------------------- /dist/lib/math/ray.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var gl_matrix_1 = require("gl-matrix"); 4 | var Ray = /** @class */ (function () { 5 | function Ray() { 6 | this.isPrev = false; 7 | this.orig = gl_matrix_1.vec3.create(); 8 | this.dir = gl_matrix_1.vec3.create(); 9 | this.worldMatrix3Inv = gl_matrix_1.mat3.create(); 10 | } 11 | Ray.prototype.intersect = function (box) { 12 | var min = box.min, max = box.max; 13 | var tmin = (min.x - this.orig[0]) / this.dir[0]; 14 | var tmax = (max.x - this.orig[0]) / this.dir[0]; 15 | var minY = tmin * this.dir[1] + this.orig[1]; 16 | var maxY = tmax * this.dir[1] + this.orig[1]; 17 | if (minY > maxY) { 18 | var _a = this.swap(minY, maxY), minVal = _a.minVal, maxVal = _a.maxVal; 19 | minY = minVal; 20 | maxY = maxVal; 21 | } 22 | if (minY > max.y || maxY < min.y) { 23 | return false; 24 | } 25 | var minZ = tmin * this.dir[2] + this.orig[2]; 26 | var maxZ = tmax * this.dir[2] + this.orig[2]; 27 | if (minZ > maxZ) { 28 | var _b = this.swap(minZ, maxZ), minVal = _b.minVal, maxVal = _b.maxVal; 29 | minZ = minVal; 30 | maxZ = maxVal; 31 | } 32 | if (minZ > max.z || maxZ < min.z) { 33 | return false; 34 | } 35 | this.isPrev = true; 36 | return { tmin: tmin, tmax: tmax }; 37 | }; 38 | Ray.prototype.rayCast = function (faces, worldMatrixInv) { 39 | var transDir = gl_matrix_1.vec3.create(); 40 | var transOrig = gl_matrix_1.vec3.create(); 41 | gl_matrix_1.mat3.fromMat4(this.worldMatrix3Inv, worldMatrixInv); 42 | gl_matrix_1.vec3.transformMat3(transDir, this.dir, this.worldMatrix3Inv); 43 | gl_matrix_1.vec3.normalize(transDir, transDir); 44 | gl_matrix_1.vec3.transformMat4(transOrig, this.orig, worldMatrixInv); 45 | return this.intersectFaces(faces, transDir, transOrig); 46 | }; 47 | Ray.prototype.intersectFaces = function (faces, dir, orig) { 48 | var intersectFace; 49 | for (var ii = 0; ii < faces.length; ii++) { 50 | var pts = faces[ii]; 51 | var intersect = this.intersectPts(pts[0], pts[1], pts[2], dir, orig); 52 | if (intersect) { 53 | if (!intersectFace || intersectFace.t > intersect.t) 54 | intersectFace = intersect; 55 | } 56 | } 57 | return intersectFace; 58 | }; 59 | // https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/ray-triangle-intersection-geometric-solution 60 | // https://stackoverflow.com/questions/42740765/intersection-between-line-and-triangle-in-3d 61 | Ray.prototype.intersectPts = function (pt0, pt1, pt2, dir, orig) { 62 | var dir0Vec = gl_matrix_1.vec3.create(); 63 | var dir1Vec = gl_matrix_1.vec3.create(); 64 | var nVec = gl_matrix_1.vec3.create(); 65 | gl_matrix_1.vec3.subtract(dir0Vec, pt1, pt0); 66 | gl_matrix_1.vec3.subtract(dir1Vec, pt2, pt0); 67 | gl_matrix_1.vec3.cross(nVec, dir0Vec, dir1Vec); 68 | var D = -this.dot(nVec, pt0); 69 | if (Math.abs(this.dot(dir, nVec)) < Number.EPSILON) 70 | return false; 71 | var t = -(this.dot(nVec, orig) + D) / this.dot(nVec, dir); 72 | var intersectPt = [dir[0] * t + orig[0], dir[1] * t + orig[1], dir[2] * t + orig[2]]; 73 | var dir0 = [pt1[0] - pt0[0], pt1[1] - pt0[1], pt1[2] - pt0[2]]; 74 | var intersectPt0 = [ 75 | intersectPt[0] - pt0[0], 76 | intersectPt[1] - pt0[1], 77 | intersectPt[2] - pt0[2] 78 | ]; 79 | var dotProduct0Vec = gl_matrix_1.vec3.create(); 80 | gl_matrix_1.vec3.cross(dotProduct0Vec, dir0, intersectPt0); 81 | var judge0 = this.dot(dotProduct0Vec, nVec); 82 | if (judge0 < 0) 83 | return false; 84 | var dir1 = [pt2[0] - pt1[0], pt2[1] - pt1[1], pt2[2] - pt1[2]]; 85 | var intersectPt1 = [ 86 | intersectPt[0] - pt1[0], 87 | intersectPt[1] - pt1[1], 88 | intersectPt[2] - pt1[2] 89 | ]; 90 | var dotProduct1Vec = gl_matrix_1.vec3.create(); 91 | gl_matrix_1.vec3.cross(dotProduct1Vec, dir1, intersectPt1); 92 | var judge1 = this.dot(dotProduct1Vec, nVec); 93 | if (judge1 < 0) 94 | return false; 95 | var dir2 = [pt0[0] - pt2[0], pt0[1] - pt2[1], pt0[2] - pt2[2]]; 96 | var intersectPt2 = [ 97 | intersectPt[0] - pt2[0], 98 | intersectPt[1] - pt2[1], 99 | intersectPt[2] - pt2[2] 100 | ]; 101 | var dotProduct2Vec = gl_matrix_1.vec3.create(); 102 | gl_matrix_1.vec3.cross(dotProduct2Vec, dir2, intersectPt2); 103 | var judge2 = this.dot(dotProduct2Vec, nVec); 104 | if (judge2 < 0) 105 | return false; 106 | return { t: t, pt: intersectPt }; 107 | }; 108 | Ray.prototype.calcDirection = function (startPt, endPt) { 109 | var dir = gl_matrix_1.vec3.create(); 110 | gl_matrix_1.vec3.subtract(dir, endPt, startPt); 111 | gl_matrix_1.vec3.normalize(dir, dir); 112 | this.dir = dir; 113 | this.orig = startPt; 114 | }; 115 | Ray.prototype.swap = function (valA, valB) { 116 | var tempVal = valA; 117 | valA = valB; 118 | valB = tempVal; 119 | return { minVal: valA, maxVal: valB }; 120 | }; 121 | Ray.prototype.dot = function (a, b) { 122 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; 123 | }; 124 | return Ray; 125 | }()); 126 | exports.Ray = Ray; 127 | //# sourceMappingURL=ray.js.map -------------------------------------------------------------------------------- /dist/lib/math/ray.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"ray.js","sourceRoot":"","sources":["../../../src/math/ray.ts"],"names":[],"mappings":";;AAAA,uCAA6C;AAG7C;IAAA;QACS,WAAM,GAAY,KAAK,CAAC;QACxB,SAAI,GAAS,gBAAI,CAAC,MAAM,EAAE,CAAC;QAC3B,QAAG,GAAS,gBAAI,CAAC,MAAM,EAAE,CAAC;QAC1B,oBAAe,GAAS,gBAAI,CAAC,MAAM,EAAE,CAAC;IAwI/C,CAAC;IAtIA,uBAAS,GAAT,UAAU,GAAQ;QACX,IAAA,aAAG,EAAE,aAAG,CAAS;QAEvB,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChD,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAEh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iBAAG,GAAH,UAAI,CAAO,EAAE,CAAO;QACnB,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC;IACF,UAAC;AAAD,CAAC,AA5ID,IA4IC;AA5IY,kBAAG"} -------------------------------------------------------------------------------- /dist/lib/utils/common/constants.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.FLOAT = 0x1406; 4 | exports.RGB = 0x1907; 5 | // variables relating to textures 6 | exports.NEAREST = 0x2600; 7 | exports.LINEAR = 0x2601; 8 | exports.NEAREST_MIPMAP_NEAREST = 0x2700; 9 | exports.LINEAR_MIPMAP_NEAREST = 0x2701; 10 | exports.NEAREST_MIPMAP_LINEAR = 0x2702; 11 | exports.LINEAR_MIPMAP_LINEAR = 0x2703; 12 | exports.CLAMP_TO_EDGE = 0x812f; 13 | exports.REPEAT = 0x2901; 14 | // Framebuffers and renderbuffers 15 | // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants#Framebuffers_and_renderbuffers 16 | exports.DEPTH_COMPONENT16 = 0x81a5; 17 | // Data types 18 | // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants#Data_types 19 | exports.UNSIGNED_BYTE = 0x1401; 20 | exports.EMPTY_CANVAS_SIZE = 16; 21 | exports.EMPTY_CANVAS_COLOR = '#ff0000'; 22 | exports.COLOR_REPEAT = 4; 23 | exports.UNIFORM_1F = '1f'; 24 | exports.UNIFORM_1I = '1i'; 25 | exports.UNIFORM_2F = '2f'; 26 | exports.UNIFORM_3F = '3f'; 27 | exports.UNIFORM_MAT_4F = 'mat4'; 28 | //# sourceMappingURL=constants.js.map -------------------------------------------------------------------------------- /dist/lib/utils/common/constants.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/utils/common/constants.ts"],"names":[],"mappings":";;AAAa,QAAA,KAAK,GAAW,MAAM,CAAC;AAEvB,QAAA,GAAG,GAAW,MAAM,CAAC;AAElC,iCAAiC;AACpB,QAAA,OAAO,GAAW,MAAM,CAAC;AACzB,QAAA,MAAM,GAAW,MAAM,CAAC;AACxB,QAAA,sBAAsB,GAAW,MAAM,CAAC;AACxC,QAAA,qBAAqB,GAAW,MAAM,CAAC;AACvC,QAAA,qBAAqB,GAAW,MAAM,CAAC;AACvC,QAAA,oBAAoB,GAAW,MAAM,CAAC;AACtC,QAAA,aAAa,GAAW,MAAM,CAAC;AAC/B,QAAA,MAAM,GAAW,MAAM,CAAC;AAErC,iCAAiC;AACjC,sGAAsG;AAEzF,QAAA,iBAAiB,GAAW,MAAM,CAAC;AAEhD,aAAa;AACb,kFAAkF;AAErE,QAAA,aAAa,GAAW,MAAM,CAAC;AAE/B,QAAA,iBAAiB,GAAG,EAAE,CAAC;AACvB,QAAA,kBAAkB,GAAG,SAAS,CAAC;AAC/B,QAAA,YAAY,GAAG,CAAC,CAAC;AAEjB,QAAA,UAAU,GAAG,IAAI,CAAC;AAClB,QAAA,UAAU,GAAG,IAAI,CAAC;AAClB,QAAA,UAAU,GAAG,IAAI,CAAC;AAClB,QAAA,UAAU,GAAG,IAAI,CAAC;AAClB,QAAA,cAAc,GAAG,MAAM,CAAC"} -------------------------------------------------------------------------------- /dist/lib/utils/common/shaders.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.fullscreenVertShader = "\nprecision highp float;\n\nattribute vec3 position;\n\nuniform vec2 px;\n\nvarying vec2 vUv;\n\nvoid main(){\n vUv = vec2(0.5)+(position.xy)*0.5;\n gl_Position = vec4(position, 1.0);\n}\n"; 4 | exports.fillFragShader = "\nprecision highp float;\n\nvarying vec2 vUv;\n\nvoid main(){\n gl_FragColor = vec4(vUv, 0.0, 1.0);\n}\n"; 5 | exports.texFragShader = "\nprecision highp float;\n\nuniform sampler2D uTexture;\n\nvarying vec2 vUv;\n\nvoid main(){\n vec4 texColor = texture2D(uTexture, vUv);\n gl_FragColor = texColor;\n}\n"; 6 | //# sourceMappingURL=shaders.js.map -------------------------------------------------------------------------------- /dist/lib/utils/common/shaders.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"shaders.js","sourceRoot":"","sources":["../../../../src/utils/common/shaders.ts"],"names":[],"mappings":";;AAAa,QAAA,oBAAoB,GAAG,oMAanC,CAAC;AAEW,QAAA,cAAc,GAAG,6GAQ7B,CAAC;AAEW,QAAA,aAAa,GAAG,gLAW5B,CAAC"} -------------------------------------------------------------------------------- /dist/lib/utils/functions/assets-functions.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | /** 4 | * load json with ajax 5 | * 6 | * @param url url to load json file 7 | */ 8 | function getAjaxJson(url, callback) { 9 | var xhr = new XMLHttpRequest(); 10 | xhr.open('GET', url, true); 11 | xhr.onreadystatechange = function () { 12 | if (xhr.readyState === 4) { 13 | if (xhr.status === 200) { 14 | var resp = xhr.responseText; 15 | var respJson = JSON.parse(resp); 16 | callback(respJson); 17 | // resolve(respJson); 18 | } 19 | else { 20 | // reject(xhr.status); 21 | } 22 | } 23 | else { 24 | // reject(xhr.status); 25 | } 26 | }; 27 | xhr.send(); 28 | } 29 | exports.getAjaxJson = getAjaxJson; 30 | /** 31 | * 32 | * @param imageUrl 33 | */ 34 | function getImage(imageUrl, callback) { 35 | var image = new Image(); 36 | image.onload = function () { 37 | callback(image); 38 | }; 39 | image.onerror = function () { 40 | console.warn("image(" + imageUrl + ") load err"); 41 | }; 42 | image.src = imageUrl; 43 | } 44 | exports.getImage = getImage; 45 | /** 46 | * 47 | * @param dracoUrl 48 | * @param callback 49 | * 50 | * https://github.com/kioku-systemk/dracoSample/blob/5611528416d4e0afb10cbec52d70493602d8a552/dracoloader.js#L210 51 | * 52 | */ 53 | function loadDraco(dracoUrl, callback) { 54 | var xhr = new XMLHttpRequest(); 55 | xhr.responseType = 'arraybuffer'; 56 | xhr.onreadystatechange = function () { 57 | if (xhr.readyState === 4) { 58 | if (xhr.status === 200 || xhr.status === 0) { 59 | callback(xhr.response); 60 | } 61 | else { 62 | console.error("Couldn't load [" + dracoUrl + '] [' + xhr.status + ']'); 63 | } 64 | } 65 | }; 66 | xhr.open('GET', dracoUrl, true); 67 | xhr.send(null); 68 | } 69 | exports.loadDraco = loadDraco; 70 | //# sourceMappingURL=assets-functions.js.map -------------------------------------------------------------------------------- /dist/lib/utils/functions/assets-functions.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"assets-functions.js","sourceRoot":"","sources":["../../../../src/utils/functions/assets-functions.ts"],"names":[],"mappings":";;AAGA;;;;GAIG;AACH,SAAgB,WAAW,CAAC,GAAW,EAAE,QAAkB;IAC1D,IAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;IACjC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAE3B,GAAG,CAAC,kBAAkB,GAAG;QACxB,IAAI,GAAG,CAAC,UAAU,KAAK,CAAC,EAAE;YACzB,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;gBACvB,IAAM,IAAI,GAAW,GAAG,CAAC,YAAY,CAAC;gBACtC,IAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAClC,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBACnB,qBAAqB;aACrB;iBAAM;gBACN,sBAAsB;aACtB;SACD;aAAM;YACN,sBAAsB;SACtB;IACF,CAAC,CAAC;IAEF,GAAG,CAAC,IAAI,EAAE,CAAC;AACZ,CAAC;AApBD,kCAoBC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CAAC,QAAgB,EAAE,QAAkB;IAC5D,IAAM,KAAK,GAAqB,IAAI,KAAK,EAAE,CAAC;IAC5C,KAAK,CAAC,MAAM,GAAG;QACd,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,GAAG;QACf,OAAO,CAAC,IAAI,CAAC,WAAS,QAAQ,eAAY,CAAC,CAAC;IAC7C,CAAC,CAAC;IAEF,KAAK,CAAC,GAAG,GAAG,QAAQ,CAAC;AACtB,CAAC;AAVD,4BAUC;AAED;;;;;;;GAOG;AACH,SAAgB,SAAS,CAAC,QAAgB,EAAE,QAAkB;IAC7D,IAAI,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;IAC/B,GAAG,CAAC,YAAY,GAAG,aAAa,CAAC;IACjC,GAAG,CAAC,kBAAkB,GAAG;QACxB,IAAI,GAAG,CAAC,UAAU,KAAK,CAAC,EAAE;YACzB,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC3C,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;aACvB;iBAAM;gBACN,OAAO,CAAC,KAAK,CAAC,iBAAiB,GAAG,QAAQ,GAAG,KAAK,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;aACvE;SACD;IACF,CAAC,CAAC;IACF,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IAChC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAdD,8BAcC"} -------------------------------------------------------------------------------- /dist/lib/utils/functions/gl-functions.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"gl-functions.js","sourceRoot":"","sources":["../../../../src/utils/functions/gl-functions.ts"],"names":[],"mappings":";;AAAA,iDAA4C;AAC5C,uCAA6C;AAO7C,SAAgB,mBAAmB,CAClC,EAAyB,EACzB,OAAqB,EACrB,GAAa;IAEb,IAAM,SAAS,GAAmB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,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC;IAC3C,EAAE,CAAC,eAAe,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAChD,EAAE,CAAC,oBAAoB,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,iBAAiB,EAAE,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAEzF,OAAO,WAAW,CAAC;AACpB,CAAC;AAND,oEAMC;AAED,SAAgB,wBAAwB,CAAC,EAAyB,EAAE,KAAa,EAAE,MAAc;IAChG,IAAM,KAAK,GAAG,EAAE,CAAC,kBAAkB,EAAE,CAAC;IACtC,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IAC5C,EAAE,CAAC,mBAAmB,CAAC,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,iBAAiB,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAE7E,OAAO,KAAK,CAAC;AACd,CAAC;AAND,4DAMC;AAED,SAAgB,UAAU,CAAC,OAAe,EAAE,QAAuB;IAClE,IAAI,QAAQ,KAAK,IAAI,EAAE;QACtB,OAAO,OAAO,CAAC;KACf;IAED,OAAO,QAAQ,GAAG,OAAO,CAAC;AAC3B,CAAC;AAND,gCAMC"} -------------------------------------------------------------------------------- /dist/lib/utils/functions/gl-textures.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var constants_1 = require("../common/constants"); 4 | /** 5 | * 6 | * @param gl 7 | * @param textureWidth 8 | * @param textureHeight 9 | * @param format 10 | * @param minFilter 11 | * @param magFilter 12 | * @param wrapS 13 | * @param wrapT 14 | * @param type 15 | */ 16 | function createEmptyTexture(gl, textureWidth, textureHeight, format, minFilter, magFilter, wrapS, wrapT, type) { 17 | if (format === void 0) { format = constants_1.RGB; } 18 | if (minFilter === void 0) { minFilter = constants_1.LINEAR; } 19 | if (magFilter === void 0) { magFilter = constants_1.LINEAR; } 20 | if (wrapS === void 0) { wrapS = constants_1.CLAMP_TO_EDGE; } 21 | if (wrapT === void 0) { wrapT = constants_1.CLAMP_TO_EDGE; } 22 | if (type === void 0) { type = constants_1.UNSIGNED_BYTE; } 23 | var texture = gl.createTexture(); 24 | updateEmptyImageTexture(gl, texture, textureWidth, textureHeight, format, minFilter, magFilter, wrapS, wrapT, type); 25 | return texture; 26 | } 27 | exports.createEmptyTexture = createEmptyTexture; 28 | function createImageTexture(gl, canvasImage, format, isFlip, isMipmap) { 29 | if (format === void 0) { format = constants_1.RGB; } 30 | if (isFlip === void 0) { isFlip = false; } 31 | if (isMipmap === void 0) { isMipmap = false; } 32 | return createCustomTypeImageTexture(gl, canvasImage, format, gl.UNSIGNED_BYTE, isFlip, isMipmap); 33 | } 34 | exports.createImageTexture = createImageTexture; 35 | function createCustomTypeImageTexture(gl, canvasImage, format, type, isFlip, isMipmap) { 36 | if (format === void 0) { format = constants_1.RGB; } 37 | if (isFlip === void 0) { isFlip = false; } 38 | if (isMipmap === void 0) { isMipmap = false; } 39 | var texture = gl.createTexture(); 40 | gl.bindTexture(gl.TEXTURE_2D, texture); 41 | gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, isFlip ? 0 : 1); 42 | gl.texImage2D(gl.TEXTURE_2D, 0, format, format, type, canvasImage); 43 | if (isPowerOf2(canvasImage.width) && isPowerOf2(canvasImage.height) && isMipmap) { 44 | // Yes, it's a power of 2. Generate mips. 45 | gl.generateMipmap(gl.TEXTURE_2D); 46 | } 47 | else { 48 | // No, it's not a power of 2. Turn of mips and set 49 | // wrapping to clamp to edge 50 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 51 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 52 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 53 | } 54 | return texture; 55 | } 56 | exports.createCustomTypeImageTexture = createCustomTypeImageTexture; 57 | function isPowerOf2(value) { 58 | return (value & (value - 1)) === 0; 59 | } 60 | /** 61 | * 62 | * @param gl 63 | * @param texture 64 | * @param image 65 | * @param format 66 | */ 67 | function updateImageTexture(gl, texture, image, format) { 68 | if (format === void 0) { format = constants_1.RGB; } 69 | gl.bindTexture(gl.TEXTURE_2D, texture); 70 | gl.texImage2D(gl.TEXTURE_2D, 0, format, format, gl.UNSIGNED_BYTE, image); 71 | if (isPowerOf2(image.width) && isPowerOf2(image.height)) { 72 | // Yes, it's a power of 2. Generate mips. 73 | gl.generateMipmap(gl.TEXTURE_2D); 74 | } 75 | else { 76 | // No, it's not a power of 2. Turn of mips and set 77 | // wrapping to clamp to edge 78 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 79 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 80 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 81 | } 82 | } 83 | exports.updateImageTexture = updateImageTexture; 84 | function updateEmptyImageTexture(gl, texture, textureWidth, textureHeight, format, minFilter, magFilter, wrapS, wrapT, type) { 85 | if (format === void 0) { format = constants_1.RGB; } 86 | if (minFilter === void 0) { minFilter = constants_1.LINEAR; } 87 | if (magFilter === void 0) { magFilter = constants_1.LINEAR; } 88 | if (wrapS === void 0) { wrapS = constants_1.CLAMP_TO_EDGE; } 89 | if (wrapT === void 0) { wrapT = constants_1.CLAMP_TO_EDGE; } 90 | if (type === void 0) { type = constants_1.UNSIGNED_BYTE; } 91 | gl.bindTexture(gl.TEXTURE_2D, texture); 92 | // define size and format of level 0 93 | var level = 0; 94 | var border = 0; 95 | // https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texImage2D 96 | gl.texImage2D(gl.TEXTURE_2D, level, format, textureWidth, textureHeight, 0, format, type, null); 97 | // set the filtering so we don't need mips 98 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter); 99 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter); 100 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS); 101 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT); 102 | return texture; 103 | } 104 | exports.updateEmptyImageTexture = updateEmptyImageTexture; 105 | /** 106 | * 107 | * @param gl 108 | * @param texture 109 | * @param uniformLocation 110 | * @param textureNum 111 | */ 112 | function activeTexture(gl, texture, uniformLocation, textureNum) { 113 | if (textureNum === void 0) { textureNum = 0; } 114 | var activeTextureNum = gl.TEXTURE0 + textureNum; 115 | gl.activeTexture(activeTextureNum); 116 | gl.bindTexture(gl.TEXTURE_2D, texture); 117 | gl.uniform1i(uniformLocation, textureNum); 118 | } 119 | exports.activeTexture = activeTexture; 120 | //# sourceMappingURL=gl-textures.js.map -------------------------------------------------------------------------------- /dist/lib/utils/functions/gl-textures.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"gl-textures.js","sourceRoot":"","sources":["../../../../src/utils/functions/gl-textures.ts"],"names":[],"mappings":";;AAAA,iDAAgF;AAEhF;;;;;;;;;;;GAWG;AACH,SAAgB,kBAAkB,CACjC,EAAyB,EACzB,YAAoB,EACpB,aAAqB,EACrB,MAAoB,EACpB,SAA0B,EAC1B,SAA0B,EAC1B,KAA6B,EAC7B,KAA6B,EAC7B,IAA4B;IAL5B,uBAAA,EAAA,SAAiB,eAAG;IACpB,0BAAA,EAAA,YAAoB,kBAAM;IAC1B,0BAAA,EAAA,YAAoB,kBAAM;IAC1B,sBAAA,EAAA,QAAgB,yBAAa;IAC7B,sBAAA,EAAA,QAAgB,yBAAa;IAC7B,qBAAA,EAAA,OAAe,yBAAa;IAE5B,IAAM,OAAO,GAAG,EAAE,CAAC,aAAa,EAAkB,C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,CAAC,CAAC;IAC1D,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IAE1D,OAAO,OAAO,CAAC;AAChB,CAAC;AA5BD,0DA4BC;AAED;;;;;;GAMG;AACH,SAAgB,aAAa,CAC5B,EAAyB,EACzB,OAAqB,EACrB,eAAqC,EACrC,UAAsB;IAAtB,2BAAA,EAAA,cAAsB;IAEtB,IAAM,gBAAgB,GAAG,EAAE,CAAC,QAAQ,GAAG,UAAU,CAAC;IAClD,EAAE,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IACnC,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACvC,EAAE,CAAC,SAAS,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;AAC3C,CAAC;AAVD,sCAUC"} -------------------------------------------------------------------------------- /dist/lib/utils/generate/generateGeometry.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | function getSphere(radius, latitudeBands, longitudeBands) { 4 | if (radius === void 0) { radius = 2; } 5 | if (latitudeBands === void 0) { latitudeBands = 64; } 6 | if (longitudeBands === void 0) { longitudeBands = 64; } 7 | var vertices = []; 8 | var textures = []; 9 | var normals = []; 10 | var indices = []; 11 | for (var latNumber = 0; latNumber <= latitudeBands; latNumber = latNumber + 1) { 12 | var theta = (latNumber * Math.PI) / latitudeBands; 13 | var sinTheta = Math.sin(theta); 14 | var cosTheta = Math.cos(theta); 15 | for (var longNumber = 0; longNumber <= longitudeBands; longNumber = longNumber + 1) { 16 | var phi = (longNumber * 2 * Math.PI) / longitudeBands; 17 | var sinPhi = Math.sin(phi); 18 | var cosPhi = Math.cos(phi); 19 | var x = cosPhi * sinTheta; 20 | var y = cosTheta; 21 | var z = sinPhi * sinTheta; 22 | var u = 1 - longNumber / longitudeBands; 23 | var v = 1 - latNumber / latitudeBands; 24 | normals.push(x, y, z); 25 | textures.push(u, v); 26 | vertices.push(radius * x, radius * y, radius * z); 27 | } 28 | } 29 | for (var latNumber = 0; latNumber < latitudeBands; latNumber = latNumber + 1) { 30 | for (var longNumber = 0; longNumber < longitudeBands; longNumber = longNumber + 1) { 31 | var first = latNumber * (longitudeBands + 1) + longNumber; 32 | var second = first + longitudeBands + 1; 33 | indices.push(second, first, first + 1, second + 1, second, first + 1); 34 | } 35 | } 36 | return { 37 | vertices: vertices, 38 | uvs: textures, 39 | normals: normals, 40 | indices: indices 41 | }; 42 | } 43 | exports.getSphere = getSphere; 44 | function getPlane(width, height, widthSegment, heightSegment) { 45 | var vertices = []; 46 | var uvs = []; 47 | var xRate = 1 / widthSegment; 48 | var yRate = 1 / heightSegment; 49 | // set vertices and barycentric vertices 50 | for (var yy = 0; yy <= heightSegment; yy++) { 51 | var yPos = (-0.5 + yRate * yy) * height; 52 | for (var xx = 0; xx <= widthSegment; xx++) { 53 | var xPos = (-0.5 + xRate * xx) * width; 54 | vertices.push(xPos); 55 | vertices.push(yPos); 56 | uvs.push(xx / widthSegment); 57 | uvs.push(yy / heightSegment); 58 | } 59 | } 60 | var indices = []; 61 | for (var yy = 0; yy < heightSegment; yy++) { 62 | for (var xx = 0; xx < widthSegment; xx++) { 63 | var rowStartNum = yy * (widthSegment + 1); 64 | var nextRowStartNum = (yy + 1) * (widthSegment + 1); 65 | indices.push(rowStartNum + xx); 66 | indices.push(rowStartNum + xx + 1); 67 | indices.push(nextRowStartNum + xx); 68 | indices.push(rowStartNum + xx + 1); 69 | indices.push(nextRowStartNum + xx + 1); 70 | indices.push(nextRowStartNum + xx); 71 | } 72 | } 73 | return { 74 | vertices: vertices, 75 | uvs: uvs, 76 | indices: indices 77 | }; 78 | } 79 | exports.getPlane = getPlane; 80 | function mergeGeomtory(geometries) { 81 | var vertices = []; 82 | var normals = []; 83 | var uvs = []; 84 | var indices = []; 85 | var lastVertices = 0; 86 | for (var ii = 0; ii < geometries.length; ii++) { 87 | var geometry = geometries[ii]; 88 | if (geometry.indices.length > 0) { 89 | for (var ii_1 = 0; ii_1 < geometry.indices.length; ii_1++) { 90 | indices.push(geometry.indices[ii_1] + lastVertices / 3); 91 | } 92 | } 93 | if (geometry.vertices.length > 0) { 94 | for (var ii_2 = 0; ii_2 < geometry.vertices.length; ii_2++) { 95 | vertices.push(geometry.vertices[ii_2]); 96 | } 97 | lastVertices += geometry.vertices.length; 98 | } 99 | if (geometry.normals.length > 0) { 100 | for (var ii_3 = 0; ii_3 < geometry.normals.length; ii_3++) { 101 | normals.push(geometry.normals[ii_3]); 102 | } 103 | } 104 | if (geometry.uvs.length > 0) { 105 | for (var ii_4 = 0; ii_4 < geometry.uvs.length; ii_4++) { 106 | uvs.push(geometry.uvs[ii_4]); 107 | } 108 | } 109 | } 110 | return { 111 | vertices: vertices, 112 | normals: normals, 113 | uvs: uvs, 114 | indices: indices 115 | }; 116 | } 117 | exports.mergeGeomtory = mergeGeomtory; 118 | //# sourceMappingURL=generateGeometry.js.map -------------------------------------------------------------------------------- /dist/lib/utils/generate/generateGeometry.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"generateGeometry.js","sourceRoot":"","sources":["../../../../src/utils/generate/generateGeometry.ts"],"names":[],"mappings":";;AAAA,SAAgB,SAAS,CACxB,MAAkB,EAClB,aAA0B,EAC1B,cAA2B;IAF3B,uBAAA,EAAA,UAAkB;IAClB,8BAAA,EAAA,kBAA0B;IAC1B,+BAAA,EAAA,mBAA2B;IAE3B,IAAM,QAAQ,GAAG,EAAE,CAAC;IACpB,IAAM,QAAQ,GAAG,EAAE,CAAC;IACpB,IAAM,OAAO,GAAG,EAAE,CAAC;IACnB,IAAM,OAAO,GAAG,EAAE,CAAC;IAEnB,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,IAAI,aAAa,EAAE,SAAS,GAAG,SAAS,GAAG,CAAC,EAAE;QAC9E,IAAM,KAAK,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,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QACN,QAAQ,UAAA;QACR,OAAO,SAAA;QACP,GAAG,KAAA;QACH,OAAO,SAAA;KACP,CAAC;AACH,CAAC;AA9CD,sCA8CC"} -------------------------------------------------------------------------------- /dist/lib/utils/generate/generateSimpleGeometry.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | // segment is one 4 | function createSimpleBox() { 5 | var unit = 0.5; 6 | var positions = [ 7 | // Front face 8 | -unit, 9 | -unit, 10 | unit, 11 | unit, 12 | -unit, 13 | unit, 14 | unit, 15 | unit, 16 | unit, 17 | -unit, 18 | unit, 19 | unit, 20 | // Back face 21 | -unit, 22 | -unit, 23 | -unit, 24 | -unit, 25 | unit, 26 | -unit, 27 | unit, 28 | unit, 29 | -unit, 30 | unit, 31 | -unit, 32 | -unit, 33 | // Top face 34 | -unit, 35 | unit, 36 | -unit, 37 | -unit, 38 | unit, 39 | unit, 40 | unit, 41 | unit, 42 | unit, 43 | unit, 44 | unit, 45 | -unit, 46 | // Bottom face 47 | -unit, 48 | -unit, 49 | -unit, 50 | unit, 51 | -unit, 52 | -unit, 53 | unit, 54 | -unit, 55 | unit, 56 | -unit, 57 | -unit, 58 | unit, 59 | // Right face 60 | unit, 61 | -unit, 62 | -unit, 63 | unit, 64 | unit, 65 | -unit, 66 | unit, 67 | unit, 68 | unit, 69 | unit, 70 | -unit, 71 | unit, 72 | // Left face 73 | -unit, 74 | -unit, 75 | -unit, 76 | -unit, 77 | -unit, 78 | unit, 79 | -unit, 80 | unit, 81 | unit, 82 | -unit, 83 | unit, 84 | -unit 85 | ]; 86 | var indices = [ 87 | 0, 88 | 1, 89 | 2, 90 | 0, 91 | 2, 92 | 3, 93 | 4, 94 | 5, 95 | 6, 96 | 4, 97 | 6, 98 | 7, 99 | 8, 100 | 9, 101 | 10, 102 | 8, 103 | 10, 104 | 11, 105 | 12, 106 | 13, 107 | 14, 108 | 12, 109 | 14, 110 | 15, 111 | 16, 112 | 17, 113 | 18, 114 | 16, 115 | 18, 116 | 19, 117 | 20, 118 | 21, 119 | 22, 120 | 20, 121 | 22, 122 | 23 // left 123 | ]; 124 | var uvs = [ 125 | // Front 126 | 0.0, 127 | 0.0, 128 | 1.0, 129 | 0.0, 130 | 1.0, 131 | 1.0, 132 | 0.0, 133 | 1.0, 134 | // Back 135 | 0.0, 136 | 0.0, 137 | 1.0, 138 | 0.0, 139 | 1.0, 140 | 1.0, 141 | 0.0, 142 | 1.0, 143 | // Top 144 | 0.0, 145 | 0.0, 146 | 1.0, 147 | 0.0, 148 | 1.0, 149 | 1.0, 150 | 0.0, 151 | 1.0, 152 | // Bottom 153 | 0.0, 154 | 0.0, 155 | 1.0, 156 | 0.0, 157 | 1.0, 158 | 1.0, 159 | 0.0, 160 | 1.0, 161 | // Right 162 | 0.0, 163 | 0.0, 164 | 1.0, 165 | 0.0, 166 | 1.0, 167 | 1.0, 168 | 0.0, 169 | 1.0, 170 | // Left 171 | 0.0, 172 | 0.0, 173 | 1.0, 174 | 0.0, 175 | 1.0, 176 | 1.0, 177 | 0.0, 178 | 1.0 179 | ]; 180 | var normals = [ 181 | // Front 182 | 0.0, 183 | 0.0, 184 | 1.0, 185 | 0.0, 186 | 0.0, 187 | 1.0, 188 | 0.0, 189 | 0.0, 190 | 1.0, 191 | 0.0, 192 | 0.0, 193 | 1.0, 194 | // Back 195 | 0.0, 196 | 0.0, 197 | -1.0, 198 | 0.0, 199 | 0.0, 200 | -1.0, 201 | 0.0, 202 | 0.0, 203 | -1.0, 204 | 0.0, 205 | 0.0, 206 | -1.0, 207 | // Top 208 | 0.0, 209 | 1.0, 210 | 0.0, 211 | 0.0, 212 | 1.0, 213 | 0.0, 214 | 0.0, 215 | 1.0, 216 | 0.0, 217 | 0.0, 218 | 1.0, 219 | 0.0, 220 | // Bottom 221 | 0.0, 222 | -1.0, 223 | 0.0, 224 | 0.0, 225 | -1.0, 226 | 0.0, 227 | 0.0, 228 | -1.0, 229 | 0.0, 230 | 0.0, 231 | -1.0, 232 | 0.0, 233 | // Right 234 | 1.0, 235 | 0.0, 236 | 0.0, 237 | 1.0, 238 | 0.0, 239 | 0.0, 240 | 1.0, 241 | 0.0, 242 | 0.0, 243 | 1.0, 244 | 0.0, 245 | 0.0, 246 | // Left 247 | -1.0, 248 | 0.0, 249 | 0.0, 250 | -1.0, 251 | 0.0, 252 | 0.0, 253 | -1.0, 254 | 0.0, 255 | 0.0, 256 | -1.0, 257 | 0.0, 258 | 0.0 259 | ]; 260 | return { 261 | vertices: positions, 262 | normals: normals, 263 | uvs: uvs, 264 | indices: indices 265 | }; 266 | } 267 | exports.createSimpleBox = createSimpleBox; 268 | function createSimplePlane() { 269 | var unit = 0.5; 270 | var positions = [-unit, -unit, 0.0, unit, -unit, 0.0, unit, unit, 0.0, -unit, unit, 0.0]; 271 | var indices = [ 272 | 0, 273 | 1, 274 | 2, 275 | 0, 276 | 2, 277 | 3 // front 278 | ]; 279 | var uvs = [0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0]; 280 | var normals = [ 281 | // Front 282 | 0.0, 283 | 0.0, 284 | 1.0, 285 | 0.0, 286 | 0.0, 287 | 1.0, 288 | 0.0, 289 | 0.0, 290 | 1.0, 291 | 0.0, 292 | 0.0, 293 | 1.0 294 | ]; 295 | return { 296 | vertices: positions, 297 | normals: normals, 298 | uvs: uvs, 299 | indices: indices 300 | }; 301 | } 302 | exports.createSimplePlane = createSimplePlane; 303 | function createSuperSimpleplane(scaleX, scaleY) { 304 | if (scaleX === void 0) { scaleX = 1; } 305 | if (scaleY === void 0) { scaleY = 1; } 306 | return new Float32Array([-scaleX, -scaleY, scaleX, -scaleY, -scaleX, scaleY, scaleX, scaleY]); 307 | } 308 | exports.createSuperSimpleplane = createSuperSimpleplane; 309 | //# sourceMappingURL=generateSimpleGeometry.js.map -------------------------------------------------------------------------------- /dist/lib/utils/generate/generateSimpleGeometry.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"generateSimpleGeometry.js","sour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EAAE,GAAG,CAAC,CAAC;IAE3F,IAAM,OAAO,GAAG;QACf,CAAC;QACD,CAAC;QACD,CAAC;QACD,CAAC;QACD,CAAC;QACD,CAAC,CAAC,QAAQ;KACV,CAAC;IAEF,IAAM,GAAG,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAErD,IAAM,OAAO,GAAG;QACf,QAAQ;QACR,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;QACH,GAAG;KACH,CAAC;IAEF,OAAO;QACN,QAAQ,EAAE,SAAS;QACnB,OAAO,EAAE,OAAO;QAChB,GAAG,EAAE,GAAG;QACR,OAAO,EAAE,OAAO;KAChB,CAAC;AACH,CAAC;AAtCD,8CAsCC;AAED,SAAgB,sBAAsB,CAAC,MAAkB,EAAE,MAAkB;IAAtC,uBAAA,EAAA,UAAkB;IAAE,uBAAA,EAAA,UAAkB;IAC5E,OAAO,IAAI,YAAY,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/F,CAAC;AAFD,wDAEC"} -------------------------------------------------------------------------------- /dist/types/camera/camera.d.ts: -------------------------------------------------------------------------------- 1 | import { mat4 } from 'gl-matrix'; 2 | import { Vector3 } from '../interfaces/interface'; 3 | export declare class Camera { 4 | type: string; 5 | position: Vector3; 6 | lookAtPosition: Vector3; 7 | viewMatrix: mat4; 8 | viewMatrixInverse: mat4; 9 | projectionMatrix: mat4; 10 | projectionMatrixInverse: mat4; 11 | constructor(type?: string); 12 | updatePosition(xx?: number, yy?: number, zz?: number): void; 13 | updateLookAtPosition(xx?: number, yy?: number, zz?: number): void; 14 | updateViewMatrix(): void; 15 | } 16 | export declare class PerspectiveCamera extends Camera { 17 | private width; 18 | private height; 19 | private fov; 20 | private near; 21 | private far; 22 | constructor(width: number, height: number, fov?: number, near?: number, far?: number); 23 | updatePerspective(): void; 24 | updateSize(width: number, height: number): void; 25 | updateFocus(near: number, far: number): void; 26 | updatefov(angle: number): void; 27 | } 28 | export declare class OrthoCamera extends Camera { 29 | private left; 30 | private right; 31 | private bottom; 32 | private top; 33 | private near; 34 | private far; 35 | constructor(left: number, right: number, bottom: number, top: number, near: number, far: number); 36 | updateSize(left: number, right: number, bottom: number, top: number): void; 37 | updateFocus(near: number, far: number): void; 38 | updatePerspective(): void; 39 | } 40 | -------------------------------------------------------------------------------- /dist/types/dan-shari-gl.d.ts: -------------------------------------------------------------------------------- 1 | export * from './utils/functions/gl-functions'; 2 | export * from './utils/functions/gl-textures'; 3 | export * from './utils/functions/assets-functions'; 4 | export * from './utils/generate/generateGeometry'; 5 | export * from './utils/generate/generateSimpleGeometry'; 6 | export * from './utils/common/constants'; 7 | export * from './utils/common/shaders'; 8 | export * from './math/math'; 9 | export * from './math/ray'; 10 | export * from './camera/camera'; 11 | export * from './extra/cameracontroller'; 12 | export * from './extra/textLayout'; 13 | export * from './extra/textRendering'; 14 | export * from './extra/TexturePool'; 15 | export * from './extra/swapRenderer'; 16 | export * from './extra/fbo'; 17 | -------------------------------------------------------------------------------- /dist/types/extra/TexturePool.d.ts: -------------------------------------------------------------------------------- 1 | export declare class TexturePools { 2 | private static instance; 3 | textures: { 4 | [key: string]: WebGLTexture; 5 | }; 6 | private gl; 7 | private constructor(); 8 | static GET_INSTANCE(): TexturePools; 9 | static GET_TEXTURE(name: string): WebGLTexture; 10 | setGL(gl: WebGLRenderingContext): void; 11 | setImage(name: string, element: HTMLImageElement | HTMLCanvasElement): void; 12 | private createEmptyCanvas; 13 | } 14 | -------------------------------------------------------------------------------- /dist/types/extra/cameracontroller.d.ts: -------------------------------------------------------------------------------- 1 | import { Camera } from '../camera/camera'; 2 | export declare class CameraController { 3 | private camera; 4 | private domElement; 5 | private target; 6 | private minDistance; 7 | private maxDistance; 8 | private isEnabled; 9 | private isDamping; 10 | private dampingFactor; 11 | private isZoom; 12 | private zoomSpeed; 13 | private isRotate; 14 | private rotateSpeed; 15 | private isPan; 16 | private keyPanSpeed; 17 | private enableKeys; 18 | private keys; 19 | private originTarget; 20 | private originPosition; 21 | private targetXDampedAction; 22 | private targetYDampedAction; 23 | private targetZDampedAction; 24 | private targetThetaDampedAction; 25 | private targetPhiDampedAction; 26 | private targetRadiusDampedAction; 27 | private _isShiftDown; 28 | private _rotateStart; 29 | private _rotateEnd; 30 | private _roatteDelta; 31 | private _spherical; 32 | private _zoomDistanceEnd; 33 | private _zoomDistance; 34 | private state; 35 | private loopId; 36 | private _panStart; 37 | private _panDelta; 38 | private _panEnd; 39 | constructor(camera: Camera, domElement?: HTMLElement); 40 | setEventHandler(): void; 41 | removeEventHandler(): void; 42 | startTick(): void; 43 | tick(): void; 44 | updateDampedAction(): void; 45 | updateCamera(): void; 46 | _bindEvens(): void; 47 | _contextMenuHandler(event: MouseEvent): void; 48 | _mouseDownHandler(event: MouseEvent): void; 49 | _mouseUpHandler(): void; 50 | _mouseMoveHandler(event: MouseEvent): void; 51 | _mouseWheelHandler(event: WheelEvent): void; 52 | _touchStartHandler(event: TouchEvent): void; 53 | _touchMoveHandler(event: TouchEvent): void; 54 | _onKeyDownHandler(event: KeyboardEvent): void; 55 | _onKeyUpHandler(event: KeyboardEvent): void; 56 | _updatePanHandler(): void; 57 | _updateRotateHandler(): void; 58 | } 59 | -------------------------------------------------------------------------------- /dist/types/extra/fbo.d.ts: -------------------------------------------------------------------------------- 1 | export declare class FBO { 2 | private gl; 3 | private width; 4 | private height; 5 | private buffer; 6 | private texture; 7 | private depth?; 8 | constructor(gl: WebGLRenderingContext, width: number, height: number, texture?: WebGLTexture | null, isDepthNeed?: boolean); 9 | private bindTex; 10 | private createDepth; 11 | private updateDepth; 12 | bind(): void; 13 | unbind(): void; 14 | resize(width: number, height: number, texture?: WebGLTexture): void; 15 | getTexture(): WebGLTexture | null; 16 | } 17 | -------------------------------------------------------------------------------- /dist/types/extra/swapRenderer.d.ts: -------------------------------------------------------------------------------- 1 | export declare class SwapRenderer { 2 | private gl; 3 | private textures; 4 | private framebuffers; 5 | private programs; 6 | private positionVbos; 7 | constructor(gl: WebGLRenderingContext); 8 | setSize(width: number, height: number): void; 9 | createProgram(programName: string, vertexShader: string, fragmentShader: string): void; 10 | initTexture(name: string, width: number, height: number, type: number): void; 11 | initTextureWithImage(name: string, type: number, image: HTMLImageElement): void; 12 | initFramebufferForTexture(textureName: string): void; 13 | initDepthTexture(width: number, height: number): void; 14 | setProgram(programName: string): void; 15 | use(programName: string): void; 16 | getProgram(programName: string): WebGLProgram; 17 | createPositionVBO(name: string, scaleX?: number, scaleY?: number): void; 18 | usePositionVBO(): void; 19 | updateVBO(name: string): void; 20 | run(programName: string, inputNameArr: string[], outputName: string): void; 21 | swapTextures(texture1Name: string, texture2Name: string): void; 22 | setUniform(programName: string, name: string, val: number | number[] | Float32List, type: string): void; 23 | reset(): void; 24 | } 25 | -------------------------------------------------------------------------------- /dist/types/extra/textLayout.d.ts: -------------------------------------------------------------------------------- 1 | export declare class TextLayout { 2 | private fontData; 3 | private options; 4 | private glyphs; 5 | private width; 6 | private height; 7 | private descender; 8 | private baseline; 9 | private xHeight; 10 | private capHeight; 11 | private lineHeight; 12 | private ascender; 13 | private linesTotal; 14 | private _fallbackTabGlyph; 15 | private _fallbackSpaceGlyph; 16 | private fallbackSpaceGlyph; 17 | private fallbackTabGlyph; 18 | constructor(data: any, text: any, options?: {}); 19 | update(): void; 20 | getGlyph(font: any, id: any): any; 21 | getAlignType(align: string): 1 | 0 | 2; 22 | setupSpaceGlyphs(fontData: any): void; 23 | extendObject(objectData: { 24 | [index: string]: any; 25 | }, data: { 26 | [index: string]: any; 27 | }): { 28 | [index: string]: any; 29 | }; 30 | findChar(objectValue: { 31 | [index: string]: any; 32 | }, value: any): string | -1; 33 | getMGlyph(fontData: any): any; 34 | } 35 | export declare class TextLines { 36 | private fontData; 37 | lines: any; 38 | constructor(text: any, fontData: any, width?: number, start?: number, mode?: string, letterSpacing?: number); 39 | greedy(text: any, start: any, end: any, width: number, mode: any): void; 40 | idxOf(text: any, chr: any, start: number, end: number): any; 41 | isWhitespace(chr: string): boolean; 42 | measure(text: any, fontData: any, start: any, end: any, width: any): { 43 | start: any; 44 | end: any; 45 | width: number; 46 | }; 47 | computeMetrics(text: any, font: any, start: any, end: any, width: any, letterSpacing?: number): { 48 | start: any; 49 | end: any; 50 | width: number; 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /dist/types/extra/textRendering.d.ts: -------------------------------------------------------------------------------- 1 | export declare class TextRendering { 2 | vertices: Float32Array; 3 | uvs: Float32Array; 4 | indices: Uint16Array; 5 | constructor(gl: WebGLRenderingContext, textLayout: any, bitmapImage: any); 6 | } 7 | -------------------------------------------------------------------------------- /dist/types/interfaces/interface.d.ts: -------------------------------------------------------------------------------- 1 | export interface Vector3 { 2 | x: number; 3 | y: number; 4 | z: number; 5 | } 6 | export interface Box { 7 | max: Vector3; 8 | min: Vector3; 9 | } 10 | -------------------------------------------------------------------------------- /dist/types/math/math.d.ts: -------------------------------------------------------------------------------- 1 | import { Vector3 } from '../interfaces/interface'; 2 | export declare function clamp(value: number, min: number, max: number): number; 3 | export declare function range(min: number, max: number): number; 4 | export declare function calculateCircleCenter(A: Vector3, B: Vector3, C: Vector3): { 5 | x: number; 6 | y: number; 7 | z: number; 8 | }; 9 | export declare function mix(x: number, y: number, a: number): number; 10 | export declare function degToRad(value: number): number; 11 | export declare function radToDeg(value: number): number; 12 | -------------------------------------------------------------------------------- /dist/types/math/ray.d.ts: -------------------------------------------------------------------------------- 1 | import { vec3, mat4 } from 'gl-matrix'; 2 | import { Box } from '../interfaces/interface'; 3 | export declare class Ray { 4 | private isPrev; 5 | private orig; 6 | private dir; 7 | private worldMatrix3Inv; 8 | intersect(box: Box): false | { 9 | tmin: number; 10 | tmax: number; 11 | }; 12 | rayCast(faces: [vec3, vec3, vec3][], worldMatrixInv: mat4): { 13 | t: number; 14 | pt: number[]; 15 | } | undefined; 16 | intersectFaces(faces: [vec3, vec3, vec3][], dir: vec3, orig: vec3): { 17 | t: number; 18 | pt: number[]; 19 | } | undefined; 20 | intersectPts(pt0: vec3, pt1: vec3, pt2: vec3, dir: vec3, orig: vec3): false | { 21 | t: number; 22 | pt: number[]; 23 | }; 24 | calcDirection(startPt: vec3, endPt: vec3): void; 25 | swap(valA: number, valB: number): { 26 | minVal: number; 27 | maxVal: number; 28 | }; 29 | dot(a: vec3, b: vec3): number; 30 | } 31 | -------------------------------------------------------------------------------- /dist/types/src/camera/camera.d.ts: -------------------------------------------------------------------------------- 1 | import { mat4 } from 'gl-matrix'; 2 | import { Vector3 } from '../interfaces/interface'; 3 | export declare class Camera { 4 | type: string; 5 | position: Vector3; 6 | lookAtPosition: Vector3; 7 | viewMatrix: mat4; 8 | viewMatrixInverse: mat4; 9 | projectionMatrix: mat4; 10 | projectionMatrixInverse: mat4; 11 | constructor(type?: string); 12 | updatePosition(xx?: number, yy?: number, zz?: number): void; 13 | updateLookAtPosition(xx?: number, yy?: number, zz?: number): void; 14 | updateViewMatrix(): void; 15 | } 16 | export declare class PerspectiveCamera extends Camera { 17 | private width; 18 | private height; 19 | private fov; 20 | private near; 21 | private far; 22 | constructor(width: number, height: number, fov?: number, near?: number, far?: number); 23 | updatePerspective(): void; 24 | updateSize(width: number, height: number): void; 25 | updateFocus(near: number, far: number): void; 26 | updatefov(angle: number): void; 27 | } 28 | export declare class OrthoCamera extends Camera { 29 | private left; 30 | private right; 31 | private bottom; 32 | private top; 33 | private near; 34 | private far; 35 | constructor(left: number, right: number, bottom: number, top: number, near: number, far: number); 36 | updateSize(left: number, right: number, bottom: number, top: number): void; 37 | updateFocus(near: number, far: number): void; 38 | updatePerspective(): void; 39 | } 40 | -------------------------------------------------------------------------------- /dist/types/src/extra/TexturePool.d.ts: -------------------------------------------------------------------------------- 1 | export declare class TexturePools { 2 | private static instance; 3 | textures: { 4 | [key: string]: WebGLTexture; 5 | }; 6 | private gl; 7 | private constructor(); 8 | static GET_INSTANCE(): TexturePools; 9 | static GET_TEXTURE(name: string): WebGLTexture; 10 | setGL(gl: WebGLRenderingContext): void; 11 | setImage(name: string, element: HTMLImageElement | HTMLCanvasElement): void; 12 | private createEmptyCanvas; 13 | } 14 | -------------------------------------------------------------------------------- /dist/types/src/extra/cameracontroller.d.ts: -------------------------------------------------------------------------------- 1 | import { Camera } from '../camera/camera'; 2 | export declare class CameraController { 3 | private camera; 4 | private domElement; 5 | private target; 6 | private minDistance; 7 | private maxDistance; 8 | private isEnabled; 9 | private isDamping; 10 | private dampingFactor; 11 | private isZoom; 12 | private zoomSpeed; 13 | private isRotate; 14 | private rotateSpeed; 15 | private isPan; 16 | private keyPanSpeed; 17 | private enableKeys; 18 | private keys; 19 | private originTarget; 20 | private originPosition; 21 | private targetXDampedAction; 22 | private targetYDampedAction; 23 | private targetZDampedAction; 24 | private targetThetaDampedAction; 25 | private targetPhiDampedAction; 26 | private targetRadiusDampedAction; 27 | private _isShiftDown; 28 | private _rotateStart; 29 | private _rotateEnd; 30 | private _roatteDelta; 31 | private _spherical; 32 | private _zoomDistanceEnd; 33 | private _zoomDistance; 34 | private state; 35 | private loopId; 36 | private _panStart; 37 | private _panDelta; 38 | private _panEnd; 39 | constructor(camera: Camera, domElement?: HTMLElement); 40 | setEventHandler(): void; 41 | removeEventHandler(): void; 42 | startTick(): void; 43 | tick(): void; 44 | updateDampedAction(): void; 45 | updateCamera(): void; 46 | _bindEvens(): void; 47 | _contextMenuHandler(event: MouseEvent): void; 48 | _mouseDownHandler(event: MouseEvent): void; 49 | _mouseUpHandler(): void; 50 | _mouseMoveHandler(event: MouseEvent): void; 51 | _mouseWheelHandler(event: WheelEvent): void; 52 | _touchStartHandler(event: TouchEvent): void; 53 | _touchMoveHandler(event: TouchEvent): void; 54 | _onKeyDownHandler(event: KeyboardEvent): void; 55 | _onKeyUpHandler(event: KeyboardEvent): void; 56 | _updatePanHandler(): void; 57 | _updateRotateHandler(): void; 58 | } 59 | -------------------------------------------------------------------------------- /dist/types/src/extra/fbo.d.ts: -------------------------------------------------------------------------------- 1 | export declare class FBO { 2 | private gl; 3 | private width; 4 | private height; 5 | private buffer; 6 | private texture; 7 | private depth?; 8 | constructor(gl: WebGLRenderingContext, width: number, height: number, texture?: WebGLTexture | null, isDepthNeed?: boolean); 9 | private bindTex; 10 | private createDepth; 11 | private updateDepth; 12 | bind(): void; 13 | unbind(): void; 14 | resize(width: number, height: number, texture?: WebGLTexture): void; 15 | getTexture(): WebGLTexture | null; 16 | } 17 | -------------------------------------------------------------------------------- /dist/types/src/extra/textLayout.d.ts: -------------------------------------------------------------------------------- 1 | export declare class TextLayout { 2 | private fontData; 3 | private options; 4 | private glyphs; 5 | private width; 6 | private height; 7 | private descender; 8 | private baseline; 9 | private xHeight; 10 | private capHeight; 11 | private lineHeight; 12 | private ascender; 13 | private linesTotal; 14 | private _fallbackTabGlyph; 15 | private _fallbackSpaceGlyph; 16 | private fallbackSpaceGlyph; 17 | private fallbackTabGlyph; 18 | constructor(data: any, text: any, options?: {}); 19 | update(): void; 20 | getGlyph(font: any, id: any): any; 21 | getAlignType(align: string): 0 | 1 | 2; 22 | setupSpaceGlyphs(fontData: any): void; 23 | extendObject(objectData: { 24 | [index: string]: any; 25 | }, data: { 26 | [index: string]: any; 27 | }): { 28 | [index: string]: any; 29 | }; 30 | findChar(objectValue: { 31 | [index: string]: any; 32 | }, value: any): string | -1; 33 | getMGlyph(fontData: any): any; 34 | } 35 | export declare class TextLines { 36 | private fontData; 37 | lines: any; 38 | constructor(text: any, fontData: any, width?: number, start?: number, mode?: string, letterSpacing?: number); 39 | greedy(text: any, start: any, end: any, width: number, mode: any): void; 40 | idxOf(text: any, chr: any, start: number, end: number): any; 41 | isWhitespace(chr: string): boolean; 42 | measure(text: any, fontData: any, start: any, end: any, width: any): { 43 | start: any; 44 | end: any; 45 | width: number; 46 | }; 47 | computeMetrics(text: any, font: any, start: any, end: any, width: any, letterSpacing?: number): { 48 | start: any; 49 | end: any; 50 | width: number; 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /dist/types/src/extra/textRendering.d.ts: -------------------------------------------------------------------------------- 1 | export declare class TextRendering { 2 | vertices: Float32Array; 3 | uvs: Float32Array; 4 | indices: Uint16Array; 5 | constructor(gl: WebGLRenderingContext, textLayout: any, bitmapImage: any); 6 | } 7 | -------------------------------------------------------------------------------- /dist/types/src/math/math.d.ts: -------------------------------------------------------------------------------- 1 | import { Vector3 } from '../interfaces/interface'; 2 | export declare function clamp(value: number, min: number, max: number): number; 3 | export declare function range(min: number, max: number): number; 4 | export declare function calculateCircleCenter(A: Vector3, B: Vector3, C: Vector3): { 5 | x: number; 6 | y: number; 7 | z: number; 8 | }; 9 | export declare function mix(x: number, y: number, a: number): number; 10 | export declare function degToRad(value: number): number; 11 | export declare function radToDeg(value: number): number; 12 | -------------------------------------------------------------------------------- /dist/types/src/math/ray.d.ts: -------------------------------------------------------------------------------- 1 | import { vec3, mat4 } from 'gl-matrix'; 2 | import { Box } from '../interfaces/interface'; 3 | export declare class Ray { 4 | private isPrev; 5 | private orig; 6 | private dir; 7 | private worldMatrix3Inv; 8 | intersect(box: Box): false | { 9 | tmin: number; 10 | tmax: number; 11 | }; 12 | rayCast(faces: [vec3, vec3, vec3][], worldMatrixInv: mat4): { 13 | t: number; 14 | pt: number[]; 15 | } | undefined; 16 | intersectFaces(faces: [vec3, vec3, vec3][], dir: vec3, orig: vec3): { 17 | t: number; 18 | pt: number[]; 19 | } | undefined; 20 | intersectPts(pt0: vec3, pt1: vec3, pt2: vec3, dir: vec3, orig: vec3): false | { 21 | t: number; 22 | pt: number[]; 23 | }; 24 | calcDirection(startPt: vec3, endPt: vec3): void; 25 | swap(valA: number, valB: number): { 26 | minVal: number; 27 | maxVal: number; 28 | }; 29 | dot(a: vec3, b: vec3): number; 30 | } 31 | -------------------------------------------------------------------------------- /dist/types/src/utils/common/constants.d.ts: -------------------------------------------------------------------------------- 1 | export declare const FLOAT: number; 2 | export declare const RGB: number; 3 | export declare const NEAREST: number; 4 | export declare const LINEAR: number; 5 | export declare const NEAREST_MIPMAP_NEAREST: number; 6 | export declare const LINEAR_MIPMAP_NEAREST: number; 7 | export declare const NEAREST_MIPMAP_LINEAR: number; 8 | export declare const LINEAR_MIPMAP_LINEAR: number; 9 | export declare const CLAMP_TO_EDGE: number; 10 | export declare const REPEAT: number; 11 | export declare const DEPTH_COMPONENT16: number; 12 | export declare const UNSIGNED_BYTE: number; 13 | export declare const EMPTY_CANVAS_SIZE = 16; 14 | export declare const EMPTY_CANVAS_COLOR = "#ff0000"; 15 | export declare const COLOR_REPEAT = 4; 16 | export declare const UNIFORM_1F = "1f"; 17 | export declare const UNIFORM_1I = "1i"; 18 | export declare const UNIFORM_2F = "2f"; 19 | export declare const UNIFORM_3F = "3f"; 20 | export declare const UNIFORM_MAT_4F = "mat4"; 21 | -------------------------------------------------------------------------------- /dist/types/src/utils/common/shaders.d.ts: -------------------------------------------------------------------------------- 1 | export declare const fullscreenVertShader = "\nprecision highp float;\n\nattribute vec3 position;\n\nuniform vec2 px;\n\nvarying vec2 vUv;\n\nvoid main(){\n vUv = vec2(0.5)+(position.xy)*0.5;\n gl_Position = vec4(position, 1.0);\n}\n"; 2 | export declare const fillFragShader = "\nprecision highp float;\n\nvarying vec2 vUv;\n\nvoid main(){\n gl_FragColor = vec4(vUv, 0.0, 1.0);\n}\n"; 3 | export declare const texFragShader = "\nprecision highp float;\n\nuniform sampler2D uTexture;\n\nvarying vec2 vUv;\n\nvoid main(){\n vec4 texColor = texture2D(uTexture, vUv);\n gl_FragColor = texColor;\n}\n"; 4 | -------------------------------------------------------------------------------- /dist/types/src/utils/functions/assets-functions.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * load json with ajax 3 | * 4 | * @param url url to load json file 5 | */ 6 | export declare function getAjaxJson(url: string, callback: Function): void; 7 | /** 8 | * 9 | * @param imageUrl 10 | */ 11 | export declare function getImage(imageUrl: string, callback: Function): void; 12 | /** 13 | * 14 | * @param dracoUrl 15 | * @param callback 16 | * 17 | * https://github.com/kioku-systemk/dracoSample/blob/5611528416d4e0afb10cbec52d70493602d8a552/dracoloader.js#L210 18 | * 19 | */ 20 | export declare function loadDraco(dracoUrl: string, callback: Function): void; 21 | -------------------------------------------------------------------------------- /dist/types/src/utils/functions/gl-functions.d.ts: -------------------------------------------------------------------------------- 1 | import { vec2, vec3, mat4 } from 'gl-matrix'; 2 | interface IUniformObject { 3 | [key: string]: WebGLUniformLocation; 4 | } 5 | export declare function getUniformLocations(gl: WebGLRenderingContext, program: WebGLProgram, arr: string[]): IUniformObject; 6 | /** 7 | * display error of shader. 8 | * @param text 9 | */ 10 | export declare function addLineNumbers(text: string): string; 11 | /** 12 | * compile webgl shader 13 | * @param gl 14 | * @param glType 15 | * @param shaderSource 16 | */ 17 | export declare function compileGLShader(gl: WebGLRenderingContext, glType: number, shaderSource: string): WebGLShader | undefined; 18 | /** 19 | * 20 | * @param gl 21 | * @param vertexShaderSrc 22 | * @param fragmentShaderSrc 23 | */ 24 | export declare function createProgram(gl: WebGLRenderingContext, vertexShaderSrc: string, fragmentShaderSrc: string): WebGLProgram; 25 | /** 26 | * 27 | * create buffer and get location from program 28 | * 29 | * @param gl 30 | * @param program 31 | * @param data 32 | * @param str 33 | * 34 | * @returns uniformLocation 35 | */ 36 | export declare function createBufferWithLocation(gl: WebGLRenderingContext, program: WebGLProgram, data: Float32Array, str: string): { 37 | buffer: WebGLBuffer | null; 38 | location: number; 39 | }; 40 | /** 41 | * creates and initializes WebGLBuffer with data 42 | * 43 | * @param gl 44 | * @param data 45 | */ 46 | export declare function createBuffer(gl: WebGLRenderingContext, data: Float32Array): WebGLBuffer | null; 47 | /** 48 | * update array buffer 49 | * 50 | * @param gl 51 | * @param buffer 52 | * @param data 53 | * @param isBind 54 | */ 55 | export declare function updateArrayBuffer(gl: WebGLRenderingContext, buffer: WebGLBuffer, data: Float32Array, isBind?: boolean): void; 56 | /** 57 | * 58 | * make index buffer 59 | * 60 | * @param gl 61 | * @param indices 62 | */ 63 | export declare function createIndex(gl: WebGLRenderingContext, indices: Uint16Array | Uint32Array): { 64 | cnt: number; 65 | buffer: WebGLBuffer | null; 66 | }; 67 | /** 68 | * 69 | * @param {WebGLRenderingContext} gl 70 | * @param {WebGLBuffer} buffer 71 | * @param {Number} location 72 | * @param {Number} size 73 | * @param {Boolean} normalized 74 | * @param {Number} stride 75 | * @param {Number} offset 76 | */ 77 | export declare function bindBuffer(gl: WebGLRenderingContext, buffer: WebGLBuffer, location?: number, size?: number, type?: number, normalized?: boolean, stride?: number, offset?: number, isBind?: boolean): void; 78 | export declare function generateFaceFromIndex(vertices: number[], indices: number[]): [vec3, vec3, vec3][]; 79 | export declare function castMouse(mouse: vec2, viewMatrixInverse: mat4, projectionMatrixInverse: mat4, depth?: number): vec3; 80 | export declare function createFrameBufferWithTexture(gl: WebGLRenderingContext, texture: WebGLTexture): WebGLFramebuffer | null; 81 | export declare function createAndBindDepthBuffer(gl: WebGLRenderingContext, width: number, height: number): WebGLRenderbuffer | null; 82 | export declare function addKeyword(sources: string, keywords: string | null): string; 83 | export {}; 84 | -------------------------------------------------------------------------------- /dist/types/src/utils/functions/gl-textures.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @param gl 4 | * @param textureWidth 5 | * @param textureHeight 6 | * @param format 7 | * @param minFilter 8 | * @param magFilter 9 | * @param wrapS 10 | * @param wrapT 11 | * @param type 12 | */ 13 | export declare function createEmptyTexture(gl: WebGLRenderingContext, textureWidth: number, textureHeight: number, format?: number, minFilter?: number, magFilter?: number, wrapS?: number, wrapT?: number, type?: number): WebGLTexture; 14 | export declare function createImageTexture(gl: WebGLRenderingContext, canvasImage: HTMLImageElement | HTMLCanvasElement, format?: number, isFlip?: boolean, isMipmap?: boolean): WebGLTexture | null; 15 | export declare function createCustomTypeImageTexture(gl: WebGLRenderingContext, canvasImage: HTMLImageElement | HTMLCanvasElement, format: number | undefined, type: number, isFlip?: boolean, isMipmap?: boolean): WebGLTexture | null; 16 | /** 17 | * 18 | * @param gl 19 | * @param texture 20 | * @param image 21 | * @param format 22 | */ 23 | export declare function updateImageTexture(gl: WebGLRenderingContext, texture: WebGLTexture, image: HTMLImageElement, format?: number): void; 24 | export declare function updateEmptyImageTexture(gl: WebGLRenderingContext, texture: WebGLTexture, textureWidth: number, textureHeight: number, format?: number, minFilter?: number, magFilter?: number, wrapS?: number, wrapT?: number, type?: number): WebGLTexture; 25 | /** 26 | * 27 | * @param gl 28 | * @param texture 29 | * @param uniformLocation 30 | * @param textureNum 31 | */ 32 | export declare function activeTexture(gl: WebGLRenderingContext, texture: WebGLTexture, uniformLocation: WebGLUniformLocation, textureNum?: number): void; 33 | -------------------------------------------------------------------------------- /dist/types/src/utils/generate/generateGeometry.d.ts: -------------------------------------------------------------------------------- 1 | export declare function getSphere(radius?: number, latitudeBands?: number, longitudeBands?: number): { 2 | vertices: number[]; 3 | uvs: number[]; 4 | normals: number[]; 5 | indices: number[]; 6 | }; 7 | export declare function getPlane(width: number, height: number, widthSegment: number, heightSegment: number): { 8 | vertices: number[]; 9 | uvs: number[]; 10 | indices: number[]; 11 | }; 12 | export declare function mergeGeomtory(geometries: { 13 | vertices: number[]; 14 | indices: number[]; 15 | normals: number[]; 16 | uvs: number[]; 17 | }[]): { 18 | vertices: number[]; 19 | normals: number[]; 20 | uvs: number[]; 21 | indices: number[]; 22 | }; 23 | -------------------------------------------------------------------------------- /dist/types/src/utils/generate/generateSimpleGeometry.d.ts: -------------------------------------------------------------------------------- 1 | export declare function createSimpleBox(): { 2 | vertices: number[]; 3 | normals: number[]; 4 | uvs: number[]; 5 | indices: number[]; 6 | }; 7 | export declare function createSimplePlane(): { 8 | vertices: number[]; 9 | normals: number[]; 10 | uvs: number[]; 11 | indices: number[]; 12 | }; 13 | export declare function createSuperSimpleplane(scaleX?: number, scaleY?: number): Float32Array; 14 | -------------------------------------------------------------------------------- /dist/types/utils/common/constants.d.ts: -------------------------------------------------------------------------------- 1 | export declare const FLOAT: number; 2 | export declare const RGB: number; 3 | export declare const NEAREST: number; 4 | export declare const LINEAR: number; 5 | export declare const NEAREST_MIPMAP_NEAREST: number; 6 | export declare const LINEAR_MIPMAP_NEAREST: number; 7 | export declare const NEAREST_MIPMAP_LINEAR: number; 8 | export declare const LINEAR_MIPMAP_LINEAR: number; 9 | export declare const CLAMP_TO_EDGE: number; 10 | export declare const REPEAT: number; 11 | export declare const DEPTH_COMPONENT16: number; 12 | export declare const UNSIGNED_BYTE: number; 13 | export declare const EMPTY_CANVAS_SIZE = 16; 14 | export declare const EMPTY_CANVAS_COLOR = "#ff0000"; 15 | export declare const COLOR_REPEAT = 4; 16 | export declare const UNIFORM_1F = "1f"; 17 | export declare const UNIFORM_1I = "1i"; 18 | export declare const UNIFORM_2F = "2f"; 19 | export declare const UNIFORM_3F = "3f"; 20 | export declare const UNIFORM_MAT_4F = "mat4"; 21 | -------------------------------------------------------------------------------- /dist/types/utils/common/shaders.d.ts: -------------------------------------------------------------------------------- 1 | export declare const fullscreenVertShader = "\nprecision highp float;\n\nattribute vec3 position;\n\nuniform vec2 px;\n\nvarying vec2 vUv;\n\nvoid main(){\n vUv = vec2(0.5)+(position.xy)*0.5;\n gl_Position = vec4(position, 1.0);\n}\n"; 2 | export declare const fillFragShader = "\nprecision highp float;\n\nvarying vec2 vUv;\n\nvoid main(){\n gl_FragColor = vec4(vUv, 0.0, 1.0);\n}\n"; 3 | export declare const texFragShader = "\nprecision highp float;\n\nuniform sampler2D uTexture;\n\nvarying vec2 vUv;\n\nvoid main(){\n vec4 texColor = texture2D(uTexture, vUv);\n gl_FragColor = texColor;\n}\n"; 4 | -------------------------------------------------------------------------------- /dist/types/utils/functions/assets-functions.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * load json with ajax 3 | * 4 | * @param url url to load json file 5 | */ 6 | export declare function getAjaxJson(url: string, callback: Function): void; 7 | /** 8 | * 9 | * @param imageUrl 10 | */ 11 | export declare function getImage(imageUrl: string, callback: Function): void; 12 | /** 13 | * 14 | * @param dracoUrl 15 | * @param callback 16 | * 17 | * https://github.com/kioku-systemk/dracoSample/blob/5611528416d4e0afb10cbec52d70493602d8a552/dracoloader.js#L210 18 | * 19 | */ 20 | export declare function loadDraco(dracoUrl: string, callback: Function): void; 21 | -------------------------------------------------------------------------------- /dist/types/utils/functions/gl-functions.d.ts: -------------------------------------------------------------------------------- 1 | import { vec2, vec3, mat4 } from 'gl-matrix'; 2 | interface IUniformObject { 3 | [key: string]: WebGLUniformLocation; 4 | } 5 | export declare function getUniformLocations(gl: WebGLRenderingContext, program: WebGLProgram, arr: string[]): IUniformObject; 6 | /** 7 | * display error of shader. 8 | * @param text 9 | */ 10 | export declare function addLineNumbers(text: string): string; 11 | /** 12 | * compile webgl shader 13 | * @param gl 14 | * @param glType 15 | * @param shaderSource 16 | */ 17 | export declare function compileGLShader(gl: WebGLRenderingContext, glType: number, shaderSource: string): WebGLShader | undefined; 18 | /** 19 | * 20 | * @param gl 21 | * @param vertexShaderSrc 22 | * @param fragmentShaderSrc 23 | */ 24 | export declare function createProgram(gl: WebGLRenderingContext, vertexShaderSrc: string, fragmentShaderSrc: string): WebGLProgram; 25 | /** 26 | * 27 | * create buffer and get location from program 28 | * 29 | * @param gl 30 | * @param program 31 | * @param data 32 | * @param str 33 | * 34 | * @returns uniformLocation 35 | */ 36 | export declare function createBufferWithLocation(gl: WebGLRenderingContext, program: WebGLProgram, data: Float32Array, str: string): { 37 | buffer: WebGLBuffer | null; 38 | location: number; 39 | }; 40 | /** 41 | * creates and initializes WebGLBuffer with data 42 | * 43 | * @param gl 44 | * @param data 45 | */ 46 | export declare function createBuffer(gl: WebGLRenderingContext, data: Float32Array): WebGLBuffer | null; 47 | /** 48 | * update array buffer 49 | * 50 | * @param gl 51 | * @param buffer 52 | * @param data 53 | * @param isBind 54 | */ 55 | export declare function updateArrayBuffer(gl: WebGLRenderingContext, buffer: WebGLBuffer, data: Float32Array, isBind?: boolean): void; 56 | /** 57 | * 58 | * make index buffer 59 | * 60 | * @param gl 61 | * @param indices 62 | */ 63 | export declare function createIndex(gl: WebGLRenderingContext, indices: Uint16Array | Uint32Array): { 64 | cnt: number; 65 | buffer: WebGLBuffer | null; 66 | }; 67 | /** 68 | * 69 | * @param {WebGLRenderingContext} gl 70 | * @param {WebGLBuffer} buffer 71 | * @param {Number} location 72 | * @param {Number} size 73 | * @param {Boolean} normalized 74 | * @param {Number} stride 75 | * @param {Number} offset 76 | */ 77 | export declare function bindBuffer(gl: WebGLRenderingContext, buffer: WebGLBuffer, location?: number, size?: number, type?: number, normalized?: boolean, stride?: number, offset?: number, isBind?: boolean): void; 78 | export declare function generateFaceFromIndex(vertices: number[], indices: number[]): [vec3, vec3, vec3][]; 79 | export declare function castMouse(mouse: vec2, viewMatrixInverse: mat4, projectionMatrixInverse: mat4, depth?: number): vec3; 80 | export declare function createFrameBufferWithTexture(gl: WebGLRenderingContext, texture: WebGLTexture): WebGLFramebuffer | null; 81 | export declare function createAndBindDepthBuffer(gl: WebGLRenderingContext, width: number, height: number): WebGLRenderbuffer | null; 82 | export declare function addKeyword(sources: string, keywords: string | null): string; 83 | export {}; 84 | -------------------------------------------------------------------------------- /dist/types/utils/functions/gl-textures.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @param gl 4 | * @param textureWidth 5 | * @param textureHeight 6 | * @param format 7 | * @param minFilter 8 | * @param magFilter 9 | * @param wrapS 10 | * @param wrapT 11 | * @param type 12 | */ 13 | export declare function createEmptyTexture(gl: WebGLRenderingContext, textureWidth: number, textureHeight: number, format?: number, minFilter?: number, magFilter?: number, wrapS?: number, wrapT?: number, type?: number): WebGLTexture; 14 | export declare function createImageTexture(gl: WebGLRenderingContext, canvasImage: HTMLImageElement | HTMLCanvasElement, format?: number, isFlip?: boolean, isMipmap?: boolean): WebGLTexture | null; 15 | export declare function createCustomTypeImageTexture(gl: WebGLRenderingContext, canvasImage: HTMLImageElement | HTMLCanvasElement, format: number | undefined, type: number, isFlip?: boolean, isMipmap?: boolean): WebGLTexture | null; 16 | /** 17 | * 18 | * @param gl 19 | * @param texture 20 | * @param image 21 | * @param format 22 | */ 23 | export declare function updateImageTexture(gl: WebGLRenderingContext, texture: WebGLTexture, image: HTMLImageElement, format?: number): void; 24 | export declare function updateEmptyImageTexture(gl: WebGLRenderingContext, texture: WebGLTexture, textureWidth: number, textureHeight: number, format?: number, minFilter?: number, magFilter?: number, wrapS?: number, wrapT?: number, type?: number): WebGLTexture; 25 | /** 26 | * 27 | * @param gl 28 | * @param texture 29 | * @param uniformLocation 30 | * @param textureNum 31 | */ 32 | export declare function activeTexture(gl: WebGLRenderingContext, texture: WebGLTexture, uniformLocation: WebGLUniformLocation, textureNum?: number): void; 33 | -------------------------------------------------------------------------------- /dist/types/utils/generate/generateGeometry.d.ts: -------------------------------------------------------------------------------- 1 | export declare function getSphere(radius?: number, latitudeBands?: number, longitudeBands?: number): { 2 | vertices: number[]; 3 | uvs: number[]; 4 | normals: number[]; 5 | indices: number[]; 6 | }; 7 | export declare function getPlane(width: number, height: number, widthSegment: number, heightSegment: number): { 8 | vertices: number[]; 9 | uvs: number[]; 10 | indices: number[]; 11 | }; 12 | export declare function mergeGeomtory(geometries: { 13 | vertices: number[]; 14 | indices: number[]; 15 | normals: number[]; 16 | uvs: number[]; 17 | }[]): { 18 | vertices: number[]; 19 | normals: number[]; 20 | uvs: number[]; 21 | indices: number[]; 22 | }; 23 | -------------------------------------------------------------------------------- /dist/types/utils/generate/generateSimpleGeometry.d.ts: -------------------------------------------------------------------------------- 1 | export declare function createSimpleBox(): { 2 | vertices: number[]; 3 | normals: number[]; 4 | uvs: number[]; 5 | indices: number[]; 6 | }; 7 | export declare function createSimplePlane(): { 8 | vertices: number[]; 9 | normals: number[]; 10 | uvs: number[]; 11 | indices: number[]; 12 | }; 13 | export declare function createSuperSimpleplane(scaleX?: number, scaleY?: number): Float32Array; 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dan-shari-gl", 3 | "version": "1.3.2", 4 | "description": "minimum webgl framework", 5 | "keywords": [], 6 | "main": "dist/dan-shari-gl.umd.js", 7 | "module": "dist/dan-shari-gl.es5.js", 8 | "types": "dist/types/dan-shari-gl.d.ts", 9 | "files": [ 10 | "dist" 11 | ], 12 | "author": "kenji ", 13 | "repository": { 14 | "type": "git", 15 | "url": "kenjiSpecial/dan-shari-gl" 16 | }, 17 | "license": "MIT", 18 | "engines": { 19 | "node": ">=6.0.0" 20 | }, 21 | "scripts": { 22 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 23 | "prebuild": "rimraf dist", 24 | "build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out site/documents --target es6 --theme minimal --mode file src", 25 | "start": "rollup -c rollup.config.ts -w", 26 | "deploy-docs": "ts-node tools/gh-pages-publish", 27 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 28 | "commit": "git-cz", 29 | "semantic-release": "semantic-release", 30 | "semantic-release-prepare": "ts-node tools/semantic-release-prepare", 31 | "precommit": "lint-staged", 32 | "travis-deploy-once": "travis-deploy-once", 33 | "serve": " http-server -p 9000" 34 | }, 35 | "lint-staged": { 36 | "{src,test}/**/*.ts": [ 37 | "prettier --write", 38 | "git add" 39 | ] 40 | }, 41 | "config": { 42 | "commitizen": { 43 | "path": "node_modules/cz-conventional-changelog" 44 | } 45 | }, 46 | "prettier": { 47 | "semi": true, 48 | "singleQuote": true, 49 | "useTabs": true, 50 | "tabWidth": 4 51 | }, 52 | "commitlint": { 53 | "extends": [ 54 | "@commitlint/config-conventional" 55 | ] 56 | }, 57 | "devDependencies": { 58 | "@commitlint/cli": "^8.1.0", 59 | "@commitlint/config-conventional": "^8.1.0", 60 | "@types/gl-matrix": "^2.4.5", 61 | "@types/node": "^12.6.8", 62 | "colors": "^1.3.2", 63 | "commitizen": "^4.0.3", 64 | "coveralls": "^3.0.5", 65 | "cross-env": "^5.2.0", 66 | "cz-conventional-changelog": "^3.0.2", 67 | "husky": "^3.0.1", 68 | "lint-staged": "^9.2.1", 69 | "lodash.camelcase": "^4.3.0", 70 | "prettier": "^1.18.2", 71 | "prompt": "^1.0.0", 72 | "replace-in-file": "^4.1.1", 73 | "rimraf": "^2.6.2", 74 | "rollup": "^1.17.0", 75 | "rollup-plugin-commonjs": "^10.0.1", 76 | "rollup-plugin-json": "^4.0.0", 77 | "rollup-plugin-node-resolve": "^5.2.0", 78 | "rollup-plugin-sourcemaps": "^0.4.2", 79 | "rollup-plugin-typescript2": "^0.22.1", 80 | "semantic-release": "^15.13.18", 81 | "shelljs": "^0.8.3", 82 | "travis-deploy-once": "^5.0.9", 83 | "ts-jest": "^24.0.2", 84 | "ts-node": "^8.3.0", 85 | "tslint": "^5.18.0", 86 | "tslint-config-prettier": "^1.15.0", 87 | "tslint-config-standard": "^8.0.1", 88 | "typedoc": "^0.15.0", 89 | "typescript": "^3.5.3" 90 | }, 91 | "dependencies": { 92 | "gl-matrix": "^3.0.0" 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /rollup.config.ts: -------------------------------------------------------------------------------- 1 | import resolve from 'rollup-plugin-node-resolve'; 2 | import commonjs from 'rollup-plugin-commonjs'; 3 | import sourceMaps from 'rollup-plugin-sourcemaps'; 4 | import camelCase from 'lodash.camelcase'; 5 | import typescript from 'rollup-plugin-typescript2'; 6 | import json from 'rollup-plugin-json'; 7 | 8 | const pkg = require('./package.json'); 9 | 10 | const librarySrcName = 'dan-shari-gl'; 11 | const libraryName = 'dsr'; 12 | 13 | export default { 14 | input: `src/${librarySrcName}.ts`, 15 | output: [ 16 | { file: pkg.main, name: camelCase(libraryName), format: 'umd', sourcemap: true }, 17 | { file: pkg.module, format: 'es', sourcemap: true } 18 | ], 19 | // Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash') 20 | external: [], 21 | watch: { 22 | include: 'src/**' 23 | }, 24 | plugins: [ 25 | // Allow json resolution 26 | json(), 27 | // Compile TypeScript files 28 | typescript({ useTsconfigDeclarationDir: true }), 29 | // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs) 30 | commonjs(), 31 | // Allow node_modules resolution, so you can use 'external' to control 32 | // which external modules to include in the bundle 33 | // https://github.com/rollup/rollup-plugin-node-resolve#usage 34 | resolve(), 35 | 36 | // Resolve source maps to the original source 37 | sourceMaps() 38 | ] 39 | }; 40 | -------------------------------------------------------------------------------- /site/documents/assets/images/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjiSpecial/dan-shari-gl/61881737aba19e078838b251acbf6858f93d9e3e/site/documents/assets/images/icons.png -------------------------------------------------------------------------------- /site/documents/assets/images/icons@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjiSpecial/dan-shari-gl/61881737aba19e078838b251acbf6858f93d9e3e/site/documents/assets/images/icons@2x.png -------------------------------------------------------------------------------- /site/documents/assets/images/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjiSpecial/dan-shari-gl/61881737aba19e078838b251acbf6858f93d9e3e/site/documents/assets/images/widgets.png -------------------------------------------------------------------------------- /site/documents/assets/images/widgets@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjiSpecial/dan-shari-gl/61881737aba19e078838b251acbf6858f93d9e3e/site/documents/assets/images/widgets@2x.png -------------------------------------------------------------------------------- /site/examples/00-sphere.html: -------------------------------------------------------------------------------- 1 | 2 | DEV 3 | 4 | 5 | 37 | 41 | 42 | 43 |

#00 - rendering sphere

44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 200 | 201 | 202 | 211 | 212 | 213 | -------------------------------------------------------------------------------- /site/examples/assets/draco/dragon.drc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjiSpecial/dan-shari-gl/61881737aba19e078838b251acbf6858f93d9e3e/site/examples/assets/draco/dragon.drc -------------------------------------------------------------------------------- /site/examples/assets/fonts/roboto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjiSpecial/dan-shari-gl/61881737aba19e078838b251acbf6858f93d9e3e/site/examples/assets/fonts/roboto.png -------------------------------------------------------------------------------- /site/examples/assets/images/shari.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjiSpecial/dan-shari-gl/61881737aba19e078838b251acbf6858f93d9e3e/site/examples/assets/images/shari.jpg -------------------------------------------------------------------------------- /site/examples/vendors/parser.js: -------------------------------------------------------------------------------- 1 | // yarn start -f your_file -p 2 2 | // parse obj file with index attributes 3 | 4 | var fs = require('fs'); 5 | var parseOBJ = require('parse-obj'); 6 | var argv = require('minimist')(process.argv.slice(2)); 7 | 8 | var fileName = argv.f; 9 | var precisoin = argv.p; 10 | 11 | if (precisoin < 0 || !precisoin) { 12 | precision = 3; 13 | } 14 | 15 | if (!fileName) { 16 | console.log('you missed fileName. yarn start -f your_file -p detail_of_number'); 17 | return; 18 | } 19 | 20 | parseOBJ(fs.createReadStream(`./obj-parser/obj/${fileName}.obj`), function(err, result) { 21 | if (err) { 22 | throw new Error('Error parsing OBJ file: ' + err); 23 | } 24 | 25 | var dataObj = {}; 26 | updateVertex(result, dataObj); 27 | updateNormals(result, dataObj); 28 | updateUvs(result, dataObj); 29 | updateIndex(result, dataObj); 30 | 31 | writeObjFile(dataObj); 32 | }); 33 | function updateVertex(result, dataObj) { 34 | if (result.vertexPositions.length == 0) return; 35 | 36 | dataObj.verts = []; 37 | 38 | for (let ii = 0; ii < result.facePositions.length; ii++) { 39 | for (let jj = 0, length = result.facePositions[ii].length - 2; jj < length; jj++) { 40 | // dataObj.index[ii][jj] = Number(dataObj.index[ii][jj].toFixed(precisoin)); 41 | let index0 = (0 + jj * 2) % result.facePositions[ii].length; 42 | let index1 = (1 + jj * 2) % result.facePositions[ii].length; 43 | let index2 = (2 + jj * 2) % result.facePositions[ii].length; 44 | 45 | let faceIndex0 = result.facePositions[ii][index0]; 46 | let faceIndex1 = result.facePositions[ii][index1]; 47 | let faceIndex2 = result.facePositions[ii][index2]; 48 | 49 | let pos0 = result.vertexPositions[faceIndex0]; 50 | let pos1 = result.vertexPositions[faceIndex1]; 51 | let pos2 = result.vertexPositions[faceIndex2]; 52 | 53 | dataObj.verts.push( 54 | Number(pos0[0].toFixed(precision)), 55 | Number(pos0[1].toFixed(precision)), 56 | Number(pos0[2].toFixed(precision)), 57 | Number(pos1[0].toFixed(precision)), 58 | Number(pos1[1].toFixed(precision)), 59 | Number(pos1[2].toFixed(precision)), 60 | Number(pos2[0].toFixed(precision)), 61 | Number(pos2[1].toFixed(precision)), 62 | Number(pos2[2].toFixed(precision)) 63 | ); 64 | } 65 | } 66 | } 67 | 68 | function updateNormals(result, dataObj) { 69 | if (result.vertexNormals.length == 0) return; 70 | 71 | dataObj.normals = []; 72 | 73 | for (let ii = 0; ii < result.faceNormals.length; ii++) { 74 | for (let jj = 0, length = result.faceNormals[ii].length - 2; jj < length; jj++) { 75 | // dataObj.index[ii][jj] = Number(dataObj.index[ii][jj].toFixed(precisoin)); 76 | let index0 = (0 + jj * 2) % result.faceNormals[ii].length; 77 | let index1 = (1 + jj * 2) % result.faceNormals[ii].length; 78 | let index2 = (2 + jj * 2) % result.faceNormals[ii].length; 79 | 80 | let faceIndex0 = result.faceNormals[ii][index0]; 81 | let faceIndex1 = result.faceNormals[ii][index1]; 82 | let faceIndex2 = result.faceNormals[ii][index2]; 83 | 84 | let pos0 = result.vertexNormals[faceIndex0]; 85 | let pos1 = result.vertexNormals[faceIndex1]; 86 | let pos2 = result.vertexNormals[faceIndex2]; 87 | 88 | // dataObj.normals.push(pos0[0], pos0[1], pos0[2], pos1[0], pos1[1], pos1[2], pos2[0], pos2[1], pos2[2]); 89 | dataObj.normals.push( 90 | Number(pos0[0].toFixed(precision)), 91 | Number(pos0[1].toFixed(precision)), 92 | Number(pos0[2].toFixed(precision)), 93 | Number(pos1[0].toFixed(precision)), 94 | Number(pos1[1].toFixed(precision)), 95 | Number(pos1[2].toFixed(precision)), 96 | Number(pos2[0].toFixed(precision)), 97 | Number(pos2[1].toFixed(precision)), 98 | Number(pos2[2].toFixed(precision)) 99 | ); 100 | } 101 | } 102 | } 103 | 104 | function updateUvs(result, dataObj) { 105 | // dataObj 106 | if (result.vertexUVs.length == 0) return; 107 | 108 | dataObj.texcoords = []; 109 | 110 | for (let ii = 0; ii < result.faceUVs.length; ii++) { 111 | for (let jj = 0, length = result.faceUVs[ii].length - 2; jj < length; jj++) { 112 | // dataObj.index[ii][jj] = Number(dataObj.index[ii][jj].toFixed(precisoin)); 113 | let index0 = (0 + jj * 2) % result.faceUVs[ii].length; 114 | let index1 = (1 + jj * 2) % result.faceUVs[ii].length; 115 | let index2 = (2 + jj * 2) % result.faceUVs[ii].length; 116 | 117 | let faceIndex0 = result.faceUVs[ii][index0]; 118 | let faceIndex1 = result.faceUVs[ii][index1]; 119 | let faceIndex2 = result.faceUVs[ii][index2]; 120 | 121 | let pos0 = result.vertexUVs[faceIndex0]; 122 | let pos1 = result.vertexUVs[faceIndex1]; 123 | let pos2 = result.vertexUVs[faceIndex2]; 124 | 125 | // dataObj.texcoords.push(pos0[0], pos0[1], pos1[0], pos1[1], pos2[0], pos2[1]); 126 | dataObj.texcoords.push( 127 | Number(pos0[0].toFixed(precision)), 128 | Number(pos0[1].toFixed(precision)), 129 | Number(pos1[0].toFixed(precision)), 130 | Number(pos1[1].toFixed(precision)), 131 | Number(pos2[0].toFixed(precision)), 132 | Number(pos2[1].toFixed(precision)) 133 | ); 134 | } 135 | } 136 | } 137 | 138 | function updateIndex(result, dataObj) { 139 | dataObj.indices = []; 140 | 141 | for (let ii = 0; ii < result.facePositions.length; ii++) { 142 | let cnt; 143 | if (result.facePositions[ii].length === 3) cnt = 3; 144 | else cnt = 6; 145 | 146 | for (let jj = 0; jj < cnt; jj++) { 147 | dataObj.indices.push(dataObj.indices.length); 148 | } 149 | } 150 | } 151 | 152 | function writeObjFile(dataObj) { 153 | const content = JSON.stringify(dataObj); 154 | 155 | fs.writeFile(`./examples/assets/data/${fileName}.json`, content, 'utf8', function(err) { 156 | if (err) { 157 | return console.log(err); 158 | } 159 | 160 | console.log('json file was saved.'); 161 | }); 162 | } 163 | -------------------------------------------------------------------------------- /site/examples/vendors/stats.min.js: -------------------------------------------------------------------------------- 1 | // stats.js - http://github.com/mrdoob/stats.js 2 | (function(f,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"===typeof define&&define.amd?define(e):f.Stats=e()})(this,function(){var f=function(){function e(a){c.appendChild(a.dom);return a}function u(a){for(var d=0;dg+1E3&&(r.update(1E3*a/(c-g),100),g=c,a=0,t)){var d=performance.memory;t.update(d.usedJSHeapSize/ 4 | 1048576,d.jsHeapSizeLimit/1048576)}return c},update:function(){k=this.end()},domElement:c,setMode:u}};f.Panel=function(e,f,l){var c=Infinity,k=0,g=Math.round,a=g(window.devicePixelRatio||1),r=80*a,h=48*a,t=3*a,v=2*a,d=3*a,m=15*a,n=74*a,p=30*a,q=document.createElement("canvas");q.width=r;q.height=h;q.style.cssText="width:80px;height:48px";var b=q.getContext("2d");b.font="bold "+9*a+"px Helvetica,Arial,sans-serif";b.textBaseline="top";b.fillStyle=l;b.fillRect(0,0,r,h);b.fillStyle=f;b.fillText(e,t,v); 5 | b.fillRect(d,m,n,p);b.fillStyle=l;b.globalAlpha=.9;b.fillRect(d,m,n,p);return{dom:q,update:function(h,w){c=Math.min(c,h);k=Math.max(k,h);b.fillStyle=l;b.globalAlpha=1;b.fillRect(0,0,r,m);b.fillStyle=f;b.fillText(g(h)+" "+e+" ("+g(c)+"-"+g(k)+")",t,v);b.drawImage(q,d+a,m,n-a,p,d,m,n-a,p);b.fillRect(d+n-a,m,a,p);b.fillStyle=l;b.globalAlpha=.9;b.fillRect(d+n-a,m,a,g((1-h/w)*p))}}};return f}); 6 | -------------------------------------------------------------------------------- /site/index.md: -------------------------------------------------------------------------------- 1 | - [Documents](https://kenjispecial.github.io/dan-shari-gl/documents/) 2 | - [Examples](https://kenjispecial.github.io/dan-shari-gl/examples/) 3 | - Tutorials 4 | -------------------------------------------------------------------------------- /site/sketches/index.html: -------------------------------------------------------------------------------- 1 | 2 | DEV 3 | 4 | 5 | 6 | 7 | 124 | 128 | 129 | 130 | 131 | 132 |
133 |
134 |

DanShaRiGL Tutorial

135 |
断捨離GLチュートリアル
136 | 137 |

Geometry

138 | 141 | 142 | 143 |

144 | 145 | 148 | 163 | 164 | Sketches 165 |

166 | 167 | 168 |
169 |
170 | 171 | 172 | 173 | 174 | 175 | 267 | 268 | 269 | 278 | 279 | -------------------------------------------------------------------------------- /site/tutorials/00-triangle.html: -------------------------------------------------------------------------------- 1 | 2 | DEV 3 | 4 | 5 | 37 | 41 | 42 | 43 |

#00 - rendering sphere

44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 200 | 201 | 202 | 211 | 212 | 213 | -------------------------------------------------------------------------------- /site/tutorials/index.html: -------------------------------------------------------------------------------- 1 | 2 | DEV 3 | 4 | 5 | 6 | 7 | 124 | 128 | 129 | 130 | 131 | 132 |
133 |
134 |

DanShaRiGL Tutorial

135 |
断捨離GLチュートリアル
136 | 137 |

Geometry

138 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
148 |
149 | 150 | 151 | 152 | 153 | 154 | 246 | 247 | 248 | 257 | 258 | -------------------------------------------------------------------------------- /src/camera/camera.ts: -------------------------------------------------------------------------------- 1 | import { mat4 } from 'gl-matrix'; 2 | import { Vector3 } from '../interfaces/interface'; 3 | 4 | export class Camera { 5 | public type: string; 6 | public position: Vector3 = { x: 0, y: 0, z: 0 }; 7 | public lookAtPosition: Vector3 = { x: 0, y: 0, z: 0 }; 8 | public viewMatrix: mat4 = mat4.create(); 9 | public viewMatrixInverse: mat4 = mat4.create(); 10 | public projectionMatrix: mat4 = mat4.create(); 11 | public projectionMatrixInverse: mat4 = mat4.create(); 12 | 13 | constructor(type: string = 'camera') { 14 | this.type = type; 15 | } 16 | 17 | public updatePosition(xx = 0, yy = 0, zz = 0) { 18 | this.position.x = xx; 19 | this.position.y = yy; 20 | this.position.z = zz; 21 | } 22 | 23 | public updateLookAtPosition(xx = 0, yy = 0, zz = -100) { 24 | this.lookAtPosition.x = xx; 25 | this.lookAtPosition.y = yy; 26 | this.lookAtPosition.z = zz; 27 | } 28 | 29 | public updateViewMatrix() { 30 | mat4.lookAt( 31 | this.viewMatrix, 32 | [this.position.x, this.position.y, this.position.z], 33 | [this.lookAtPosition.x, this.lookAtPosition.y, this.lookAtPosition.z], 34 | [0, 1, 0] 35 | ); 36 | 37 | mat4.invert(this.viewMatrixInverse, this.viewMatrix); 38 | } 39 | } 40 | 41 | // --------------------- 42 | 43 | export class PerspectiveCamera extends Camera { 44 | private width: number; 45 | private height: number; 46 | private fov: number; 47 | private near: number; 48 | private far: number; 49 | 50 | constructor( 51 | width: number, 52 | height: number, 53 | fov: number = 45, 54 | near: number = 0.1, 55 | far: number = 1000 56 | ) { 57 | super('perspective'); 58 | 59 | this.width = width; 60 | this.height = height; 61 | this.fov = fov; 62 | this.near = near; 63 | this.far = far; 64 | 65 | this.updatePerspective(); 66 | } 67 | 68 | public updatePerspective() { 69 | mat4.perspective( 70 | this.projectionMatrix, 71 | (this.fov / 180) * Math.PI, 72 | this.width / this.height, 73 | this.near, 74 | this.far 75 | ); 76 | 77 | mat4.invert(this.projectionMatrixInverse, this.projectionMatrix); 78 | } 79 | 80 | public updateSize(width: number, height: number) { 81 | this.width = width; 82 | this.height = height; 83 | 84 | this.updatePerspective(); 85 | } 86 | 87 | public updateFocus(near: number, far: number) { 88 | if (near) this.near = near; 89 | if (far) this.far = far; 90 | 91 | this.updatePerspective(); 92 | } 93 | 94 | public updatefov(angle: number) { 95 | this.fov = angle; 96 | 97 | this.updatePerspective(); 98 | } 99 | } 100 | 101 | // --------------------- 102 | 103 | export class OrthoCamera extends Camera { 104 | private left: number; 105 | private right: number; 106 | private bottom: number; 107 | private top: number; 108 | private near: number; 109 | private far: number; 110 | 111 | constructor( 112 | left: number, 113 | right: number, 114 | bottom: number, 115 | top: number, 116 | near: number, 117 | far: number 118 | ) { 119 | super('ortho'); 120 | 121 | this.left = left; 122 | this.right = right; 123 | this.bottom = bottom; 124 | this.top = top; 125 | this.near = near; 126 | this.far = far; 127 | 128 | this.updatePerspective(); 129 | } 130 | 131 | public updateSize(left: number, right: number, bottom: number, top: number) { 132 | this.left = left; 133 | this.right = right; 134 | this.bottom = bottom; 135 | this.top = top; 136 | 137 | this.updatePerspective(); 138 | } 139 | 140 | public updateFocus(near: number, far: number) { 141 | if (near) this.near = near; 142 | if (far) this.far = far; 143 | 144 | this.updatePerspective(); 145 | } 146 | 147 | public updatePerspective() { 148 | mat4.ortho( 149 | this.projectionMatrix, 150 | this.left, 151 | this.right, 152 | this.bottom, 153 | this.top, 154 | this.near, 155 | this.far 156 | ); 157 | 158 | mat4.invert(this.projectionMatrixInverse, this.projectionMatrix); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/dan-shari-gl.ts: -------------------------------------------------------------------------------- 1 | export * from './utils/functions/gl-functions'; 2 | export * from './utils/functions/gl-textures'; 3 | export * from './utils/functions/assets-functions'; 4 | 5 | export * from './utils/generate/generateGeometry'; 6 | export * from './utils/generate/generateSimpleGeometry'; 7 | 8 | export * from './utils/common/constants'; 9 | export * from './utils/common/shaders'; 10 | 11 | export * from './math/math'; 12 | export * from './math/ray'; 13 | 14 | export * from './camera/camera'; 15 | 16 | // sub compoents 17 | export * from './extra/cameracontroller'; 18 | export * from './extra/textLayout'; 19 | export * from './extra/textRendering'; 20 | export * from './extra/TexturePool'; 21 | export * from './extra/swapRenderer'; 22 | export * from './extra/fbo'; 23 | -------------------------------------------------------------------------------- /src/extra/TexturePool.ts: -------------------------------------------------------------------------------- 1 | import { createImageTexture } from '../utils/functions/gl-textures'; 2 | import { EMPTY_CANVAS_SIZE, EMPTY_CANVAS_COLOR, COLOR_REPEAT } from '../utils/common/constants'; 3 | 4 | export class TexturePools { 5 | private static instance: TexturePools; 6 | public textures: { [key: string]: WebGLTexture } = {}; 7 | private gl!: WebGLRenderingContext; 8 | private constructor() {} 9 | 10 | public static GET_INSTANCE() { 11 | if (!TexturePools.instance) { 12 | TexturePools.instance = new TexturePools(); 13 | // ... any one time initialization goes here ... 14 | } 15 | 16 | return TexturePools.instance; 17 | } 18 | 19 | public static GET_TEXTURE(name: string) { 20 | return TexturePools.instance.textures[name]; 21 | } 22 | 23 | public setGL(gl: WebGLRenderingContext) { 24 | this.gl = gl; 25 | this.setImage('empty', this.createEmptyCanvas()); 26 | } 27 | 28 | public setImage(name: string, element: HTMLImageElement | HTMLCanvasElement) { 29 | const texture = createImageTexture(this.gl, element) as WebGLTexture; 30 | this.textures[name] = texture; 31 | } 32 | 33 | private createEmptyCanvas() { 34 | const canvas = document.createElement('canvas'); 35 | canvas.width = EMPTY_CANVAS_SIZE; 36 | canvas.height = EMPTY_CANVAS_SIZE; 37 | const ctx = canvas.getContext('2d') as CanvasRenderingContext2D; 38 | ctx.fillStyle = '#ffffff'; 39 | ctx.fillRect(0, 0, EMPTY_CANVAS_SIZE, EMPTY_CANVAS_SIZE); 40 | ctx.fillStyle = EMPTY_CANVAS_COLOR; 41 | let cnt = 0; 42 | const unitWidthSize = EMPTY_CANVAS_SIZE / COLOR_REPEAT; 43 | for (let xx = 0; xx < COLOR_REPEAT; xx = xx + 1) { 44 | for (let yy = 0; yy < COLOR_REPEAT; yy = yy + 1) { 45 | if (cnt % 2 === 0) { 46 | const xpos = xx * unitWidthSize; 47 | const ypos = yy * unitWidthSize; 48 | ctx.fillRect(xpos, ypos, unitWidthSize, unitWidthSize); 49 | } 50 | cnt = cnt + 1; 51 | } 52 | } 53 | 54 | return canvas; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/extra/fbo.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createImageTexture, 3 | createEmptyTexture, 4 | updateEmptyImageTexture 5 | } from '../utils/functions/gl-textures'; 6 | export class FBO { 7 | private gl: WebGLRenderingContext; 8 | private width: number; 9 | private height: number; 10 | private buffer: WebGLFramebuffer | null; 11 | private texture: WebGLTexture | null; 12 | private depth?: WebGLRenderbuffer | null; 13 | 14 | constructor( 15 | gl: WebGLRenderingContext, 16 | width: number, 17 | height: number, 18 | texture?: WebGLTexture | null, 19 | isDepthNeed: boolean = false 20 | ) { 21 | this.gl = gl; 22 | this.width = width; 23 | this.height = height; 24 | this.texture = 25 | texture === undefined || texture === null 26 | ? createEmptyTexture(this.gl, width, height) 27 | : texture; 28 | 29 | this.buffer = this.gl.createFramebuffer(); 30 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.buffer); 31 | this.bindTex(); 32 | 33 | if (isDepthNeed) { 34 | this.createDepth(); 35 | this.updateDepth(); 36 | } 37 | } 38 | 39 | private bindTex() { 40 | this.gl.framebufferTexture2D( 41 | this.gl.FRAMEBUFFER, 42 | this.gl.COLOR_ATTACHMENT0, 43 | this.gl.TEXTURE_2D, 44 | this.texture, 45 | 0 46 | ); 47 | } 48 | 49 | private createDepth() { 50 | this.depth = this.gl.createRenderbuffer(); 51 | } 52 | 53 | private updateDepth() { 54 | this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, this.depth as WebGLRenderbuffer); 55 | this.gl.renderbufferStorage( 56 | this.gl.RENDERBUFFER, 57 | this.gl.DEPTH_COMPONENT16, 58 | this.width, 59 | this.height 60 | ); 61 | this.gl.framebufferRenderbuffer( 62 | this.gl.FRAMEBUFFER, 63 | this.gl.DEPTH_ATTACHMENT, 64 | this.gl.RENDERBUFFER, 65 | this.depth as WebGLRenderbuffer 66 | ); 67 | } 68 | 69 | public bind() { 70 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.buffer); 71 | } 72 | 73 | public unbind() { 74 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null); 75 | } 76 | 77 | public resize(width: number, height: number, texture?: WebGLTexture) { 78 | this.width = width; 79 | this.height = height; 80 | 81 | this.bind(); 82 | 83 | updateEmptyImageTexture(this.gl, this.texture as WebGLTexture, width, height); 84 | this.bindTex(); 85 | this.updateDepth(); 86 | } 87 | 88 | public getTexture() { 89 | return this.texture; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/extra/swapRenderer.ts: -------------------------------------------------------------------------------- 1 | import { createProgram } from '../utils/functions/gl-functions'; 2 | 3 | import { 4 | createEmptyTexture, 5 | createImageTexture, 6 | createCustomTypeImageTexture 7 | } from '../utils/functions/gl-textures'; 8 | import { 9 | RGB, 10 | LINEAR, 11 | CLAMP_TO_EDGE, 12 | UNIFORM_1F, 13 | UNIFORM_2F, 14 | UNIFORM_3F, 15 | UNIFORM_1I, 16 | UNIFORM_MAT_4F 17 | } from '../utils/common/constants'; 18 | import { createSuperSimpleplane } from '../utils/generate/generateSimpleGeometry'; 19 | 20 | export class SwapRenderer { 21 | private gl: WebGLRenderingContext; 22 | 23 | private textures: { 24 | [key: string]: WebGLTexture | null; 25 | } = {}; 26 | 27 | private framebuffers: { 28 | [key: string]: WebGLFramebuffer | null; 29 | } = {}; 30 | 31 | private programs: { 32 | [key: string]: { 33 | id: WebGLProgram; 34 | uniforms: { [key: string]: WebGLUniformLocation | null }; 35 | }; 36 | } = {}; 37 | 38 | private positionVbos: { 39 | [key: string]: WebGLBuffer | null; 40 | } = {}; 41 | 42 | constructor(gl: WebGLRenderingContext) { 43 | this.gl = gl; 44 | } 45 | 46 | public setSize(width: number, height: number) { 47 | this.gl.viewport(0, 0, width, height); 48 | } 49 | 50 | public createProgram(programName: string, vertexShader: string, fragmentShader: string) { 51 | const program = createProgram(this.gl, vertexShader, fragmentShader); 52 | 53 | this.gl.useProgram(program); 54 | 55 | this.programs[programName] = { 56 | id: program, 57 | uniforms: {} 58 | }; 59 | } 60 | 61 | public initTexture(name: string, width: number, height: number, type: number) { 62 | const texture = createEmptyTexture( 63 | this.gl, 64 | width, 65 | height, 66 | RGB, 67 | LINEAR, 68 | LINEAR, 69 | CLAMP_TO_EDGE, 70 | CLAMP_TO_EDGE, 71 | type 72 | ); 73 | 74 | this.textures[name] = texture; 75 | } 76 | 77 | public initTextureWithImage(name: string, type: number, image: HTMLImageElement) { 78 | const texture = createCustomTypeImageTexture(this.gl, image, this.gl.RGB, type, true); 79 | 80 | this.textures[name] = texture; 81 | } 82 | 83 | public initFramebufferForTexture(textureName: string) { 84 | const texture = this.textures[textureName]; 85 | const framebuffer = this.gl.createFramebuffer(); 86 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, framebuffer); 87 | this.gl.framebufferTexture2D( 88 | this.gl.FRAMEBUFFER, 89 | this.gl.COLOR_ATTACHMENT0, 90 | this.gl.TEXTURE_2D, 91 | texture, 92 | 0 93 | ); 94 | 95 | this.framebuffers[textureName] = framebuffer; 96 | } 97 | 98 | public initDepthTexture(width: number, height: number) { 99 | const depth = this.gl.createRenderbuffer(); 100 | this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, depth); 101 | this.gl.renderbufferStorage(this.gl.RENDERBUFFER, this.gl.DEPTH_COMPONENT16, width, height); 102 | } 103 | 104 | public setProgram(programName: string) { 105 | this.gl.useProgram(this.programs[programName].id); 106 | } 107 | 108 | public use(programName: string) { 109 | this.gl.useProgram(this.programs[programName].id); 110 | } 111 | 112 | public getProgram(programName: string) { 113 | return this.programs[programName].id; 114 | } 115 | 116 | public createPositionVBO(name: string, scaleX: number = 1, scaleY: number = 1) { 117 | const buffer = this.gl.createBuffer(); 118 | this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer); 119 | this.gl.bufferData( 120 | this.gl.ARRAY_BUFFER, 121 | createSuperSimpleplane(scaleX, scaleY), 122 | this.gl.STATIC_DRAW 123 | ); 124 | 125 | this.positionVbos[name] = buffer; 126 | } 127 | 128 | public usePositionVBO() { 129 | const location = 0; 130 | this.gl.enableVertexAttribArray(location); 131 | this.gl.vertexAttribPointer(location, 2, this.gl.FLOAT, false, 0, 0); 132 | } 133 | 134 | public updateVBO(name: string) { 135 | const buffer = this.positionVbos[name]; 136 | this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer); 137 | this.usePositionVBO(); 138 | } 139 | 140 | public run(programName: string, inputNameArr: string[], outputName: string) { 141 | this.use(programName); 142 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.framebuffers[outputName]); 143 | for (let ii = 0; ii < inputNameArr.length; ii = ii + 1) { 144 | const inputName = inputNameArr[ii]; 145 | this.gl.activeTexture(this.gl.TEXTURE0 + ii); 146 | this.gl.bindTexture(this.gl.TEXTURE_2D, this.textures[inputName]); 147 | } 148 | 149 | this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, 4); 150 | } 151 | 152 | public swapTextures(texture1Name: string, texture2Name: string) { 153 | let tempTex = this.textures[texture1Name]; 154 | this.textures[texture1Name] = this.textures[texture2Name]; 155 | this.textures[texture2Name] = tempTex; 156 | 157 | const tempFBO = this.framebuffers[texture1Name]; 158 | this.framebuffers[texture1Name] = this.framebuffers[texture2Name]; 159 | this.framebuffers[texture2Name] = tempFBO; 160 | } 161 | 162 | public setUniform( 163 | programName: string, 164 | name: string, 165 | val: number | number[] | Float32List, 166 | type: string 167 | ) { 168 | let uniforms = this.programs[programName].uniforms; 169 | // console.log(this.programs[programName].uniforms); 170 | let location = uniforms[name]; 171 | if (!location) { 172 | location = this.gl.getUniformLocation(this.programs[programName].id, name); 173 | uniforms[name] = location; 174 | 175 | if (!location) { 176 | console.warn({ programName, name }); 177 | } 178 | } 179 | 180 | if (type === UNIFORM_1F) this.gl.uniform1f(location, val as number); 181 | else if (type === UNIFORM_2F) { 182 | val = val as number[]; 183 | this.gl.uniform2f(location, val[0], val[1]); 184 | } else if (type === UNIFORM_3F) { 185 | val = val as number[]; 186 | this.gl.uniform3f(location, val[0], val[1], val[2]); 187 | } else if (type === UNIFORM_1I) { 188 | this.gl.uniform1i(location, val as number); 189 | } else if (type === UNIFORM_MAT_4F) { 190 | this.gl.uniformMatrix4fv(location, false, val as Float32List); 191 | } else { 192 | console.warn('no uniform for type ' + type); 193 | } 194 | } 195 | 196 | public reset() { 197 | this.programs = {}; 198 | this.framebuffers = {}; 199 | this.textures = {}; 200 | this.positionVbos = {}; 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /src/extra/textRendering.ts: -------------------------------------------------------------------------------- 1 | export class TextRendering { 2 | public vertices: Float32Array; 3 | public uvs: Float32Array; 4 | public indices: Uint16Array; 5 | constructor(gl: WebGLRenderingContext, textLayout: any, bitmapImage: any) { 6 | const vertices: number[] = []; 7 | const uvs: number[] = []; 8 | const indices: number[] = []; 9 | 10 | let imageWidth = bitmapImage.width; 11 | let imageHeight = bitmapImage.height; 12 | 13 | textLayout.glyphs.forEach((glyph: any, index: any) => { 14 | let bitmap = glyph.data; 15 | let [xx, yy] = glyph.position; 16 | 17 | let startX = xx + bitmap.xoffset - textLayout.width / 2; 18 | let endX = startX + bitmap.width; 19 | let startY = -1 * (yy + bitmap.yoffset + textLayout.height / 2); 20 | let endY = startY - bitmap.height; 21 | 22 | let startUVX = bitmap.x / imageWidth; 23 | let endUVX = startUVX + bitmap.width / imageWidth; 24 | let startUVY = 1 - bitmap.y / imageHeight; 25 | let endUVY = 1 - (bitmap.y + bitmap.height) / imageHeight; 26 | 27 | vertices.push(startX, startY, endX, startY, endX, endY, startX, endY); 28 | uvs.push(startUVX, startUVY, endUVX, startUVY, endUVX, endUVY, startUVX, endUVY); 29 | let lastIndex = 4 * index; 30 | indices.push( 31 | 0 + lastIndex, 32 | 2 + lastIndex, 33 | 1 + lastIndex, 34 | 0 + lastIndex, 35 | 3 + lastIndex, 36 | 2 + lastIndex 37 | ); 38 | }); 39 | 40 | this.vertices = new Float32Array(vertices); 41 | this.uvs = new Float32Array(uvs); 42 | this.indices = new Uint16Array(indices); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/interfaces/interface.ts: -------------------------------------------------------------------------------- 1 | export interface Vector3 { 2 | x: number; 3 | y: number; 4 | z: number; 5 | } 6 | 7 | export interface Box { 8 | max: Vector3; 9 | min: Vector3; 10 | } 11 | -------------------------------------------------------------------------------- /src/math/math.ts: -------------------------------------------------------------------------------- 1 | import { Vector3 } from '../interfaces/interface'; 2 | export function clamp(value: number, min: number, max: number) { 3 | return Math.min(Math.max(value, min), max); 4 | } 5 | 6 | export function range(min: number, max: number) { 7 | return (max - min) * Math.random() + min; 8 | } 9 | 10 | // https://stackoverflow.com/questions/32861804/how-to-calculate-the-centre-point-of-a-circle-given-three-points 11 | export function calculateCircleCenter(A: Vector3, B: Vector3, C: Vector3) { 12 | const yDeltaA = B.y - A.y; 13 | const xDeltaA = B.x - A.x; 14 | const yDeltaB = C.y - B.y; 15 | const xDeltaB = C.x - B.x; 16 | 17 | let center = { x: 0, y: 0, z: 0 }; 18 | 19 | const aSlope = yDeltaA / xDeltaA; 20 | const bSlope = yDeltaB / xDeltaB; 21 | 22 | center.x = 23 | (aSlope * bSlope * (A.y - C.y) + bSlope * (A.x + B.x) - aSlope * (B.x + C.x)) / 24 | (2 * (bSlope - aSlope)); 25 | center.y = (-1 * (center.x - (A.x + B.x) / 2)) / aSlope + (A.y + B.y) / 2; 26 | 27 | return center; 28 | } 29 | 30 | export function mix(x: number, y: number, a: number) { 31 | return x * (1 - a) + y * a; 32 | } 33 | 34 | export function degToRad(value: number) { 35 | // Math.PI / 180 = 0.017453292519943295 36 | return value * 0.017453292519943295; 37 | } 38 | 39 | export function radToDeg(value: number) { 40 | // 180 / Math.PI = 57.29577951308232 41 | return 57.29577951308232 * value; 42 | } 43 | -------------------------------------------------------------------------------- /src/math/ray.ts: -------------------------------------------------------------------------------- 1 | import { vec3, mat4, mat3 } from 'gl-matrix'; 2 | import { Box, Vector3 } from '../interfaces/interface'; 3 | 4 | export class Ray { 5 | private isPrev: boolean = false; 6 | private orig: vec3 = vec3.create(); 7 | private dir: vec3 = vec3.create(); 8 | private worldMatrix3Inv: mat3 = mat3.create(); 9 | 10 | intersect(box: Box) { 11 | let { min, max } = box; 12 | 13 | let tmin = (min.x - this.orig[0]) / this.dir[0]; 14 | let tmax = (max.x - this.orig[0]) / this.dir[0]; 15 | 16 | let minY = tmin * this.dir[1] + this.orig[1]; 17 | let maxY = tmax * this.dir[1] + this.orig[1]; 18 | 19 | if (minY > maxY) { 20 | let { minVal, maxVal } = this.swap(minY, maxY); 21 | minY = minVal; 22 | maxY = maxVal; 23 | } 24 | if (minY > max.y || maxY < min.y) { 25 | return false; 26 | } 27 | 28 | let minZ = tmin * this.dir[2] + this.orig[2]; 29 | let maxZ = tmax * this.dir[2] + this.orig[2]; 30 | 31 | if (minZ > maxZ) { 32 | let { minVal, maxVal } = this.swap(minZ, maxZ); 33 | minZ = minVal; 34 | maxZ = maxVal; 35 | } 36 | 37 | if (minZ > max.z || maxZ < min.z) { 38 | return false; 39 | } 40 | 41 | this.isPrev = true; 42 | 43 | return { tmin, tmax }; 44 | } 45 | 46 | rayCast(faces: [vec3, vec3, vec3][], worldMatrixInv: mat4) { 47 | const transDir = vec3.create(); 48 | const transOrig = vec3.create(); 49 | 50 | mat3.fromMat4(this.worldMatrix3Inv, worldMatrixInv); 51 | vec3.transformMat3(transDir, this.dir, this.worldMatrix3Inv); 52 | vec3.normalize(transDir, transDir); 53 | vec3.transformMat4(transOrig, this.orig, worldMatrixInv); 54 | 55 | return this.intersectFaces(faces, transDir, transOrig); 56 | } 57 | 58 | intersectFaces(faces: [vec3, vec3, vec3][], dir: vec3, orig: vec3) { 59 | let intersectFace; 60 | for (let ii = 0; ii < faces.length; ii++) { 61 | let pts = faces[ii]; 62 | let intersect = this.intersectPts(pts[0], pts[1], pts[2], dir, orig); 63 | if (intersect) { 64 | if (!intersectFace || intersectFace.t > intersect.t) intersectFace = intersect; 65 | } 66 | } 67 | 68 | return intersectFace; 69 | } 70 | 71 | // https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/ray-triangle-intersection-geometric-solution 72 | // https://stackoverflow.com/questions/42740765/intersection-between-line-and-triangle-in-3d 73 | 74 | intersectPts(pt0: vec3, pt1: vec3, pt2: vec3, dir: vec3, orig: vec3) { 75 | let dir0Vec = vec3.create(); 76 | let dir1Vec = vec3.create(); 77 | let nVec = vec3.create(); 78 | 79 | vec3.subtract(dir0Vec, pt1, pt0); 80 | vec3.subtract(dir1Vec, pt2, pt0); 81 | vec3.cross(nVec, dir0Vec, dir1Vec); 82 | let D = -this.dot(nVec, pt0); 83 | 84 | if (Math.abs(this.dot(dir, nVec)) < Number.EPSILON) return false; 85 | 86 | let t = -(this.dot(nVec, orig) + D) / this.dot(nVec, dir); 87 | let intersectPt = [dir[0] * t + orig[0], dir[1] * t + orig[1], dir[2] * t + orig[2]]; 88 | 89 | let dir0 = [pt1[0] - pt0[0], pt1[1] - pt0[1], pt1[2] - pt0[2]]; 90 | let intersectPt0 = [ 91 | intersectPt[0] - pt0[0], 92 | intersectPt[1] - pt0[1], 93 | intersectPt[2] - pt0[2] 94 | ]; 95 | let dotProduct0Vec = vec3.create(); 96 | vec3.cross(dotProduct0Vec, dir0, intersectPt0); 97 | let judge0 = this.dot(dotProduct0Vec, nVec); 98 | if (judge0 < 0) return false; 99 | 100 | let dir1 = [pt2[0] - pt1[0], pt2[1] - pt1[1], pt2[2] - pt1[2]]; 101 | let intersectPt1 = [ 102 | intersectPt[0] - pt1[0], 103 | intersectPt[1] - pt1[1], 104 | intersectPt[2] - pt1[2] 105 | ]; 106 | let dotProduct1Vec = vec3.create(); 107 | vec3.cross(dotProduct1Vec, dir1, intersectPt1); 108 | let judge1 = this.dot(dotProduct1Vec, nVec); 109 | if (judge1 < 0) return false; 110 | 111 | let dir2 = [pt0[0] - pt2[0], pt0[1] - pt2[1], pt0[2] - pt2[2]]; 112 | let intersectPt2 = [ 113 | intersectPt[0] - pt2[0], 114 | intersectPt[1] - pt2[1], 115 | intersectPt[2] - pt2[2] 116 | ]; 117 | let dotProduct2Vec = vec3.create(); 118 | vec3.cross(dotProduct2Vec, dir2, intersectPt2); 119 | let judge2 = this.dot(dotProduct2Vec, nVec); 120 | if (judge2 < 0) return false; 121 | 122 | return { t: t, pt: intersectPt }; 123 | } 124 | 125 | calcDirection(startPt: vec3, endPt: vec3) { 126 | let dir = vec3.create(); 127 | vec3.subtract(dir, endPt, startPt); 128 | vec3.normalize(dir, dir); 129 | this.dir = dir; 130 | this.orig = startPt; 131 | } 132 | 133 | swap(valA: number, valB: number) { 134 | let tempVal = valA; 135 | valA = valB; 136 | valB = tempVal; 137 | 138 | return { minVal: valA, maxVal: valB }; 139 | } 140 | 141 | dot(a: vec3, b: vec3) { 142 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/utils/common/constants.ts: -------------------------------------------------------------------------------- 1 | export const FLOAT: number = 0x1406; 2 | 3 | export const RGB: number = 0x1907; 4 | 5 | // variables relating to textures 6 | export const NEAREST: number = 0x2600; 7 | export const LINEAR: number = 0x2601; 8 | export const NEAREST_MIPMAP_NEAREST: number = 0x2700; 9 | export const LINEAR_MIPMAP_NEAREST: number = 0x2701; 10 | export const NEAREST_MIPMAP_LINEAR: number = 0x2702; 11 | export const LINEAR_MIPMAP_LINEAR: number = 0x2703; 12 | export const CLAMP_TO_EDGE: number = 0x812f; 13 | export const REPEAT: number = 0x2901; 14 | 15 | // Framebuffers and renderbuffers 16 | // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants#Framebuffers_and_renderbuffers 17 | 18 | export const DEPTH_COMPONENT16: number = 0x81a5; 19 | 20 | // Data types 21 | // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants#Data_types 22 | 23 | export const UNSIGNED_BYTE: number = 0x1401; 24 | 25 | export const EMPTY_CANVAS_SIZE = 16; 26 | export const EMPTY_CANVAS_COLOR = '#ff0000'; 27 | export const COLOR_REPEAT = 4; 28 | 29 | export const UNIFORM_1F = '1f'; 30 | export const UNIFORM_1I = '1i'; 31 | export const UNIFORM_2F = '2f'; 32 | export const UNIFORM_3F = '3f'; 33 | export const UNIFORM_MAT_4F = 'mat4'; 34 | -------------------------------------------------------------------------------- /src/utils/common/shaders.ts: -------------------------------------------------------------------------------- 1 | export const fullscreenVertShader = ` 2 | precision highp float; 3 | 4 | attribute vec3 position; 5 | 6 | uniform vec2 px; 7 | 8 | varying vec2 vUv; 9 | 10 | void main(){ 11 | vUv = vec2(0.5)+(position.xy)*0.5; 12 | gl_Position = vec4(position, 1.0); 13 | } 14 | `; 15 | 16 | export const fillFragShader = ` 17 | precision highp float; 18 | 19 | varying vec2 vUv; 20 | 21 | void main(){ 22 | gl_FragColor = vec4(vUv, 0.0, 1.0); 23 | } 24 | `; 25 | 26 | export const texFragShader = ` 27 | precision highp float; 28 | 29 | uniform sampler2D uTexture; 30 | 31 | varying vec2 vUv; 32 | 33 | void main(){ 34 | vec4 texColor = texture2D(uTexture, vUv); 35 | gl_FragColor = texColor; 36 | } 37 | `; 38 | -------------------------------------------------------------------------------- /src/utils/functions/assets-functions.ts: -------------------------------------------------------------------------------- 1 | import { vec3, vec2 } from 'gl-matrix'; 2 | import { Camera } from '../../camera/camera'; 3 | 4 | /** 5 | * load json with ajax 6 | * 7 | * @param url url to load json file 8 | */ 9 | export function getAjaxJson(url: string, callback: Function) { 10 | const xhr = new XMLHttpRequest(); 11 | xhr.open('GET', url, true); 12 | 13 | xhr.onreadystatechange = () => { 14 | if (xhr.readyState === 4) { 15 | if (xhr.status === 200) { 16 | const resp: string = xhr.responseText; 17 | const respJson = JSON.parse(resp); 18 | callback(respJson); 19 | // resolve(respJson); 20 | } else { 21 | // reject(xhr.status); 22 | } 23 | } else { 24 | // reject(xhr.status); 25 | } 26 | }; 27 | 28 | xhr.send(); 29 | } 30 | 31 | /** 32 | * 33 | * @param imageUrl 34 | */ 35 | export function getImage(imageUrl: string, callback: Function) { 36 | const image: HTMLImageElement = new Image(); 37 | image.onload = () => { 38 | callback(image); 39 | }; 40 | image.onerror = () => { 41 | console.warn(`image(${imageUrl}) load err`); 42 | }; 43 | 44 | image.src = imageUrl; 45 | } 46 | 47 | /** 48 | * 49 | * @param dracoUrl 50 | * @param callback 51 | * 52 | * https://github.com/kioku-systemk/dracoSample/blob/5611528416d4e0afb10cbec52d70493602d8a552/dracoloader.js#L210 53 | * 54 | */ 55 | export function loadDraco(dracoUrl: string, callback: Function) { 56 | let xhr = new XMLHttpRequest(); 57 | xhr.responseType = 'arraybuffer'; 58 | xhr.onreadystatechange = function() { 59 | if (xhr.readyState === 4) { 60 | if (xhr.status === 200 || xhr.status === 0) { 61 | callback(xhr.response); 62 | } else { 63 | console.error("Couldn't load [" + dracoUrl + '] [' + xhr.status + ']'); 64 | } 65 | } 66 | }; 67 | xhr.open('GET', dracoUrl, true); 68 | xhr.send(null); 69 | } 70 | -------------------------------------------------------------------------------- /src/utils/functions/gl-textures.ts: -------------------------------------------------------------------------------- 1 | import { RGB, UNSIGNED_BYTE, CLAMP_TO_EDGE, LINEAR } from '../common/constants'; 2 | 3 | /** 4 | * 5 | * @param gl 6 | * @param textureWidth 7 | * @param textureHeight 8 | * @param format 9 | * @param minFilter 10 | * @param magFilter 11 | * @param wrapS 12 | * @param wrapT 13 | * @param type 14 | */ 15 | export function createEmptyTexture( 16 | gl: WebGLRenderingContext, 17 | textureWidth: number, 18 | textureHeight: number, 19 | format: number = RGB, 20 | minFilter: number = LINEAR, 21 | magFilter: number = LINEAR, 22 | wrapS: number = CLAMP_TO_EDGE, 23 | wrapT: number = CLAMP_TO_EDGE, 24 | type: number = UNSIGNED_BYTE 25 | ) { 26 | const texture = gl.createTexture() as WebGLTexture; 27 | updateEmptyImageTexture( 28 | gl, 29 | texture, 30 | textureWidth, 31 | textureHeight, 32 | format, 33 | minFilter, 34 | magFilter, 35 | wrapS, 36 | wrapT, 37 | type 38 | ); 39 | 40 | return texture; 41 | } 42 | 43 | export function createImageTexture( 44 | gl: WebGLRenderingContext, 45 | canvasImage: HTMLImageElement | HTMLCanvasElement, 46 | format: number = RGB, 47 | isFlip: boolean = false, 48 | isMipmap: boolean = false 49 | ) { 50 | return createCustomTypeImageTexture( 51 | gl, 52 | canvasImage, 53 | format, 54 | gl.UNSIGNED_BYTE, 55 | isFlip, 56 | isMipmap 57 | ); 58 | } 59 | 60 | export function createCustomTypeImageTexture( 61 | gl: WebGLRenderingContext, 62 | canvasImage: HTMLImageElement | HTMLCanvasElement, 63 | format: number = RGB, 64 | type: number, 65 | isFlip: boolean = false, 66 | isMipmap: boolean = false 67 | ) { 68 | const texture = gl.createTexture(); 69 | gl.bindTexture(gl.TEXTURE_2D, texture); 70 | 71 | gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, isFlip ? 0 : 1); 72 | gl.texImage2D(gl.TEXTURE_2D, 0, format, format, type, canvasImage); 73 | 74 | if (isPowerOf2(canvasImage.width) && isPowerOf2(canvasImage.height) && isMipmap) { 75 | // Yes, it's a power of 2. Generate mips. 76 | gl.generateMipmap(gl.TEXTURE_2D); 77 | } else { 78 | // No, it's not a power of 2. Turn of mips and set 79 | // wrapping to clamp to edge 80 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 81 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 82 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 83 | } 84 | 85 | return texture; 86 | } 87 | 88 | function isPowerOf2(value: number) { 89 | return (value & (value - 1)) === 0; 90 | } 91 | 92 | /** 93 | * 94 | * @param gl 95 | * @param texture 96 | * @param image 97 | * @param format 98 | */ 99 | export function updateImageTexture( 100 | gl: WebGLRenderingContext, 101 | texture: WebGLTexture, 102 | image: HTMLImageElement, 103 | format: number = RGB 104 | ) { 105 | gl.bindTexture(gl.TEXTURE_2D, texture); 106 | gl.texImage2D(gl.TEXTURE_2D, 0, format, format, gl.UNSIGNED_BYTE, image); 107 | 108 | if (isPowerOf2(image.width) && isPowerOf2(image.height)) { 109 | // Yes, it's a power of 2. Generate mips. 110 | gl.generateMipmap(gl.TEXTURE_2D); 111 | } else { 112 | // No, it's not a power of 2. Turn of mips and set 113 | // wrapping to clamp to edge 114 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 115 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 116 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 117 | } 118 | } 119 | 120 | export function updateEmptyImageTexture( 121 | gl: WebGLRenderingContext, 122 | texture: WebGLTexture, 123 | textureWidth: number, 124 | textureHeight: number, 125 | format: number = RGB, 126 | minFilter: number = LINEAR, 127 | magFilter: number = LINEAR, 128 | wrapS: number = CLAMP_TO_EDGE, 129 | wrapT: number = CLAMP_TO_EDGE, 130 | type: number = UNSIGNED_BYTE 131 | ) { 132 | gl.bindTexture(gl.TEXTURE_2D, texture); 133 | 134 | // define size and format of level 0 135 | const level = 0; 136 | const border = 0; 137 | 138 | // https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texImage2D 139 | gl.texImage2D(gl.TEXTURE_2D, level, format, textureWidth, textureHeight, 0, format, type, null); 140 | 141 | // set the filtering so we don't need mips 142 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter); 143 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter); 144 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS); 145 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT); 146 | 147 | return texture; 148 | } 149 | 150 | /** 151 | * 152 | * @param gl 153 | * @param texture 154 | * @param uniformLocation 155 | * @param textureNum 156 | */ 157 | export function activeTexture( 158 | gl: WebGLRenderingContext, 159 | texture: WebGLTexture, 160 | uniformLocation: WebGLUniformLocation, 161 | textureNum: number = 0 162 | ) { 163 | const activeTextureNum = gl.TEXTURE0 + textureNum; 164 | gl.activeTexture(activeTextureNum); 165 | gl.bindTexture(gl.TEXTURE_2D, texture); 166 | gl.uniform1i(uniformLocation, textureNum); 167 | } 168 | -------------------------------------------------------------------------------- /src/utils/generate/generateGeometry.ts: -------------------------------------------------------------------------------- 1 | export function getSphere( 2 | radius: number = 2, 3 | latitudeBands: number = 64, 4 | longitudeBands: number = 64 5 | ) { 6 | const vertices = []; 7 | const textures = []; 8 | const normals = []; 9 | const indices = []; 10 | 11 | for (let latNumber = 0; latNumber <= latitudeBands; latNumber = latNumber + 1) { 12 | const theta = (latNumber * Math.PI) / latitudeBands; 13 | const sinTheta = Math.sin(theta); 14 | const cosTheta = Math.cos(theta); 15 | 16 | for (let longNumber = 0; longNumber <= longitudeBands; longNumber = longNumber + 1) { 17 | const phi = (longNumber * 2 * Math.PI) / longitudeBands; 18 | const sinPhi = Math.sin(phi); 19 | const cosPhi = Math.cos(phi); 20 | 21 | const x = cosPhi * sinTheta; 22 | const y = cosTheta; 23 | const z = sinPhi * sinTheta; 24 | const u = 1 - longNumber / longitudeBands; 25 | const v = 1 - latNumber / latitudeBands; 26 | 27 | normals.push(x, y, z); 28 | textures.push(u, v); 29 | vertices.push(radius * x, radius * y, radius * z); 30 | } 31 | } 32 | 33 | for (let latNumber = 0; latNumber < latitudeBands; latNumber = latNumber + 1) { 34 | for (let longNumber = 0; longNumber < longitudeBands; longNumber = longNumber + 1) { 35 | let first = latNumber * (longitudeBands + 1) + longNumber; 36 | let second = first + longitudeBands + 1; 37 | indices.push(second, first, first + 1, second + 1, second, first + 1); 38 | } 39 | } 40 | 41 | return { 42 | vertices: vertices, 43 | uvs: textures, 44 | normals: normals, 45 | indices: indices 46 | }; 47 | } 48 | 49 | export function getPlane( 50 | width: number, 51 | height: number, 52 | widthSegment: number, 53 | heightSegment: number 54 | ) { 55 | let vertices = []; 56 | let uvs = []; 57 | let xRate = 1 / widthSegment; 58 | let yRate = 1 / heightSegment; 59 | 60 | // set vertices and barycentric vertices 61 | for (let yy = 0; yy <= heightSegment; yy++) { 62 | let yPos = (-0.5 + yRate * yy) * height; 63 | 64 | for (let xx = 0; xx <= widthSegment; xx++) { 65 | let xPos = (-0.5 + xRate * xx) * width; 66 | vertices.push(xPos); 67 | vertices.push(yPos); 68 | uvs.push(xx / widthSegment); 69 | uvs.push(yy / heightSegment); 70 | } 71 | } 72 | 73 | let indices = []; 74 | 75 | for (let yy = 0; yy < heightSegment; yy++) { 76 | for (let xx = 0; xx < widthSegment; xx++) { 77 | let rowStartNum = yy * (widthSegment + 1); 78 | let nextRowStartNum = (yy + 1) * (widthSegment + 1); 79 | 80 | indices.push(rowStartNum + xx); 81 | indices.push(rowStartNum + xx + 1); 82 | indices.push(nextRowStartNum + xx); 83 | 84 | indices.push(rowStartNum + xx + 1); 85 | indices.push(nextRowStartNum + xx + 1); 86 | indices.push(nextRowStartNum + xx); 87 | } 88 | } 89 | 90 | return { 91 | vertices: vertices, 92 | uvs: uvs, 93 | indices: indices 94 | }; 95 | } 96 | 97 | export function mergeGeomtory( 98 | geometries: { vertices: number[]; indices: number[]; normals: number[]; uvs: number[] }[] 99 | ) { 100 | const vertices = []; 101 | const normals = []; 102 | const uvs = []; 103 | const indices = []; 104 | 105 | let lastVertices = 0; 106 | 107 | for (let ii = 0; ii < geometries.length; ii++) { 108 | let geometry = geometries[ii]; 109 | 110 | if (geometry.indices.length > 0) { 111 | for (let ii = 0; ii < geometry.indices.length; ii++) { 112 | indices.push(geometry.indices[ii] + lastVertices / 3); 113 | } 114 | } 115 | 116 | if (geometry.vertices.length > 0) { 117 | for (let ii = 0; ii < geometry.vertices.length; ii++) { 118 | vertices.push(geometry.vertices[ii]); 119 | } 120 | 121 | lastVertices += geometry.vertices.length; 122 | } 123 | 124 | if (geometry.normals.length > 0) { 125 | for (let ii = 0; ii < geometry.normals.length; ii++) { 126 | normals.push(geometry.normals[ii]); 127 | } 128 | } 129 | 130 | if (geometry.uvs.length > 0) { 131 | for (let ii = 0; ii < geometry.uvs.length; ii++) { 132 | uvs.push(geometry.uvs[ii]); 133 | } 134 | } 135 | } 136 | 137 | return { 138 | vertices, 139 | normals, 140 | uvs, 141 | indices 142 | }; 143 | } 144 | -------------------------------------------------------------------------------- /src/utils/generate/generateSimpleGeometry.ts: -------------------------------------------------------------------------------- 1 | // segment is one 2 | export function createSimpleBox() { 3 | const unit = 0.5; 4 | const positions = [ 5 | // Front face 6 | -unit, 7 | -unit, 8 | unit, 9 | unit, 10 | -unit, 11 | unit, 12 | unit, 13 | unit, 14 | unit, 15 | -unit, 16 | unit, 17 | unit, 18 | 19 | // Back face 20 | -unit, 21 | -unit, 22 | -unit, 23 | -unit, 24 | unit, 25 | -unit, 26 | unit, 27 | unit, 28 | -unit, 29 | unit, 30 | -unit, 31 | -unit, 32 | 33 | // Top face 34 | -unit, 35 | unit, 36 | -unit, 37 | -unit, 38 | unit, 39 | unit, 40 | unit, 41 | unit, 42 | unit, 43 | unit, 44 | unit, 45 | -unit, 46 | 47 | // Bottom face 48 | -unit, 49 | -unit, 50 | -unit, 51 | unit, 52 | -unit, 53 | -unit, 54 | unit, 55 | -unit, 56 | unit, 57 | -unit, 58 | -unit, 59 | unit, 60 | 61 | // Right face 62 | unit, 63 | -unit, 64 | -unit, 65 | unit, 66 | unit, 67 | -unit, 68 | unit, 69 | unit, 70 | unit, 71 | unit, 72 | -unit, 73 | unit, 74 | 75 | // Left face 76 | -unit, 77 | -unit, 78 | -unit, 79 | -unit, 80 | -unit, 81 | unit, 82 | -unit, 83 | unit, 84 | unit, 85 | -unit, 86 | unit, 87 | -unit 88 | ]; 89 | 90 | const indices = [ 91 | 0, 92 | 1, 93 | 2, 94 | 0, 95 | 2, 96 | 3, // front 97 | 4, 98 | 5, 99 | 6, 100 | 4, 101 | 6, 102 | 7, // back 103 | 8, 104 | 9, 105 | 10, 106 | 8, 107 | 10, 108 | 11, // top 109 | 12, 110 | 13, 111 | 14, 112 | 12, 113 | 14, 114 | 15, // bottom 115 | 16, 116 | 17, 117 | 18, 118 | 16, 119 | 18, 120 | 19, // right 121 | 20, 122 | 21, 123 | 22, 124 | 20, 125 | 22, 126 | 23 // left 127 | ]; 128 | 129 | const uvs = [ 130 | // Front 131 | 0.0, 132 | 0.0, 133 | 1.0, 134 | 0.0, 135 | 1.0, 136 | 1.0, 137 | 0.0, 138 | 1.0, 139 | // Back 140 | 0.0, 141 | 0.0, 142 | 1.0, 143 | 0.0, 144 | 1.0, 145 | 1.0, 146 | 0.0, 147 | 1.0, 148 | // Top 149 | 0.0, 150 | 0.0, 151 | 1.0, 152 | 0.0, 153 | 1.0, 154 | 1.0, 155 | 0.0, 156 | 1.0, 157 | // Bottom 158 | 0.0, 159 | 0.0, 160 | 1.0, 161 | 0.0, 162 | 1.0, 163 | 1.0, 164 | 0.0, 165 | 1.0, 166 | // Right 167 | 0.0, 168 | 0.0, 169 | 1.0, 170 | 0.0, 171 | 1.0, 172 | 1.0, 173 | 0.0, 174 | 1.0, 175 | // Left 176 | 0.0, 177 | 0.0, 178 | 1.0, 179 | 0.0, 180 | 1.0, 181 | 1.0, 182 | 0.0, 183 | 1.0 184 | ]; 185 | 186 | const normals = [ 187 | // Front 188 | 0.0, 189 | 0.0, 190 | 1.0, 191 | 0.0, 192 | 0.0, 193 | 1.0, 194 | 0.0, 195 | 0.0, 196 | 1.0, 197 | 0.0, 198 | 0.0, 199 | 1.0, 200 | 201 | // Back 202 | 0.0, 203 | 0.0, 204 | -1.0, 205 | 0.0, 206 | 0.0, 207 | -1.0, 208 | 0.0, 209 | 0.0, 210 | -1.0, 211 | 0.0, 212 | 0.0, 213 | -1.0, 214 | 215 | // Top 216 | 0.0, 217 | 1.0, 218 | 0.0, 219 | 0.0, 220 | 1.0, 221 | 0.0, 222 | 0.0, 223 | 1.0, 224 | 0.0, 225 | 0.0, 226 | 1.0, 227 | 0.0, 228 | 229 | // Bottom 230 | 0.0, 231 | -1.0, 232 | 0.0, 233 | 0.0, 234 | -1.0, 235 | 0.0, 236 | 0.0, 237 | -1.0, 238 | 0.0, 239 | 0.0, 240 | -1.0, 241 | 0.0, 242 | 243 | // Right 244 | 1.0, 245 | 0.0, 246 | 0.0, 247 | 1.0, 248 | 0.0, 249 | 0.0, 250 | 1.0, 251 | 0.0, 252 | 0.0, 253 | 1.0, 254 | 0.0, 255 | 0.0, 256 | 257 | // Left 258 | -1.0, 259 | 0.0, 260 | 0.0, 261 | -1.0, 262 | 0.0, 263 | 0.0, 264 | -1.0, 265 | 0.0, 266 | 0.0, 267 | -1.0, 268 | 0.0, 269 | 0.0 270 | ]; 271 | 272 | return { 273 | vertices: positions, 274 | normals: normals, 275 | uvs: uvs, 276 | indices: indices 277 | }; 278 | } 279 | 280 | export function createSimplePlane() { 281 | const unit = 0.5; 282 | 283 | const positions = [-unit, -unit, 0.0, unit, -unit, 0.0, unit, unit, 0.0, -unit, unit, 0.0]; 284 | 285 | const indices = [ 286 | 0, 287 | 1, 288 | 2, 289 | 0, 290 | 2, 291 | 3 // front 292 | ]; 293 | 294 | const uvs = [0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0]; 295 | 296 | const normals = [ 297 | // Front 298 | 0.0, 299 | 0.0, 300 | 1.0, 301 | 0.0, 302 | 0.0, 303 | 1.0, 304 | 0.0, 305 | 0.0, 306 | 1.0, 307 | 0.0, 308 | 0.0, 309 | 1.0 310 | ]; 311 | 312 | return { 313 | vertices: positions, 314 | normals: normals, 315 | uvs: uvs, 316 | indices: indices 317 | }; 318 | } 319 | 320 | export function createSuperSimpleplane(scaleX: number = 1, scaleY: number = 1) { 321 | return new Float32Array([-scaleX, -scaleY, scaleX, -scaleY, -scaleX, scaleY, scaleX, scaleY]); 322 | } 323 | -------------------------------------------------------------------------------- /tools/gh-pages-publish.ts: -------------------------------------------------------------------------------- 1 | const { cd, exec, echo, touch } = require("shelljs") 2 | const { readFileSync } = require("fs") 3 | const url = require("url") 4 | 5 | let repoUrl 6 | let pkg = JSON.parse(readFileSync("package.json") as any) 7 | if (typeof pkg.repository === "object") { 8 | if (!pkg.repository.hasOwnProperty("url")) { 9 | throw new Error("URL does not exist in repository section") 10 | } 11 | repoUrl = pkg.repository.url 12 | } else { 13 | repoUrl = pkg.repository 14 | } 15 | 16 | let parsedUrl = url.parse(repoUrl) 17 | let repository = (parsedUrl.host || "") + (parsedUrl.path || "") 18 | let ghToken = process.env.GH_TOKEN 19 | 20 | echo("Deploying docs!!!") 21 | cd("docs") 22 | touch(".nojekyll") 23 | exec("git init") 24 | exec("git add .") 25 | exec('git config user.name "kenji"') 26 | exec('git config user.email "k.saito.1985@gmail.com"') 27 | exec('git commit -m "docs(docs): update gh-pages"') 28 | exec( 29 | `git push --force --quiet "https://${ghToken}@${repository}" master:gh-pages` 30 | ) 31 | echo("Docs deployed!!") 32 | -------------------------------------------------------------------------------- /tools/semantic-release-prepare.ts: -------------------------------------------------------------------------------- 1 | const path = require("path") 2 | const { fork } = require("child_process") 3 | const colors = require("colors") 4 | 5 | const { readFileSync, writeFileSync } = require("fs") 6 | const pkg = JSON.parse( 7 | readFileSync(path.resolve(__dirname, "..", "package.json")) 8 | ) 9 | 10 | pkg.scripts.prepush = "npm run test:prod && npm run build" 11 | pkg.scripts.commitmsg = "commitlint -E HUSKY_GIT_PARAMS" 12 | 13 | writeFileSync( 14 | path.resolve(__dirname, "..", "package.json"), 15 | JSON.stringify(pkg, null, 2) 16 | ) 17 | 18 | // Call husky to set up the hooks 19 | fork(path.resolve(__dirname, "..", "node_modules", "husky", "lib", "installer", 'bin'), ['install']) 20 | 21 | console.log() 22 | console.log(colors.green("Done!!")) 23 | console.log() 24 | 25 | if (pkg.repository.url.trim()) { 26 | console.log(colors.cyan("Now run:")) 27 | console.log(colors.cyan(" npm install -g semantic-release-cli")) 28 | console.log(colors.cyan(" semantic-release-cli setup")) 29 | console.log() 30 | console.log( 31 | colors.cyan('Important! Answer NO to "Generate travis.yml" question') 32 | ) 33 | console.log() 34 | console.log( 35 | colors.gray( 36 | 'Note: Make sure "repository.url" in your package.json is correct before' 37 | ) 38 | ) 39 | } else { 40 | console.log( 41 | colors.red( 42 | 'First you need to set the "repository.url" property in package.json' 43 | ) 44 | ) 45 | console.log(colors.cyan("Then run:")) 46 | console.log(colors.cyan(" npm install -g semantic-release-cli")) 47 | console.log(colors.cyan(" semantic-release-cli setup")) 48 | console.log() 49 | console.log( 50 | colors.cyan('Important! Answer NO to "Generate travis.yml" question') 51 | ) 52 | } 53 | 54 | console.log() 55 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "moduleResolution": "node", 4 | "target": "es5", 5 | "module":"es2015", 6 | "lib": ["es2015", "es2016", "es2017", "dom"], 7 | "strict": true, 8 | "sourceMap": true, 9 | "declaration": true, 10 | "allowSyntheticDefaultImports": true, 11 | "experimentalDecorators": true, 12 | "emitDecoratorMetadata": true, 13 | "resolveJsonModule": true, 14 | "declarationDir": "dist/types", 15 | "outDir": "dist/lib", 16 | "typeRoots": [ 17 | "node_modules/@types" 18 | ] 19 | }, 20 | "include": [ 21 | "src" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "tslint-config-standard", 4 | "tslint-config-prettier" 5 | ] 6 | } --------------------------------------------------------------------------------