MicroStation to Unity to VR - Workflow

Companion videos on YouTube:

Hi everyone,

It’s probably best to work through this written tutorial step by step but as a visual aid, I’ve created a series of companion videos and posted them on YouTube.
You can find the playlist here: https://www.youtube.com/watch?v=-q965SGPzzU&list=PL0JBlaeAgD15fFWHx4d6bFTVR6Je9zCpl

Introduction (Video 1):

  • The “Unity” real time game engine is the 800 pound gorilla in the room. It has a massive following and an extensive asset store that provides a vast amount of content. With the recent commercial release of virtual reality headsets such as the HTC Vive, Unity has become the tool of choice for those interested in creating and exploring virtual environments.
  • Unity uses FBX as its native file format which means that MicroStation’s FBX exporter is quite suited to providing Unity the content that it needs to build virtual worlds.
  • After some initial setup, the workflow between MicroStation & Unity becomes seamless. Changes get automatically integrated into the Unity project with very little additional work on a user’s part.
  • I highly recommend experiencing your projects in Virtual Reality, it will change your outlook on the process of design.

Prerequisites (Video 1):

Prepare “SteamVR Unity Toolkit” project files (Video 1):

  • Download the “SteamVR Unity Toolkit” ZIP file from GitHub.
  • Unzip the file and place the extracted folder alongside your other Unity Projects.

Surface normal direction (Video 2):

  • For performance reasons, Unity's standard shader only does single sided rendering which means that the back face of a surface will be rendered invisible.
  • MicroStation's Solids are OK but you will need to be careful and make sure that all Surface geometry has its surface normal direction pointing in the correct direction.
  • We will be using Valve's “The Lab Renderer” which does allow for two sided rendering but we only want to use that feature sparingly and only for things such as chain-link fences or tree foliage.

Create collision mesh geometry (Video 2):

  • The only additional MicroStation geometry that you will need to create is a simplified collision mesh (floors and walls) that represents the boundary of where the user is allowed to walk or teleport.
  • Even though you might be able to make your entire building model a collision mesh, you will get better performance if you use simplified geometry instead. 
  • Here you can see a complex model on the left and the simplicity of the collision mesh on the right:

Export DGN geometry as FBX files (Video 2):

  • Setup a series of DGN Reference files that break up your project into a number of smaller manageable components that are ready for export. If need be, move all referenced files so that the main point of interest on the ground floor is at the global origin XYZ = 0,0,0.
  • Open each DGN export file and goto [ File > Export > FBX ] (or keyin: “mdl keyin fbxexport dialog fbx”).
  • Set “Stroke Tolerance” to about “0.005” (if you have curved objects).
  • Turn ON “Invert Y and Z” and export all of your FBX files one at a time.

Create a Unity Project (Video 3):

  • Start Unity and create a new 3D Project.
  • In the top right corner set Layout to Default.
  • In the bottom right corner of the Assets tab, drag the slider to the left to enable “List” view.
  • Goto [ Toolbar > Edit > Project Settings > Player ]
    • In the Inspector tab, set:
    • [ Other Settings > Graphics Jobs (Experimental) ] to [ ON ].
    • [ Other Settings > Virtual Reality Supported ] to [ ON ].
    • [ Other Settings > Virtual Reality SDKs ] to [ OpenVR ] ensure that it is the only VR SDK in the list.
    • [ Other Settings > Single-Pass Stereo Rendering ] to [ ON ].
  • Goto [ Toolbar > Window > Asset Store ] to make sure the Asset Store tab is docked next to the Game tab.
  • From the Asset Store, install “SteamVR Plugin” and accept all defaults.
  • From the Asset Store, install “The Lab Renderer” and accept all defaults.
  • Close the Asset Store tab or click on the Scene tab to make it active.
  • Import the “SteamVR_Unity_Toolkit”:
    • Open a second instance of Unity.
    • Open the “SteamVR_Unity_Toolkit-master” project.
    • From the “Assets” folder, drag and drop “SteamVR_Unity_Toolkit” onto the “Assets” folder of your newly created Unity project and then close the second instance of Unity.
  • Goto [ Toolbar > File > Save Scene As… ]
    • Create a new subfolder called “Scenes” under the “Assets” folder.
    • Double click on the “Scenes” folder and name the new scene “Main”.

