-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbasic.html
More file actions
179 lines (143 loc) · 5.81 KB
/
basic.html
File metadata and controls
179 lines (143 loc) · 5.81 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
<!DOCTYPE html>
<!-- include three.js -->
<script src='vendor/three.js/build/three.js'></script>
<script src='vendor/three.js/editor/js/libs/app.js'></script>
<!-- include js-aruco -->
<script src='../vendor/js-aruco/svd.js'></script>
<script src='../vendor/js-aruco/posit1-patched.js'></script>
<script src='../vendor/js-aruco/cv.js'></script>
<script src='../vendor/js-aruco/aruco.js'></script>
<!-- include some extensions -->
<script src='../src/threex.webcamgrabbing.js'></script>
<script src='../src/threex.imagegrabbing.js'></script>
<script src='../src/threex.videograbbing.js'></script>
<script src='../src/threex.jsarucomarker.js'></script>
<body style='margin: 0px; overflow: hidden; text-align:center;'>
<div id='info' style='position: absolute; top: 0px; width: 100%;font-family:arial; font-weight: bolder; padding-top: 5px;'>
Augmented Reality with <a href="http://threejs.org" target="_blank">three.js</a>
- works on desktop and mobile
- require <a href='https://get.webgl.org/'>WebGL</a> and <a href='http://caniuse.com/#feat=stream'>getUserMedia</a> Support
<br/>
Source:
<a class='webcam' href='javascript:void();'>webcam</a> -
<a class='image' href='javascript:void();'>image</a> -
<a class='video' href='javascript:void();'>video</a>
</div>
<script>
//////////////////////////////////////////////////////////////////////////////////
// Handle ui button
//////////////////////////////////////////////////////////////////////////////////
document.querySelector('#info .webcam').addEventListener('click', function(event){
location.hash = '#webcam'
location.reload()
})
document.querySelector('#info .image').addEventListener('click', function(event){
location.hash = '#image'
location.reload()
})
document.querySelector('#info .video').addEventListener('click', function(event){
location.hash = '#video'
location.reload()
})
//////////////////////////////////////////////////////////////////////////////////
// Init
//////////////////////////////////////////////////////////////////////////////////
// init renderer
var renderer = new THREE.WebGLRenderer({
antialias : true,
alpha : true,
});
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// array of functions for the rendering loop
var onRenderFcts = [];
// init scene and camera
var scene = new THREE.Scene()
var camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 0.01, 1000);
camera.position.z = 2;
//////////////////////////////////////////////////////////////////////////////////
// create a markerObject3D
//////////////////////////////////////////////////////////////////////////////////
var markerObject3D = new THREE.Object3D()
scene.add(markerObject3D)
// set the markerObject3D as visible
markerObject3D.visible = false
//////////////////////////////////////////////////////////////////////////////////
// add an object in the markerObject3D
//////////////////////////////////////////////////////////////////////////////////
// add some debug display
;(function(){
var geometry = new THREE.PlaneGeometry(1,1,10,10)
var material = new THREE.MeshBasicMaterial( {
wireframe : true
})
var mesh = new THREE.Mesh(geometry, material);
markerObject3D.add( mesh );
var mesh = new THREE.AxisHelper
markerObject3D.add( mesh );
})()
// add a awesome logo to the scene
;(function(){
var material = new THREE.SpriteMaterial({
map: THREE.ImageUtils.loadTexture( 'images/awesome.png' ),
});
var geometry = new THREE.BoxGeometry(1,1,1)
var object3d = new THREE.Sprite(material );
object3d.scale.set( 2, 2, 1 );
markerObject3D.add(object3d)
})()
//////////////////////////////////////////////////////////////////////////////////
// render the whole thing on the page
//////////////////////////////////////////////////////////////////////////////////
// handle window resize
window.addEventListener('resize', function(){
renderer.setSize( window.innerWidth, window.innerHeight )
camera.aspect = window.innerWidth / window.innerHeight
camera.updateProjectionMatrix()
}, false)
// render the scene
onRenderFcts.push(function(){
renderer.render( scene, camera );
})
// run the rendering loop
var previousTime = performance.now()
requestAnimationFrame(function animate(now){
requestAnimationFrame( animate );
onRenderFcts.forEach(function(onRenderFct){
onRenderFct(now, now - previousTime)
})
previousTime = now
})
//////////////////////////////////////////////////////////////////////////////////
// Do the Augmented Reality part
//////////////////////////////////////////////////////////////////////////////////
// init the marker recognition
var jsArucoMarker = new THREEx.JsArucoMarker()
// if no specific image source is specified, take the webcam by default
if( location.hash === '' ) location.hash = '#webcam'
// init the image source grabbing
if( location.hash === '#video' ){
var videoGrabbing = new THREEx.VideoGrabbing()
jsArucoMarker.videoScaleDown = 10
}else if( location.hash === '#webcam' ){
var videoGrabbing = new THREEx.WebcamGrabbing()
jsArucoMarker.videoScaleDown = 2
}else if( location.hash === '#image' ){
var videoGrabbing = new THREEx.ImageGrabbing()
jsArucoMarker.videoScaleDown = 10
}else console.assert(false)
// attach the videoGrabbing.domElement to the body
document.body.appendChild(videoGrabbing.domElement)
// process the image source with the marker recognition
onRenderFcts.push(function(){
var domElement = videoGrabbing.domElement
var markers = jsArucoMarker.detectMarkers(domElement)
markerObject3D.visible = false
// see if this.markerId has been found
markers.forEach(function(marker){
// if( marker.id !== 265 ) return
jsArucoMarker.markerToObject3D(marker, markerObject3D)
markerObject3D.visible = true
})
})
</script></body>