Using the power of A-Frame and pdf.js, I embarked on a quest to build an incredible VR application for viewing PDF files. Everything seemed to be working seamlessly on my desktop - flipping through PDF pages, rendering them onto a canvas, it was a sight to behold.
However, the real challenge arose when I attempted to run the application in a VR-enabled browser, specifically on my trusty Quest 2. The first attempt went swimmingly, but when it came to rendering the second page of another document onto the canvas... well, let's just say things took a mysterious turn. The new image refused to show up until I decided to exit VR mode, at which point it magically appeared, much to my bewilderment.
I delved deep into the trenches, tirelessly setting the material map.needsUpdate again and again in an A-Frame component tick loop, only to be met with no avail. As I continued my experimentation, I made a curious observation - trying to render a new page of a PDF a second time and then attempting for a third time (taking the adventurous leap of advancing by two pages while in VR), only to find that upon exiting VR mode, the texture from the second attempt was the only one that stuck. It seemed like the data from the third render had vanished into thin air. I began to ponder if these anomalies were somehow interlinked to the core issue at hand.
For those brave souls who wish to venture forth, a snippet of code for a scaled-down demonstration is provided below. And should you dare to take on the challenge yourself, a live version awaits your exploration at . Feel free to scrutinize the example in desktop mode - advance to the next page by unfurling the browser JavaScript console and entering testBook.nextPage();
, and witness the ever-changing images in all their glory. Should you dare to don your VR gear and take the plunge with a Quest headset, a simple press of the A button shall guide you to the next page.
And so, the burning question lingers in the air like a mist in the night - how does one triumphantly render multiple pages of a PDF document onto the same canvas, time and time again, whilst ensnared in the enigmatic realm of VR mode within the illustrious plane of A-Frame?