-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw6.html
468 lines (403 loc) · 15.3 KB
/
hw6.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
<!DOCTYPE html>
<<<<<<< HEAD
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Charactor</title>
<!-- three.js library -->
<script src='vendor/three.js/build/three.js'></script>
<script src='vendor/three.js/examples/js/libs/stats.min.js'></script>
<!-- jsartookit -->
<script src='../vendor/jsartoolkit5/build/artoolkit.min.js'></script>
<script src='../vendor/jsartoolkit5/js/artoolkit.api.js'></script>
<!-- include threex.artoolkit -->
<script src='../src/threex/threex-artoolkitsource.js'></script>
=======
<meta name='viewport' content='width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0'>
<!-- three.js library -->
<script src='vendor/three.js/build/three.js'></script>
<script src='vendor/three.js/examples/js/libs/stats.min.js'></script>
<!-- jsartookit -->
<script src='../vendor/jsartoolkit5/build/artoolkit.min.js'></script>
<script src='../vendor/jsartoolkit5/js/artoolkit.api.js'></script>
<!-- include threex.artoolkit -->
<script src='../src/threex/threex-artoolkitsource.js'></script>
>>>>>>> master
<script src='../src/threex/threex-artoolkitcontext.js'></script>
<script src='../src/threex/threex-artoolkitprofile.js'></script>
<script src='../src/threex/threex-arbasecontrols.js'></script>
<script src='../src/threex/threex-armarkercontrols.js'></script>
<script src='../src/threex/threex-arsmoothedcontrols.js'></script>
<script>THREEx.ArToolkitContext.baseURL = '../'</script>
<<<<<<< HEAD
</head>
<body>
<script src="../examples/js/loaders/ColladaLoader.js"></script>
<script src="../examples/js/controls/OrbitControls.js"></script>
<script src="../examples/js/Detector.js"></script>
<script src="../examples/js/libs/stats.min.js"></script>
<script>
//init renderer(初始化渲染器)
var renderer=new THREE.WebGLRenderer({
alpha:true
});
renderer.setClearColor(new THREE.Color('lightgrey'),0);
//renderer setPiexRatio(2);
renderer.setSize(window.innerWidth,window.innerHeight);
renderer.domElement.style.position='absolute';
renderer.domElement.style.top='0px';
renderer.domElement.style.left='0px';
document.body.appendChild(renderer.domElement);
//array of functions for the rendering loop(渲染處理函式組初始化)
var onRenderFcts=[];
//init scene and camera
var scene=new THREE.Scene();//初始化場景和環境
var ambient=new THREE.AmbientLight(0x666666);
scene.add(ambient);
var directctionalLight=new THREE.DirectionalLight(0x887766);
directctionalLight.position.set(-1,1,1).normalize();
scene.add(directctionalLight);
//Initialize a basic camera
//Create a camera(初始化相機新增到場景)
var camera=new THREE.Camera();
scene.add(camera);
//handle arToolkitSource(呼叫開啟相機事件,由THREEx提供)
var arToolkitSource=new THREEx.ArToolkitSource({
//to read from the webcam
sourceType:'webcam'
// // to read from an image
// sourceType : 'image',
// sourceUrl : THREEx.ArToolkitContext.baseURL + '../data/images/img.jpg',
// sourceUrl : THREEx.ArToolkitContext.baseURL + '../data/images/armchair.jpg',
// to read from a video
// sourceType : 'video',
// sourceUrl : THREEx.ArToolkitContext.baseURL + '../data/videos/headtracking.mp4',
})
arToolkitSource.init(function onReady() {
onResize();
})
//handle resize(處理重新調整大小後正常顯示)
window.addEventListener('resize',function () {
onResize();
})
function onResize() {
arToolkitSource.onResizeElement()
arToolkitSource.copyElementSizeTo(renderer.domElement)
if(arToolkitContext.arController!==null){
arToolkitSource.copyElementSizeTo(arToolkitContext.arController.canvas);
}
}
//初始化 ArcToolkit環境, 相機內部場景
//initialize arToolkitContext
//create acToolkitContext
var arToolkitContext=new THREEx.ArToolkitContext({
//相機引數設定
cameraParametersUrl:THREEx.ArToolkitContext.baseURL+'../data/data/camera_para.dat',
//debug:true,
//detectionMode:'mono_and_matrix',
detectionMode:'mono',
// detectionMode:'color_and_matrix',
// matrixCodeType:'3x3',
canvasWidth:80*3,
canvasHeight:60*3,
maxDetectionRate:30, //最大旋轉角度還是什麼滴
})
//initialize it
arToolkitContext.init(function onCompleted() {
//copy projection matrix to camera
camera.projectionMatrix.copy(arToolkitContext.getProjectionMatrix());
});
//update artoolkit on every frame
onRenderFcts.push(function () {
if(arToolkitSource.ready==false) return;
arToolkitContext.update(arToolkitSource.domElement)
})
//Create a ArMakerControls
//建立一個Ar標記
var markerRoot=new THREE.Group(); //用threejs的點集合初始化。
scene.add(markerRoot);
var markerControls=new THREEx.ArMarkerControls(arToolkitContext,markerRoot,{
//type:'barcode',
//barcodeValue:5,
type:'pattern',
patternUrl:THREEx.ArToolkitContext.baseURL+'./examples/marker-training/examples/pattern-files/pattern-marker.patt',
})
//build a smoothedControls
var smoothedRoot=new THREE.Group();
scene.add(smoothedRoot);
var smoothedControls=new THREEx.ArSmoothedControls(smoothedRoot,{
lerpPosition:0.4,
lerpQuaternion:0.3,
lerpScale:1,
//minVisibleDaly:1,
//minUnvisibleDely:1,
})
onRenderFcts.push(function (delta) {
smoothedControls.update(markerRoot)
})
smoothedControls.addEventListener('becameVisible',function () {
console.log('becameVisible event notified')
})
//add Object in the scene
//新增物體
var arWorldRoot=smoothedRoot
var mesh=new THREE.AxisHelper();
//markerRoot.add(mesh)
arWorldRoot.add(mesh);
//add a torus knot建立物體
// collada
//
var loader = new THREE.ColladaLoader();
loader.load( '../examples/models/collada/stormtrooper/stormtrooper.dae', function ( collada ) {
var animations = collada.animations;
//調整物件狀態
var avatar = collada.scene;
avatar.rotation.x=Math.PI;
avatar.rotation.z=Math.PI;
avatar.scale.set(0.5,0.5,0.5);
mixer = new THREE.AnimationMixer( avatar );
arWorldRoot.add( avatar );
var action = mixer.clipAction( animations[ 0 ] ).play();
onRenderFcts.push(function () {
avatar.rotation.z+=0.02*Math.PI;
})
} );
//renderer the Whole thing on the page
//渲染場景到頁面中
//渲染率檢視器
var stats=new Stats();
document.body.appendChild(stats.dom);
//renderer the scene
onRenderFcts.push(function () {
renderer.render(scene,camera);
stats.update();
})
//行程渲染事件環路
//run the rendering loop
var lastTimeMsec=null;
requestAnimationFrame(function animate(nowMsec){
//keep looping
requestAnimationFrame(animate);
//measure time
lastTimeMsec=lastTimeMsec||nowMsec-1000/60;
var deltaMsec=Math.min(200,nowMsec-lastTimeMsec)
//call all each update function
onRenderFcts.forEach(function (onRenderFct) {
onRenderFct(deltaMsec/1000,nowMsec/1000)
})
})
</script>
</body>
</html>
=======
<body style='margin : 0px; overflow: hidden; font-family: Monospace;'><div style='position: absolute; top: 10px; width:100%; text-align: center;z-index:1';>
<a href='https://github.com/jeromeetienne/AR.js/' target='_blank'>AR.js</a> - developement playground
<br/>
Contact me any time at <a href='https://twitter.com/jerome_etienne' target='_blank'>@jerome_etienne</a>
</div><script>
//////////////////////////////////////////////////////////////////////////////////
// Init
//////////////////////////////////////////////////////////////////////////////////
// init renderer
var renderer = new THREE.WebGLRenderer({
// antialias : true,
alpha: true
});
renderer.setClearColor(new THREE.Color('lightgrey'), 0)
// renderer.setPixelRatio( 2 );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.domElement.style.position = 'absolute'
renderer.domElement.style.top = '0px'
renderer.domElement.style.left = '0px'
document.body.appendChild( renderer.domElement );
// array of functions for the rendering loop
var onRenderFcts= [];
// init scene and camera
var scene = new THREE.Scene();
var ambient = new THREE.AmbientLight( 0x666666 );
scene.add( ambient );
var directionalLight = new THREE.DirectionalLight( 0x887766 );
directionalLight.position.set( -1, 1, 1 ).normalize();
scene.add( directionalLight );
//////////////////////////////////////////////////////////////////////////////////
// Initialize a basic camera
//////////////////////////////////////////////////////////////////////////////////
// Create a camera
var camera = new THREE.Camera();
scene.add(camera);
////////////////////////////////////////////////////////////////////////////////
// handle arToolkitSource
////////////////////////////////////////////////////////////////////////////////
var arToolkitSource = new THREEx.ArToolkitSource({
// to read from the webcam
sourceType : 'webcam',
// // to read from an image
// sourceType : 'image',
// sourceUrl : THREEx.ArToolkitContext.baseURL + '../data/images/img.jpg',
// sourceUrl : THREEx.ArToolkitContext.baseURL + '../data/images/armchair.jpg',
// to read from a video
// sourceType : 'video',
// sourceUrl : THREEx.ArToolkitContext.baseURL + '../data/videos/headtracking.mp4',
})
arToolkitSource.init(function onReady(){
onResize()
})
// handle resize
window.addEventListener('resize', function(){
onResize()
})
function onResize(){
arToolkitSource.onResizeElement()
arToolkitSource.copyElementSizeTo(renderer.domElement)
if( arToolkitContext.arController !== null ){
arToolkitSource.copyElementSizeTo(arToolkitContext.arController.canvas)
}
}
////////////////////////////////////////////////////////////////////////////////
// initialize arToolkitContext
////////////////////////////////////////////////////////////////////////////////
// create atToolkitContext
var arToolkitContext = new THREEx.ArToolkitContext({
cameraParametersUrl: THREEx.ArToolkitContext.baseURL + '../data/data/camera_para.dat',
// debug: true,
// detectionMode: 'mono_and_matrix',
detectionMode: 'mono',
// detectionMode: 'color_and_matrix',
// matrixCodeType: '3x3',
canvasWidth: 80*3,
canvasHeight: 60*3,
maxDetectionRate: 30,
})
// initialize it
arToolkitContext.init(function onCompleted(){
// copy projection matrix to camera
camera.projectionMatrix.copy( arToolkitContext.getProjectionMatrix() );
})
// update artoolkit on every frame
onRenderFcts.push(function(){
if( arToolkitSource.ready === false ) return
arToolkitContext.update( arToolkitSource.domElement )
})
////////////////////////////////////////////////////////////////////////////////
// Create a ArMarkerControls
////////////////////////////////////////////////////////////////////////////////
var markerRoot = new THREE.Group
scene.add(markerRoot)
var markerControls = new THREEx.ArMarkerControls(arToolkitContext, markerRoot, {
// type: 'barcode',
// barcodeValue: 5,
type : 'pattern',
patternUrl : THREEx.ArToolkitContext.baseURL + 'examples/marker-training/examples/pattern-files/pattern-hiro.patt',
})
// build a smoothedControls
var smoothedRoot = new THREE.Group()
scene.add(smoothedRoot)
var smoothedControls = new THREEx.ArSmoothedControls(smoothedRoot, {
lerpPosition: 0.4,
lerpQuaternion: 0.3,
lerpScale: 1,
// minVisibleDelay: 1,
// minUnvisibleDelay: 1,
})
onRenderFcts.push(function(delta){
smoothedControls.update(markerRoot)
})
// smoothedControls.addEventListener('becameVisible', function(){
// console.log('becameVisible event notified')
// })
// smoothedControls.addEventListener('becameUnVisible', function(){
// console.log('becameUnVisible event notified')
// })
//////////////////////////////////////////////////////////////////////////////////
// add an object in the scene
//////////////////////////////////////////////////////////////////////////////////
// var arWorldRoot = markerRoot
var arWorldRoot = smoothedRoot
var mesh = new THREE.AxisHelper()
// markerRoot.add(mesh)
arWorldRoot.add(mesh)
var geometry = new THREE.PlaneGeometry(0.4,0.2,10);
var material = new THREE.MeshBasicMaterial( {color: 0xffff00, side: THREE.DoubleSide} );
var plane = new THREE.Mesh( geometry, material );
plane.rotation.x=-Math.PI/2;
plane.position.set(0,0.5,0.1);
arWorldRoot.add(plane);
var material2 = new THREE.MeshBasicMaterial( {color: 0xff0000, side: THREE.DoubleSide} );
var plane2 = new THREE.Mesh( geometry, material2 );
plane2.rotation.x=-Math.PI/2;
plane2.position.set(0,0.5,0.3);
arWorldRoot.add(plane2);
var material3 = new THREE.MeshBasicMaterial( {color: 0x0000ff, side: THREE.DoubleSide} );
var plane3 = new THREE.Mesh( geometry, material3 );
plane3.rotation.x=-Math.PI/2;
plane3.position.set(0,0.5,0.5);
arWorldRoot.add(plane3);
var plane4 = new THREE.Mesh( geometry, material2 );
plane4.rotation.x=-Math.PI/2;
plane4.position.set(0.2,0.5,-0.1);
arWorldRoot.add(plane4);
var plane5 = new THREE.Mesh( geometry, material3 );
plane5.rotation.x=-Math.PI/2;
plane5.position.set(-0.2,0.5,-0.1);
arWorldRoot.add(plane5);
var plane6 = new THREE.Mesh( geometry, material );
plane6.rotation.x=-Math.PI/2;
plane6.position.set(0,0.5,-0.3);
arWorldRoot.add(plane6);
var geometry2 = new THREE.CircleGeometry( 0.3, 3,0,Math.PI );
var circle = new THREE.Mesh( geometry2, material2 );
circle.rotation.x=-Math.PI/2;circle.position.set(0,0.5,-0.40);
arWorldRoot.add(circle);
/*
// add a torus knot
var geometry = new THREE.CubeGeometry(1,1,1);
var material = new THREE.MeshNormalMaterial({
transparent : true,
opacity: 0.5,
side: THREE.DoubleSide
})
var mesh = new THREE.Mesh( geometry, material );
mesh.position.y = geometry.parameters.height/2
// markerRoot.add( mesh );
arWorldRoot.add(mesh)
var geometry = new THREE.TorusKnotGeometry(0.3,0.1,64,16);
var material = new THREE.MeshNormalMaterial();
var mesh = new THREE.Mesh( geometry, material );
mesh.position.y = 0.5
// markerRoot.add( mesh );
arWorldRoot.add( mesh );
onRenderFcts.push(function(delta){
mesh.rotation.x += delta * Math.PI
})*/
//////////////////////////////////////////////////////////////////////////////////
// render the whole thing on the page
//////////////////////////////////////////////////////////////////////////////////
var stats = new Stats();
document.body.appendChild( stats.dom );
// render the scene
onRenderFcts.push(function(){
renderer.render( scene, camera );
stats.update();
})
// run the rendering loop
var lastTimeMsec= null
requestAnimationFrame(function animate(nowMsec){
// keep looping
requestAnimationFrame( animate );
// measure time
lastTimeMsec = lastTimeMsec || nowMsec-1000/60
var deltaMsec = Math.min(200, nowMsec - lastTimeMsec)
lastTimeMsec = nowMsec
// call each update function
onRenderFcts.forEach(function(onRenderFct){
onRenderFct(deltaMsec/1000, nowMsec/1000)
})
<<<<<<< HEAD
})
</script>
</body>
>>>>>>> master
=======
})
</script></body>
>>>>>>> master