-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapp.js
100 lines (77 loc) · 2.38 KB
/
webapp.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
var renderer = Detector.webgl ? new THREE.WebGLRenderer() : new THREE.CanvasRenderer();
var width = window.innerWidth,
height = window.innerHeight;
renderer.setSize(width, height);
var webglEl = document.getElementById('sphere');
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(100, width / height, 1, 1000);
camera.position.x = 10;
/* Creates a sphere and texturemaps the projection onto the sphere */
var sphere = new THREE.Mesh(
new THREE.SphereGeometry(120, 40, 40),
new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture("./upload/"+imageFile)
})
);
sphere.scale.x = -1;
scene.add(sphere);
var cube = new THREE.Mesh(
new THREE.BoxGeometry( 10, 10, 10 ),
new THREE.MeshBasicMaterial( {color: 0x0000ff, opacity: 0.8, transparent: true} ) );
cube.position.x = -10;
cube.position.z = -10;
scene.add( cube );
var controls = new THREE.OrbitControls(camera);
controls.noPan = true;
controls.noZoom = true;
controls.autoRotate = true;
controls.autoRotateSpeed = 0.5;
webglEl.appendChild(renderer.domElement);
render();
function render() {
controls.update();
requestAnimationFrame(render);
renderer.render(scene, camera);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
window.addEventListener( 'resize', onWindowResize, false );
function onClickToggleCube() {
if(cube.visible === true) {
cube.visible = false;
} else {
cube.visible = true;
}
}
function onClickColorRed() {
cube.material.color.setHex(0xff0000);
}
function onClickColorGreen() {
cube.material.color.setHex(0x00ff00);
}
function onClickColorBlue() {
cube.material.color.setHex(0x0000ff);
}
function onClickColorReflective() {
//Add code to make the cube reflective with cubemapped environment
}
function onClickIncreaseOpacity() {
if(cube.material.opacity >= 1.0){
cube.material.opacity = 1.0;
} else {
cube.material.opacity += 0.2;
}
}
function onClickDecreaseOpacity() {
if(cube.material.opacity <= 00) {
cube.material.opacity = 1.0;
} else {
cube.material.opacity -= 0.2;
}
}
function onClickToggleAutoRotate() {
controls.autoRotate = !(controls.autoRotate);
}