This commit is contained in:
LionTion committed 2026-10-09 10:08:18 +02:00
1 parent c56377406b
commit f4fdd6cac4
2 files changed
+85 -115

No files matched your search

+74 -113
View File
@@ -27,39 +27,37 @@ export default function Riddle_7_AR_View() {
const arSystem = sceneEl.systems['mindar-image-system'];
sceneEl.addEventListener('renderstart', () => {
arSystem.start();
arSystem.start();
});
// Attach target tracking listeners for each target entity
targetsRef.current.forEach((targetEl, index) => {
if (!targetEl) return;
if (!targetEl) return;
const videoEl = videosRef.current[index];
const videoEl = videosRef.current[index];
const handleTargetFound = () => {
if (videoEl) {
// Reset video if lost for > 10 seconds
const lostTime = lostTimesRef.current[index];
if (lostTime && Date.now() - lostTime > 10000) {
videoEl.currentTime = 0;
}
lostTimesRef.current[index] = null;
const handleTargetFound = () => {
if (videoEl) {
const lostTime = lostTimesRef.current[index];
if (lostTime && Date.now() - lostTime > 10000) {
videoEl.currentTime = 0;
}
lostTimesRef.current[index] = null;
videoEl.play().catch((err) => {
console.log(`Autoplay blocked on target ${index}:`, err);
});
}
};
videoEl.play().catch((err) => {
console.log(`Autoplay blocked on target ${index}:`, err);
});
}
};
const handleTargetLost = () => {
if (videoEl) {
videoEl.pause();
lostTimesRef.current[index] = Date.now();
}
};
const handleTargetLost = () => {
if (videoEl) {
videoEl.pause();
lostTimesRef.current[index] = Date.now();
}
};
targetEl.addEventListener('targetFound', handleTargetFound);
targetEl.addEventListener('targetLost', handleTargetLost);
targetEl.addEventListener('targetFound', handleTargetFound);
targetEl.addEventListener('targetLost', handleTargetLost);
});
return () => {
@@ -70,9 +68,8 @@ export default function Riddle_7_AR_View() {
console.warn('MindAR stopped after DOM teardown:', error);
}
}
}}, []);
}}, []);
// Set width dynamically based on video aspect ratio
const handleLoadedMetadata = (index, videoEl) => {
if (videoEl) {
const aspect = videoEl.videoWidth / videoEl.videoHeight;
@@ -86,19 +83,6 @@ export default function Riddle_7_AR_View() {
}
};
// User interaction handler to unlock web audio context on mobile devices
const handleUserStart = () => {
setHasInteracted(true);
Object.values(videosRef.current).forEach((videoEl) => {
if (videoEl) {
videoEl
.play()
.then(() => videoEl.pause())
.catch((err) => console.log('Audio unlock error:', err));
}
});
};
return (
<div
style={{
@@ -111,82 +95,59 @@ export default function Riddle_7_AR_View() {
backgroundColor: '#000',
}}
>
{!hasInteracted && (
<button
onClick={handleUserStart}
style={{
position: 'absolute',
zIndex: 9999,
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
padding: '14px 28px',
fontSize: '16px',
fontWeight: 'bold',
backgroundColor: '#007bff',
color: '#fff',
border: 'none',
borderRadius: '8px',
boxShadow: '0 4px 12px rgba(0,0,0,0.3)',
cursor: 'pointer',
}}
<a-scene
ref={sceneRef}
mindar-image="imageTargetSrc: /res/tour/riddle_7/targets.mind; autoStart: false; uiLoading: no; uiError: no; uiScanning: no; filterMinCF: 0.0001; filterBeta: 0.001;"
color-space="sRGB"
embedded
renderer="colorManagement: true, physicallyCorrectLights; antialias: true"
vr-mode-ui="enabled: false"
device-orientation-permission-ui="enabled: false"
style={{ width: '100%', height: '100%' }}
>
Tap to Start AR with Audio
</button>
)}
<a-assets>
{TARGET_CONFIG.map((target) => (
<video
key={target.videoId}
id={target.videoId}
ref={(el) => (videosRef.current[target.targetIndex] = el)}
src={target.videoSrc}
preload="auto"
loop
crossOrigin="anonymous"
playsInline
onLoadedMetadata={(e) =>
handleLoadedMetadata(target.targetIndex, e.target)
}
></video>
))}
</a-assets>
<a-scene
ref={sceneRef}
mindar-image="imageTargetSrc: /res/tour/riddle_7/targets.mind; autoStart: false; uiLoading: no; uiError: no; uiScanning: no; filterMinCF: 0.0001; filterBeta: 0.001;"
color-space="sRGB"
embedded
renderer="colorManagement: true, physicallyCorrectLights; antialias: true"
vr-mode-ui="enabled: false"
device-orientation-permission-ui="enabled: false"
style={{ width: '100%', height: '100%' }}
>
<a-assets>
{TARGET_CONFIG.map((target) => (
<video
key={target.videoId}
id={target.videoId}
ref={(el) => (videosRef.current[target.targetIndex] = el)}
src={target.videoSrc}
preload="auto"
loop
crossOrigin="anonymous"
playsInline
onLoadedMetadata={(e) =>
handleLoadedMetadata(target.targetIndex, e.target)
}
></video>
))}
</a-assets>
<a-camera position="0 0 0" look-controls="enabled: false"></a-camera>
<a-camera position="0 0 0" look-controls="enabled: false"></a-camera>
{TARGET_CONFIG.map((target) => {
const dims = videoDimensions[target.targetIndex] || {
width: 1,
height: TARGET_HEIGHT,
};
return (
<a-entity
key={target.targetIndex}
ref={(el) => (targetsRef.current[target.targetIndex] = el)}
mindar-image-target={`targetIndex: ${target.targetIndex}`}
>
<a-video
src={`#${target.videoId}`}
width={dims.width}
height={dims.height}
position="0 0 0"
rotation="0 0 0"
></a-video>
</a-entity>
);
})}
</a-scene>
{TARGET_CONFIG.map((target) => {
const dims = videoDimensions[target.targetIndex] || {
width: 1,
height: TARGET_HEIGHT,
};
return (
<a-entity
key={target.targetIndex}
ref={(el) => (targetsRef.current[target.targetIndex] = el)}
mindar-image-target={`targetIndex: ${target.targetIndex}`}
>
<a-video
src={`#${target.videoId}`}
width={dims.width}
height={dims.height}
position="0 0 0"
rotation="0 0 0"
></a-video>
</a-entity>
);
})}
</a-scene>
</div>
);
};