-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
166 lines (143 loc) · 6.16 KB
/
index.html
File metadata and controls
166 lines (143 loc) · 6.16 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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/donmccurdy/aframe-extras@v7.0.0/dist/aframe-extras.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mind-ar@1.2.5/dist/mindar-image-aframe.prod.js"></script>
<style>
body {
margin: 0;
overflow: hidden;
}
#debug {
position: fixed;
top: 10px;
left: 10px;
background: rgba(255, 255, 255, 0.9);
padding: 10px;
z-index: 1000;
font-family: monospace;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 4px;
}
</style>
</head>
<script>
AFRAME.registerComponent("puff-parallax", {
tick: function () {
const cam = document.querySelector("a-camera").object3D.position;
const front = document.querySelector("#puff-front").object3D;
const mid = document.querySelector("#puff-mid").object3D;
const back = document.querySelector("#puff-back").object3D;
front.position.x = cam.x * 0.06;
front.position.y = cam.y * 0.06;
mid.position.x = cam.x * 0.03;
mid.position.y = cam.y * 0.03;
back.position.x = cam.x * 0.01;
back.position.y = cam.y * 0.01;
}
});
</script>
<body>
<div id="debug">Debug Info: Waiting for events...</div>
<video id="custom-scanner" src="./assets/circleanimation.webm" autoplay loop muted playsinline style="
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 50vw;
height: 50vh;
object-fit: contain;
z-index: 9999;
pointer-events: none;
"></video>
<a-scene
mindar-image="imageTargetSrc: assets/targets.mind; maxTrack: 2; debug: true; filterMinCF: 0.01; filterBeta: 200; uiScanning:no"
color-space="sRGB"
renderer="colorManagement: true, physicallyCorrectLights: false; antialias: true; logarithmicDepthBuffer: true;"
vr-mode-ui="enabled: false"
device-orientation-permission-ui="enabled: false"
>
<a-assets>
<!--target image asset-->
<img id="puff" src="assets/targetimgchowpuff.png" />
<img id="Maneki" src="assets/manekitiger.png" />
<!--3D overlay asset-->
<a-asset-item id="avatarModel" src="https://cdn.jsdelivr.net/gh/hiukim/mind-ar-js@1.2.5/examples/image-tracking/assets/card-example/softmind/scene.gltf"></a-asset-item>
<a-asset-item id="rose" src="assets/rose.gltf"></a-asset-item>
<video id="video" src="./assets/circleanimation.webm" preload="auto" loop playsinline crossorigin="anonymous"></video>
<a-asset-item id="testheart" src="assets/cube.gltf"></a-asset-item>
</a-assets>
<a-camera position="0 0 0" look-controls="enabled: false"></a-camera>
<!-- <a-light type="directional" intensity="0.5" castShadow="false"></a-light> -->
<a-entity mindar-image-target="targetIndex: 1" smooth="true" smoothCount="20" smoothTolerance="0.01" smoothThreshold="10">
<!--
<a-plane id ="puff-mid" src="#puff" position="0 0 0.08" height="1" width="1" rotation="0 0 0" transparent="true"></a-plane>
-->
<a-plane id ="puff-back" src="#puff" position="0 0 0.05" height="1" width="1" rotation="0 0 0" transparent="true"></a-plane>
<a-plane id ="puff-mid" src="#puff" position="0 0 0.15" height="1" width="1" rotation="0 0 0" transparent="true"></a-plane>
<a-video id ="puff-front" src="#video" position="0 0 0.25" width="1" height="1" rotation="0 0 0" id="videoPlane"></a-video>
</a-entity>
<a-entity mindar-image-target="targetIndex: 0">
<!-- <a-plane src="#Maneki" position="0 0 0" height="1" width="1" rotation="0 0 0"></a-plane> -->
<a-gltf-model
rotation="0 0 0"
position="0 0 0.1"
scale="0.005 0.005 0.005"
src="#rose"
animation="property: position; to: 0 0.1 0.1; dur: 1000; easing: easeInOutQuad; loop: true; dir: alternate">
</a-gltf-model>
</a-entity>
</a-scene>
<script>
const debugElement = document.getElementById('debug');
const scene = document.querySelector('a-scene');
const target = document.querySelector('[mindar-image-target]');
const video = document.querySelector('#video')
const scanner = document.querySelector('#custom-scanner')
document.addEventListener("DOMContentLoaded", () => {
document.querySelector("a-scene").setAttribute("puff-parallax", "");
});
// Event listener for asset loading errors
scene.addEventListener('loaded', () => {
debugElement.innerText = 'Magic Bubble is Ready!';
console.log('Scene loaded successfully!');
scanner.style.opacity = 1;
scanner.style.display = "block";
});
scene.addEventListener('error', (event) => {
debugElement.innerText = `Error: ${event.detail}`;
console.error('Error:', event.detail);
});
// Event listener for marker found
target.addEventListener('targetFound', () => {
debugElement.innerText = 'Marker Found!';
scanner.style.transition = "opacity 0.5s ease";
scanner.style.opacity = 0;
setTimeout(() => {
scanner.style.display = "none";
}, 500);
console.log('Marker Found!');
video.play();
});
// Event listener for marker lost
target.addEventListener('targetLost', () => {
debugElement.innerText = 'Marker Lost!';
console.log('Marker Lost!');
video.pause();
});
// Handle general errors
window.addEventListener('error', (event) => {
debugElement.innerText = `Error: ${event.message}`;
console.error('Error:', event.message);
});
// Handle MindAR initialization errors
scene.addEventListener('mindar-error', (event) => {
debugElement.innerText = `MindAR Error: ${event.detail}`;
console.error('MindAR Error:', event.detail);
});
</script>
</body>
</html>