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 @@
background-color: #f0f0f0;
color: #333;
display: flex;
justify-content: center;
align-items: center;
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 */
.menu-bar {
position: fixed;
top: 0;
left: 0;
width: 200px;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
padding: 20px;
box-sizing: border-box;
z-index: 10;
.container {
text-align: center;
background-color: rgba(0, 0, 0, 0.5);
padding: 50px;
border-radius: 10px;
color: white;
max-width: 80%;
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.5);
}
.menu-bar button {
background-color: #2196F3;
width: 100%;
padding: 15px;
margin-bottom: 10px;
color: white;
h1 {
font-size: 3em;
margin-bottom: 20px;
}
p {
font-size: 1.2em;
margin-bottom: 30px;
}
button {
background-color: #4CAF50;
color: white;
font-size: 1.5em;
padding: 15px 30px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
margin: 10px;
}
.menu-bar button:hover {
background-color: #1E88E5;
button:hover {
background-color: #45a049;
}
.menu-bar button:active {
background-color: #1976D2;
button:active {
background-color: #387a39;
}
/* Der Hauptbereich für die AR-Ansicht */
.main-content {
flex-grow: 1;
.menu-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: #e0e0e0;
background-color: rgba(0, 0, 0, 0.7);
padding: 10px;
z-index: 10;
}
h1 {
font-size: 3em;
margin-bottom: 20px;
.menu-bar button {
background-color: #2196F3;
}
p {
font-size: 1.2em;
margin-bottom: 30px;
.menu-bar button:hover {
background-color: #1E88E5;
}
</style>
<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://cdn.jsdelivr.net/npm/three-mesh-ui"></script>
</head>
<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>
let selectedModel = 'robot'; // Standardauswahl
let selectedModel = 'car'; // Standardauswahl
let models = {};
let reticle;
let menu;
......@@ -115,11 +116,54 @@
// Modelle laden
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) => {
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
const session = await navigator.xr.requestSession('immersive-ar', { requiredFeatures: ['hit-test'] });
......@@ -133,7 +177,7 @@
session.addEventListener("select", (event) => {
if (!reticle) return;
// Modelle platzieren
// Modell platzieren, wenn kein Button angeklickt wurde
if (models[selectedModel]) {
const clone = models[selectedModel].clone();
clone.position.copy(reticle.position);
......@@ -158,7 +202,10 @@
camera.projectionMatrix.fromArray(view.projectionMatrix);
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);
if (hitTestResults.length > 0) {
const hitPose = hitTestResults[0].getPose(referenceSpace);
......@@ -185,17 +232,6 @@
} else {
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>
</body>
</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