-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrendering.js
156 lines (134 loc) · 4.33 KB
/
rendering.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
function loadDAE(url,callback) {
var coloader = new THREE.ColladaLoader();
coloader.load(url, function (result) {
callback(result);
});
}
function modelSizeBox(scene) {
var box = new THREE.Box3().setFromObject(scene);
console.log("size box");
console.log(box.size());
return box;
}
function addSceneLight(scene,color) {
scene.add( new THREE.AmbientLight( 0xcccccc ) );
/*
var directionalLight = new THREE.DirectionalLight( 0xeeeeee );
directionalLight.position.x = Math.random() - 0.5;
directionalLight.position.y = Math.random() - 0.5;
directionalLight.position.z = Math.random() - 0.5;
directionalLight.position.normalize();
scene.add( directionalLight );
*/
}
var skybox;
var skyboxType;
var boxSize;
var skyBoxY;
function setSkyboxStage(scene,type,size,negypos) {
scene.remove(skybox);
if(type == "grid") {
console.log("type grid");
boxSize = size;
skyBoxY = negypos;
var loader = new THREE.TextureLoader();
loader.load('/img/box.png', onTextureLoaded);
}
if(type == "milky") {
loadSkysphere("/vr/skyboxes/milkyhd.jpg")
}
if(type == "fores") {
loadSkysphere("/vr/skyboxes/forest.png")
}
if(type == "icela") {
loadSkysphere("/vr/skyboxes/iceland.jpg")
}
if(type == "purdu") {
loadSkysphere("/vr/skyboxes/purdue.jpg")
}
if(type == "sunset") {
document.body.style.background = "linear-gradient(#de6161 , #2657eb)";
//setupStage();
}
}
function loadSkysphere(path,size) {
var skyGeo = new THREE.SphereGeometry(size, 64, 64);
var texture = THREE.ImageUtils.loadTexture(path);
var material = new THREE.MeshPhongMaterial({
map: texture,
});
texture.wrapS = THREE.RepeatWrapping;
material.map.repeat.x = -1;
skybox = new THREE.Mesh(skyGeo, material);
skybox.material.side = THREE.BackSide;
scene.add(skybox);
}
function onTextureLoaded(texture) {
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(boxSize, boxSize);
var geometry = new THREE.BoxGeometry(boxSize, boxSize, boxSize);
var material = new THREE.MeshBasicMaterial({
map: texture,
color: 0x01BE00,
side: THREE.BackSide
});
// Align the skybox to the floor (which is at y=0).
skybox = new THREE.Mesh(geometry, material);
skybox.position.y = boxSize/2 - skyBoxY;
scene.add(skybox);
// For high end VR devices like Vive and Oculus, take into account the stage
// parameters provided.*/
//setupStage();
}
function createText(text,font,weight,style,size) {
var textShapes = THREE.FontUtils.generateShapes( text, options );
var text = new THREE.ShapeGeometry( textShapes );
var textMesh = new THREE.Mesh( text, new THREE.MeshBasicMaterial( { color: 0xff0000 } ) ) ;
scene.add(textMesh);
}
function scaleModel(model,multiplier) {
model.scale.x = multiplier * 0.0254;
model.scale.y = multiplier * 0.0254;
model.scale.z = multiplier * 0.0254;
}
function placeModelInFrontOfCamera(model) {
var box = modelSizeBox(model)
var size = box.getSize();
var sizetotal = (size.x + size.y + size.z) / 3;
var zdisplacement = 2 * sizetotal;
model.position.z = -zdisplacement;
}
var modelsToRotate = [];
function startSpin(model,x,y,z) {
var rotation = {model: model, x: x, y: y, z: z};
modelsToRotate.push(rotation);
}
function spinLoop(delta) {
modelsToRotate.forEach(function(rotation) {
var model = rotation.model;
model.rotation.set(model.rotation.x + (rotation.x * delta * 0.0006),model.rotation.y + (rotation.y * delta * 0.0006), model.rotation.z + (rotation.z * delta * 0.0006), 'XYZ');
//rotateAroundWorldAxis(model, new THREE.Vector3(0,1,0), model.rotation.y + delta * 0.0006);
//rotateAroundWorldAxis( model,new THREE.Vector3(0, 1, 0), model.rotation.y + delta * 0.0006 );
});
}
function stopSpin(model) {
for(var i=0;i<modelsToRotate.length;i++) {
var rotation = modelsToRotate[i];
console.log("rotation stop:");
console.log(rotation);
if(rotation.model.uuid === model.uuid) {
console.log("remove that sh!t");
modelsToRotate.splice(i,1);
console.log(modelsToRotate);
}
}
}
var rotWorldMatrix;
function rotateAroundWorldAxis( object, axis, radians ) {
rotWorldMatrix = new THREE.Matrix4();
rotWorldMatrix.makeRotationAxis(axis.normalize(), radians);
rotWorldMatrix.multiply(object.matrix); // pre-multiply
object.matrix = rotWorldMatrix;
object.rotation.setEulerFromRotationMatrix(object.matrix, object.order);
}