forked from 1d10t/test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha-frame-webcam-dae.html.bak
147 lines (118 loc) · 4.88 KB
/
a-frame-webcam-dae.html.bak
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
<html>
<head>
<script src="https://aframe.io/aframe/dist/aframe-master.min.js"></script>
<script src="https://jeromeetienne.github.io/AR.js/aframe/build/aframe-ar.min.js"></script>
<script src="https://cdn.rawgit.com/chrisveness/latlon-geohash/53c3d474/latlon-geohash.js"></script>
<script>THREEx.ArToolkitContext.baseURL = 'https://jeromeetienne.github.io/AR.js/three.js/'</script>
<script src="components.js"></script>
<script>
var hash_fences = {};
function ce(t,a){ var f = document.createElement(t); for(var k in a) f.setAttribute(k, a[k]); return f; }
function load_hash(d){
hash_fences[d.hash] = d.objects;
for(var i=0; i<d.objects.length; i++){
var
o = d.objects[i],
element_id = 'fence_' + o.id.replace(':', '_')
;
if(!document.getElementById(element_id)){
fences.appendChild( ce(
'a-collada-model',
{
'id': element_id,
'src': 'https://yaglov.ru/cadastre/fence.php?id='+encodeURIComponent(o.id),
'gps-place': 'longitude: '+o.extent.xmin+'; latitude: '+o.extent.ymin,
'transparent-texture': ''
}
) );
}
}
}
window.onload = function(){
var camera = document.getElementById('camera');
camera.addEventListener('componentchanged', function (evt) {
switch(evt.detail.name){
case 'rotation':
var newData = evt.target.getAttribute('rotation');
console.log('camera rotation changed', newData);
var
compassRotation = camera.components['compass-rotation'],
lookControls = camera.components['look-controls']
;
camera_angle.innerText = newData.y;
if(lookControls){
yaw_angle.innerText = THREE.Math.radToDeg(lookControls.yawObject.rotation.y);
}
if(compassRotation){
compass_heading.innerText = compassRotation.heading;
}
break;
case 'position':
var newData = evt.target.getAttribute('position');
console.log('camera position changed', newData);
var
gpsPosition = camera.components['gps-position']
;
camera_p_x.innerText = newData.x;
camera_p_z.innerText = newData.z;
if(gpsPosition){
if(gpsPosition.crd){
crd_longitude.innerText = gpsPosition.crd.longitude;
crd_latitude.innerText = gpsPosition.crd.latitude;
var hash = Geohash.encode(gpsPosition.crd.latitude, gpsPosition.crd.longitude, 7);
geohash_7chars.innerText = hash;
if(typeof(hash_fences[hash]) == 'undefined'){
hash_fences[hash] = null;
document.head.appendChild(ce('script', {
src: 'https://yaglov.ru/cadastre/hash.php?hash='+hash+'&callback=load_hash'
}));
}
}
if(gpsPosition.zeroCrd){
zero_crd_longitude.innerText = gpsPosition.zeroCrd.longitude;
zero_crd_latitude.innerText = gpsPosition.zeroCrd.latitude;
}
}
break;
}
});
};
</script>
</head>
<body style='margin: 0px; overflow: hidden;'>
<div style="position: fixed; top: 10px; width:100%; text-align: center; z-index: 1; text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;">
<div>
coords: <span id="crd_longitude"></span>, <span id="crd_latitude"></span>
(zero coords: <span id="zero_crd_longitude"></span>, <span id="zero_crd_latitude"></span>)
</div>
<div>
camera coords: <span id="camera_p_x"></span>, <span id="camera_p_z"></span>
</div>
<div>
compass heading: <span id="compass_heading"></span>,
camera angle: <span id="camera_angle"></span>,
yaw angle: <span id="yaw_angle"></span>
</div>
<div>geohash_7chars: <span id="geohash_7chars"></span></div>
</div>
<a-scene embedded artoolkit='sourceType: webcam;'><!-- -->
<a-camera id="camera" user-height="1.6" gps-position compass-rotation><!-- --></a-camera>
<a-assets id="assets">
<!--
<a-asset-item id="fence_50_31_0040507_9_asset" src="fence_50_31_0040507_9.dae"></a-asset-item>
<a-asset-item id="fence_50_31_0040507_6_asset" src="fence_50_31_0040507_6.dae"></a-asset-item>
<a-asset-item id="fence_50_31_0040507_16_asset" src="fence_50_31_0040507_16.dae"></a-asset-item>
<a-asset-item id="fence_50_31_0040507_25_asset" src="fence_50_31_0040507_25.dae"></a-asset-item>
-->
</a-assets>
<a-entity id="fences">
<!--
<a-entity id="fence_50_31_0040507_9" collada-model="#fence_50_31_0040507_9_asset" transparent-texture gps-place="longitude: 37.469666813539; latitude: 55.153989996861"></a-entity>
<a-entity id="fence_50_31_0040507_6" collada-model="#fence_50_31_0040507_6_asset" transparent-texture gps-place="longitude: 37.469775988244; latitude: 55.154190366984"></a-entity>
<a-entity id="fence_50_31_0040507_16" collada-model="#fence_50_31_0040507_16_asset" transparent-texture gps-place="longitude: 37.469140087271; latitude: 55.153874109378"></a-entity>
<a-entity id="fence_50_31_0040507_25" collada-model="#fence_50_31_0040507_25_asset" transparent-texture gps-place="longitude: 37.470954400759; latitude: 55.153490379075"></a-entity>
-->
</a-entity>
</a-scene>
</body>
</html>