-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathREADME.html
More file actions
804 lines (703 loc) · 24.8 KB
/
Copy pathREADME.html
File metadata and controls
804 lines (703 loc) · 24.8 KB
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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
<head>
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
display: block;
}
#canvas {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
position: fixed;
position: relative;
}
.error {
font-family: Consolas;
font-size: 1.2em;
color: black;
box-sizing: border-box;
background-color: lightcoral;
border-radius: 2px;
border-color: lightblue;
border-width: thin;
border-style: solid;
line-height: 1.4em;
cursor:pointer;
}
.error:hover {
color: black;
background-color: brown;
border-color: blue;
}
#message {
font-family: Consolas;
font-size: 1.2em;
color: #ccc;
background-color: black;
font-weight: bold;
z-index: 2;
position: absolute;
}
#dat_gui_container {
position: absolute;
left: 0px; /* position inside relatively positioned parent */
top: 0px;
z-index: 3; /* adjust as needed */
}
/* Pause Button Style */
.rec_base {
position: absolute;
border: none;
right: 0px;
padding: 26px;
text-align: center;
text-decoration: none;
font-size: 26px;
border-radius: 8px;
margin: 8px;
transform: translateX(0%);
z-index: 1;
}
.rec_base:nth-of-type(2) {
top: 60px;
}
/* Screenshot Button Style */
/* Record Button Style */
/* Reload Button Style */
</style>
</head>
<body>
<div id="message"></div>
<div id="dat_gui_container"></div>
<div id="container">
<!-- Pause Element -->
</div>
<!-- Screenshot Element -->
<!-- Record Element -->
<!-- Reload Element -->
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/110/three.min.js"></script>
<!-- Stats.js -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/stats.js/r16/Stats.min.js' onload="
let stats = new Stats();
compileTimePanel = stats.addPanel(new Stats.Panel('CT MS', '#ff8', '#221'));
stats.showPanel(1);
document.body.appendChild(stats.domElement);
requestAnimationFrame(function loop() {
stats.update();
requestAnimationFrame(loop);
});
"></script>
<!-- dat.gui -->
<canvas id="canvas"></canvas>
<!-- Shaders -->
<script id='/Users/weekit/Desktop/Feat/flutter-assets-gen/README.md' type='x-shader/x-fragment'>
uniform vec3 iResolution;
uniform float iTime;
uniform float iTimeDelta;
uniform int iFrame;
uniform vec4 iDate;
uniform vec3 iChannelResolution[10];
uniform vec4 iMouse;
uniform vec4 iMouseButton;
uniform mat4 iViewMatrix;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;
uniform sampler2D iChannel4;
uniform sampler2D iChannel5;
uniform sampler2D iChannel6;
uniform sampler2D iChannel7;
uniform sampler2D iChannel8;
uniform sampler2D iChannel9;
uniform sampler2D iKeyboard;
uniform float iSampleRate;
#define iGlobalTime iTime
#define iGlobalFrame iFrame
#define SHADER_TOY
## 命令 (Provide commands)
- F1 > Search flutter assets
- `Flutter Assets: Watch`
- `Flutter Assets: Stop Watch`
- `Flutter Assets: Generate`

