Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Priyanka
ARNishat
Commits
f1a1aa4c
Commit
f1a1aa4c
authored
Jun 09, 2023
by
Priyanka
Browse files
Update public/index.html
parent
e7c4f54c
Changes
1
Hide whitespace changes
Inline
Side-by-side
public/index.html
View file @
f1a1aa4c
...
@@ -20,8 +20,12 @@ async function activateXR() {
...
@@ -20,8 +20,12 @@ async function activateXR() {
const
canvas
=
document
.
createElement
(
"
canvas
"
);
const
canvas
=
document
.
createElement
(
"
canvas
"
);
document
.
body
.
appendChild
(
canvas
);
document
.
body
.
appendChild
(
canvas
);
const
gl
=
canvas
.
getContext
(
"
webgl
"
,
{
xrCompatible
:
true
});
const
gl
=
canvas
.
getContext
(
"
webgl
"
,
{
xrCompatible
:
true
});
const
scene
=
new
THREE
.
Scene
();
const
scene
=
new
THREE
.
Scene
();
const
directionalLight
=
new
THREE
.
DirectionalLight
(
0xffffff
,
0.3
);
directionalLight
.
position
.
set
(
10
,
15
,
10
);
scene
.
add
(
directionalLight
);
// The sphere will have a different color on each side.
// The sphere will have a different color on each side.
const
materials
=
[
const
materials
=
[
...
@@ -34,9 +38,9 @@ const materials = [
...
@@ -34,9 +38,9 @@ const materials = [
];
];
// Create the sphere and add it to the demo scene.
// Create the sphere and add it to the demo scene.
const
sphere
=
new
THREE
.
Mesh
(
new
THREE
.
SphereBufferGeometry
(
0.5
,
0.5
,
0.5
),
materials
);
//
const sphere = new THREE.Mesh(new THREE.SphereBufferGeometry(0.5, 0.5, 0.5), materials);
sphere
.
position
.
set
(
0
,
0
,
-
1
);
//
sphere.position.set(0, 0, -1);
scene
.
add
(
sphere
);
//
scene.add(sphere);
// Set up the WebGLRenderer, which handles rendering to the session's base layer.
// Set up the WebGLRenderer, which handles rendering to the session's base layer.
const
renderer
=
new
THREE
.
WebGLRenderer
({
const
renderer
=
new
THREE
.
WebGLRenderer
({
...
@@ -62,6 +66,34 @@ session.updateRenderState({
...
@@ -62,6 +66,34 @@ session.updateRenderState({
// A 'local' reference space has a native origin that is located
// A 'local' reference space has a native origin that is located
// near the viewer's position at the time the session was created.
// near the viewer's position at the time the session was created.
const
referenceSpace
=
await
session
.
requestReferenceSpace
(
'
local
'
);
const
referenceSpace
=
await
session
.
requestReferenceSpace
(
'
local
'
);
// Create another XRReferenceSpace that has the viewer as the origin.
const
viewerSpace
=
await
session
.
requestReferenceSpace
(
'
viewer
'
);
// Perform hit testing using the viewer as origin.
const
hitTestSource
=
await
session
.
requestHitTestSource
({
space
:
viewerSpace
});
const
loader
=
new
THREE
.
GLTFLoader
();
let
reticle
;
loader
.
load
(
"
https://immersive-web.github.io/webxr-samples/media/gltf/reticle/reticle.gltf
"
,
function
(
gltf
)
{
reticle
=
gltf
.
scene
;
reticle
.
visible
=
false
;
scene
.
add
(
reticle
);
})
let
flower
;
loader
.
load
(
"
https://immersive-web.github.io/webxr-samples/media/gltf/sunflower/sunflower.gltf
"
,
function
(
gltf
)
{
flower
=
gltf
.
scene
;
});
session
.
addEventListener
(
"
select
"
,
(
event
)
=>
{
if
(
flower
)
{
const
clone
=
flower
.
clone
();
clone
.
position
.
copy
(
reticle
.
position
);
scene
.
add
(
clone
);
}
});
// Create a render loop that allows us to draw on the AR view.
// Create a render loop that allows us to draw on the AR view.
const
onXRFrame
=
(
time
,
frame
)
=>
{
const
onXRFrame
=
(
time
,
frame
)
=>
{
...
@@ -86,13 +118,26 @@ const onXRFrame = (time, frame) => {
...
@@ -86,13 +118,26 @@ const onXRFrame = (time, frame) => {
camera
.
projectionMatrix
.
fromArray
(
view
.
projectionMatrix
);
camera
.
projectionMatrix
.
fromArray
(
view
.
projectionMatrix
);
camera
.
updateMatrixWorld
(
true
);
camera
.
updateMatrixWorld
(
true
);
const
hitTestResults
=
frame
.
getHitTestResults
(
hitTestSource
);
if
(
hitTestResults
.
length
>
0
&&
reticle
)
{
const
hitPose
=
hitTestResults
[
0
].
getPose
(
referenceSpace
);
reticle
.
visible
=
true
;
reticle
.
position
.
set
(
hitPose
.
transform
.
position
.
x
,
hitPose
.
transform
.
position
.
y
,
hitPose
.
transform
.
position
.
z
)
reticle
.
updateMatrixWorld
(
true
);
}
// Render the scene with THREE.WebGLRenderer.
// Render the scene with THREE.WebGLRenderer.
renderer
.
render
(
scene
,
camera
)
renderer
.
render
(
scene
,
camera
)
}
}
}
}
session
.
requestAnimationFrame
(
onXRFrame
);
session
.
requestAnimationFrame
(
onXRFrame
);
}
}
</script>
</script>
</body>
</body>
</html>
</html>
\ No newline at end of file
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