Add Prefabs and Scripts to the Unity project (Video 3):

  • Make sure the “Main” scene tree structure is expanded in the Hierarchy tab.
  • Delete the default “Main Camera” from the “Main” scene.
  • Drag and drop [ Project tab > Assets > SteamVR > Prefabs > CameraRig ] onto [ Hierarchy tab > Main ].
    • Set [ Inspector tab > CameraRig > Transform > Position X,Y,Z ] to [ 0,0,0 ].
    • Set [ Inspector tab > Steam VR_Play Area > Draw in Game ] to [ OFF ].
  • Drag and drop [ Project tab > Assets > SteamVR_Unity_Toolkit > Scripts > VRTK_ControllerEvents ] onto [ Hierarchy tab > Main > CameraRig > Controller (left) AND Controller (right) ].
    • For both controllers set [ Inspector tab > VRTK_Controller Events > Pointer Toggle Button ] to [ Touchpad_Press ].
  • Drag and drop [ Project tab > Assets > SteamVR_Unity_Toolkit > Scripts > VRTK_BezierPointer ] onto [ Hierarchy tab > Main > CameraRig > Controller (left) AND Controller (right) ].
  • Drag and drop [ Project tab > Assets > SteamVR_Unity_Toolkit > Scripts > VRTK_HeightAdjustTeleport ] onto [ Hierarchy tab > Main > CameraRig ].
    • Set [ Inspector tab > VRTK_Height Adjust Teleport > Play Space Falling ] to [ OFF ].

Import FBX files and set default attributes (Video 4):

  • Close Unity and with Windows File Explorer navigate to the “Assets” folder in your Unity project.
  • Create a new sub-folder called "FBX" and copy the previously exported FBX files to this folder.
  • Restart Unity and open your project. Unity will import all new or changed files automatically.
  • Goto [ Project tab > Assets > FBX ] and highlight the collision mesh FBX file.
  • In the Inspector tab set the following default attributes:
    • Read/Write Enabled = OFF
    • Generate Colliders = ON
    • Normals = Import   (NOT Calculate)
    • Smoothing Angle = 30 (Set low so things aren't rounded that shouldn't be)
    • Tangents = None
    • Import Materials = OFF
    • Press the "Apply" button.
  • Goto [ Project > Assets > FBX ] and highlight all FBX files except for the collision mesh.
  • In the Inspector tab set the following default attributes:
    • Read/Write Enabled = OFF
    • Generate Colliders = OFF
    • Normals = Import   (NOT Calculate)
    • Smoothing Angle = 30 (Set low so things aren't rounded that shouldn't be)
    • Tangents = None
    • Press the "Apply" button.
    • By default, Unity does not use MicroStation’s Material names. To fix this:
      • Goto [ Project tab > Assets > FBX > Materials ] and delete all of the materials.
      • Goto [ Project tab > Assets > FBX ] and highlight all FBX files except for the collision mesh.
      • In the Inspector tab set the following default attribute:
        • Material Naming = From Model’s Materials
        • Press the “Apply” button.
  • Material settings need to be tweaked but we won’t do this until after “The Lab Renderer” has been setup.

Add FBX files to the Unity project (Video 4):

  • Right click in the Hierarchy window and choose “Create Empty” GameObject.
    • Set [ Inspector tab > GameObject > Transform > Position X,Y,Z ] to [ 0,0,0 ]
    • Rename the “GameObject” to something that describes your project geometry.
  • From [ Project tab > Assets > FBX ] drag and drop all FBX files onto the GameObject container created earlier.
    • Make sure the Position Transform for the FBX files is set to X,Y,Z = 0,0,0
  • Click on the collision mesh in the Hierarchy window.
  • Goto [ Inspector tab > Mesh Renderer > Settings cog Icon on the right ] and select [ Remove Component ].
  • The CameraRig position has already been set to 0,0,0 but you can move it to suit the geometry in your scene.

