-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (36 loc) · 903 Bytes
/
index.js
File metadata and controls
40 lines (36 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const glsl = require('glslify');
class GLSLProcessor {
/**
*
* @param {Cube} cube 对象
* @param {Object} config 来自process配置里传入的配置信息
* basedir: require的根目录
*
*/
constructor(cube, config) {
this.cube = cube;
this.config = config || {};
if (!config.basedir) {
config.basedir = cube.config.root;
}
}
/**
* @param {Object} data [description]
* @param {Function} callback [description]
*/
process(data, callback) {
let code = data.code;
try {
code = glsl(code, this.config);
} catch (e) {
e.code = 'GLSL_COMPILE_ERROR';
return callback(e);
}
data.code = 'module.exports = \n' + JSON.stringify(code) + ';';
callback(null, data);
}
}
GLSLProcessor.type = 'script';
GLSLProcessor.ext = '.glsl';
module.exports = GLSLProcessor;