-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
240 lines (185 loc) · 7.35 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
<!doctype html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Title -->
<title>bu3nPattern</title>
<meta property="og:title" content="bu3nPattern">
<!--Favicon-->
<link rel="icon" href="https://mathigatti.com/favicon/favicon.png">
<!--Preview Images-->
<meta property="og:image" content="https://bu3namigue.github.io/bu3npattern/demo.gif">
<link rel="image_src" href="/demo.gif">
<!--Description-->
<meta name="description" content="Apply real time pattern effects to your webcam online">
<meta property="og:description" content="Apply real time pattern effects to your webcam online">
<!--Author-->
<meta name="author" content="bu3nAmigue">
<!--Twitter config-->
<meta name="twitter:title" content="bu3nPattern">
<meta name="twitter:description"content="Apply real time pattern effects to your webcam online">
<meta name="twitter:image" content="https://bu3namigue.github.io/bu3npattern/demo.gif">
<meta name="twitter:card" content="summary_large_image">
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<script src="https://cdn.jsdelivr.net/npm/twgl.js@4.15.0/dist/4.x/twgl-full.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dat.gui@0.7.7/build/dat.gui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.3.4/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.3.4/EasePack.min.js"></script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="module" src="ca.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css"
integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<link href="/bu3npattern/styles.css" rel="stylesheet">
</head>
<body>
<a id="screenshot" class="info">
<span class="fab fas fa-camera-retro fa-2x"></span>
<span class="text">Take screenshot</span>
</a>
<a id="btn" class="info">
<span class="fab fas fa-plus-circle "></span>
<span class="text">Add new pattern</span>
</a>
<div id="showInfo" class="modal">
<div class="modal-header">
<p>bu3n pattern</p>
<span class="close">×
</span>
</div>
<div class="modal-content">
<form enctype="multipart/form-data">
<p>Create your own effect by adding a customized pattern.</p>
<p>Generate a personalized model from images using <a href="https://colab.research.google.com/drive/1KMlVFi2zXhE0_PHCBXC07oblcJf9E13s" target="_blank">this colab</a></p>
<p>After you download the models JSON file</p>
<p>Load it and try it! </p>
<input class="button" id="upload" type="file" accept="text/json" value="Upload JSON here!" size="60"/>
<label for="upload">Upload file</label>
</form>
</div>
</div>
</div>
<a href="https://github.com/bu3nAmigue/bu3npattern" class="info"
title="View source on Github" target="_blank">
<span class="fab fa-github"></span>
<span class="text">View source</span>
</a>
<a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="info" id="tweetB">
<i class="fab fa-twitter"></i>
<span class="text">Share</span>
</a>
<a href='https://ko-fi.com/Q5Q62LLVG' class="info" target="_blank">
<span class="fab fa-gratipay"></span>
<span class="text">Support us </span>
</a>
<a href="https://forms.gle/bA6HMw27b2w5LyXW8" class="info" target="_blank">
<span class="fas fa-comment-dots "></span>
<span class="text">Send feedback!</span>
</a>
<canvas id="glCanvas" style='z-index: 1'></canvas>
<script src="/bu3npattern/helper.js"></script>
<script src="/bu3npattern/FileSaver.js"></script>
<script type="module">
import { CA } from "./ca.js"
const canvas = document.querySelector('#glCanvas');
const devicePixelRatio = window.devicePixelRatio || 1;
const quality = .5;
const gl = canvas.getContext("webgl", {preserveDrawingBuffer: true});
const W = 256, H = 256;
var videoLoaded = false;
let ca;
resizeGLCanvas(window.innerWidth, window.innerHeight);
function resizeGLCanvas(width, height) {
canvas.width = width / quality;
canvas.height = height / quality;
canvas.style.width = width + 'px';
canvas.style.height = height + 'px';
gl.viewport(0, 0, canvas.width, canvas.height);
}
const video = document.createElement('video');
video.autoplay="";
video.style="display:none";
video.id="feedCam";
const param = {
active: true,
model: 132,
zoom: 0.,
speed: 1,
paintMode: false,
};
function create_gui(){
var gui = new dat.GUI();
gui.add(param, 'active');
gui.add(param, 'zoom', -0.5, .5).step(0.0001);
gui.add(param, 'speed', 0, 6);
return gui;
}
var gui = create_gui();
let name2idx, modelController;
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia && video) {
var constraints = {audio: false, video: true};
navigator.mediaDevices.getUserMedia( constraints ).then( function ( stream ) {
video.playsInline = true;
video.srcObject = stream;
video.play();
videoLoaded = true;
ca.loadVideoTexture(video);
} ).catch( function ( error ) {
console.error( 'Unable to access the camera/webcam.', error );
} );
} else {
console.error( 'MediaDevices interface not available.' );
}
function update_model(models){
ca.setWeights(models);
name2idx = Object.fromEntries(models.model_names.map((s, i) => [s, i]));
gui.remove(modelController);
modelController = gui.add(param, 'model').options(name2idx).listen();
param.model=0;
}
function load_model(models) {
ca = new CA(gl, models, [W, H], gui);
window.ca = ca;
ca.alignment = 0;
name2idx = Object.fromEntries(models.model_names.map((s, i) => [s, i]));
modelController = gui.add(param, 'model').options(name2idx).listen();
ca.paint(128, 128, 1000, param.model);
$( ".target" ).change(function() {
alert( "Handler for .change() called." );
});
function render() {
if (videoLoaded){
ca.updateVideoTex(video);
}
if (param.active) {
//ca.clearCircle(Math.sin(t * 2.0) * W / 3 + W / 2, Math.cos(t * 3.1) * H / 3 + H / 2, 20);
for (let i=0; i<param.speed; ++i) ca.step('all', param.zoom);
}
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
ca.draw();
ca.paint(128, 128, 1000, param.model);
requestAnimationFrame(render);
}
requestAnimationFrame(render);
}
fetch('data/models.json').then(r => r.json()).then(models => {
console.log(models);
load_model(models);
});
function handleFileSelect(evt) {
var files = evt.target.files;
var f = files[0];
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
var models = e.target.result;
var json_models = JSON.parse(models);
update_model(json_models);
};
})(f);
reader.readAsText(f);
}
document.getElementById('upload').addEventListener('change', handleFileSelect, false);
</script>
</body>