forked from theta360developers/theta-viewer.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeta-viewer.js
115 lines (107 loc) · 3.54 KB
/
theta-viewer.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// theta-viewer.js v0.0.2
// https://github.com/shokai/theta-viewer.js
// (c) 2014-2015 Sho Hashimoto <[email protected]>
// The MIT License
(function() {
var ThetaViewer;
ThetaViewer = (function() {
function ThetaViewer(dom) {
var _oldHeight, _oldWidth;
this.dom = dom;
this.__defineGetter__('width', function() {
return this.dom.clientWidth;
});
this.__defineGetter__('height', function() {
return this.dom.clientHeight;
});
this.images = [];
this.interval = 1000;
this.materialOffset = 0;
this.camera = new THREE.PerspectiveCamera(100, this.width / this.height);
this.camera.position.set(0, 0, 180);
this.scene = new THREE.Scene;
this.renderer = new THREE.WebGLRenderer;
this.renderer.setSize(this.width, this.height);
this.dom.appendChild(this.renderer.domElement);
this.controls = new THREE.OrbitControls(this.camera);
this.controls.addEventListener('change', (function(_this) {
return function() {
return _this.renderer.render(_this.scene, _this.camera);
};
})(this));
this.sphere = new THREE.SphereGeometry(300, 100, 100);
this.mesh = new THREE.Mesh(this.sphere);
this.mesh.scale.x = -1;
this.scene.add(this.mesh);
this.autoRotate = false;
this.running = false;
_oldWidth = this.width;
_oldHeight = this.height;
setInterval((function(_this) {
return function() {
if (_oldWidth !== _this.width || _oldHeight !== _this.height) {
_oldWidth = _this.width;
_oldHeight = _this.height;
return _this.renderer.setSize(_this.width, _this.height);
}
};
})(this), 100);
}
ThetaViewer.prototype.load = function(callback) {
if (callback == null) {
callback = function() {};
}
return this.loadMaterials((function(_this) {
return function() {
if (_this.running) {
return;
}
_this.running = true;
_this.displayNextMaterial();
setInterval(function() {
return _this.displayNextMaterial();
}, _this.interval);
if (_this.autoRotate) {
return setInterval(function() {
_this.controls.rotateLeft(0.003);
return _this.controls.update();
}, 50);
}
};
})(this));
};
ThetaViewer.prototype.loadMaterials = function(callback) {
var mapping;
mapping = new THREE.UVMapping;
return async.map(this.images, function(img, done) {
var texture;
return texture = THREE.ImageUtils.loadTexture(img, mapping, function() {
var material;
material = new THREE.MeshBasicMaterial({
map: texture
});
return done(null, material);
});
}, (function(_this) {
return function(err, results) {
_this.materials = results;
return callback();
};
})(this));
};
ThetaViewer.prototype.displayNextMaterial = function() {
this.materialOffset += 1;
if (!(this.materialOffset < this.materials.length)) {
this.materialOffset = 0;
}
this.mesh.material = this.materials[this.materialOffset];
return this.renderer.render(this.scene, this.camera);
};
return ThetaViewer;
})();
if ((typeof module !== "undefined" && module !== null ? module.exports : void 0) != null) {
module.exports = ThetaViewer;
} else {
window.ThetaViewer = ThetaViewer;
}
}).call(this);