## 如何使用 (How to use)
- step 1. 在项目pubspec.yaml下添加 (Add under project pubspec.yaml):
```yaml
flutter_assets:
assets_path: assets/
output_path: lib/constants/
filename: assets.dart
```
- **field_prefix为可选字段,如果想去掉assets前缀,则提供一个空,默认为assets** (**field_prefix is an optional field, if you want to remove the assets prefix, provide an empty value, the default is assets**)
```yaml
flutter_assets:
assets_path: assets/
output_path: lib/constants/
filename: assets.dart
field_prefix:
```
- **修改prefix** (**Modify prefix**)
```yaml
flutter_assets:
assets_path: assets/
output_path: lib/constants/
filename: assets.dart
field_prefix: resource
```
- step 2. 生成文件内容 (Generate file content)
```dart
class Assets {
Assets._();
/// Assets for loginLogo
/// assets/images/login/logo.png
static const String assetsImagesLoginLogo = "assets/images/login/logo.png";
/// Assets for tabHome
/// assets/images/tab/home.png
static const String assetsImagesTabHome = "assets/images/tab/home.png";
}
```
- step 3. 引入 (introduce)
```dart
import 'constants/assets.dart';
/// example1:
Image.asset(Assets.assetsImagesLoginLogo, height: 30, width: 30),
/// example2:
Image(image: AssetImage(Assets.assetsImagesTabHome,), height: 30, width: 30),
```
## 修改类名 (Modify class name)
```yaml
flutter_assets:
assets_path: assets/
output_path: lib/constants/
filename: assets.dart
field_prefix:
classname: R
```
生成内容 (Generate content)
```dart
class R {
R._();
/// Assets for loginLogo
/// assets/images/login/logo.png
static const String assetsImagesLoginLogo = "assets/images/login/logo.png";
/// Assets for tabHome
/// assets/images/tab/home.png
static const String assetsImagesTabHome = "assets/images/tab/home.png";
}
```
</script>
<!-- FlyControls -->
<script type="text/javascript">
let vscode = undefined;
if (typeof acquireVsCodeApi === 'function') {
vscode = acquireVsCodeApi();
}
var compileTimePanel;
let revealError = function(line, file) {
if (vscode) {
vscode.postMessage({
command: 'showGlslsError',
line: line,
file: file
});
}
};
let currentShader = {};
// Error Callback
console.error = function () {
if('7' in arguments) {
let errorRegex = /ERROR: \d+:(\d+):\W(.*)\n/g;
let rawErrors = arguments[7];
let match;
let diagnostics = [];
let message = '';
while(match = errorRegex.exec(rawErrors)) {
let lineNumber = Number(match[1]) - currentShader.LineOffset;
let error = match[2];
diagnostics.push({
line: lineNumber,
message: error
});
let lineHighlight = `<a class='error' unselectable onclick='revealError(${lineNumber}, "${currentShader.File}")'>Line ${lineNumber}</a>`;
message += `<li>${lineHighlight}: ${error}</li>`;
}
console.log(message);
let diagnosticBatch = {
filename: currentShader.File,
diagnostics: diagnostics
};
if (vscode !== undefined) {
vscode.postMessage({
command: 'showGlslDiagnostic',
type: 'error',
diagnosticBatch: diagnosticBatch
});
}
$('#message').append(`<h3>Shader failed to compile - ${currentShader.Name} </h3>`);
$('#message').append('<ul>');
$('#message').append(message);
$('#message').append('</ul>');
}
};
// Development feature: Output warnings from third-party libraries
// console.warn = function (message) {
// $("#message").append(message + '<br>');
// };
let clock = new THREE.Clock();
let pausedTime = 0.0;
let deltaTime = 0.0;
let startingTime = 0;
let time = startingTime;
let date = new THREE.Vector4();
let updateDate = function() {
let today = new Date();
date.x = today.getFullYear();
date.y = today.getMonth();
date.z = today.getDate();
date.w = today.getHours() * 60 * 60
+ today.getMinutes() * 60
+ today.getSeconds()
+ today.getMilliseconds() * 0.001;
};
updateDate();
let paused = false;
let forceRenderOneFrame = paused;
let pauseButton = document.getElementById('pause-button');
if (pauseButton) {
pauseButton.checked = paused;
pauseButton.onclick = function(){
paused = pauseButton.checked;
if (!paused) {
// Audio Resume
pausedTime += clock.getDelta();
}
else {
// Audio Pause
}
if (vscode !== undefined) {
vscode.postMessage({
command: 'setPause',
paused: paused
});
}
};
}
{
let screenshotButton = document.getElementById("screenshot");
if (screenshotButton) {
screenshotButton.addEventListener('click', saveScreenshot);
}
}
{
let recordButton = document.getElementById("record");
if (recordButton) {
recordButton.addEventListener('click', recordAction);
}
}
{
let reloadButton = document.getElementById("reload");
if (reloadButton) {
reloadButton.addEventListener('click', reloadWebview);
}
}
window.addEventListener('message', event => {
const message = event.data; // The JSON data our extension sent
switch (message.command) {
case 'pause':
if (pauseButton) {
pauseButton.checked = !pauseButton.checked;
}
paused = !paused;
if (!paused) {
// Audio Resume
pausedTime += clock.getDelta();
}
else {
// Audio Pause
}
if (vscode !== undefined) {
vscode.postMessage({
command: 'setPause',
paused: paused
});
}
break;
case 'screenshot':
saveScreenshot();
break;
}
});
let canvas = document.getElementById('canvas');
let gl = canvas.getContext('webgl2');
let isWebGL2 = gl != null;
if (gl == null) gl = canvas.getContext('webgl');
let supportsFloatFramebuffer = (gl.getExtension('EXT_color_buffer_float') != null) || (gl.getExtension('WEBGL_color_buffer_float') != null);
let supportsHalfFloatFramebuffer = (gl.getExtension('EXT_color_buffer_half_float') != null);
let framebufferType = THREE.UnsignedByteType;
if (supportsFloatFramebuffer) framebufferType = THREE.FloatType;
else if (supportsHalfFloatFramebuffer) framebufferType = THREE.HalfFloatType;
let renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true, context: gl, preserveDrawingBuffer: true });
let resolution = forceAspectRatio(window.innerWidth, window.innerHeight);
let mouse = new THREE.Vector4(-1, -1, -1, -1);
let mouseButton = new THREE.Vector4(0, 0, 0, 0);
let normalizedMouse = new THREE.Vector2(0, 0);
let frameCounter = 0;
let recorder = null;
// Audio Init
const audioContext = {
sampleRate: 0
};
// Audio Resume
let buffers = [];
// Buffers
buffers.push({
Name: '/Users/weekit/Desktop/Feat/flutter-assets-gen/README.md',
File: '/Users/weekit/Desktop/Feat/flutter-assets-gen/README.md',
LineOffset: 134,
Target: null,
ChannelResolution: Array(10).fill(new THREE.Vector3(0,0,0)),
PingPongTarget: null,
PingPongChannel: 0,
Dependents: [],
Shader: new THREE.ShaderMaterial({
fragmentShader: document.getElementById('/Users/weekit/Desktop/Feat/flutter-assets-gen/README.md').textContent,
depthWrite: false,
depthTest: false,
uniforms: {
iResolution: { type: 'v3', value: resolution },
iTime: { type: 'f', value: 0.0 },
iTimeDelta: { type: 'f', value: 0.0 },
iFrame: { type: 'i', value: 0 },
iMouse: { type: 'v4', value: mouse },
iMouseButton: { type: 'v2', value: mouseButton },
iViewMatrix: {type: 'm44', value: new THREE.Matrix4() },
iChannelResolution: { type: 'v3v', value: Array(10).fill(new THREE.Vector3(0,0,0)) },
iDate: { type: 'v4', value: date },
iSampleRate: { type: 'f', value: audioContext.sampleRate },
iChannel0: { type: 't' },
iChannel1: { type: 't' },
iChannel2: { type: 't' },
iChannel3: { type: 't' },
iChannel4: { type: 't' },
iChannel5: { type: 't' },
iChannel6: { type: 't' },
iChannel7: { type: 't' },
iChannel8: { type: 't' },
iChannel9: { type: 't' },
resolution: { type: 'v2', value: resolution },
time: { type: 'f', value: 0.0 },
mouse: { type: 'v2', value: normalizedMouse },
}
})
});
let commonIncludes = [];
// Includes
// WebGL2 inserts more lines into the shader
if (isWebGL2) {
for (let buffer of buffers) {
buffer.LineOffset += 16;
}
}
// Keyboard Init
// Uniforms Init
// Uniforms Update
let texLoader = new THREE.TextureLoader();
// Texture Init
let scene = new THREE.Scene();
let quad = new THREE.Mesh(
new THREE.PlaneGeometry(resolution.x, resolution.y),
null
);
scene.add(quad);
let controlState = new THREE.Camera();
controlState.position.set(0,0,0);
controlState.quaternion.set(0,0,0,1);
scene.add(controlState);
let flyControls = undefined;
if (typeof FlyControls === 'function') {
flyControls = new FlyControls(controlState, renderer.domElement, vscode);
flyControls.movementSpeed = 1;
flyControls.domElement = renderer.domElement;
flyControls.rollSpeed = Math.PI / 24;
flyControls.autoForward = false;
flyControls.dragToLook = true;
}
let camera = new THREE.OrthographicCamera(-resolution.x / 2.0, resolution.x / 2.0, resolution.y / 2.0, -resolution.y / 2.0, 1, 1000);
camera.position.set(0, 0, 10);
// Run every shader once to check for compile errors
let compileTimeStart = performance.now();
let failed=0;
for (let include of commonIncludes) {
currentShader = {
Name: include.Name,
File: include.File,
// add two for version and precision lines
LineOffset: 27 + 2
};
// Test Compile Included Files
// bail if there is an error found in the include script
if(compileFragShader(gl, document.getElementById(include.Name).textContent) == false) {
throw Error(`Failed to compile ${include.Name}`);
}
}
for (let buffer of buffers) {
currentShader = {
Name: buffer.Name,
File: buffer.File,
LineOffset: buffer.LineOffset
};
quad.material = buffer.Shader;
renderer.setRenderTarget(buffer.Target);
renderer.render(scene, camera);
}
currentShader = {};
let compileTimeEnd = performance.now();
let compileTime = compileTimeEnd - compileTimeStart;
if (compileTimePanel !== undefined) {
for (let i = 0; i < 200; i++) {
compileTimePanel.update(compileTime, 200);
}
}
computeSize();
render();
function addLineNumbers( string ) {
let lines = string.split( '\\n' );
for ( let i = 0; i < lines.length; i ++ ) {
lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
}
return lines.join( '\\n' );
}
function compileFragShader(gl, fsSource) {
const fs = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fs, fsSource);
gl.compileShader(fs);
if (!gl.getShaderParameter(fs, gl.COMPILE_STATUS)) {
const fragmentLog = gl.getShaderInfoLog(fs);
console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.COMPILE_STATUS', null, null, null, null, fragmentLog );
return false;
}
return true;
}
function render() {
requestAnimationFrame(render);
if (!forceRenderOneFrame) {
// Pause Whole Render
if (paused) return;
}
forceRenderOneFrame = false;
// Advance Time
deltaTime = clock.getDelta();
time = startingTime + clock.getElapsedTime() - pausedTime;
if (vscode !== undefined) {
vscode.postMessage({
command: 'updateTime',
time: time
});
}
updateDate();
if(flyControls)
{
flyControls.update(0.1);
}
// Audio Update
for (let buffer of buffers) {
buffer.Shader.uniforms['iResolution'].value = resolution;
buffer.Shader.uniforms['iTimeDelta'].value = deltaTime;
buffer.Shader.uniforms['iTime'].value = time;
buffer.Shader.uniforms['iFrame'].value = frameCounter;
buffer.Shader.uniforms['iMouse'].value = mouse;
buffer.Shader.uniforms['iMouseButton'].value = mouseButton;
buffer.Shader.uniforms['iViewMatrix'].value = controlState.matrixWorld;
buffer.Shader.uniforms['resolution'].value = resolution;
buffer.Shader.uniforms['time'].value = time;
buffer.Shader.uniforms['mouse'].value = normalizedMouse;
quad.material = buffer.Shader;
renderer.setRenderTarget(buffer.Target);
renderer.render(scene, camera);
}
// Uniforms Update
// Keyboard Update
if (mouse.w > 0.0) {
mouse.w = -mouse.w;
updateMouse();
}
for (let buffer of buffers) {
if (buffer.PingPongTarget) {
[buffer.PingPongTarget, buffer.Target] = [buffer.Target, buffer.PingPongTarget];
buffer.Shader.uniforms[`iChannel${buffer.PingPongChannel}`].value = buffer.PingPongTarget.texture;
for (let dependent of buffer.Dependents) {
const dependentBuffer = buffers[dependent.Index];
dependentBuffer.Shader.uniforms[`iChannel${dependent.Channel}`].value = buffer.Target.texture;
}
}
}
frameCounter++;
}
function forceAspectRatio(width, height) {
// Forced aspect ratio
let forcedAspects = [0,0];
let forcedAspectRatio = forcedAspects[0] / forcedAspects[1];
let aspectRatio = width / height;
if (forcedAspectRatio <= 0 || !isFinite(forcedAspectRatio)) {
let resolution = new THREE.Vector3(width, height, 1.0);
return resolution;
}
else if (aspectRatio < forcedAspectRatio) {
let resolution = new THREE.Vector3(width, Math.floor(width / forcedAspectRatio), 1);
return resolution;
}
else {
let resolution = new THREE.Vector3(Math.floor(height * forcedAspectRatio), height, 1);
return resolution;
}
}
function computeSize() {
// Compute forced aspect ratio and align canvas
resolution = forceAspectRatio(window.innerWidth, window.innerHeight);
canvas.style.left = `${(window.innerWidth - resolution.x) / 2}px`;
canvas.style.top = `${(window.innerHeight - resolution.y) / 2}px`;
for (let buffer of buffers) {
if (buffer.Target) {
buffer.Target.setSize(resolution.x, resolution.y);
}
if (buffer.PingPongTarget) {
buffer.PingPongTarget.setSize(resolution.x, resolution.y);
}
}
renderer.setSize(resolution.x, resolution.y, false);
// Update Camera and Mesh
quad.geometry = new THREE.PlaneGeometry(resolution.x, resolution.y);
camera.left = -resolution.x / 2.0;
camera.right = resolution.x / 2.0;
camera.top = resolution.y / 2.0;
camera.bottom = -resolution.y / 2.0;
camera.updateProjectionMatrix();
// Reset iFrame on resize for shaders that rely on first-frame setups
frameCounter = 0;
}
function saveScreenshot() {
let doSaveScreenshot = () => {
renderer.domElement.toBlob(function(blob){
let a = document.createElement('a');
let url = URL.createObjectURL(blob);
a.href = url;
a.download = 'shadertoy.png';
a.click();
}, 'image/png', 1.0);
};
let forcedScreenshotResolution = [0,0];
if (forcedScreenshotResolution[0] <= 0 || forcedScreenshotResolution[1] <= 0) {
renderer.render(scene, camera);
doSaveScreenshot();
}
else {
renderer.setSize(forcedScreenshotResolution[0], forcedScreenshotResolution[1], false);
for (let buffer of buffers) {
buffer.Shader.uniforms['iResolution'].value = new THREE.Vector3(forcedScreenshotResolution[0], forcedScreenshotResolution[1], 1);
buffer.Shader.uniforms['resolution'].value = new THREE.Vector3(forcedScreenshotResolution[0], forcedScreenshotResolution[1], 1);
quad.material = buffer.Shader;
renderer.setRenderTarget(buffer.Target);
renderer.render(scene, camera);
}
doSaveScreenshot();
renderer.setSize(resolution.x, resolution.y, false);
}
}
function recordAction() {
let recordButton = document.getElementById("record");
if (recorder == null) {
recordButton.classList.add('recording');
let stream = canvas.captureStream(30);
let recorderOptions = {
mimeType: "video/webm"
};
recorder = new MediaRecorder(stream, recorderOptions);
recorder.start();
recorder.ondataavailable = function(evt) {
let a = document.createElement('a');
let url = URL.createObjectURL(evt.data);
a.href = url;
a.download = 'shadertoy.webm';
a.click();
};
}
else {
recordButton.classList.remove('recording');
recorder.stop();
recorder = null;
}
}
function reloadWebview() {
if (vscode !== undefined) {
vscode.postMessage({ command: 'reloadWebview' });
}
}
function updateMouse() {
if (vscode !== undefined) {
vscode.postMessage({
command: 'updateMouse',
mouse: {
x: mouse.x,
y: mouse.y,
z: mouse.z,
w: mouse.w
},
normalizedMouse: {
x: normalizedMouse.x,
y: normalizedMouse.y
}
});
}
}
let dragging = false;
function updateNormalizedMouseCoordinates(clientX, clientY) {
let rect = canvas.getBoundingClientRect();
let mouseX = clientX - rect.left;
let mouseY = resolution.y - clientY - rect.top;
if (mouseButton.x + mouseButton.y != 0) {
mouse.x = mouseX;
mouse.y = mouseY;
}
normalizedMouse.x = mouseX / resolution.x;
normalizedMouse.y = mouseY / resolution.y;
}
canvas.addEventListener('mousemove', function(evt) {
updateNormalizedMouseCoordinates(evt.clientX, evt.clientY);
updateMouse();
}, false);
canvas.addEventListener('mousedown', function(evt) {
if (evt.button == 0)
mouseButton.x = 1;
if (evt.button == 2)
mouseButton.y = 1;
if (!dragging) {
updateNormalizedMouseCoordinates(evt.clientX, evt.clientY);
mouse.z = mouse.x;
mouse.w = mouse.y;
dragging = true
}
updateMouse();
}, false);
canvas.addEventListener('mouseup', function(evt) {
if (evt.button == 0)
mouseButton.x = 0;
if (evt.button == 2)
mouseButton.y = 0;
dragging = false;
mouse.z = -mouse.z;
mouse.w = -mouse.w;
updateMouse();
}, false);
window.addEventListener('resize', function() {
computeSize();
});
// Keyboard Callbacks
</script>