-
Notifications
You must be signed in to change notification settings - Fork 6
/
RenderWidgets.js
81 lines (70 loc) · 2.29 KB
/
RenderWidgets.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict'
var RenderWidgets = {
Instances: ko.observableArray(),
Main3D: null,
AddRenderer: function (renderer) {
this.Instances.push(renderer);
},
Add3DRenderer: function (renderer) {
this.Main3D = renderer;
this.Instances.push(renderer);
},
InitializeAll: function()
{
ko.utils.arrayForEach(this.Instances(), function (item) {
if (!item.IsInitialized())
item.Init();//.apply(item);
});
},
UpdateComplete: function () {
ko.utils.arrayForEach(this.Instances(), function (item) {
if (item.IsInitialized() && item.OnUpdateCompleted)
item.OnUpdateCompleted();
});
},
UsePrerenderedImage: function (enabled) {
ko.utils.arrayForEach(this.Instances(), function (item) {
if (item.IsInitialized() && item.hasOwnProperty("imgOverride")) {
item.imgOverride = enabled;
if (item.container)
$(item.container).css({ opacity: enabled ? 0.001 : 1.0 });
}
});
},
MainCamera: function () {
function MitsubaCam(camera) {
var pos = camera.position;
var up = camera.up;
var x = new THREE.Vector3();
var y = new THREE.Vector3();
var z = new THREE.Vector3();
camera.matrix.extractBasis(x, y, z);
var result = camera.position.clone();
result.sub(z);
return { pos: pos.toArray().toString(), up: up.toArray().toString(), target: result.toArray().toString(), fov: camera.fov };
}
if (this.Main3D) {
var container = this.Main3D.container;
var cam = MitsubaCam(this.Main3D.camera);
return {
width: container.innerWidth(),
height: container.innerHeight(),
pos: cam.pos,
up: cam.up,
target: cam.target,
fov: cam.fov
};
}
else
return null;
}
/*
AllInitialized: function()
{
var result = true;
ko.utils.arrayForEach(this.Instances, function (item) {
result &= item.IsInitialized();
});
}
*/
}