How to use DAE files for Android Cardboard in Unity

In this article I will write about Android Cardboard development using DAE files obtained from an OAR, the files are generated with a free tool, you can read my article about it here. This article includes tips, tricks and references to files needed to create an interesting Cardboard app.

For your own convenience you can download a package containing a ready made scene at the bottom of this article. The scene contains a player object and anything else needed for Cardboard, just download it, insert your objects into the scene and export the Unity project as an Android apk for Cardboard.

Unity

Android Cardboard development with Unity requires Unity “Version 2018.3.14f”. Unity with different versions properly generate the APK file without errors, however the installed app then fails to react to Cardboard user input (head-movement).

Importing the DAE files in Unity

You can follow the guide here (link the old one). To reiterate, you have too place the SelectOARShader.cs script in the Editor subfolder in your Assets folder, then place the DAE folder in the Assets folder and let Unity process them. You can then move the objects from the DAE folder in Assets into the “Hierarchy View”. Finally if there are errors with transparent textures in the Scene you have to set the object’s materials to “Use External Materials (Legacy)”, you then have to change the shader of the object in the “Hierarchy View”. For example a suiting shader is “Legacy Shaders/Transparent/Bumped Specular”.

A fresh project with some DAE files imported.

Setting up Unity for Android Cardboard

To use Unity for Android Cardboard Development we first have to install the tools required for Android development in Unity. First, add the Android module to your Unity version 2018.3.14f, to do this you go to Installs in Unity Hub, then click Add Module and add Android.

Then you have to switch the Unity project’s platform to Android, go to File/Build Settings, select Android on the left, click “Switch Platform” and wait for Unity to change platform.

After you switch the platform to Android for the first time you will also have to add an Android SDK and NDK when you try to build an APK. When you are prompted to do so, just select the SDK and NDK you have downloaded previously. (link to them here)

Cardboard Development prerequisites

For Cardboard Development I recommend you set the orientation of the Android device to “Landscape Left”, these settings can be found in the Player Settings. Furthermore you have to add Cardboard in the XR Settings.

Changing the orientation to Landscape Left
Adding Cardboard in the XR Settings

Next you will need to import the Cardboard SDK from Google, simply download the SDK (a Unity package) and import the package. You will need to copy a few prefabs/objects from the GVR SDK into your scene, GvrControllerMain, GvrEditorEmulator, GvrEventSystem and GvrReticlePointer.

The GvrReticlePointer should be placed as a child object of your scene’s Main Camera, this prefab provides you with a dot in the middle of the screen, showing the position of the gaze to the Cardboard user. It also ensures your camera changes orientation depending on the user’s head movement. You should also add the GvrPointerPhysicsRaycaster.cs script to the Camera.

From this point you should be able to generate an App, where the user is at the position of the Main Camera and can look around by moving his head. If you imported the DAE objects the user can look at them but he cannot move or interact with them at all, this will be covered in the next section.

Cardboard development

The pointer from the GvrReticlePointer prefab can be used to interact with in-world objects by setting event triggers on objects, for example a Pointer enter or Pointer exit trigger. This can be used in many ways, you can for instance program a button, that moves an object when the player looks at the button (Pointer Enter trigger).

The object in the view has a Pointer Enter and Pointer Exit trigger. If the gaze pointer enters the object, the function PaceEntered gets called in the PlayerMoveScript in the PlayerCube object.

However we want to do more than just buttons, we want to move in the Virtual Reality, maybe we also want to fly or do anything else.

To make the player move around you could move the Camera object around based on where the player is looking. To do this you can read out the Camera’s orientation and use it as input to your game. Alternatively you could move the player around if he looks at certain objects, like in a click adventure game.

For the app “The Faked VR” I built an interface for the user, that combines the two ways. The user is moved based on where he looks and what buttons he looked at previously. The user will see an interface when he looks downwards where he can select his movement mode from the buttons. The user can chose to “Fast Fly”, “Fly”, “Move” or “Stand”. These buttons change how the game will interpret his head movement. In case he choses one of the two flying modes the player/camera is moved in the direction the user looks at. In case he choses the “Move” mode he will move where he looks without really changing his height, this mode is ideal for walking around and looking at objects. The last real movement option is not moving at all, if he choses to stand the player will not be moved at all, he can stand still and look all around without changing position.

Furthermore there is a “Teleport” button, that teleports the player to the starting position. This button can help the player get back if he gets stuck anywhere or does not wish to go back himself.

To make the navigation bar responsive I made the buttons change colors when they are selected. Furthermore I made the reticle in the middle of the screen expand for a bit when the mode was changed.

In the app the player has to focus each button for a bit before the mode is changed, this ensures the player doesn’t select a mode he doesn’t want unintentionally.

Furthermore there are a few objects in the world that the player can interact with, the player can look at them for a short duration and is subsequently teleported away. These objects can lead the player around the world or to secret spots he would not likely find himself.

I made this navigation tool freely available at the bottom of this article, go there for more information and a download link.

Cardboard tips and tricks

Adding a Menu: If you ever try to use a menu for a Cardboard app, make sure the Canvas’ Render Mode is set to World Space. If the Canvas is placed somewhere in your world, it will appear to Cardboard users like a billboard in real life. Alternatively you can attach a Canvas to the player’s GameObject and position it relative to the camera.

You can see the scene with a Canvas is world space, relative to the camera, the canvas is in the bottom half of the camera’s field of vision.
When you import DAE files into a new project in Unity it will most likely still look a bit barren and empty.

Adding Water: To fill up the world and to make it more lively you can commonly add water and turn the contents in the middle into a nice looking island. Unfortunately the standard water does not work with Android Cardboard, it may look good in the Unity editor but not on the actual phone. The default water has wrong reflections in Cardboard, which completely destroys the immersion. Luckily there is a solution, you can use the Water from here. Simply add the files to you Assets folder and move a water prefab into the object, then make the water object bigger and move it where you want. The Water object is in the downloaded subfolder under WaterVRTest-master\Assets\Standard Assets\Environment\WaterVR2\Prefabs.

Adding a Skybox: On a similar note you can add a skybox to your world, you will need a few textures and insert them in Unity. You can get a lot of skybox textures on the internet, I got mine from here. Click here for the very good official documentation.

A good water and a nice skybox make an app more immersive.

Get started with my navigation bar

Above you can download a unitypackage with a scene, that includes my navigation tool, a nice skybox and a good water object. The scene is a ready made environment, you just have to insert your DAE files and create a game world in the scene. Without any programming you can create an app where players can explore your world in Cardboard VR.

When you have the package downloaded, create a new Unity project using Unity 2018.3.14f 1 and import the unitypackage by navigating to Assets\Import Package\Custom Package in the main menu. Then select all objects to be imported.

Navigate to the Scenes folder in your project’s Assets folder. Double-click on navigationBarScene, you will then have a prepared scene with a skybox, a PlayerObject, a water object and all necessary prefabs from the Google VR package. Everything in the scene is ready for Cardboard VR, you can add objects into the scene and export it for Android Cardboard or Daydream.

The content from my unitypackage
Make sure to add Cardboard VR in XR Settings in Player Settings when you build an Apk for Cardboard

Leave a Reply

Your email address will not be published. Required fields are marked *