Support   /   Tutorials   /   How to show BIM data in runtime

How to show BIM data in runtime

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("");
            }
        }
    }
}

NEXT TUTORIAL

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

How it Works Use Cases Pricing News Support Contact
Log in Sign up for free