Developer tools   /   Tutorials   /   How to Show BIM Data in Runtime

How to Show BIM Data in Runtime

In this tutorial you will learn how to show BIM data in Unity in runtime. If you don’t have an account set up, sign up to Tridify BIM Publishing Service and start a FREE 14 DAY TRIAL. Then you need to upload and process your IFC file and then import it to Unity.

We have created this simple C# script as an example of how to show BIM data in runtime, just by clicking a GameObject. When clicking an object in the Game view, the script will print BIM data to the console.

Show BIM data in console
Show BIM data in console

Few things for you to do:

  • Add the script to a GameObject e.g. the Main Camera
  • Link Main Camera GameObject from hierarchy to ShowBimData.cs script RaycastCamera public field in the Inspector
  • Add colliders to all mesh objects as we are using raycast in the script!
using UnityEngine;
using Tridify;
using System;
using System.Linq;

public class ShowBimData : MonoBehaviour
{

    public Camera raycastCamera;
    private GameObject _selectedObject;

    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Ray ray = raycastCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 1000))
            {
                _selectedObject = hit.transform.gameObject;
                
                // Here we get all IfcPropertySets
                var ifcPropertySets = _selectedObject.GetComponents<IfcPropertySet>();

                foreach(var pSet in ifcPropertySets)
                {
                    var attributeStrings = pSet.Attributes
                        .Select(attr => attr.Name + ": " + attr.Value);
                    var attributesString =
                        string.Join(Environment.NewLine, attributeStrings);

                    Debug.Log("Selected: " + pSet.GetType().Name
                        + Environment.NewLine + attributesString);

                }

                //Here we get IfcType. Just change the parameter if you want eg. IfcWallType
                var ifcType = _selectedObject.GetComponent<IfcType>();

                if (ifcType != null)
                {
                    var attributeStrings = ifcType.Attributes
                        .Select(attr => attr.Name + ": " + attr.Value);
                    var attributesString =
                        string.Join(Environment.NewLine, attributeStrings);

                    Debug.Log("Selected: " + ifcType.GetType().Name
                        + Environment.NewLine + attributesString);
                }
                else
                {
                    Debug.Log("No IfcType found on object " + _selectedObject.name);
                }
            }
            else
            {
                Debug.Log("");
            }
        }
    }
}

 

READY TO GET STARTED?

Sign up for a free 14 day Tridify trial »
You can test the service using our Sample IFC »

Explore the benefits of the Tridify BIM Publishing Service right now, starting with our FREE 14 day trial. Please note you will need this in order to use your FREE Tridify BIM Tools for Unity.

No credit card required

Tridify BIM Tools for Unity

With the Tridify BIM Tools for Unity, you'll speed up your Unity development; import processed IFC files, search objects by their BIM data, generate lighting and replace materials. These tools are FREE; you'll just need to activate a Tridify BIM Publishing Service Account from $20 per month to start using your BIM Tools in Unity. Simply open a FREE 14 day trial account (see above) and download the FREE BIM Tools for Unity here to start exploring the benefits today!

How It Works
Case Studies
Developers
Pricing
News
Support
Contact
Log in Sign up for free