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
080b9780
Commit
080b9780
authored
4 months ago
by
Percen
Browse files
Options
Download
Email Patches
Plain Diff
Update public/index.html
parent
f6a43379
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
public/index.html
+96
-55
public/index.html
with
96 additions
and
55 deletions
+96
-55
public/index.html
+
96
-
55
View file @
080b9780
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
<head>
<head>
<meta
charset=
"UTF-8"
>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
AR
Kamera
mit Menüleiste
</title>
<title>
AR mit Menüleiste
</title>
<style>
<style>
*
{
*
{
margin
:
0
;
margin
:
0
;
...
@@ -13,24 +13,29 @@
...
@@ -13,24 +13,29 @@
body
{
body
{
font-family
:
Arial
,
sans-serif
;
font-family
:
Arial
,
sans-serif
;
background-color
:
#000
;
color
:
#fff
;
display
:
flex
;
flex-direction
:
column
;
height
:
100vh
;
overflow
:
hidden
;
overflow
:
hidden
;
background-color
:
#000
;
color
:
white
;
}
}
/* Container für die AR-Kamera */
/* Der AR-Bereich: Reduziert durch Skalierung */
#camera-container
{
#ar-container
{
flex
:
1
;
/* Nimmt den oberen Teil des Bildschirms ein */
position
:
absolute
;
position
:
relative
;
top
:
0
;
background-color
:
#111
;
left
:
0
;
right
:
0
;
bottom
:
80px
;
/* Platz für die Menüleiste */
overflow
:
hidden
;
background-color
:
#000
;
}
}
/* Menüleiste
unterhalb der Kamera
*/
/* Menüleiste */
#menu-bar
{
#menu-bar
{
height
:
80px
;
/* Höhe der Menüleiste */
position
:
absolute
;
bottom
:
0
;
left
:
0
;
width
:
100%
;
height
:
80px
;
background-color
:
rgba
(
0
,
0
,
0
,
0.8
);
background-color
:
rgba
(
0
,
0
,
0
,
0.8
);
display
:
flex
;
display
:
flex
;
justify-content
:
space-around
;
justify-content
:
space-around
;
...
@@ -40,13 +45,12 @@
...
@@ -40,13 +45,12 @@
button
{
button
{
background-color
:
#2196F3
;
background-color
:
#2196F3
;
color
:
#fff
;
color
:
white
;
font-size
:
16px
;
padding
:
10px
20px
;
padding
:
10px
20px
;
font-size
:
18px
;
border
:
none
;
border
:
none
;
border-radius
:
5px
;
border-radius
:
5px
;
cursor
:
pointer
;
cursor
:
pointer
;
transition
:
background-color
0.3s
;
}
}
button
:hover
{
button
:hover
{
...
@@ -55,40 +59,44 @@
...
@@ -55,40 +59,44 @@
</style>
</style>
</head>
</head>
<body>
<body>
<!--
AR-Kamera-Container
-->
<!--
Container für die AR-Ansicht
-->
<div
id=
"
camer
a-container"
></div>
<div
id=
"a
r
-container"
></div>
<!-- Menüleiste -->
<!-- Menüleiste -->
<div
id=
"menu-bar"
>
<div
id=
"menu-bar"
>
<button
onclick=
"se
lec
tModel('car')"
>
Auto
</button>
<button
onclick=
"setModel('car')"
>
Auto
</button>
<button
onclick=
"se
lec
tModel('lamp')"
>
Lampe
</button>
<button
onclick=
"setModel('lamp')"
>
Lampe
</button>
</div>
</div>
<!-- Three.js & AR-Skripte -->
<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>
<script>
let
selectedModel
=
'
car
'
;
let
selectedModel
=
'
car
'
;
let
models
=
{};
let
models
=
{};
let
reticle
;
async
function
activateXR
()
{
async
function
activateXR
()
{
const
cameraContainer
=
document
.
getElementById
(
'
camera-container
'
);
const
container
=
document
.
getElementById
(
'
ar-container
'
);
const
canvas
=
document
.
createElement
(
'
canvas
'
);
container
.
appendChild
(
canvas
);
// Renderer erstellen
const
gl
=
canvas
.
getContext
(
'
webgl
'
,
{
xrCompatible
:
true
});
const
renderer
=
new
THREE
.
WebGLRenderer
({
alpha
:
true
});
const
renderer
=
new
THREE
.
WebGLRenderer
({
alpha
:
true
,
canvas
,
context
:
gl
});
renderer
.
setSize
(
cameraContainer
.
clientWidth
,
cameraContainer
.
clientHeight
);
renderer
.
autoClear
=
false
;
cameraContainer
.
appendChild
(
renderer
.
domElement
);
// Szene und Kamera erstellen
const
scene
=
new
THREE
.
Scene
();
const
scene
=
new
THREE
.
Scene
();
const
camera
=
new
THREE
.
PerspectiveCamera
(
70
,
cameraContainer
.
clientWidth
/
cameraContainer
.
clientHeight
,
0.01
,
100
);
const
camera
=
new
THREE
.
PerspectiveCamera
();
camera
.
position
.
z
=
2
;
camera
.
matrixAutoUpdate
=
false
;
// Licht
hinzufügen
// Licht
const
light
=
new
THREE
.
DirectionalLight
(
0xffffff
,
1
);
const
light
=
new
THREE
.
DirectionalLight
(
0xffffff
,
1
);
light
.
position
.
set
(
10
,
10
,
10
);
light
.
position
.
set
(
10
,
10
,
10
);
scene
.
add
(
light
);
scene
.
add
(
light
);
// Modelle
laden
//
GLTF-Loader für
Modelle
const
loader
=
new
THREE
.
GLTFLoader
();
const
loader
=
new
THREE
.
GLTFLoader
();
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
.
car
=
gltf
.
scene
;
models
.
car
=
gltf
.
scene
;
...
@@ -97,40 +105,73 @@
...
@@ -97,40 +105,73 @@
models
.
lamp
=
gltf
.
scene
;
models
.
lamp
=
gltf
.
scene
;
});
});
// Animation
// Reticle (Cursor für Platzierung)
function
animate
()
{
loader
.
load
(
"
https://immersive-web.github.io/webxr-samples/media/gltf/reticle/reticle.gltf
"
,
(
gltf
)
=>
{
requestAnimationFrame
(
animate
);
reticle
=
gltf
.
scene
;
renderer
.
render
(
scene
,
camera
);
reticle
.
visible
=
false
;
}
scene
.
add
(
reticle
);
animate
();
});
// Dummy-Reticle (nur zur Demo)
const
session
=
await
navigator
.
xr
.
requestSession
(
'
immersive-ar
'
,
{
requiredFeatures
:
[
'
hit-test
'
]
});
const
reticleGeometry
=
new
THREE
.
CircleGeometry
(
0.05
,
32
);
session
.
updateRenderState
({
baseLayer
:
new
XRWebGLLayer
(
session
,
gl
)
});
const
reticleMaterial
=
new
THREE
.
MeshBasicMaterial
({
color
:
0xff0000
});
const
referenceSpace
=
await
session
.
requestReferenceSpace
(
'
local
'
);
const
reticle
=
new
THREE
.
Mesh
(
reticleGeometry
,
reticleMaterial
);
const
viewerSpace
=
await
session
.
requestReferenceSpace
(
'
viewer
'
);
reticle
.
position
.
set
(
0
,
-
0.5
,
-
2
);
const
hitTestSource
=
await
session
.
requestHitTestSource
({
space
:
viewerSpace
});
scene
.
add
(
reticle
);
session
.
requestAnimationFrame
(
onXRFrame
);
// Modell platzieren
window
.
addEventListener
(
'
click
'
,
()
=>
{
session
.
addEventListener
(
"
select
"
,
()
=>
{
if
(
models
[
selectedModel
])
{
if
(
reticle
&&
models
[
selectedModel
])
{
const
modelClone
=
models
[
selectedModel
].
clone
();
const
clone
=
models
[
selectedModel
].
clone
();
modelClone
.
position
.
set
(
0
,
-
0.5
,
-
2
);
clone
.
position
.
copy
(
reticle
.
position
);
modelClone
.
scale
.
set
(
0.5
,
0.5
,
0.5
);
scene
.
add
(
clone
);
scene
.
add
(
modelClone
);
console
.
log
(
`
${
selectedModel
}
platziert`
);
console
.
log
(
`
${
selectedModel
}
platziert`
);
}
}
});
});
function
onXRFrame
(
time
,
frame
)
{
session
.
requestAnimationFrame
(
onXRFrame
);
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
session
.
renderState
.
baseLayer
.
framebuffer
);
const
pose
=
frame
.
getViewerPose
(
referenceSpace
);
if
(
pose
)
{
const
view
=
pose
.
views
[
0
];
const
viewport
=
session
.
renderState
.
baseLayer
.
getViewport
(
view
);
renderer
.
setSize
(
container
.
clientWidth
,
container
.
clientHeight
);
camera
.
matrix
.
fromArray
(
view
.
transform
.
matrix
);
camera
.
projectionMatrix
.
fromArray
(
view
.
projectionMatrix
);
camera
.
updateMatrixWorld
(
true
);
const
hitTestResults
=
frame
.
getHitTestResults
(
hitTestSource
);
if
(
hitTestResults
.
length
>
0
)
{
const
hitPose
=
hitTestResults
[
0
].
getPose
(
referenceSpace
);
reticle
.
visible
=
true
;
reticle
.
position
.
set
(
hitPose
.
transform
.
position
.
x
,
hitPose
.
transform
.
position
.
y
,
hitPose
.
transform
.
position
.
z
);
}
renderer
.
render
(
scene
,
camera
);
}
}
}
}
// Modell auswählen
function
setModel
(
model
)
{
function
selectModel
(
model
)
{
selectedModel
=
model
;
selectedModel
=
model
;
console
.
log
(
`
${
model
}
ausgewählt`
);
console
.
log
(
`
${
model
}
ausgewählt`
);
}
}
// AR aktivieren
if
(
navigator
.
xr
)
{
activateXR
();
const
startButton
=
document
.
createElement
(
'
button
'
);
startButton
.
textContent
=
'
Start AR
'
;
startButton
.
style
.
cssText
=
"
position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 100;
"
;
document
.
body
.
appendChild
(
startButton
);
startButton
.
onclick
=
()
=>
{
startButton
.
remove
();
activateXR
();
};
}
else
{
alert
(
'
WebXR wird nicht unterstützt.
'
);
}
</script>
</script>
</body>
</body>
</html>
</html>
This diff is collapsed.
Click to expand it.
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