3D on the Web & WebXR

Creating a VR Scene

3D on the Web & WebXR

Check out a free preview of the full 3D on the Web & WebXR course

The "Creating a VR Scene" Lesson is part of the full, 3D on the Web & WebXR course featured in this preview video. Here's what you'd learn in this lesson:

Ayşegül creates a VRButton component to launch the VR experience. The Chrome WebXR extension can be used to simulate the VR experience in the browser or inspect and debug the experience on a connected mobile device.


Transcript from the "Creating a VR Scene" Lesson

>> Last thing that we did was creating the earth with the cloud texture on top of it. We are going to start from that. And you can copy and paste the whole thing into the ar.ts file, if you like. So, you will have exactly the same thing and we will start from there and create the experience here, cool.

Now, we have exactly the same thing as we did before. Number one thing that we are going to do is have imports of VR button. VR button is going to do a lot of stuff for us. First of all, when we have a VR experience, we have to start a session and we always have to ask users permission before we go into an immersive experience.

We never want to make anyone directly go into universal experience when they're not expecting. So, that is a requirement of the spec API. We are going to do that. And VR button nicely does that for us. I believe it's GSM web VR button. From expected [LAUGH] And we have the VR button edits as an important.

We also have to add it on to our documents, we append it to our documents. So, when we can do that on our image function, document, body appendchild. This is the AR button but I'm going to do a VR, Create button and then give it a render. And this requirements is for Augmented reality, but for our case, the renderer is just fine.

If we go back to our experience and refresh it, we should see the Enter VR button. Now, the challenging part is to see it in a VR experience, because here we won't be able to go into it. But if you already downloaded the extension, WebXR extension, then you can try to go into the VR and move the headset to see around.

Let's see if we are having an issue here. Okay, I'm going to exit there and try to run it on my device. My Android device, I've already enabled the developer mode and all I need to do is now plug it into my computer. And open up your developer tools.

And now, you can go to remote devices. If you're not seeing remote devices, it might be hidden over here, or you can click on the hamburger menu and go under more tools and find it here. So, remote devices are here. Or you can directly go into inspect devices and open up the inspect devices panel.

Right now, I have a browser open. Chrome browser is open, so one thing I have to do is add the port forward then if you already happens. Currently, our example is running on port 3000. So, you have to add both port 3000 and then the IP address local hosts 3000.

Once you've done that, you have to just wait for device portal to find your device. It should be under remote targets. Let me refresh. Here we go, now I have it. I already have a local host 3000 open, but if it wasn't you can just copy and paste it here, and it will open up a new tab for you with your code.

And I will share what I'm seeing, hopefully. All right, here. This is another tool that I'm using to be able to share what I'm seeing on my phone, and it's called YVWYSOR. If you are not able to see things over here, that's also another option for you to try out.

Usually, for these things to work properly, you have to be on the same network. Sometimes, you might be using a different version of the same network, and you might run into issues. If you are able to see your device here, then, you can click on Inspect, and this will open up the Inspect.

So, everything that happens here, you can see the catalogs and everything that we are doing. Normally, the button got really, really small here. So, I'm gonna press it on my device but you can actually see that it was pressed. When I do that, usually it stops refreshing, but hopefully we'll be able to see it on the site.

So, I have a two view. I have two renders for two different eyes. So, we are in a VR mode, basically, but it's a little bit dark. If you have any thing like a Cardboard, Google Cardboard, or Samsung device, then you can put your phone into it and then you'll be able to see the VR experience.

You should be able to see it but just in case, what we can do is also check the flags, Current flags that you have for Chrome. Are you using Chrome?
>> Yeah.
>> Okay. So, you can type in chrome;//flags, and this will open up your Chrome flags. And what you can do is enable anything that's related to WebXR.

So, in my case, WebXR incubations enables. If it's a default, I would enable it too. And once we do that, we have to restart our browser too. Force WebXR Runtime and we can keep this as default and relaunch.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now