When creating a VR space, you need ‘world’ components, that is, the ground, the sky, mountains, and the sea.
Some skies are available in STYLY by default and you can also create your original one from Unity’s ‘Skybox’ assets.
However, you cannot create your favorite ground and mountains with existing assets.
In this case, you will find a terrain engine called ‘Terrain’ useful.
‘Terrain’ is an engine to create pseudo terrains or mountains, which is a built-in function of Unity.
But, when uploading a terrain created by ‘Terrain’ to STYLY directly, you may not be able to resize or rotate it. In the worst case, you can’t even upload it due to the insufficient capacity.
Therefore, in this article, I will show how to convert terrain into an OBJ file and upload it to STYLY by using a free function called ‘TerrainObjExporter’.
※ This article doesn’t introduce how to create terrains with the ‘Terrain’ engine, so please refer to the following article if you use ‘Terrain’ for the first time.
How to Use TerrainObjExporter
TerrainObjExporter is a script that exports a terrain as an OBJ-format 3D model.
In the Project window, create a C# script under the Assets folder (Right-click in the blank space in the Assets folder and select ‘Create > C#Script’).
Any file name will do. This time I named it ‘Editor’.
Next, click on the following link to open the site for ‘TerrainObjExporter’.
There are two scripts, ‘ExportTerrain.js’ and ‘ExportTerrain.cs’.
We copy ExportTerrain.cs into ‘Editor’ to use.
Open the Editor script created earlier, delete the default code, and then copy and paste the contents of ‘ExportTerrain.cs’.
Save the script. Now, you can check that ‘ExportTerrain.cs’ has been applied by the Unity’s Inspector window of the Editor script.
In the Unity’s menu bar, you can see an item ‘Terrain’ added (It may take a while to be added).
When finished creating the terrain, select ‘Terrain > Export To Obj’ in the menu bar.
It brings up the Export-setting window.
Set ‘Export Format’ to ‘Triangles’.
This time I set ‘Resolution’ to ‘Half’. You can reduce the number of vertices to export (i.e. you can reduce the file size) by selecting anything other than ‘Full’. So set ‘Quarter’ or less if you found the output file size too large.
Edit the Exported 3D Model in Unity
The exported 3D model doesn’t have any texture.
So, upload the 3D model back to Unity to apply textures.
First, upload the exported 3D-model file to Unity’s ‘Assets’ and place it in Unity’s Scene.
Next, find the Texture file used earlier.
Open the Inspector window for the terrain you created first and select ‘Edit Textures > Edit Texture’.
You will find the texture created when you created ‘Terrain’. Click it to display the location of the texture file.
Drag and drop the texture file into the 3D model placed earlier in the Scene.
The texture has been applied.
Then, we finally upload ‘Terrain’ to STYLY. However, it causes the following error when uploading the Prefab converted from this 3D model.
So, after converting the ‘Terrain’ (obj) with the texture into a Prefab, you need to delete the Editor script (ExportTerrain.cs).
Please refer to the following article to learn about how to upload a Prefab to STYLY.
It’s uploaded successfully.
The terrain uploaded in this way can be rotated and resized, so you can make it more suitable for the Scene.