sf-1eb / main.js
Rebel Artimus
Add 2 files
6023d45
// Set up the scene, camera, and renderer
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ canvas: document.getElementById("canvas") });
// Set up the pdf loader and add it to the scene
const pdfLoader = new THREE.PDFLoader();
pdfLoader.setPath("path/to/pdf");
// Add the pdf to the scene
const pdfGeometry = pdfLoader.parse(pdfLoader.load("pdf.pdf"));
const pdfMaterial = new THREE.MeshBasicMaterial({ color: 0x0066cc });
const pdfObject = new THREE.Mesh(pdfGeometry, pdfMaterial);
pdfObject.position.set(0, 0, 0);
scene.add(pdfObject);
// Set up the camera position and controls
camera.position.z = 5;
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.target.set(0, 0, 0);
controls.update();
// Listen for key input and change the pdf page accordingly
document.addEventListener("keydown", (event) => {
if (event.key === "ArrowRight") {
pdfObject.geometry.layers.next();
render();
} else if (event.key === "ArrowLeft") {
pdfObject.geometry.layers.prev();
render();
}
});
// Render the scene
function render() {
renderer.render(scene, camera);
}
// Update the UI when the pdf changes
pdfObject.geometry.layers.callback = () => {
controls.update();
render();
};