-
Notifications
You must be signed in to change notification settings - Fork 0
/
world-multi.html
294 lines (236 loc) · 7.06 KB
/
world-multi.html
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Three.js Geometry Browser</title>
<style>
body {
margin:0;
font-family: "Lucida Console", monospace;
font-size: 15px;
line-height: 18px;
overflow: hidden;
}
#info{
position: absolute;
top: 0;
left: 0;
right: 0;
text-align: center;
padding: 5px;
pointer-events: none;
font-family: inherit;
}
</style>
</head>
<body>
<div id="info"></div>
<script src="https://threejs.org/build/three.min.js"></script>
<script src='https://threejs.org/examples/js/libs/dat.gui.min.js'></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="js/shaders.js"></script>
<script>
var gui = null
var guiParam = {};
var spaceLength = {
x: 176,
y: 256,
z: 256
}
var renderer = null
var scene = null
var camera = null
var container = null
var shaderMat = null;
var boxHelper = null;
var screenContainer = null;
var textureLoader = null;
var texturePaths = [
'data/176_256_256_zspace_23x4_0.png', // 1/3
'data/176_256_256_zspace_23x4_1.png', // 2/3
'data/176_256_256_zspace_23x4_2.png', // 3/3
];
var textures = [];
function init(){
// init renderer
renderer = new THREE.WebGLRenderer( { antialias: false } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0xEEEEEE, 1 );
document.body.appendChild( renderer.domElement );
textureLoader = new THREE.TextureLoader();
// THREE environment
scene = new THREE.Scene();
var axisHelper = new THREE.AxisHelper( 10 );
scene.add( axisHelper );
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
var orbit = new THREE.OrbitControls( camera, renderer.domElement );
container = new THREE.Object3D();
scene.add( container );
initGui();
initBox();
//loadingImage();
addTexture(0);
}
function addTexture( textureIndex ){
var infoDiv = document.getElementById("info");
textureLoader.load(
// resource URL
texturePaths[textureIndex],
// Function when resource is loaded
function ( texture ) {
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestFilter;
texture.flipY = false;
textures.push( texture );
infoDiv.innerHTML = textures.length + "/" + texturePaths.length + " texture files loaded...";
if(textures.length == texturePaths.length){
initScreen();
infoDiv.innerHTML = "texture loaded."
}else{
addTexture(textureIndex+1);
}
},
// Function called when download progresses
function ( xhr ) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
// Function called when download errors
function ( xhr ) {
console.log( 'An error happened' );
}
);
}
function initGui(){
gui = new dat.GUI();
guiParam.xPos = Math.floor(spaceLength.x / 2);
gui.add(guiParam, 'xPos', 0, spaceLength.x)
.step(0.05)
.onChange(function(val){
screenContainer.position.x = val - spaceLength.x / 2;
})
guiParam.yPos = Math.floor(spaceLength.y / 2);
gui.add(guiParam, 'yPos', 0, spaceLength.y)
.step(0.05)
.onChange(function(val){
screenContainer.position.y = val - spaceLength.y / 2;
})
guiParam.zPos = Math.floor(spaceLength.z / 2);
gui.add(guiParam, 'zPos', 0, spaceLength.z)
.step(0.05)
.onChange(function(val){
screenContainer.position.z = val - spaceLength.z / 2;
})
guiParam.xRot = 0;
gui.add(guiParam, 'xRot', -Math.PI/2, Math.PI/2)
.step(Math.PI/2 / 100)
.onChange(function(val){
screenContainer.rotation.x = val;
})
guiParam.yRot = 0;
gui.add(guiParam, 'yRot', -Math.PI/2, Math.PI/2)
.step(Math.PI/2 / 100)
.onChange(function(val){
screenContainer.rotation.y = val;
})
guiParam.zRot = 0;
gui.add(guiParam, 'zRot', -Math.PI/2, Math.PI/2)
.step(Math.PI/2 / 100)
.onChange(function(val){
screenContainer.rotation.z = val;
})
}
/**
* Initialize the ouside box
*/
function initBox(xspaceLength, yspaceLength, zspaceLength){
var boxMaterial = new THREE.MeshBasicMaterial();
var boxGeom = new THREE.CubeGeometry(
spaceLength.x,
spaceLength.y,
spaceLength.z
);
var boxMesh = new THREE.Mesh( boxGeom, boxMaterial )
boxHelper = new THREE.EdgesHelper( boxMesh, 0xff9999 );
container.add( boxHelper );
// adjust the camera to the box
camera.position.z = spaceLength.z;
}
function initScreen(){
screenContainer = new THREE.Object3D();
shaderMat = new THREE.ShaderMaterial( {
uniforms: {
// the textures
nbOfTextureUsed: {
type: "i",
value: textures.length
},
// the number of slice per row
nbSlicePerRow: {
type: "f",
value: 23.0
},
// the number of slice per column
nbSlicePerCol: {
type: "f",
value: 4.0
},
// the number of slice in total
nbSliceTotal: {
type: "f",
value: spaceLength.z // because along zspace
},
// xspace length
xspaceLength: {
type: "f",
value: spaceLength.x
},
// yspace length
yspaceLength: {
type: "f",
value: spaceLength.y
},
// zspace length
zspaceLength: {
type: "f",
value: spaceLength.z
},
textures: {
type: "t",
value: textures
}
}
,
vertexShader: shaders.vertex,
fragmentShader: shaders.fragmentMultiple,
side: THREE.DoubleSide,
transparent: true
});
var largestSide = Math.sqrt(spaceLength.x*spaceLength.x + spaceLength.y*spaceLength.y + spaceLength.z*spaceLength.z) * 2;
var zPlaneGeometry = new THREE.PlaneBufferGeometry( largestSide, largestSide, 1 );
var zPlaneMesh = new THREE.Mesh( zPlaneGeometry, shaderMat );
screenContainer.add( zPlaneMesh );
var xPlaneGeometry = new THREE.PlaneBufferGeometry( largestSide, largestSide, 1 );
var xPlaneMesh = new THREE.Mesh( xPlaneGeometry, shaderMat );
xPlaneMesh.rotation.y = Math.PI / 2;
screenContainer.add( xPlaneMesh );
var zPlaneGeometry = new THREE.PlaneBufferGeometry( largestSide, largestSide, 1 );
var zPlaneMesh = new THREE.Mesh( zPlaneGeometry, shaderMat );
zPlaneMesh.rotation.x = Math.PI / 2;
screenContainer.add( zPlaneMesh );
container.add( screenContainer );
}
function render() {
requestAnimationFrame( render );
renderer.render( scene, camera );
};
window.addEventListener( 'resize', function () {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}, false );
init();
render();
</script>
</body>
</html>