Use first person controls to move in the scene
import { Vector3 } from "three";
import FirstPersonControls from "@giro3d/giro3d/controls/FirstPersonControls.js";
import Instance from "@giro3d/giro3d/core/Instance.js";
import Tiles3D from "@giro3d/giro3d/entities/Tiles3D.js";
import Tiles3DSource from "@giro3d/giro3d/sources/Tiles3DSource.js";
import Inspector from "@giro3d/giro3d/gui/Inspector.js";
Instance.registerCRS(
"EPSG:2154",
"+proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs",
);
const instance = new Instance({
target: "view",
crs: "EPSG:2154",
backgroundColor: null,
});
const pointCloud = new Tiles3D(
new Tiles3DSource(
"https://3d.oslandia.com/3dtiles/eglise_saint_blaise_arles/tileset.json",
),
);
instance.add(pointCloud);
// Position our camera
const camera = instance.view.camera;
camera.position.set(831542.2870560559, 6287655.35350404, 31.86644500706522);
camera.lookAt(new Vector3(831585.923, 6287652.23, 27.461));
camera.updateMatrixWorld();
// And create our controls
const controls = new FirstPersonControls(instance, { focusOnMouseOver: true });
controls.reset();
instance.domElement.focus();
instance.notifyChange(camera);
Inspector.attach("inspector", instance);
<!doctype html>
<html lang="en">
<head>
<title>First Person Controls</title>
<meta charset="UTF-8" />
<meta name="name" content="first_person_controls" />
<meta
name="description"
content="Use first person controls to move in the scene"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="https://giro3d.org/images/favicon.svg" />
<link
href="https://giro3d.org/assets/bootstrap-custom.css"
rel="stylesheet"
/>
<script src="https://giro3d.org/assets/bootstrap.bundle.min.js"></script>
<link
rel="stylesheet"
type="text/css"
href="https://giro3d.org/latest/examples/css/example.css"
/>
</head>
<body>
<div id="view" class="m-0 p-0 w-100 h-100"></div>
<div
id="inspector"
class="position-absolute top-0 start-0 mh-100 overflow-auto"
></div>
<script type="module" src="index.js"></script>
<script>
/* activate popovers */
const popoverTriggerList = [].slice.call(
document.querySelectorAll('[data-bs-toggle="popover"]'),
);
popoverTriggerList.map(
// bootstrap is used as script in the template, disable warning about undef
// eslint-disable-next-line no-undef
(popoverTriggerEl) =>
new bootstrap.Popover(popoverTriggerEl, {
trigger: "hover",
placement: "left",
content: document.getElementById(
popoverTriggerEl.getAttribute("data-bs-content"),
).innerHTML,
html: true,
}),
);
</script>
</body>
</html>
{
"name": "first_person_controls",
"dependencies": {
"@giro3d/giro3d": "0.41.0"
},
"devDependencies": {
"vite": "^3.2.3"
},
"scripts": {
"start": "vite",
"build": "vite build"
}
}