-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.html
159 lines (118 loc) · 4.12 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="res/css/main.css" />
</head>
<body>
<canvas id="screen"></canvas>
</body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/ashes.main.js"></script>
<!-- <script src="build/ashes.main.js"></script> -->
<script>
let { Asset, EntityMgr, Camera, vec3, Screen, OrbitControl, Filter, Shader, Material } = Ashes;
// let assetRoot = 'https://but0n.github.io/Ashes/'
let assetRoot = ''
Material.SHADER_PATH = assetRoot + Material.SHADER_PATH;
let [, cuspath, scale, yoffset, threshold, radiu, intensity] = [, , , ,];
// BoomBox
let gltf = assetRoot + 'gltfsamples/BoomBox.glb';
// kgirls01: Skin, Animation:
// ----------------------------
scale = 0.003;
yoffset = 3;
// threshold = 0.9;
gltf = assetRoot + 'gltfsamples/kgirls01/scene.gltf';
gltf = assetRoot + 'res/CesiumMan.glb';
// gltf = assetRoot + 'res/BrainStem.glb';
// gltf = assetRoot + 'res/project_polly.glb';
gltf = assetRoot + 'gltfsamples/3_seconds_of_vacations/scene.gltf';
scale = 1;
yoffset = 0.1;
async function main() {
let screen = new Screen('#screen');
screen.bgColor = [0.2, 0.2, 0.2, 1];
// Filters
// Bloom.initFilters(screen, threshold || 0.6, radiu || 80, intensity || 1.2);
// screen.attachFilter(new Vignetting(screen));
let loading = new loadingAnim(screen);
loading.cb = () => {
screen.deleteFilter(0);
console.log('delete');
}
screen.attachFilter(loading);
Asset.taskObserve = (finished, total) => {
let p = finished / total;
loading.cur = p;
}
let skybox = await Asset.loadCubemap(assetRoot + 'res/envmap/GoldenGateBridge2/');
let scene = EntityMgr.create('root - (Click each bar which has yellow border to toggle visible)');
// Camera and controls
let mainCamera = scene.appendChild(EntityMgr.create('camera'));
let cameraTrans = mainCamera.components.Transform;
let cam = mainCamera.addComponent(new Camera(screen.width / screen.height));
vec3.set(cameraTrans.translate, 0, 10, 10);
mainCamera.addComponent(new OrbitControl(screen, mainCamera));
document.querySelector('body').appendChild(scene);
let gltfroot = scene.appendChild(await Asset.loadGLTF(gltf, screen, skybox));
let root = gltfroot.components.Transform;
root.translate[1] = yoffset || 0;
vec3.scale(root.scale, root.scale, scale || 200)
// scene.appendChild(await Asset.loadGLTF(assetRoot + 'res/BrainStem.glb', screen, skybox));
}
let loading_vs = `
attribute vec3 POSITION;
attribute vec2 TEXCOORD_0;
varying vec2 uv;
varying vec4 pos;
void main() {
uv = TEXCOORD_0;
vec4 position = vec4(POSITION, 1);
pos = position;
gl_Position = position;
}
`;
let loading_fs = `
precision highp float;
uniform sampler2D base;
uniform float cur;
uniform float powcur;
varying vec2 uv;
varying vec4 pos;
void main() {
vec4 base = texture2D(base, uv);
float prog = abs(uv.y - 0.5) * 2.;
// Middle out
if(cur < prog) {
gl_FragColor = vec4(1);
} else {
gl_FragColor = vec4(base.rgb * powcur, base.a);
}
}
`;
class loadingAnim extends Filter {
constructor(screen) {
let macro = {};
let shader = new Shader(loading_vs, loading_fs, macro);
super(screen, shader);
this.cur = 0;
this.stop = false;
let cur = 0;
Material.setUniform(this.material, 'cur', this.cur);
let loop = () => {
cur += (this.cur - cur) * 0.05;
Material.setUniform(this.material, 'cur', cur);
Material.setUniform(this.material, 'powcur', Math.pow(cur, 8));
if (cur < 0.999) {
requestAnimationFrame(loop);
} else {
Material.setUniform(this.material, 'cur', 1);
Material.setUniform(this.material, 'powcur', 1);
if (this.cb) this.cb();
}
};
loop();
}
}
main();
</script>
</html>