BimRv SDK: Materials and Appearance Assets (Part 1 of 2)

Evgeniy Tikhonov

July 04, 2019

Using Helper Classes for Appearance Assets

Materials in .rvt/.rfa files contain properties for rendering entities in different views. The properties that define a material are organized into assets.

  • Appearance properties — Control how the material looks in Realistic views and Ray Trace views.
  • Graphics properties — Control how the material looks in other views.
  • Physical properties — Used for structural analysis.
  • Thermal properties — Used for energy analysis.

A material can have up to four assets, one of each type, but cannot have more than one of the same asset type. Generally assets are groups of properties that control certain characteristics or behaviors of an object. Assets can be connected to each other.

Each property is a descendant of the OdBmAProperty type and can be accessed by the getAProperty method of the OdBmAsset class:

template <class T> 
bool getAProperty(const OdString &parameter, OdSmartPtr<T> &value)

To simplify access to properties in assets, BimRv SDK has these helper classes:

  • OdBmAppearanceAssetHelper
  • OdBmStructuralAssetHelper
  • OdBmThermalAssetHelper

The AppearanceAssetHelper class provides several methods to access material data:

  • Access the name of the asset:
    OdResult getName(OdString&) const;
    void setName(const OdString&);
  • Apply properties defined in an appearance asset to the material object:
    void applyToMaterial(OdBmMaterialPtr&);
  • Return the array of connected assets that define the appearance of the material:
    OdResult getAppearanceAssets(OdBmObjectPtrArray& pAssets) const;
  • Return the type of the asset based on the asset name:
    OdBm::PredefinedAppearanceAsset::Enum getSchemaType() const;

There are also static methods:

  • Fill an asset with properties of a specified predefined asset:
    static OdResult fillAppearanceAssetWith(OdBmAssetPtr&,
    OdBm::PredefinedAppearanceAsset::Enum,
    const OdString& texture = OdString::kEmpty);
  • Return a connected asset only if the asset defines a bitmap of the material appearance.
    static OdResult getTextureAsset(const OdBmAssetPtr&,
    OdBmAssetPtr&, const OdString& propertyName = OdString::kEmpty);
  • Return the type of asset based on the asset name:
    static OdBm::PredefinedAppearanceAsset::Enum
    getSchemaType(const OdBmAssetPtr&);

The appearance of generic materials in rendering views (Realistic and Ray Trace) can be one of the following types: Image, Checker, Gradient, Marble, Noise, Speckle, Tiles, Waves or Wood.

Currently there are helpers implemented to work with Image and Noise assets.

To work with Image assets, use OdBmUnifiedBitmapSchemaHelper, and for the Noise asset use OdBmNoiseSchemaHelper. The next example shows how to work with helpers:

OdBmDatabasePtr pDb = app->readFile("modern_villa_floor.rvt");
  OdBmMaterialElemPtr pMatElem = 
pDb->getObjectId(OdDbHandle(400770)).safeOpenObject();
  OdBmMaterialPtr pMaterial = pMatElem->getMaterial();
  OdBmObjectPtrArray pAssets;
  OdBmAppearanceAssetHelper 
helper(pMaterial->getAppearanceAssetId().safeOpenObject());
  helper.getAppearanceAssets(pAssets);
  OdBmAssetPtr pAsset = pAssets[0];
  OdBm::PredefinedAppearanceAsset::Enum type =    OdBmAppearanceAssetHelper::getSchemaType(pAsset);
       // type == OdBm::PredefinedAppearanceAsset::Noise;
  OdBmNoiseSchemaHelper nhelper(pAsset);
  OdBmAssetPtr noise1;
  nhelper.getAppearanceAsset1(noise1);
  OdBmUnifiedBitmapSchemaHelper bhelper(noise1);
  OdString filename;
  bhelper.getTextureFileName(filename);
 

The next article in this two-part series will show helper class methods and details about creating a new material.