This is the second article in the two-part series about using materials and appearance assets in ODA BimRv SDK. For the first article, see Part 1.
Creating a New Material
With ODA BimRv you can create new materials using the OdBmAppearanceAssetHelper class. See the following code example:
OdBmMaterialElemPtr pMaterialElem = OdBmMaterialElem::createObject();
pMaterialElem->setName(L"Textured_Material");
OdBmAppearanceAssetElemPtr pAppAsset = OdBmAppearanceAssetElem::createObject();
OdBmAppearanceAssetHelper appAssetHelper(pDb, pMaterialElem->getName(),
pAppAsset, OdBm::PredefinedAppearanceAsset::Generic, L"texture.png");
// set properties of material texture
OdBmAssetPtr textureAsset;
OdResult es = appAssetHelper.getTextureAsset(textureAsset);
OdBmUnifiedBitmapSchemaHelper textureHelper(textureAsset);
textureHelper.setLinkTextureTransforms(true);
textureHelper.setOffsetLock(true);
textureHelper.setRealWorldOffset(OdGePoint2d(50., 50.),
OdBm::DisplayUnitType::DUT_DECIMAL_INCHES);
textureHelper.setRealWorldScale(OdGePoint2d(50., 50.),
OdBm::DisplayUnitType::DUT_DECIMAL_INCHES);
textureHelper.setScaleLock(false);
textureHelper.setUVRepeat(true, true);
textureHelper.setWAngle(OdaPI4);
textureHelper.setBlur(1.5);
textureHelper.setFiltering(1);
textureHelper.setInvert(false);
OdBmMaterialPtr pMaterial = pMaterialElem->getMaterial();
appAssetHelper.applyToMaterial(pMaterial);
pMaterialElem->setMaterial(pMaterial);
pMaterialElem->subSetDatabaseDefaults(pDb, true);
OdBmCmColor oColor;
oColor.setRGB(8031132);
pMaterialElem->setColor(oColor); // color for non-rendering view
pDb->addElement(pMaterialElem);
The next example shows how to construct a generic material with the Noise appearance based on bitmap and color.
const OdString sMaterialName(L"Noise_Material");
OdBmAppearanceAssetElemPtr pAppAsset = OdBmAppearanceAssetElem::createObject();
OdBmAppearanceAssetHelper appAssetHelper(pDb, sMaterialName, pAppAsset,
OdBm::PredefinedAppearanceAsset::Generic);
OdBmAssetPtr pAsset;
OdBmNoiseSchemaHelper nhelper(pAsset);
nhelper.createDefaultSchema();
OdBmAssetPtr pTextureAsset;
nhelper.getAppearanceAsset1(pTextureAsset);
OdBmUnifiedBitmapSchemaHelper bhelper(pTextureAsset);
bhelper.createDefaultSchema();
bhelper.setTextureFileName(L"texture.png");
nhelper.setAppearanceAsset1(bhelper.getAsset());
OdBmObjectPtrArray pAssets;
pAssets.push_back(nhelper.getAsset());
appAssetHelper.setAppearanceAssets(pAssets);
OdBmMaterialElemPtr pMaterialElem = OdBmMaterialElem::createObject();
pMaterialElem->setName(sMaterialName);
OdBmMaterialPtr pMaterial = pMaterialElem->getMaterial();
appAssetHelper.applyToMaterial(pMaterial);
pMaterialElem->setMaterial(pMaterial);
pMaterialElem->subSetDatabaseDefaults(pDb, true);
pDb->addElement(pMaterialElem);
Methods of Helper Classes
OdBmNoiseSchemaHelper:
OdResult getNoiseType(OdInt32&) const;
void setNoiseType(OdInt32);
OdResult getNoiseLevels(double&) const;
void setNoiseLevels(double);
OdResult getNoisePhase(double&) const;
void setNoisePhase(double);
OdResult getNoiseSize(double&) const;
void setNoiseSize(double);
OdResult getNoiseThresholdHigh(double&) const;
void setNoiseThresholdHigh(double);
OdResult getNoiseThresholdLow(double&) const;
void setNoiseThresholdLow(double);
OdResult getTextureAngle(OdGeVector3d&) const;
void setTextureAngle(OdGeVector3d);
OdResult getTextureOffset(OdGePoint3d&) const;
void setTextureOffset(OdGePoint3d);
OdResult getLinkTextureTransforms(bool&) const;
void setLinkTextureTransforms(bool);
/**
Description:
Returns asset #1 in Noise schema.
The asset can be one of the following types:
image, checker, gradient, marble, noise, speckle, tiles, wave, wood
*/
OdResult getAppearanceAsset1(OdBmAssetPtr&) const;
void setAppearanceAsset1(const OdBmAssetPtr&);
/**
Description:
Returns asset #2 in Noise schema.
The asset can be one of the following types:
image, checker, gradient, marble, noise, speckle, tiles, wave, wood
*/
OdResult getAppearanceAsset2(OdBmAssetPtr&) const;
void setAppearanceAsset2(const OdBmAssetPtr&);
/**
Description:
Returns color #1 in Noise schema.
The asset can be one of the following types:
image, checker, gradient, marble, noise, speckle, tiles, wave, wood
*/
OdResult getNoiseColor1(double& red, double& green, double& blue) const;
void setNoiseColor1(double red, double green, double blue);
/**
Description:
Returns asset #2 in Noise schema.
The asset can be one of the following types:
image, checker, gradient, marble, noise, speckle, tiles, wave, wood
*/
OdResult getNoiseColor2(double& red, double& green, double& blue) const;
void setNoiseColor2(double red, double green, double blue);
OdBmUnifiedBitmapSchemaHelper:
OdResult getLinkTextureTransforms(bool&) const;
void setLinkTextureTransforms(bool);
OdResult getOffsetLock(bool&) const;
void setOffsetLock(bool);
OdResult getRealWorldOffset(OdGePoint2d&, OdInt32&) const;
void setRealWorldOffset(const OdGePoint2d&, OdInt32);
OdResult getRealWorldScale(OdGePoint2d&, OdInt32&) const;
void setRealWorldScale(const OdGePoint2d&, OdInt32);
OdResult getScaleLock(bool&) const;
void setScaleLock(bool);
OdResult getUVOffset(double&, double&) const;
void setUVOffset(double, double);
OdResult getUVRepeat(bool&, bool&) const;
void setUVRepeat(bool, bool);
OdResult getUVScale(double&, double&) const;
void setUVScale(double, double);
OdResult getUVScale(double&) const;
void setUVScale(double);
OdResult getWAngle(double&) const;
void setWAngle(double);
OdResult getBlur(double&) const;
void setBlur(double);
OdResult getBlur_Offset(double&) const;
void setBlur_Offset(double);
OdResult getFiltering(OdInt32&) const;
void setFiltering(OdInt32);
OdResult getInvert(bool&) const;
void setInvert(bool);
OdResult getRGBAmount(double&) const;
void setRGBAmount(double);
OdBmAssetPtr getAsset() const;
OdResult getTextureFileName(OdString&) const;
void setTextureFileName(const OdString&);
/**
Description:
Loads texture using getTextureFileName() then using sTextureFileName if unsuccess with getTextureFileName().
Returns eOk if success and sTextureFileName contains texture filename.
Returns eFileNotFound if can't find texture file.
Returns eLoadFailed if can't load RASTER_SERVICES app.
*/
OdResult getTextureRasterImage(OdString&, OdGiRasterImagePtr&) const;
Rendering Example
Please see the CreateDirectShapeWithTexture method in the TB_ExCreateDummyObject example.