Simple portal demo with Unity, AR Foundation, and echoAR.
Don’t have an API key? Make sure to register for FREE at echoAR.
- Clone this project and open the project in Unity.
- In the Portals folder, open up the Portal.unity scene (same as sample scene, but includes tags ‘portal’, ‘portalVideo’ and ‘skyDome’, and a box collider on the Main Camera).
- In Portal < Prefabs, drag portalController into the Hierarchy.
- Click on portalController in the Hierarchy and drag SkyDome and PortalPlane into their respective fields in the Portal Controller script in the Inspector.
- Click the echoAR prefab and enter your API key.
How to Create a Portal
- Upload one of the portal models the Models folder.
- Add in the metadata from metadata.csv in the Models folder.
- Upload a 360 video to the console (e.g. ‘Beach Sunrise’ in the Portals folder).
- In the uploaded video’s metadata, assign it the key-value pair, ‘name: “portalVideo”’.
- At this point, the portal plane and skyDome will be created, the video will be projected on the inside of the skyDome, and you should be able to get a peek into the skyDome through the portal plane.
- Going through the portal plane will unmask the rest of the video sphere, going back through the portal will mask it again.
Simply press the Play button in Unity.
Using Different Portal Models and Videos
- If you would like to use a portal model other than the one provided, you can upload it to the console and assign it the name ‘portal’ in the object’s metadata. Just make sure there is only one named portal in the console!
- Similarly, if you would like to use a different portal video, you can upload it to the console and assign it the name ‘portalVideo’.
Adjusting the Portal Plane
- Since different models are configured in different ways, you may need to align or scale the portal plane with your model manually. There are a number of parameters for the portal plane that can be tweaked through its metadata.
- Translation: portalPlaneX, portalPlaneY, portalPlaneZ
- Rotation: portalPlaneXAngle, portalPlaneYAngle, portalPlaneZAngle
- Scale: portalPlaneScale
- If a model and video are uploaded without “portal” or “portalVideo” names: Model and video plane just get instantiated as normal.
- If a model has a “portal” name, but there is no video with “portalVideo” name: A skyDome and portalPlane will be instantiated as children of the model, but the skyDome will not have a videoPlayer, until a “portalVideo” can be detected.
- If a video with a “portalVideo” name is found, but no model with a “portal” name: Video just gets displayed on a plane until a model with the “portal” name can be found.
- The portal project relies on tags. Checks are made for models tagged as “portal” and “portalVideo” in order to be able to fuse these together to create the portal if both are present.
- The project works best if the portal model used is one with a gap or open space, such as an open door or window.
- Sometimes the model used as the portal may not have (0, 0, 0) as its origin (not aligned properly).
- Portal model: This could be an obj file of an open door, window, etc.
- portalPlane: This acts as the “window” into the portal (its material is what makes it act like a portal). The camera needs to go through this plane in order to enter the portal.
- skyDome: This is the large sphere that acts as the actual portal world. The 360 video is projected onto the inside of this sphere. It’s hidden until the camera penetrates the portalPlane.
- portalVideo: This is just a VideoPlayer component that gets added to the skyDome once a video with the name “portalVideo” is added to the console.
- Sometimes the relative positioning between the portal model and portalPlane is flipped (suspected to be related to model alignment).
- Removing the “portalVideo” name from a video on the console will remove the VideoPlayer from the portal, but not instantiate a video plane again. Delete the video from the console and reupload it if you would like it to be on a video plane.
Refer to our documentation to learn more about how to use Unity and echoAR.