Skip to content

Commit

Permalink
add TS support for twgl deformer
Browse files Browse the repository at this point in the history
  • Loading branch information
yofreke committed Sep 21, 2016
1 parent 82921c6 commit 94bc65f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 4 deletions.
20 changes: 20 additions & 0 deletions js/deformers/IDeformer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
interface IDeformer {
init (canvas: HTMLCanvasElement): void;

load (
canvas: HTMLCanvasElement,
points: Number[][],
tracker,
bgElement: HTMLElement
): void;

draw (points: Number[][]): void;

setPoints (points: Number[][]): void;

setMaskTexture (element: HTMLElement): void;

getGLContext (): WebGLRenderingContext;
}

export default IDeformer;
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ import twgl from 'twgl.js/dist/twgl';
import createBgVert from './shaders/background.vert';
import createBgFrag from './shaders/background.frag';

import IDeformer from '../IDeformer';


export default class Background {
private _deformer: IDeformer;

private _element;

private _bgBufferInfo;
private _bgProgramInfo;
private _bgTextures;
private _bgUniforms;

constructor (deformer) {
this._deformer = deformer;

Expand Down
26 changes: 25 additions & 1 deletion js/deformers/twgl/index.js → js/deformers/twgl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,31 @@ import Background from './Background';
import createDeformVert from './shaders/deform.vert';
import createDeformFrag from './shaders/deform.frag';

import IDeformer from '../IDeformer';


export default class Deformer implements IDeformer {
private _isLoaded: boolean;

private background: Background;
private debug: Background;

private _tracker;
private _gl;

private _verticeMap;

private _dynamicMaskTexture;
private _maskTextureSrcElement;
private _maskTextureCanvas;
private _pointBB;

private _maskTextureCoord;
private _maskProgramInfo;
private _maskTextures;
private _maskUniforms;
private _maskBufferInfo;

export default class Deformer {
constructor (params = {}) {
twgl.setDefaults({ attribPrefix: 'a_' });

Expand All @@ -32,6 +55,7 @@ export default class Deformer {
this._maskProgramInfo = null;
this._maskTextures = null;
this._maskUniforms = null;
this._maskBufferInfo = null;
}

getGLContext () {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Javascript library for precise tracking of facial features via Constrained Local Models",
"scripts": {
"build": "NODE_ENV=production webpack --optimize-minimize --optimize-dedupe",
"watch": "webpack --debug --devtool inline-source-map --output-pathinfo --progress --colors --watch",
"serve": "webpack-dev-server --debug --devtool inline-source-map --output-pathinfo --inline --hot --host localhost",
"watch": "webpack --debug --devtool eval-source-map --output-pathinfo --progress --colors --watch",
"serve": "webpack-dev-server --debug --devtool eval-source-map --output-pathinfo --inline --hot --host localhost",
"clean": "rm -rf dist",
"postinstall": "npm run build",
"publish": "./publish.sh",
Expand All @@ -32,7 +32,9 @@
"raf": "^3.1.0",
"stylus": "^0.54.5",
"stylus-loader": "^2.3.1",
"ts-loader": "^0.8.2",
"twgl.js": "^1.9.0",
"typescript": "^1.8.10",
"uglify": "^0.1.5",
"webpack": "^1.13.2",
"webpack-dev-server": "^1.15.1",
Expand Down
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es6",
"sourceMap": true,
"removeComments": false
},
"exclude": [
"node_modules"
]
}
8 changes: 7 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const config = {
alias: {
'clmtrackr': path.resolve(__dirname),
'stats.js': path.resolve(__dirname, 'lib', 'stats.js')
}
},
extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js']
},
module: {
loaders: [
Expand All @@ -34,6 +35,11 @@ const config = {
test: /\.worker\.js$/,
loader: 'worker-loader?inline=true'
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'babel-loader?presets[]=es2015&presets[]=react!ts-loader?ignoreDiagnostics[]=2307'
},
{
test: /\.js$/,
loader: 'babel-loader',
Expand Down

0 comments on commit 94bc65f

Please sign in to comment.