Setup Valve’s “The Lab Renderer” (Video 5):

  • Goto [ Toolbar > Edit > Project Settings > Quality ]
    • In the Inspector tab, set:
    • [ Shadows > Shadows ] to [Disable Shadows ]
  • Drag and drop [ Project tab > Assets > TheLabRenderer > Scripts > ValveCamera ] onto [ Hierarchy tab > Main > CameraRig > Camera (head) > Camera (eye) ].
    • In the Inspector tab, set:
    • [ Camera > Clipping Planes > Near/Far ] to appropriate values.
    • [ Valve Camera > Valve Shadow Texture Width/Height ] to [ 8192 ]
  • Drag and drop [ Project tab > Assets > TheLabRenderer > Scripts > ValveRealtimeLight ] onto each realtime light in your scene.
  • Goto [ Toolbar > Valve > ShaderDev > Convert All Materials to Valve Shaders ]
  • Goto [ Project tab > Assets > FBX > Materials ] and tweak Material settings to suit.

Setup Directional Light (Video 5):

  • Goto [ Toolbar > Window > Lighting ] and dock the Lighting tab next to the Inspector tab.
  • Drag and drop [ Hierarchy tab > Main > Directional Light ] onto the [ Lighting tab > Environment Lighting > Sun ] slot.
  • Set [ Lighting tab > Baked GI ] to [ OFF ].
  • In the Scene tab, move and rotate the “Directional Light” so that it is sufficiently above and in front of your project geometry.
  • Click on the “Directional Light” in the Hierarchy tab.
    • In the Inspector tab, set:
    • [ Light > Shadow Type > Resolution ] to [ Very High Resolution ].
    • [ Valve Realtime Light > Shadow Resolution ] to [ 8192 ]
    • [ Valve Realtime Light > Directional Light Shadow Radius/Range ] to appropriate values for your scene scale.

View your scene in VR with the HTC Vive headset (Video 6):

  • Start SteamVR from your desktop and make sure that the Vive headset, base stations, and controllers are all up and running.
  • From within the Unity editor, press the “Play” button at the top of the screen.
  • Put the Vive headset on and walk around the scene as you would in real life.
  • To travel further than the confines of your physical room, press the big Touchpad button on your tracked controllers and aim the Bezier curve to the spot where you would like to be teleported.
  • You can teleport up and down slopes and stairs and also onto roofs. It all depends on how you’ve setup your collision mesh.
  • Press the “Play” button again to exit out of VR mode.
  • To share your project with a client who also has an HTC Vive, you can build a standalone executable of your project by going to [ Toolbar > File > Build Settings… ].

Known workflow difficulties (Video 6):

  • I’m still using MicroStation SS3 but apparently the FBX exporter in MicroStation SS4 has some issues.
  • The FBX exporter does not export elements of type “Surface” to the Unity game engine. To fix this problem, I’ve gotten into the habit of using the “CONVERT BREP” command to convert all elements of type “Surface” to elements of type “Smart Surface”.
  • Geometry that has materials that don’t use a texture map gets exported without UV texture coordinates. For Unity’s Baked Lighting to work, all geometry needs to have properly applied UV texture coordinates.
  • The FBX exporter appends the DGN file name to the material name. This leads to very long material names in the Unity editor but it also means that you get duplicate materials when you use multiple FBX files to export your project in smaller more manageable chunks.
  • Unity’s Standard shader uses single sided rendering which means that surface normal directions are critical. MicroStation needs a more efficient method of show the direction of ALL surface normals at once.
  • MicroStation’s mirror tool makes a mess of all surface normals so use it as sparingly as possible.
  • You can see a more in depth discussion of these issues here:   http://communities.bentley.com/products/microstation/f/273/t/120578
  • On very large sites, “The Lab Renderer” has a tendency to generates shadows that are quite fuzzy.
  • At the moment, “The Lab Renderer” does not generate proper shadows for the SpeedTree asset.

And that's all there is to it :-)

Andrew.