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.

Parents
  • Hi Andrew,

    Thanks for the fabulous tutorial! It's very clearly explained and easy to follow.

    I am currently working on a MicroStation to Unity to VR workflow and need some of your help if possible.

    I'm using MicroStation CONNECT Edition.

    I followed your tutorial very closely to export each DGN to FBX in small chunks.

    Then I imported all FBXs in Unity 5.4.2f2 Personal Edition. However, when I drag the models in the scene, they are all centered at a given non-zero origin, all piled up on each other.

    In MicroStation, these DGNs are all part of a big structure so that each DGN fits like a piece of the puzzle. I would expect them to retain their original position when imported in Unity.

    Any hints on what's happening and how to fix this?

Reply
  • Hi Andrew,

    Thanks for the fabulous tutorial! It's very clearly explained and easy to follow.

    I am currently working on a MicroStation to Unity to VR workflow and need some of your help if possible.

    I'm using MicroStation CONNECT Edition.

    I followed your tutorial very closely to export each DGN to FBX in small chunks.

    Then I imported all FBXs in Unity 5.4.2f2 Personal Edition. However, when I drag the models in the scene, they are all centered at a given non-zero origin, all piled up on each other.

    In MicroStation, these DGNs are all part of a big structure so that each DGN fits like a piece of the puzzle. I would expect them to retain their original position when imported in Unity.

    Any hints on what's happening and how to fix this?

Children
  • Unknown said:
    Any hints on what's happening and how to fix this?

    Hi KR, sorry it took me a while to respond but I didn’t realise you had posted a question. All that aside, it’s great seeing people embrace VR :-)

    I’m still using MicroStation SS3 but I do remember some people reporting an issue with the FBX exporter in MicroStation Connect. I don’t know if the problem has been fixed in the various updates but the more I think about it, the more I think that this might be your problem.

    Is there any chance that you could try exporting the FBX files using MicroStation SS3 just to confirm that the problem is not with MicroStation Connect?

    It’s hard to troubleshoot because it looks like you’re doing everything correctly but lets just run through a few things…

    * When you dragged the FBX files into the “Main” scene in your Unity project, did you click on each FBX file and check in the “Inspector” window that the Position, Rotation, & Scale transforms were set to (0,0,0), (0,0,0), & (1,1,1) respectively?

    * Is your MicroStation geometry drawn near the design cube origin? If not, I think it’s worth creating a special set of Reference files for the Unity export process. These files should reference the relevant geometry but move it all to the same relative spot near the design cube origin (0,0,0).

    If none of that works and if it’s feasible to upload your MicroStation project somewhere, I could take a look at it and see if I can make it work with my setup.

    Cheers,

    Andrew.

    P.S. In my spare time I’ve been working on a model of the “Eagle Transporter” space ship from the “Space 1999” television series. If anyone has an HTC Vive and is interested in seeing the model in VR, send me a Private Message with your Email address and I’ll send you a download link. It’s still a work in progress but I’m so chuffed with the outcome :-)

  • Fantastic model. What were the render & material settings?
  • Unknown said:
    What were the render & material settings?


    Hi Duncan,

    Do you mean the settings for the image or the Unity Project? Anyone who knows me, knows that I'm a Maxwell Render fanboy so of course the image was done with Maxwell and a very simple HDR light. The materials are a work in progress but are simple Maxwell two layer BSDF materials.

    As far as the Unity settings go, well they're pretty standard as well but I do struggle with the baked lighting. The next version of Unity (v5.6) is supposed to come with OctaneRender built in for free so I'm quite excited to see how that handles baked global illumination :-)

    Andrew.

  • Hi Andrew

    Yes the image. Nice render. I was wondering whether you had used Microstation or a 3rd part renderer.
  • Hi Andrew,

    In the meanwhile, I had read your comments in an earlier post on FBX issues with CONNECT, so I installed SS4, and then downgraded to SS3. I have both CONNECT and SS3 installed.

    I tried exporting the FBX files in SS3, and when I imported in Unity, some of the FBXs aligned correctly, but others were misaligned. With CONNECT, the FBXs are relatively close to each other, but not at all in their proper place.

    When you say "drag the FBX into the Main scene", do you mean dragging in the hierarchy or the actual 3D scene viewer? I know that there is a difference between both methods as to the positioning of objects.

    To answer your two questions:

    - All three, position, rotation, and scale were set to (0,0,0), (0,0,0), and (1,1,1). But the position & rotation transforms were bold.

    - No, my MicroStation geometry is drawn very far from the design cube origin. In fact, the X, Y, Z values in MicroStation are in the hundreds and thousands of units away from the origin. But I'm really new to MicroStation and don't know how to create those reference files and how to move them to the design cube origin.

    In fact, I have several hundreds of DGN files that fit into one big structure. Most DGNs have a list of reference files attached to them, while some don't or simply are referenced by other files. This seems to indicate that reference files already exist in my project. Am I right to deduce that?

    In the past I have been using NavisWorks Manage exclusively to convert my DGNs to FBX and import in Unity. The FBX files generated by NavisWorks fit perfectly in Unity with no position readjustment to make. However, I can't really use NavisWorks anymore because its FBX export workflow does not work with VR. My scene in VR is all very jerky and dizzying. Also, those NavisWorks FBXs have rendering issues (textures, weird transparency of objects when viewed from different angles, etc.) and are less optimal (batches, setpass calls, etc.). That is why I went back to MicroStation after finding out that its FBXs work very well in VR.
    Should I use a different version of Unity? PRO maybe?

    Just as an information, I have done a FBX export comparison between CONNECT and v8i SS4, and CONNECT is better when imported in Unity in terms of rendering performance (e.g. better FPS, fewer batches & setpass calls).

    Looking forward to any help on how to fix this issue!
    Thanks