-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathculling.js
49 lines (39 loc) · 1.24 KB
/
culling.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
pc.script.create('culling', function (app) {
// Creates a new Culling instance
var Culling = function (entity) {
this.entity = entity;
};
Culling.prototype = {
initialize: function () {
this.frustum = null;
this.list = [ ];
},
update: function (dt) {
if (! this.frustum)
return;
var culled = false;
var item = null;
for(var i = 0; i < this.list.length; i++) {
item = this.list[i];
if (item.ignore)
continue;
culled = ! this.frustum.containsSphere(item.sphere);
if (culled !== item.culled)
item.state(culled);
}
},
setCamera: function(camera) {
this.frustum = camera && camera.frustum || null;
},
add: function(item) {
this.list.push(item);
},
remove: function(item) {
var ind = this.list.indexOf(item);
if (ind === -1)
return;
this.list.splice(ind, 1);
}
};
return Culling;
});