meta-quest / immersive-web-emulation-runtime

Javascript WebXR Runtime for Emulation
https://meta-quest.github.io/immersive-web-emulation-runtime/
MIT License
33 stars 0 forks source link

injection to webXR apps built by various game engines #3

Open cyberfoxmeow opened 1 month ago

cyberfoxmeow commented 1 month ago

Injection to some webXR apps has failed maybe because there is existing webXR runtime attached to the build.

The webXR apps I failed to inject are built by Needle Engine with Unity and Wonderland .

Is there any solution for injection to the apps built by these two engines?

Thanks.

felixtrz commented 1 month ago

I have a patch for Wonderland coming out soon. Still need to look into Needle Tools

cyberfoxmeow commented 1 month ago

ok. thanks. I will also have a look at Needle. Hope I can give a help.

felixtrz commented 1 month ago

I've just released version 1.0.1 on NPM, which you can find here: iwer package. This update addresses the issue affecting both Wonderland and Needle Tools.

The root of the problem was in how I managed the updateRenderState method. Originally, I set up a pending render state to be applied on the next device frame. However, I overlooked the scenario where updateRenderState could be invoked multiple times before the next frame, causing only the last state to be recorded and previous updates to be lost. Since updateRenderState allows for partial updates, this oversight led to the loss of crucial information.

To resolve this, I implemented a fix in commit d45bd66 that compounds any pending updates whenever updateRenderState is called and a pending state already exists. This solution has resolved the integration issues with both Wonderland and Needle Tools.

cyberfoxmeow commented 1 month ago

Thanks.

It works for Wonderland.

But It does not work for Needle on my side.........

I tried injection in two methods: For the first method, I directly inject the .js scripts into the <head> of dist/index.html, just like what I did for Wonderland. For the second method, I establish a new .ts script under src/scripts folder, and inside the .ts I put the xrDevice position keyboard control inside the update() loop. (for example, I press ArrowLeft, and xrDevice.position.x -= 0.1;)

For both two methods above, after I click enter VR, the screen gets freezed. There is no error shown in the console of my browser. I put console log for debug the second method, and I find that, if I press a key ArrowLeft once, the console log shows that the script xrDevice.position.x -= 0.1; is run for many times. image

felixtrz commented 1 month ago

@cyberfoxmeow that is strange, any chance you can provide a test link for me to try and repro this on my side?

cyberfoxmeow commented 1 month ago

sure.

The Needle I am using is a Unity plugin . I just use the scene template, and add one cube.

The build web src is: dist.zip . According to Needle policy, it only supports HTTPS.

#!/usr/bin/python3

# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes

from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl,sys,os

context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain(certfile='server.pem', keyfile='server.pem')
context.check_hostname = False

if len(sys.argv) > 1:
    os.chdir(sys.argv[1])

with HTTPServer(("0.0.0.0", 14443), SimpleHTTPRequestHandler) as httpd:
    httpd.socket = context.wrap_socket(httpd.socket, server_side=True)
    httpd.serve_forever()

# python https_server.py '.\Needle 3D example\Needle\newProject\dist'

I have commented out IWER injection in index.html.

For your reference, the whole Unity project file is: https://drive.google.com/file/d/1dnpYj3GmFWoFp9j4hhxtfj_rHjYDufwn/view?usp=sharing
In this Unity project, I also tried to import IWER in Needle/newProject/src/scripts/iwerControl.ts. Also, it does not work, and only with a freeze screen after clicking Enter VR.