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 runtime. Before you do this, you will need to sign up to Tridify Service and start a free 14 day Tridify trial and start uploading your IFC files.

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

Show BIM data in console
Show BIM data in console

Few things for you TODO:

  • Add the script to a gameobject Eg. the Main Camera
  • Link Main Camera gameobject from hierarchy to ShowBimData.cs script RaycastCamera public field in 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;
 
                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 »

By continuing to browse the site you are agreeing to our Terms of Use

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