create a website called "algorithmic garden" that uses webxr or xr.js plus three.js to display a list of .glb models that can overlayed over whatever a cellphone camera sees (AR). There should be pinch to zoom and rotate commands on the phone interface.
Browse files- README.md +8 -5
- components/footer.js +52 -0
- components/header.js +64 -0
- index.html +72 -19
- script.js +259 -0
- style.css +42 -18
README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title: Algorithmic
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Algorithmic ARboretum 🌿
|
| 3 |
+
colorFrom: yellow
|
| 4 |
+
colorTo: red
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://huggingface.co/deepsite).
|
components/footer.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomFooter extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
:host {
|
| 7 |
+
display: block;
|
| 8 |
+
width: 100%;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
footer {
|
| 12 |
+
background: linear-gradient(135deg, rgba(16, 185, 129, 0.05) 0%, rgba(5, 150, 105, 0.1) 100%);
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
.footer-link {
|
| 16 |
+
transition: all 0.2s ease;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
.footer-link:hover {
|
| 20 |
+
transform: translateY(-2px);
|
| 21 |
+
color: #10b981;
|
| 22 |
+
}
|
| 23 |
+
</style>
|
| 24 |
+
<footer class="py-8 px-6 border-t border-emerald-200 dark:border-gray-700 mt-12">
|
| 25 |
+
<div class="container mx-auto">
|
| 26 |
+
<div class="flex flex-col md:flex-row justify-between items-center">
|
| 27 |
+
<div class="mb-4 md:mb-0">
|
| 28 |
+
<p class="text-sm text-gray-600 dark:text-gray-300">
|
| 29 |
+
© ${new Date().getFullYear()} Algorithmic ARboretum. All rights reserved.
|
| 30 |
+
</p>
|
| 31 |
+
</div>
|
| 32 |
+
<div class="flex gap-4">
|
| 33 |
+
<a href="#" class="footer-link text-gray-600 dark:text-gray-300 hover:text-emerald-500">
|
| 34 |
+
<i data-feather="github"></i>
|
| 35 |
+
</a>
|
| 36 |
+
<a href="#" class="footer-link text-gray-600 dark:text-gray-300 hover:text-emerald-500">
|
| 37 |
+
<i data-feather="twitter"></i>
|
| 38 |
+
</a>
|
| 39 |
+
<a href="#" class="footer-link text-gray-600 dark:text-gray-300 hover:text-emerald-500">
|
| 40 |
+
<i data-feather="mail"></i>
|
| 41 |
+
</a>
|
| 42 |
+
</div>
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
</footer>
|
| 46 |
+
`;
|
| 47 |
+
|
| 48 |
+
feather.replace();
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
customElements.define('custom-footer', CustomFooter);
|
components/header.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomHeader extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
:host {
|
| 7 |
+
display: block;
|
| 8 |
+
width: 100%;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
header {
|
| 12 |
+
background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(5, 150, 105, 0.2) 100%);
|
| 13 |
+
backdrop-filter: blur(10px);
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
.theme-toggle {
|
| 17 |
+
transition: all 0.3s ease;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.theme-toggle:hover {
|
| 21 |
+
transform: rotate(30deg);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
@media (max-width: 640px) {
|
| 25 |
+
.logo-text {
|
| 26 |
+
display: none;
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
</style>
|
| 30 |
+
<header class="py-4 px-6 border-b border-emerald-200 dark:border-gray-700">
|
| 31 |
+
<div class="container mx-auto flex justify-between items-center">
|
| 32 |
+
<a href="/" class="flex items-center gap-2">
|
| 33 |
+
<i data-feather="leaf" class="text-emerald-600 dark:text-emerald-400"></i>
|
| 34 |
+
<span class="logo-text text-xl font-bold text-emerald-800 dark:text-emerald-200">Algorithmic ARboretum</span>
|
| 35 |
+
</a>
|
| 36 |
+
|
| 37 |
+
<div class="flex items-center gap-4">
|
| 38 |
+
<button class="theme-toggle p-2 rounded-full bg-emerald-100 dark:bg-gray-700 text-emerald-600 dark:text-emerald-300">
|
| 39 |
+
<i data-feather="moon" class="dark:hidden"></i>
|
| 40 |
+
<i data-feather="sun" class="hidden dark:block"></i>
|
| 41 |
+
</button>
|
| 42 |
+
</div>
|
| 43 |
+
</div>
|
| 44 |
+
</header>
|
| 45 |
+
`;
|
| 46 |
+
|
| 47 |
+
// Theme toggle functionality
|
| 48 |
+
const toggleBtn = this.shadowRoot.querySelector('.theme-toggle');
|
| 49 |
+
toggleBtn.addEventListener('click', () => {
|
| 50 |
+
document.documentElement.classList.toggle('dark');
|
| 51 |
+
localStorage.setItem('theme', document.documentElement.classList.contains('dark') ? 'dark' : 'light');
|
| 52 |
+
feather.replace();
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
// Check for saved theme preference
|
| 56 |
+
if (localStorage.getItem('theme') === 'dark' || (!localStorage.getItem('theme') && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
| 57 |
+
document.documentElement.classList.add('dark');
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
feather.replace();
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
customElements.define('custom-header', CustomHeader);
|
index.html
CHANGED
|
@@ -1,19 +1,72 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en" class="h-full">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<meta name="description" content="Algorithmic ARboretum - An immersive AR garden experience">
|
| 7 |
+
<title>Algorithmic ARboretum 🌿</title>
|
| 8 |
+
<link rel="stylesheet" href="style.css">
|
| 9 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 10 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 11 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 12 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.132.2/build/three.min.js"></script>
|
| 13 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/controls/OrbitControls.js"></script>
|
| 14 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/loaders/GLTFLoader.js"></script>
|
| 15 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/WebXR.js"></script>
|
| 16 |
+
</head>
|
| 17 |
+
<body class="bg-emerald-50 dark:bg-gray-900 text-gray-900 dark:text-emerald-50 min-h-screen flex flex-col">
|
| 18 |
+
<custom-header></custom-header>
|
| 19 |
+
|
| 20 |
+
<main class="flex-grow container mx-auto px-4 py-8">
|
| 21 |
+
<div id="ar-container" class="relative rounded-xl overflow-hidden shadow-xl">
|
| 22 |
+
<!-- AR Viewport will be inserted here -->
|
| 23 |
+
<div id="xr-button" class="absolute top-4 right-4 z-10">
|
| 24 |
+
<button class="bg-emerald-500 hover:bg-emerald-600 text-white px-4 py-2 rounded-full flex items-center gap-2 transition-all">
|
| 25 |
+
<i data-feather="eye"></i> Enter AR
|
| 26 |
+
</button>
|
| 27 |
+
</div>
|
| 28 |
+
<div id="loading" class="absolute inset-0 bg-black bg-opacity-70 flex items-center justify-center text-white">
|
| 29 |
+
<div class="text-center">
|
| 30 |
+
<div class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-emerald-500 mx-auto mb-4"></div>
|
| 31 |
+
<p>Loading AR experience...</p>
|
| 32 |
+
</div>
|
| 33 |
+
</div>
|
| 34 |
+
<canvas id="ar-viewport" class="w-full h-full min-h-[60vh]"></canvas>
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
<section class="mt-12">
|
| 38 |
+
<h2 class="text-2xl font-bold mb-6 flex items-center gap-2">
|
| 39 |
+
<i data-feather="grid"></i> Available Plants
|
| 40 |
+
</h2>
|
| 41 |
+
|
| 42 |
+
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6" id="model-gallery">
|
| 43 |
+
<!-- Models will be loaded here -->
|
| 44 |
+
</div>
|
| 45 |
+
</section>
|
| 46 |
+
|
| 47 |
+
<div id="ar-controls" class="fixed bottom-0 left-0 right-0 bg-white dark:bg-gray-800 shadow-lg p-4 flex justify-center gap-6 hidden">
|
| 48 |
+
<button id="rotate-btn" class="bg-emerald-500 hover:bg-emerald-600 text-white p-3 rounded-full">
|
| 49 |
+
<i data-feather="rotate-cw"></i>
|
| 50 |
+
</button>
|
| 51 |
+
<button id="scale-btn" class="bg-emerald-500 hover:bg-emerald-600 text-white p-3 rounded-full">
|
| 52 |
+
<i data-feather="maximize-2"></i>
|
| 53 |
+
</button>
|
| 54 |
+
<button id="place-btn" class="bg-emerald-500 hover:bg-emerald-600 text-white p-3 rounded-full">
|
| 55 |
+
<i data-feather="map-pin"></i>
|
| 56 |
+
</button>
|
| 57 |
+
</div>
|
| 58 |
+
</main>
|
| 59 |
+
|
| 60 |
+
<custom-footer></custom-footer>
|
| 61 |
+
|
| 62 |
+
<!-- Web Components -->
|
| 63 |
+
<script src="components/header.js"></script>
|
| 64 |
+
<script src="components/footer.js"></script>
|
| 65 |
+
|
| 66 |
+
<script src="script.js"></script>
|
| 67 |
+
<script>
|
| 68 |
+
feather.replace();
|
| 69 |
+
</script>
|
| 70 |
+
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 71 |
+
</body>
|
| 72 |
+
</html>
|
script.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 2 |
+
// Initialize Three.js scene
|
| 3 |
+
let scene, camera, renderer, controls;
|
| 4 |
+
let currentModel = null;
|
| 5 |
+
let isARSupported = false;
|
| 6 |
+
let isInARMode = false;
|
| 7 |
+
|
| 8 |
+
// Model gallery data
|
| 9 |
+
const modelData = [
|
| 10 |
+
{
|
| 11 |
+
id: 'bamboo',
|
| 12 |
+
title: 'Bamboo Cluster',
|
| 13 |
+
description: 'A peaceful cluster of bamboo stalks',
|
| 14 |
+
thumbnail: 'https://static.photos/nature/640x360/1',
|
| 15 |
+
path: 'https://cdn.glitch.global/8e8b5d9a-7e4d-4a8b-9e8f-8f8e8f8e8f8e/bamboo.glb'
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
id: 'bonsai',
|
| 19 |
+
title: 'Zen Bonsai',
|
| 20 |
+
description: 'A meticulously crafted bonsai tree',
|
| 21 |
+
thumbnail: 'https://static.photos/nature/640x360/2',
|
| 22 |
+
path: 'https://cdn.glitch.global/8e8b5d9a-7e4d-4a8b-9e8f-8f8e8f8e8f8e/bonsai.glb'
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
id: 'fern',
|
| 26 |
+
title: 'Lush Fern',
|
| 27 |
+
description: 'A vibrant green fern plant',
|
| 28 |
+
thumbnail: 'https://static.photos/nature/640x360/3',
|
| 29 |
+
path: 'https://cdn.glitch.global/8e8b5d9a-7e4d-4a8b-9e8f-8f8e8f8e8f8e/fern.glb'
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
id: 'lotus',
|
| 33 |
+
title: 'Floating Lotus',
|
| 34 |
+
description: 'A beautiful water lotus flower',
|
| 35 |
+
thumbnail: 'https://static.photos/nature/640x360/4',
|
| 36 |
+
path: 'https://cdn.glitch.global/8e8b5d9a-7e4d-4a8b-9e8f-8f8e8f8e8f8e/lotus.glb'
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
id: 'palm',
|
| 40 |
+
title: 'Tropical Palm',
|
| 41 |
+
description: 'A tall tropical palm tree',
|
| 42 |
+
thumbnail: 'https://static.photos/nature/640x360/5',
|
| 43 |
+
path: 'https://cdn.glitch.global/8e8b5d9a-7e4d-4a8b-9e8f-8f8e8f8e8f8e/palm.glb'
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
id: 'sakura',
|
| 47 |
+
title: 'Cherry Blossom',
|
| 48 |
+
description: 'A delicate cherry blossom tree',
|
| 49 |
+
thumbnail: 'https://static.photos/nature/640x360/6',
|
| 50 |
+
path: 'https://cdn.glitch.global/8e8b5d9a-7e4d-4a8b-9e8f-8f8e8f8e8f8e/sakura.glb'
|
| 51 |
+
}
|
| 52 |
+
];
|
| 53 |
+
|
| 54 |
+
// Check for WebXR support
|
| 55 |
+
function checkXRSupport() {
|
| 56 |
+
if ('xr' in navigator) {
|
| 57 |
+
navigator.xr.isSessionSupported('immersive-ar').then((supported) => {
|
| 58 |
+
isARSupported = supported;
|
| 59 |
+
document.getElementById('xr-button').style.display = supported ? 'block' : 'none';
|
| 60 |
+
});
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// Initialize Three.js scene
|
| 65 |
+
function initScene() {
|
| 66 |
+
const canvas = document.getElementById('ar-viewport');
|
| 67 |
+
|
| 68 |
+
// Scene
|
| 69 |
+
scene = new THREE.Scene();
|
| 70 |
+
|
| 71 |
+
// Camera
|
| 72 |
+
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 73 |
+
camera.position.set(0, 1.6, 3);
|
| 74 |
+
|
| 75 |
+
// Renderer
|
| 76 |
+
renderer = new THREE.WebGLRenderer({
|
| 77 |
+
canvas: canvas,
|
| 78 |
+
antialias: true,
|
| 79 |
+
alpha: true
|
| 80 |
+
});
|
| 81 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 82 |
+
renderer.setPixelRatio(window.devicePixelRatio);
|
| 83 |
+
renderer.xr.enabled = true;
|
| 84 |
+
|
| 85 |
+
// Lighting
|
| 86 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.8);
|
| 87 |
+
scene.add(ambientLight);
|
| 88 |
+
|
| 89 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.6);
|
| 90 |
+
directionalLight.position.set(0, 10, 5);
|
| 91 |
+
scene.add(directionalLight);
|
| 92 |
+
|
| 93 |
+
// Controls (for non-AR mode)
|
| 94 |
+
controls = new THREE.OrbitControls(camera, renderer.domElement);
|
| 95 |
+
controls.enableDamping = true;
|
| 96 |
+
controls.dampingFactor = 0.25;
|
| 97 |
+
|
| 98 |
+
// Load default model
|
| 99 |
+
loadModel(modelData[0].path);
|
| 100 |
+
|
| 101 |
+
// Check XR support
|
| 102 |
+
checkXRSupport();
|
| 103 |
+
|
| 104 |
+
// Start animation loop
|
| 105 |
+
animate();
|
| 106 |
+
|
| 107 |
+
// Hide loading screen
|
| 108 |
+
setTimeout(() => {
|
| 109 |
+
document.getElementById('loading').style.display = 'none';
|
| 110 |
+
}, 1500);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// Load 3D model
|
| 114 |
+
function loadModel(path) {
|
| 115 |
+
const loader = new THREE.GLTFLoader();
|
| 116 |
+
|
| 117 |
+
if (currentModel) {
|
| 118 |
+
scene.remove(currentModel);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
loader.load(path, (gltf) => {
|
| 122 |
+
currentModel = gltf.scene;
|
| 123 |
+
currentModel.scale.set(0.5, 0.5, 0.5);
|
| 124 |
+
currentModel.position.set(0, 0, 0);
|
| 125 |
+
scene.add(currentModel);
|
| 126 |
+
}, undefined, (error) => {
|
| 127 |
+
console.error('Error loading model:', error);
|
| 128 |
+
});
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
// Animation loop
|
| 132 |
+
function animate() {
|
| 133 |
+
requestAnimationFrame(animate);
|
| 134 |
+
|
| 135 |
+
if (!isInARMode) {
|
| 136 |
+
controls.update();
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
renderer.render(scene, camera);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
// Initialize AR session
|
| 143 |
+
function startARSession() {
|
| 144 |
+
if (!isARSupported) return;
|
| 145 |
+
|
| 146 |
+
const sessionInit = { optionalFeatures: ['dom-overlay', 'dom-overlay-for-handheld-ar'] };
|
| 147 |
+
|
| 148 |
+
navigator.xr.requestSession('immersive-ar', sessionInit).then((session) => {
|
| 149 |
+
isInARMode = true;
|
| 150 |
+
document.getElementById('ar-controls').classList.remove('hidden');
|
| 151 |
+
|
| 152 |
+
renderer.xr.setSession(session);
|
| 153 |
+
|
| 154 |
+
// Add reticle for placing objects
|
| 155 |
+
const reticle = new THREE.Mesh(
|
| 156 |
+
new THREE.RingGeometry(0.15, 0.2, 32).rotateX(-Math.PI / 2),
|
| 157 |
+
new THREE.MeshBasicMaterial({ color: 0xffffff })
|
| 158 |
+
);
|
| 159 |
+
reticle.matrixAutoUpdate = false;
|
| 160 |
+
reticle.visible = false;
|
| 161 |
+
scene.add(reticle);
|
| 162 |
+
|
| 163 |
+
// Handle session end
|
| 164 |
+
session.addEventListener('end', () => {
|
| 165 |
+
isInARMode = false;
|
| 166 |
+
document.getElementById('ar-controls').classList.add('hidden');
|
| 167 |
+
currentModel.position.set(0, 0, 0);
|
| 168 |
+
});
|
| 169 |
+
|
| 170 |
+
// Handle select events (placing objects)
|
| 171 |
+
session.addEventListener('select', () => {
|
| 172 |
+
if (currentModel && reticle.visible) {
|
| 173 |
+
currentModel.position.setFromMatrixPosition(reticle.matrix);
|
| 174 |
+
}
|
| 175 |
+
});
|
| 176 |
+
});
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
// Event listeners
|
| 180 |
+
document.getElementById('xr-button').addEventListener('click', startARSession);
|
| 181 |
+
|
| 182 |
+
document.getElementById('rotate-btn').addEventListener('click', () => {
|
| 183 |
+
if (currentModel) {
|
| 184 |
+
currentModel.rotation.y += Math.PI / 4;
|
| 185 |
+
}
|
| 186 |
+
});
|
| 187 |
+
|
| 188 |
+
document.getElementById('scale-btn').addEventListener('touchstart', (e) => {
|
| 189 |
+
if (e.touches.length === 2 && currentModel) {
|
| 190 |
+
const touch1 = e.touches[0];
|
| 191 |
+
const touch2 = e.touches[1];
|
| 192 |
+
const dist1 = Math.hypot(
|
| 193 |
+
touch2.pageX - touch1.pageX,
|
| 194 |
+
touch2.pageY - touch1.pageY
|
| 195 |
+
);
|
| 196 |
+
|
| 197 |
+
function handleMove(e) {
|
| 198 |
+
const touch1 = e.touches[0];
|
| 199 |
+
const touch2 = e.touches[1];
|
| 200 |
+
const dist2 = Math.hypot(
|
| 201 |
+
touch2.pageX - touch1.pageX,
|
| 202 |
+
touch2.pageY - touch1.pageY
|
| 203 |
+
);
|
| 204 |
+
|
| 205 |
+
const scale = dist2 / dist1;
|
| 206 |
+
currentModel.scale.set(scale, scale, scale);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
function handleEnd() {
|
| 210 |
+
document.removeEventListener('touchmove', handleMove);
|
| 211 |
+
document.removeEventListener('touchend', handleEnd);
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
document.addEventListener('touchmove', handleMove);
|
| 215 |
+
document.addEventListener('touchend', handleEnd);
|
| 216 |
+
}
|
| 217 |
+
});
|
| 218 |
+
|
| 219 |
+
document.getElementById('place-btn').addEventListener('click', () => {
|
| 220 |
+
// In AR mode, this would place the object at the reticle position
|
| 221 |
+
if (isInARMode && currentModel) {
|
| 222 |
+
currentModel.position.set(0, 0, -1);
|
| 223 |
+
}
|
| 224 |
+
});
|
| 225 |
+
|
| 226 |
+
// Populate model gallery
|
| 227 |
+
function populateModelGallery() {
|
| 228 |
+
const gallery = document.getElementById('model-gallery');
|
| 229 |
+
|
| 230 |
+
modelData.forEach((model) => {
|
| 231 |
+
const card = document.createElement('div');
|
| 232 |
+
card.className = 'model-card bg-white dark:bg-gray-800 rounded-xl overflow-hidden shadow-md cursor-pointer transition-all';
|
| 233 |
+
card.innerHTML = `
|
| 234 |
+
<div class="h-48 overflow-hidden">
|
| 235 |
+
<img src="${model.thumbnail}" alt="${model.title}" class="w-full h-full object-cover">
|
| 236 |
+
</div>
|
| 237 |
+
<div class="p-4">
|
| 238 |
+
<h3 class="font-bold text-lg mb-1">${model.title}</h3>
|
| 239 |
+
<p class="text-gray-600 dark:text-gray-300 text-sm mb-3">${model.description}</p>
|
| 240 |
+
<button class="bg-emerald-500 hover:bg-emerald-600 text-white px-3 py-1 rounded-full text-sm transition-colors">
|
| 241 |
+
View in AR
|
| 242 |
+
</button>
|
| 243 |
+
</div>
|
| 244 |
+
`;
|
| 245 |
+
|
| 246 |
+
card.addEventListener('click', () => loadModel(model.path));
|
| 247 |
+
gallery.appendChild(card);
|
| 248 |
+
});
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
// Initialize everything
|
| 252 |
+
populateModelGallery();
|
| 253 |
+
initScene();
|
| 254 |
+
window.addEventListener('resize', () => {
|
| 255 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 256 |
+
camera.updateProjectionMatrix();
|
| 257 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 258 |
+
});
|
| 259 |
+
});
|
style.css
CHANGED
|
@@ -1,28 +1,52 @@
|
|
|
|
|
|
|
|
| 1 |
body {
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
}
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
margin-bottom: 10px;
|
| 15 |
-
margin-top: 5px;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
border-radius: 16px;
|
| 24 |
}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@400;500;600;700&display=swap');
|
| 2 |
+
|
| 3 |
body {
|
| 4 |
+
font-family: 'Inter', sans-serif;
|
| 5 |
+
transition: background-color 0.3s ease;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
h1, h2, h3 {
|
| 9 |
+
font-family: 'Playfair Display', serif;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
#ar-viewport {
|
| 13 |
+
width: 100%;
|
| 14 |
+
height: 100%;
|
| 15 |
+
display: block;
|
| 16 |
+
background-color: #f0fdf4;
|
| 17 |
}
|
| 18 |
|
| 19 |
+
.model-card {
|
| 20 |
+
transition: all 0.3s ease;
|
| 21 |
+
transform: translateY(0);
|
| 22 |
}
|
| 23 |
|
| 24 |
+
.model-card:hover {
|
| 25 |
+
transform: translateY(-4px);
|
| 26 |
+
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
+
/* AR controls animation */
|
| 30 |
+
@keyframes pulse {
|
| 31 |
+
0% { transform: scale(1); }
|
| 32 |
+
50% { transform: scale(1.05); }
|
| 33 |
+
100% { transform: scale(1); }
|
|
|
|
| 34 |
}
|
| 35 |
|
| 36 |
+
#ar-controls button {
|
| 37 |
+
animation: pulse 2s infinite;
|
| 38 |
}
|
| 39 |
+
|
| 40 |
+
/* Dark mode transitions */
|
| 41 |
+
.dark #ar-viewport {
|
| 42 |
+
background-color: #1a2e05;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/* Loading spinner */
|
| 46 |
+
@keyframes spin {
|
| 47 |
+
to { transform: rotate(360deg); }
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
.animate-spin {
|
| 51 |
+
animation: spin 1s linear infinite;
|
| 52 |
+
}
|