-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene.js
More file actions
140 lines (105 loc) · 3.74 KB
/
scene.js
File metadata and controls
140 lines (105 loc) · 3.74 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//Android housekeeping
window.oncontextmenu = function(event) {
event.preventDefault();
event.stopPropagation();
return false;
};
var renderer = new THREE.WebGLRenderer({antialias: true, alpha: true});
var scene = new THREE.Scene();
var sceneWidth, sceneHeight, effect, camera, controls, manager;
function createBaseScene(width,height) {
sceneWidth = width;
sceneHeight = height;
// Setup three.js WebGL renderer. Note: Antialiasing is a big performance hit.
// Only enable it if you actually need to.
// Apply VR stereo rendering to renderer.
effect = new THREE.VREffect(renderer);
// Append the canvas element created by the renderer to document body element
// Create a three.js scene.
// Create a three.js camera.
camera = new THREE.PerspectiveCamera(75, sceneWidth / sceneHeight, 0.1, 10000);
controls = new THREE.VRControls(camera);
console.log("vr controls");
console.log(controls);
console.log("camera");
console.log(camera);
controls.standing = true;
// Create a VR manager helper to enter and exit VR mode.
var params = {
hideButton: false, // Default: false. `
isUndistorted: false // Default: false.
};
manager = new WebVRManager(renderer, effect, params);
// Create 3D objects.
var geometry = new THREE.BoxGeometry(0.5, 0.5, 0.5);
var material = new THREE.MeshNormalMaterial();
if(width == window.innerWidth) {
window.addEventListener('resize', onResize, true);
}
window.addEventListener('vrdisplaypresentchange', onResize, true);
addSceneLight(scene,"");
effect.setSize(sceneWidth,sceneHeight);
camera.aspect = sceneWidth / sceneHeight;
camera.updateProjectionMatrix();
setupStage();
/*buildInitialScene({
models: [{path: "/vr/jupiter.dae", posx: 0, posy: 0, posz: 0, scale: 1, rotx: -Math.PI / 2, roty: 0, rotz: 0, spin: 'true', spinaxis: 'Z'}],
skybox: "milkyway",
skyboxSize: 50,
skyboxPos: 12.5,
cameraHeight: 1.5,
});*/
/*setTimeout(function() {
receiveSceneData({models: [{path: "jupiter.dae", posx: -3, posy: 0, posz: 0, scale: 1, rotx: -Math.PI / 2, roty: 0, rotz: 0, spin: false, spinaxis: 'Z'}]})
}, 10000);*/
}
//simulate a socket.io callback to start the scene
/*setTimeout(function() {
renderInBody();
}, 4000);x Z*/
// Request animation frame loop function
var lastRender = 0;
function animate(timestamp) {
var delta = Math.min(timestamp - lastRender, 500);
lastRender = timestamp;
// Apply rotation to cube mesh
spinLoop(delta);
Reticulum.update();
controls.update();
// Render the scene through the manager.
manager.render(scene, camera, timestamp);
effect.render(scene, camera);
vrDisplay.requestAnimationFrame(animate);
}
function onResize(e) {
effect.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
}
var vrDisplay;
// Get the HMD, and if we're dealing with something that specifies
// stageParameters, rearrange the scene.
function setupStage() {
navigator.getVRDisplays().then(function(displays) {
if (displays.length > 0) {
vrDisplay = displays[0];
if (vrDisplay.stageParameters) {
setStageDimensions(vrDisplay.stageParameters);
}
vrDisplay.requestAnimationFrame(animate);
}
});
}
function setStageDimensions(stage) {
// Make the skybox fit the stage.
var material = skybox.material;
scene.remove(skybox);
// Size the skybox according to the size of the actual stage.
var geometry = new THREE.BoxGeometry(stage.sizeX, boxSize, stage.sizeZ);
skybox = new THREE.Mesh(geometry, material);
// Place it on the floor.
skybox.position.y = boxSize/2 - skyBoxY;
scene.add(skybox);
// Place the cube in the middle of the scene, at user height.
//cube.position.set(0, controls.userHeight, 0);
}