Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GeoVistoogsi
AR
Commits
04efc158
Commit
04efc158
authored
Dec 14, 2024
by
Percen
Browse files
Update public/index.html
parent
4ab0ed0f
Changes
1
Show whitespace changes
Inline
Side-by-side
public/index.html
View file @
04efc158
...
@@ -11,79 +11,78 @@
...
@@ -11,79 +11,78 @@
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
;
}
.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
);
}
}
h1
{
/* Fixiertes Menü auf der linken Seite */
font-size
:
3em
;
.menu-bar
{
margin-bottom
:
20px
;
position
:
fixed
;
}
top
:
0
;
left
:
0
;
p
{
width
:
200px
;
font-size
:
1.2em
;
height
:
100%
;
margin-bottom
:
30px
;
background-color
:
rgba
(
0
,
0
,
0
,
0.7
);
padding
:
20px
;
box-sizing
:
border-box
;
z-index
:
10
;
}
}
button
{
.menu-bar
button
{
background-color
:
#4CAF50
;
background-color
:
#2196F3
;
width
:
100%
;
padding
:
15px
;
margin-bottom
:
10px
;
color
:
white
;
color
:
white
;
font-size
:
1.5em
;
font-size
:
1.2em
;
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
;
}
}
button
:hover
{
.menu-bar
button
:hover
{
background-color
:
#
45a049
;
background-color
:
#
1E88E5
;
}
}
button
:active
{
.menu-bar
button
:active
{
background-color
:
#
387a39
;
background-color
:
#
1976D2
;
}
}
.menu-bar
{
/* Der Hauptbereich für die AR-Ansicht */
position
:
fixed
;
.main-content
{
top
:
0
;
flex-grow
:
1
;
left
:
0
;
right
:
0
;
display
:
flex
;
display
:
flex
;
justify-content
:
center
;
justify-content
:
center
;
background-color
:
rgba
(
0
,
0
,
0
,
0.7
);
align-items
:
center
;
padding
:
10px
;
background-color
:
#e0e0e0
;
z-index
:
10
;
}
}
.menu-bar
button
{
h1
{
background-color
:
#2196F3
;
font-size
:
3em
;
margin
:
0
1
0px
;
margin
-bottom
:
2
0px
;
}
}
.menu-bar
button
:hover
{
p
{
background-color
:
#1E88E5
;
font-size
:
1.2em
;
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>
</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
=
'
robot
'
;
// Standardauswahl
let
models
=
{};
let
models
=
{};
...
@@ -122,30 +121,6 @@
...
@@ -122,30 +121,6 @@
models
.
sunflower
=
gltf
.
scene
;
models
.
sunflower
=
gltf
.
scene
;
});
});
// AR-Menü erstellen
const
menuGeometry
=
new
THREE
.
PlaneGeometry
(
0.5
,
0.2
);
// Menügröße
const
menuMaterial
=
new
THREE
.
MeshBasicMaterial
({
color
:
0x333333
,
opacity
:
0.8
,
transparent
:
true
});
menu
=
new
THREE
.
Mesh
(
menuGeometry
,
menuMaterial
);
menu
.
position
.
set
(
0
,
-
0.5
,
-
1
);
// Unten im Kamerasichtfeld
scene
.
add
(
menu
);
// Menü-Buttons als Flächen
const
buttonGeometry
=
new
THREE
.
PlaneGeometry
(
0.15
,
0.1
);
const
buttonMaterial1
=
new
THREE
.
MeshBasicMaterial
({
color
:
0x2196F3
});
const
buttonMaterial2
=
new
THREE
.
MeshBasicMaterial
({
color
:
0xFF9800
});
const
robotButton
=
new
THREE
.
Mesh
(
buttonGeometry
,
buttonMaterial1
);
robotButton
.
position
.
set
(
-
0.2
,
-
0.5
,
-
0.99
);
// Links unten
scene
.
add
(
robotButton
);
const
sunflowerButton
=
new
THREE
.
Mesh
(
buttonGeometry
,
buttonMaterial2
);
sunflowerButton
.
position
.
set
(
0.2
,
-
0.5
,
-
0.99
);
// Rechts unten
scene
.
add
(
sunflowerButton
);
// Raycaster für Button-Interaktion
const
raycaster
=
new
THREE
.
Raycaster
();
const
pointer
=
new
THREE
.
Vector2
();
// 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
'
]
});
session
.
updateRenderState
({
baseLayer
:
new
XRWebGLLayer
(
session
,
gl
)
});
session
.
updateRenderState
({
baseLayer
:
new
XRWebGLLayer
(
session
,
gl
)
});
...
@@ -158,24 +133,8 @@
...
@@ -158,24 +133,8 @@
session
.
addEventListener
(
"
select
"
,
(
event
)
=>
{
session
.
addEventListener
(
"
select
"
,
(
event
)
=>
{
if
(
!
reticle
)
return
;
if
(
!
reticle
)
return
;
// Raycaster von der Kameraposition (Mitte des Bildschirms)
// Modelle platzieren
raycaster
.
setFromCamera
(
pointer
,
camera
);
if
(
models
[
selectedModel
])
{
const
intersects
=
raycaster
.
intersectObjects
([
robotButton
,
sunflowerButton
]);
// Prüfen, ob ein Button getroffen wurde
if
(
intersects
.
length
>
0
)
{
const
clickedButton
=
intersects
[
0
].
object
;
if
(
clickedButton
===
robotButton
)
{
selectedModel
=
'
robot
'
;
console
.
log
(
'
Robot ausgewählt
'
);
}
else
if
(
clickedButton
===
sunflowerButton
)
{
selectedModel
=
'
sunflower
'
;
console
.
log
(
'
Sunflower ausgewählt
'
);
}
}
// Kein Button getroffen -> Modell platzieren
else
if
(
models
[
selectedModel
])
{
const
clone
=
models
[
selectedModel
].
clone
();
const
clone
=
models
[
selectedModel
].
clone
();
clone
.
position
.
copy
(
reticle
.
position
);
clone
.
position
.
copy
(
reticle
.
position
);
clone
.
scale
.
set
(
0.5
,
0.5
,
0.5
);
// Größe anpassen
clone
.
scale
.
set
(
0.5
,
0.5
,
0.5
);
// Größe anpassen
...
@@ -199,13 +158,7 @@
...
@@ -199,13 +158,7 @@
camera
.
projectionMatrix
.
fromArray
(
view
.
projectionMatrix
);
camera
.
projectionMatrix
.
fromArray
(
view
.
projectionMatrix
);
camera
.
updateMatrixWorld
(
true
);
camera
.
updateMatrixWorld
(
true
);
// Menü bleibt fixiert vor der Kamera
// AR-Ansicht aktualisieren
menu
.
position
.
set
(
0
,
-
0.5
,
-
1
);
menu
.
lookAt
(
camera
.
position
);
robotButton
.
position
.
set
(
-
0.2
,
-
0.5
,
-
0.99
);
sunflowerButton
.
position
.
set
(
0.2
,
-
0.5
,
-
0.99
);
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
);
...
@@ -232,6 +185,17 @@
...
@@ -232,6 +185,17 @@
}
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>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment