-
Notifications
You must be signed in to change notification settings - Fork 0
/
Uniforms.js
54 lines (46 loc) · 1.07 KB
/
Uniforms.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Copyright 2017 Marcel Greter
https://www.github.com/mgreter
*/
// private scope
(function (THREE, THREEAPP)
{
"use strict";
// helper function to get a shared uniform
// the uniform will be created on demand!
function uniform(name, type, def)
{
// default type is float
if (!type) type = 'f';
// create uniform on demand
if (!this.uniforms[name]) {
this.uniforms[name] = {
type: type,
value: def || 0
}
}
// return the shared uniform
return this.uniforms[name];
}
var Uniforms = THREEAPP.Class.create('Uniforms', null, ['Plugin'])
.ctor(function (app)
{
// store uniforms
app.uniforms = [];
// add uniform method
app.uniform = uniform;
})
.ready(function (app)
{
if (app.hasOwnProperty("time")) {
app.listen('preframe', function () {
// update the shared time uniform
app.uniform('time').value = app.time;
}, 999999) // run very very early
}
})
;
// assign class to global namespace
THREEAPP('Plugin.Uniforms', Uniforms);
// EO private scope
})(THREE, THREEAPP);