Commit 36602065 authored by Percen's avatar Percen
Browse files

Merge branch '21pesi1bif-master-patch-58714' into 'master'

Update public/index.html

See merge request !49
1 merge request!49Update public/index.html
Pipeline #10537 passed with stage
in 7 seconds
Showing with 96 additions and 60 deletions
+96 -60
...@@ -11,80 +11,81 @@ ...@@ -11,80 +11,81 @@
background-color: #f0f0f0; background-color: #f0f0f0;
color: #333; color: #333;
display: flex; display: flex;
justify-content: center;
align-items: center;
height: 100vh; height: 100vh;
background-image: url('https://www.hft-stuttgart.de/fileadmin/Dateien/Hochschule/-_R_Juergen_Pollak_HFT_18.04.18-0091.jpg');
background-size: cover;
background-position: center;
} }
/* Fixiertes Menü auf der linken Seite */ .container {
.menu-bar { text-align: center;
position: fixed; background-color: rgba(0, 0, 0, 0.5);
top: 0; padding: 50px;
left: 0; border-radius: 10px;
width: 200px; color: white;
height: 100%; max-width: 80%;
background-color: rgba(0, 0, 0, 0.7); box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.5);
padding: 20px;
box-sizing: border-box;
z-index: 10;
} }
.menu-bar button { h1 {
background-color: #2196F3; font-size: 3em;
width: 100%; margin-bottom: 20px;
padding: 15px; }
margin-bottom: 10px;
color: white; p {
font-size: 1.2em; font-size: 1.2em;
margin-bottom: 30px;
}
button {
background-color: #4CAF50;
color: white;
font-size: 1.5em;
padding: 15px 30px;
border: none; border: none;
border-radius: 5px; border-radius: 5px;
cursor: pointer; cursor: pointer;
transition: background-color 0.3s; transition: background-color 0.3s;
margin: 10px;
} }
.menu-bar button:hover { button:hover {
background-color: #1E88E5; background-color: #45a049;
} }
.menu-bar button:active { button:active {
background-color: #1976D2; background-color: #387a39;
} }
/* Der Hauptbereich für die AR-Ansicht */ .menu-bar {
.main-content { position: fixed;
flex-grow: 1; top: 0;
left: 0;
right: 0;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; background-color: rgba(0, 0, 0, 0.7);
background-color: #e0e0e0; padding: 10px;
z-index: 10;
} }
h1 { .menu-bar button {
font-size: 3em; background-color: #2196F3;
margin-bottom: 20px;
} }
p { .menu-bar button:hover {
font-size: 1.2em; background-color: #1E88E5;
margin-bottom: 30px;
} }
</style> </style>
<script src="https://unpkg.com/three@0.126.0/build/three.js"></script> <script src="https://unpkg.com/three@0.126.0/build/three.js"></script>
<script src="https://unpkg.com/three@0.126.0/examples/js/loaders/GLTFLoader.js"></script> <script src="https://unpkg.com/three@0.126.0/examples/js/loaders/GLTFLoader.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three-mesh-ui"></script>
</head> </head>
<body> <body>
<!-- Menü auf der linken Seite -->
<div class="menu-bar">
<button id="robotButton">RobotExpressive</button>
<button id="sunflowerButton">Sunflower</button>
</div>
<!-- AR-Bereich -->
<div class="main-content" id="arArea">
<h1>AR Modell</h1>
<p>Wählen Sie ein Modell aus dem Menü auf der linken Seite.</p>
</div>
<script> <script>
let selectedModel = 'robot'; // Standardauswahl let selectedModel = 'car'; // Standardauswahl
let models = {}; let models = {};
let reticle; let reticle;
let menu; let menu;
...@@ -115,11 +116,54 @@ ...@@ -115,11 +116,54 @@
// Modelle laden // Modelle laden
loader.load("https://threejs.org/examples/models/gltf/RobotExpressive/RobotExpressive.glb", (gltf) => { loader.load("https://threejs.org/examples/models/gltf/RobotExpressive/RobotExpressive.glb", (gltf) => {
models.robot = gltf.scene; models.car = gltf.scene;
}); });
loader.load("https://immersive-web.github.io/webxr-samples/media/gltf/sunflower/sunflower.gltf", (gltf) => { loader.load("https://immersive-web.github.io/webxr-samples/media/gltf/sunflower/sunflower.gltf", (gltf) => {
models.sunflower = gltf.scene; models.lamp = gltf.scene;
});
// 3D-Menü erstellen
const ui = new THREE.MeshUI.UI({
containerWidth: 3,
containerHeight: 2,
fontSize: 0.1,
padding: 0.05,
}); });
scene.add(ui);
// Text hinzufügen
const text = new THREE.MeshUI.Text({
content: 'Modell auswählen',
fontSize: 0.2,
color: new THREE.Color(0xFFFFFF)
});
ui.add(text);
// Buttons hinzufügen
const buttonGeometry = new THREE.PlaneGeometry(0.5, 0.3);
const button1 = new THREE.MeshUI.Button({
width: 0.8,
height: 0.4,
backgroundColor: new THREE.Color(0x2196F3),
});
button1.position.set(-0.5, -0.8, 0);
button1.onClick = () => {
selectedModel = 'car';
console.log('Auto ausgewählt');
};
ui.add(button1);
const button2 = new THREE.MeshUI.Button({
width: 0.8,
height: 0.4,
backgroundColor: new THREE.Color(0xFF9800),
});
button2.position.set(0.5, -0.8, 0);
button2.onClick = () => {
selectedModel = 'lamp';
console.log('Laterne ausgewählt');
};
ui.add(button2);
// AR-Session starten // AR-Session starten
const session = await navigator.xr.requestSession('immersive-ar', { requiredFeatures: ['hit-test'] }); const session = await navigator.xr.requestSession('immersive-ar', { requiredFeatures: ['hit-test'] });
...@@ -133,7 +177,7 @@ ...@@ -133,7 +177,7 @@
session.addEventListener("select", (event) => { session.addEventListener("select", (event) => {
if (!reticle) return; if (!reticle) return;
// Modelle platzieren // Modell platzieren, wenn kein Button angeklickt wurde
if (models[selectedModel]) { if (models[selectedModel]) {
const clone = models[selectedModel].clone(); const clone = models[selectedModel].clone();
clone.position.copy(reticle.position); clone.position.copy(reticle.position);
...@@ -158,7 +202,10 @@ ...@@ -158,7 +202,10 @@
camera.projectionMatrix.fromArray(view.projectionMatrix); camera.projectionMatrix.fromArray(view.projectionMatrix);
camera.updateMatrixWorld(true); camera.updateMatrixWorld(true);
// AR-Ansicht aktualisieren // Menü bleibt fixiert vor der Kamera
ui.position.set(0, -0.5, -1);
ui.lookAt(camera.position);
const hitTestResults = frame.getHitTestResults(hitTestSource); const hitTestResults = frame.getHitTestResults(hitTestSource);
if (hitTestResults.length > 0) { if (hitTestResults.length > 0) {
const hitPose = hitTestResults[0].getPose(referenceSpace); const hitPose = hitTestResults[0].getPose(referenceSpace);
...@@ -185,17 +232,6 @@ ...@@ -185,17 +232,6 @@
} else { } else {
alert('WebXR wird nicht unterstützt.'); alert('WebXR wird nicht unterstützt.');
} }
// Button-Klicks zur Auswahl des Modells
document.getElementById('robotButton').addEventListener('click', () => {
selectedModel = 'robot';
console.log('Robot ausgewählt');
});
document.getElementById('sunflowerButton').addEventListener('click', () => {
selectedModel = 'sunflower';
console.log('Sunflower ausgewählt');
});
</script> </script>
</body> </body>
</html> </html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment