-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewer.html
186 lines (161 loc) · 3.56 KB
/
viewer.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>vox</title>
</head>
<body>
<style>
* {
background: #d0d0e1;
padding: 0;
margin: 0;
}
head {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
user-select: none;
-webkit-user-select: none;
}
.screen {
/*display: flex;
align-items: center;
justify-content: center;*/
width: 100%;
height: 100%;
}
#canvas {
touch-action: none;
image-rendering: pixelated;
position: absolute;
background: #000;
}
.tab {
position: absolute;
overflow: hidden;
}
@media (orientation: portrait) {
#canvas {
width: 100vw;
height: 100vw;
}
.tab {
width: 90vw;
height: calc(100% - 110vw);
margin: 5vw;
bottom: 0;
background: #e3e6ef;
border-radius: 2.5vw;
}
.sprite {
transform: rotateZ(90deg) translateX(-500%) translateY(-45%);
}
}
@media (orientation: landscape) {
#canvas {
width: 100vh;
height: 100vh;
right: 0;
}
.tab {
height: 90vh;
width: calc(100vw - 100vh);
margin: 5vh;
background: #e3e6ef;
border-radius: 2.5vh;
left: 0;
}
}
</style>
<div class="screen">
<canvas id="canvas"></canvas>
<div class="tab">
<input type="file" accept="image/*" onchange="load(this)"><hr>
resolution
<input type="range" value="4" min="1" max="6" class="res" onchange="update()"><hr>
stacks
<input type="range" value="8" min="1" max="8" class="stk" onchange="update()"><hr>
<img class="sprite" src="models/clown.png">
</div>
</div>
<script src="vox.js"></script>
<script src="camera.js"></script>
<script>
image = document.querySelector('.sprite');
resv = document.querySelector('.res');
stkv = document.querySelector('.stk');
updated = true;
init();
function load(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
image.src = e.target.result;
};
reader.readAsDataURL(input.files[0]);
}
}
function update() {
updated = false;
init();
}
image.onload = function(){updated=false;init();};
function init() {
width = image.width;
height = image.height;
//resolution of screen
scaleSize = 16/(width/Math.pow(2,resv.value));
//number of stacks
resolution = stkv.value;
res = scaleSize/resolution;
layers = height/width;
size = layers*scaleSize;
canvas.width = size;
canvas.height = size;
layers2 = layers*scaleSize/res;
is = scaleSize/(scaleSize/res*2);
x = size/2-size/4;
y = x;
scale = size/2;
t = 0;
draw();
}
function draw() {
if (updated == true) {
requestAnimationFrame(draw);
}
else {
cancelAnimationFrame(draw);
}
Yaw = Yaw + YawV;
Pitch = Math.min(Math.max(Pitch + PitchV,-90),90);
YawV = YawV * .9;
PitchV = PitchV * .9;
//sorting stacks
if (Pitch > 0) {
ctx.globalCompositeOperation = 'source-over';
}
else {
ctx.globalCompositeOperation = 'destination-over';
}
t = t+1;
//updating screen
cls(ctx);
z = 0;
rotx = Pitch;
roty = Yaw;
for (i = layers2; i > 0; i--) {
if (i%(scaleSize/res)==0) {
z++;
}
ssprr(ctx,x,y+(i*is-layers2*is/2)*Math.cos(rotx*Math.PI/180),scale,scale,0,z*-width+height,width,width,roty,rotx);
}
updated = true;
}
</script>
</body>
</html>