-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
553 lines (501 loc) · 19.1 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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
<!DOCTYPE html>
<html lang="en">
<head>
<script src="neatWASM.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.8.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.0/addons/p5.sound.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/peers/[email protected]/dist/peerjs.min.js"></script>
<!-- <script src="https://d3js.org/d3.v6.min.js"></script> -->
<script>
document.addEventListener('DOMContentLoaded', (event) => {
window.socketIO = io('http://127.0.0.1:4001/', { transports: ['websocket', 'polling'] });
console.warn('socketIO', socketIO)
// connect to "testOpenAIServer" and send a prompt message
socketIO.on('message', function(data){
// This event listener will trigger for any type of message received from the server
console.log("received message from server", data);
system.log(`${JSON.stringify(data)}`);
});
socketIO.on('connect', function(){
console.log("connected to socket.io server");
// don't do that on boot, it costs money!
// socketIO.emit('prompt', "hello world");
});
socketIO.on('result', function(data){
console.log("received result from server", data);
});
socketIO.on('upgrade', function(){
console.log("socket.io connection upgraded");
});
socketIO.connect();
});
</script>
<script type="module">
// TODO: make these "toggle-able" via flipping state bool
// and let this code know when to construct/destruct the instance for rendering in the scene
const ENABLE_FIELD_PREVIEW = true;
const ENABLE_STAR_PREVIEW = true;
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.module.js';
let _camera, scene, renderer, _cube, _sphere;
let _stars = [];
let flow_lattice = [];
let _gizmo;
// aka domready
document.addEventListener('DOMContentLoaded', (event) => {
// setTimeout(() => {
// init();
// animate();
// }, 1000);
function deinit(){
document.body.removeChild( _renderer.domElement );
_renderer, _scene, _camera, _cube, _sphere, _stars = null;
}
window.disableTHREEMode = function(){
window.three_mode_initialized = false;
}
window.initTHREEMode = function(){
window.three_mode_initialized = true;
init();
// kickstart renderer:
animate();
}
});
async function init() {
// function waitReturnTrue(fn){
// return new Promise((resolve, reject) => {
// let interval = setInterval(() => {
// if(fn()){
// clearInterval(interval);
// resolve();
// }
// }, 1000);
// });
// }
// await waitReturnTrue(() => typeof noise !== "undefined");
// init the flow lattice, a 3D array of 3D vectors
if(ENABLE_FIELD_PREVIEW){
for(let x = 0; x < 10; x++){
flow_lattice[x] = [];
for(let y = 0; y < 10; y++){
flow_lattice[x][y] = [];
for(let z = 0; z < 10; z++){
let nx = Math.random();
let ny = Math.random();
let nz = Math.random();
flow_lattice[x][y][z] = new THREE.Vector3(nx, ny, nz);
}
}
}
}
// wait for this to load
//: THREE.FresnelShader
// while(typeof THREE.FresnelShader === "undefined"){
// await new Promise(resolve => setTimeout(resolve, 1000));
// //console.warn("waiting for THREE.FresnelShader to load")
// }
init_phase_2();
}
function init_phase_2(){
_camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 100 );
_camera.position.z = 2;
scene = new THREE.Scene();
// set Gizmo to a nesting of 3 arrows generated by 3 cynlinders and cones
_gizmo = new THREE.Group();
_gizmo.add(new THREE.ArrowHelper(new THREE.Vector3(1, 0, 0), new THREE.Vector3(0, 0, 0), 1, 0xff0000)); // Red
_gizmo.add(new THREE.ArrowHelper(new THREE.Vector3(0, 1, 0), new THREE.Vector3(0, 0, 0), 1, 0x00ff00)); // Green
_gizmo.add(new THREE.ArrowHelper(new THREE.Vector3(0, 0, 1), new THREE.Vector3(0, 0, 0), 1, 0x0000ff)); // Blue
scene.add(_gizmo);
// render arrows for each vector in the flow lattice
if(ENABLE_FIELD_PREVIEW){
flow_lattice.forEach((x, i) => {
x.forEach((y, j) => {
y.forEach((z, k) => {
let arrow = new THREE.ArrowHelper(z, new THREE.Vector3(i, j, k), 0.5, 0x00ff00);
scene.add(arrow);
});
});
});
}
if(ENABLE_STAR_PREVIEW){
// generate stars (random points in space within a sphere)
const starsGeometry = new THREE.SphereGeometry(0.01, 32, 32);
const starsMaterial = new THREE.MeshBasicMaterial({
color: 0xFFFFFF
});
// fill _stars array with 1000 random points
for (let i = 0; i < 1000; i++) {
const starVector = new THREE.Vector3(
THREE.MathUtils.randFloatSpread(2),
THREE.MathUtils.randFloatSpread(2),
THREE.MathUtils.randFloatSpread(2)
);
const starSphere = new THREE.Mesh(starsGeometry, new THREE.MeshBasicMaterial({
color: 0xFFFFFF
}));
starSphere.castShadow = true; // Enable shadow casting by the star
starSphere.receiveShadow = true; // Enable shadow receiving by the star
starSphere.position.set(starVector.x, starVector.y, starVector.z);
scene.add(starSphere);
_stars.push(starSphere);
}
}
// Add a directional light
const light = new THREE.DirectionalLight(0xFFC0CB, 1.0);
light.position.set(1, 1, 1);
light.castShadow = true; // Enable shadow casting by the light
scene.add(light);
// add a second cross-directional light
const light2 = new THREE.DirectionalLight(0xFFA500, 1.0);
light2.position.set(-1, -1, -1);
light2.target.position.set(0, 0, 0);
light2.castShadow = true; // Enable shadow casting by the light
const texture = new THREE.TextureLoader().load( 'res/crate.gif' );
// Create a transparent cube
let geometry = new THREE.BoxGeometry(1, 1, 1);
// For the cube
let material = new THREE.MeshPhongMaterial({
color: 0x00ff00,
transparent: true,
opacity: 0.5
});
_cube = new THREE.Mesh(geometry, material);
_cube.castShadow = true; // Enable shadow casting by the cube
_cube.receiveShadow = true; // Enable shadow receiving by the cube
scene.add(_cube);
// Create a solid sphere
geometry = new THREE.SphereGeometry(0.5, 32, 32);
material = new THREE.MeshPhongMaterial({
color: 0xff0000
});
_sphere = new THREE.Mesh(geometry, material);
_sphere.castShadow = true; // Enable shadow casting by the sphere
_sphere.receiveShadow = true; // Enable shadow receiving by the sphere
scene.add(_sphere);
renderer = new THREE.WebGLRenderer( { antialias: true, alpha: true } ); // Enable transparency of the background
renderer.setClearColor( 0x000000, 0 ); // Set clear color to black (default) and fully transparent
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.shadowMap.enabled = true; // Enable shadow mapping in the renderer
renderer.shadowMap.enabled = true;
light.castShadow = true;
_cube.castShadow = true;
_cube.receiveShadow = true;
_sphere.castShadow = true;
_sphere.receiveShadow = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap; // Use PCFSoftShadowMap for softer shadows
document.body.appendChild( renderer.domElement );
console.warn("append renderer.domElement", renderer.domElement)
renderer.domElement.id = "threejscanvas";
// big plane
const planeGeometry = new THREE.PlaneGeometry( 100, 100, 32 );
let fresnelUniforms = {
"mRefractionRatio": { value: 1.02 },
"mFresnelBias": { value: 0.1 },
"mFresnelPower": { value: 2.0 },
"mFresnelScale": { value: 1.0 },
"tCube": { value: null }
};
// let planeMaterial = new THREE.ShaderMaterial({
// uniforms: fresnelUniforms,
// // vertexShader: THREE.FresnelShader.vertexShader,
// // fragmentShader: THREE.FresnelShader.fragmentShader,
// side: THREE.DoubleSide,
// transparent: true
// });
// const plane = new THREE.Mesh( planeGeometry, planeMaterial );
// plane.receiveShadow = true;
// // rotate 90 on x axis
// plane.rotation.x = Math.PI / 2;
// scene.add( plane );
window.addEventListener( 'resize', onWindowResize );
}
function onWindowResize() {
_camera.aspect = window.innerWidth / window.innerHeight;
_camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
let baseFrequency = 0.001; // Base frequency for the sinusoidal movement
let phaseShift = Math.PI; // Phase shift to make the movements out of phase
function animate() {
if(!_camera){
return;
}
// rotate the camera around the origin at a radius of 2
let distanceFromCenter = Math.abs(window.innerWidth/2 - window.mouseX);
// Re-map 0-1 in screenspace to 0-360 in rotation space
let rotationSpace = (distanceFromCenter / window.innerWidth) * 360;
distanceFromCenter *= (window.mouseX < window.innerWidth/2 ? 1 : -1);
let rotationFactor = distanceFromCenter / (window.innerWidth / 2);
rotationFactor = rotationFactor * 1e-9;
_camera.position.x = 2 * Math.sin(Date.now() * 0.001 * rotationFactor) * (1/window.zoom);
_camera.position.z = 2 * Math.cos(Date.now() * 0.001 * rotationFactor) * (1/window.zoom);
//_camera.position.y = (-panY - mouseY) * 0.0001;
_camera.lookAt(0, 0, 0);
// Perturb the stars with 4D Perlin noise
_stars.forEach(star => {
if(typeof noise !== "undefined"){
let factor = 0.1;
let scale = 0.05;
let _noise = noise(star.position.x, star.position.y, star.position.z, Date.now() * 0.0015);
star.position.x += _noise * factor - scale;
star.position.y += _noise * factor - scale;
star.position.z += _noise * factor - scale;
// set star color based on position
star.material.color.setRGB(
Math.abs(star.position.x),
Math.abs(star.position.y),
Math.abs(star.position.z)
);
}
});
// update camera FOV to match "window.zoom"
_camera.fov = window.fov; // 70 / window.zoom;
// Sinusoidal movement for cube and sphere
let time = Date.now() * baseFrequency;
let distance = Math.sqrt(
Math.pow(window.innerWidth/2 - window.mouseX, 2) +
Math.pow(window.innerHeight/2 - window.mouseY, 2)
);
let speedFactor = 1; //1 - (distance / (window.innerWidth / 2));
_cube.position.y = Math.sin(time * speedFactor);
_sphere.position.y = Math.sin((time + phaseShift) * speedFactor);
// move the camera based on panX and panY
// _camera.position.x = window.panX * window.zoom * 0.01;
// _camera.position.y = -window.panY * window.zoom * 0.01;
// _camera.position.z = 1/window.zoom;
try{
// console.warn({renderer, scene, _camera})
renderer.render( scene, _camera );
}catch(e){
console.error(e)
}
// Request the next frame at the end of the function to ensure all updates are rendered before the next frame is requested
if(window.three_mode_initialized){
requestAnimationFrame( animate );
}
}
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>NeatBox</title>
<style>
html, body {
overscroll-behavior-x: none;
background: #000;
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
}
body.monochrome {
filter: grayscale(100%);
}
input {
z-index: 3;
}
#bg-image {
opacity: 0;
position: fixed;
width: 100vw;
height: 100vh;
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
opacity: 0.3;
z-index: 1;
object-fit: cover;
transition: filter 1s ease-in-out, opacity 1s ease-in-out;
filter: blur(1000px);
}
main {
/* backdrop-filter: blur(10px); */
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
z-index: 2;
}
canvas {
display: block;
transition: filter 1s ease-in-out;
}
.deep-canvas {
pointer-events: none;
}
iframe {
position: absolute;
transition: filter 1s ease-in-out;
}
#cmdprompt-input {
border-radius: 100px;
outline: none;
}
#cmdprompt-input:focus {
outline: none;
}
canvas {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
}
#deep-canvas-1 {
z-index: 3;
}
#deep-canvas-2 {
z-index: 4;
}
#deep-canvas-3 {
z-index: 5;
}
iframe, video {
z-index: 999;
}
video {
position: absolute;
}
#glcanvas {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
width: 100%;
height: 100%;
z-index: 998;
box-sizing: border-box;
}
#glcanvas canvas {
width: 100%;
height: 100%;
z-index: 998;
/* border: 10px solid red; */
box-sizing: border-box;
/* top: 10px;
left: 10px; */
}
#threejscanvas, #threejscanvas canvas {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
width: 100%;
height: 100%;
z-index: 1000;
box-sizing: border-box;
}
#under-ui-elms {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
width: 100%;
height: 100%;
z-index: 9001;
}
#html-foreground {
pointer-events: none;
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
width: 100%;
height: 100%;
z-index: 9002;
}
#deep-canvas-ui {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 9003;
}
#file-drop-ui {
z-index: 9004;
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
width: 100%;
height: 100%;
}
video {
border-radius: 50px;
z-index: 9005;
position: absolute;
overflow: hidden;
border: 10px solid blue;
background: blue;
box-shadow: 5px 5px 5px rgba(255,255,255,0.1);
}
</style>
<meta charset="utf-8" />
</head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-GYK2ZMX0M9"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-GYK2ZMX0M9');
</script>
<body ondragover="event.preventDefault();"
ondrop="system.onDrop(event);">
<svg width="500" height="300" id="d3-layer-001"></svg>
<style>
#file-drop-ui {
opacity: 0;
border: 10px dashed yellow;
pointer-events: none;
backdrop-filter: blur(10px);
}
#file-drop-ui #drop-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 2em;
color: yellow;
}
body.dragover #file-drop-ui {
opacity: 1;
}
</style>
<script>
document.body.ondragenter = function(event) {
event.preventDefault();
document.body.classList.add('dragover');
}
document.body.ondragleave = function(event) {
// if the target is NOT the document element, leave it
console.warn('left', event.target);
if (event.target !== document) {
return;
}
document.body.classList.remove('dragover');
}
</script>
<img id="bg-image" src="./res/bg-1.jpg" alt="">
<div id="file-drop-ui">
<div id="drop-text">DROP STUFF HERE</div>
</div>
<div id="deep-canvas-1" class="deep-canvas"></div>
<div id="deep-canvas-2" class="deep-canvas"></div>
<div id="deep-canvas-3" class="deep-canvas"></div>
<main id="main-canvas-context"></main>
<div id="p5-3d"></div>
<div id="under-ui-elms"><!-- iFrames and stuff go here --></div>
<div id="html-foreground"><!-- html inputs that need to go above iframes --></div>
<div id="deep-canvas-ui"></div>
<a href="https://github.com/jakedowns/starpages" target="_blank" style="position: absolute; top: 0; right: 0; border: 0; z-index: 9999;">
Github
</a>
<!-- place a github stars badge in the bottom right -->
<div class="github-stars-badge">
<a href="https://github.com/jakedowns/starpages" target="_blank">
<img src="https://img.shields.io/github/stars/jakedowns/starpages?style=social" alt="Github Stars">
</a>
</div>
<script>
var script = document.createElement('script');
script.src = "./neat.js?version=" //+ new Date().getTime();
document.head.appendChild(script);
// load neat-typescript.js TOO
var script2 = document.createElement('script');
script2.src = "./neat-typescript.js";
document.head.appendChild(script2);
</script>
<script src="https://code.responsivevoice.org/responsivevoice.js?key=QTmqQZWr"></script>
</body>
</html>