本文介绍 Revit 的 Material 材质。
下面介绍材质的图形和外观选项卡。
从界面的管理 Tab 下,选择材质,调整到图形选项卡:
材质在 API 中用 Autodesk.Revit.DB.Material
表示,这一页的信息,可以通过下面的代码获得:
private void GetMaterialInformation(Material material)
{
StringBuilder message = new StringBuilder("Material : " + material.Name);
//材质的颜色
message.Append(string.Format("\nColor: Red[{0}]; Green[{1}]; Blue[{2}]",
material.Color.Red, material.Color.Green, material.Color.Blue));
//材质截面的前景图案和颜色
FillPatternElement cutForegroundPattern = material.Document.GetElement(material.CutForegroundPatternId) as FillPatternElement;
if (null != cutForegroundPattern)
{
message.Append("\nCut Foreground Pattern: " + cutForegroundPattern.Name);
message.Append(string.Format("\nCut Foreground Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
material.CutForegroundPatternColor.Red, material.CutForegroundPatternColor.Green, material.CutForegroundPatternColor.Blue));
}
//材质表面的前景图案和颜色
FillPatternElement surfaceForegroundPattern = material.Document.GetElement(material.SurfaceForegroundPatternId) as FillPatternElement;
if (null != surfaceForegroundPattern)
{
message.Append("\nSurface Foreground Pattern: " + surfaceForegroundPattern.Name);
message.Append(string.Format("\nSurface Foreground Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
material.SurfaceForegroundPatternColor.Red, material.SurfaceForegroundPatternColor.Green, material.SurfaceForegroundPatternColor.Blue));
}
//材质截面的背景图案和颜色
FillPatternElement cutBackgroundPattern = material.Document.GetElement(material.CutBackgroundPatternId) as FillPatternElement;
if (null != cutBackgroundPattern)
{
message.Append("\nCut Background Pattern: " + cutBackgroundPattern.Name);
message.Append(string.Format("\nCut Background Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
material.CutBackgroundPatternColor.Red, material.CutBackgroundPatternColor.Green, material.CutBackgroundPatternColor.Blue));
}
//材质表面的背景图案和颜色
FillPatternElement surfaceBackgroundPattern = material.Document.GetElement(material.SurfaceBackgroundPatternId) as FillPatternElement;
if (null != surfaceBackgroundPattern)
{
message.Append("\nSurface Background Pattern: " + surfaceBackgroundPattern.Name);
message.Append(string.Format("\nSurface Background Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
material.SurfaceBackgroundPatternColor.Red, material.SurfaceBackgroundPatternColor.Green, material.SurfaceBackgroundPatternColor.Blue));
}
//材质的着色器属性
int shininess = material.Shininess;
message.Append("\nShininess: " + shininess);
int smoothness = material.Smoothness;
message.Append("\nSmoothness: " + smoothness);
int transparency = material.Transparency;
message.Append("\nTransparency: " + transparency);
TaskDialog.Show("Revit", message.ToString());
}
从界面的管理 Tab 下,选择材质,调整到外观选项卡:
获取材质的外观:
ElementId appearanceAssetId = material.AppearanceAssetId;
AppearanceAssetElement appearanceAssetElem = doc.GetElement(appearanceAssetId) as AppearanceAssetElement;
这里的类 AppearanceAssetElement
即使描述外观这部分的,这个类是如何描述外观的呢?
下满是这个类的接口:
namespace Autodesk.Revit.DB
{
//
// 摘要:
// An element that contains a rendering asset used as a portion of a material definition.
public class AppearanceAssetElement : Element
{
public static AppearanceAssetElement Create(Document document, string name, Asset asset);
public static AppearanceAssetElement GetAppearanceAssetElementByName(Document doc, string name);
public AppearanceAssetElement Duplicate(string name);
public Asset GetRenderingAsset();
public void SetRenderingAsset(Asset asset);
}
}
显然,关键在于通过 GetRenderingAsset
得到 Asset
。
先看这个继承关系:
System::Object
Autodesk.Revit.DB.Visual::AssetProperty
Autodesk.Revit.DB.Visual::AssetProperties
Autodesk.Revit.DB.Visual::Asset
Autodesk.Revit.DB.Visual::AssetPropertyBoolean
Autodesk.Revit.DB.Visual::AssetPropertyDistance
Autodesk.Revit.DB.Visual::AssetPropertyDouble
Autodesk.Revit.DB.Visual::AssetPropertyDoubleArray2d
Autodesk.Revit.DB.Visual::AssetPropertyDoubleArray3d
Autodesk.Revit.DB.Visual::AssetPropertyDoubleArray4d
Autodesk.Revit.DB.Visual::AssetPropertyDoubleMatrix44
Autodesk.Revit.DB.Visual::AssetPropertyEnum
Autodesk.Revit.DB.Visual::AssetPropertyFloat
Autodesk.Revit.DB.Visual::AssetPropertyFloatArray
Autodesk.Revit.DB.Visual::AssetPropertyInt64
Autodesk.Revit.DB.Visual::AssetPropertyInteger
Autodesk.Revit.DB.Visual::AssetPropertyList
Autodesk.Revit.DB.Visual::AssetPropertyReference
Autodesk.Revit.DB.Visual::AssetPropertyString
Autodesk.Revit.DB.Visual::AssetPropertyTime
Autodesk.Revit.DB.Visual::AssetPropertyUInt64
在这里面,Asset
继承自 AssetProperties
,而 AssetProperties
继承自 AssetProperty
。显然,AssetProperties
从字面上看就知道它带了很多的 AssetProperty
。多么熟悉的味道,从这个上面看到设计模式中的组合模式的影子,但是又不完全相同。
写点逻辑,把 Asset
中的内容打印出来:
// 通过反射,把 AssetProperty 里面的值取出来
string printType(AssetProperty assetProp)
{
string output = "";
Type type = assetProp.GetType();
PropertyInfo[] propInfos = type.GetProperties();
foreach(PropertyInfo propertyInfo in propInfos)
{
if(propertyInfo.Name == "Value")
output += propertyInfo.GetValue(assetProp);
}
return output;
}
void printAsset(Asset asset, StreamWriter sw, int indent)
{
string indentStr = new string(' ', indent * 2);
int size = asset.Size;
for (int assetIdx = 0; assetIdx < size; assetIdx++)
{
AssetProperty aProperty = asset.Get(assetIdx);
sw.WriteLine(indentStr + aProperty.Name + ", " + aProperty.Type.ToString() + ", " + printType(aProperty));
for (int ii = 0; ii < aProperty.NumberOfConnectedProperties; ii++)
{
string indentStr2 = new string(' ', indent * 2 + 2);
AssetProperty conProp = aProperty.GetConnectedProperty(ii);
sw.WriteLine(indentStr + conProp.Name + ", " + conProp.Type.ToString());
Asset conAsset = conProp as Asset;
if(conAsset != null)
{
printAsset(conAsset, sw, indent + 2);
}
}
}
}
以 Brick 为例:
Mats/MasonryCMU
出现了 6 次。
Line 1: AdvancedUIDefinition, String, Mats/MasonryCMU/MasonryCMUAdvancedUI.xml
Line 6: ImplementationGeneric, String, Mats/MasonryCMU/Generic.xml
Line 7: ImplementationMentalRay, String, Mats/MasonryCMU/MentalImage.xml
Line 8: ImplementationOGS, String, Mats/MasonryCMU/OGS.xml
Line 9: ImplementationPreview, String, Mats/MasonryCMU/PreviewColor.xml
Line 11: UIDefinition, String, Mats/MasonryCMU/MasonryCMUUI.xml
可以从电脑中找到:
Maps/UnifiedBitmap
出现了 8 次。
Line 30: AdvancedUIDefinition, String, Maps/UnifiedBitmap/UnifiedBitmapAdvancedUI.xml
Line 36: ImplementationMentalRay, String, Maps/UnifiedBitmap/MentalImage.xml
Line 37: ImplementationOGS, String, Maps/UnifiedBitmap/OGS.xml
Line 40: UIDefinition, String, Maps/UnifiedBitmap/UnifiedBitmapUI.xml
Line 86: AdvancedUIDefinition, String, Maps/UnifiedBitmap/UnifiedBitmapAdvancedUI.xml
Line 92: ImplementationMentalRay, String, Maps/UnifiedBitmap/MentalImage.xml
Line 93: ImplementationOGS, String, Maps/UnifiedBitmap/OGS.xml
Line 96: UIDefinition, String, Maps/UnifiedBitmap/UnifiedBitmapUI.xml
Line 73: unifiedbitmap_Bitmap, String, 1\mats\brick_non_uniform_running_burgundy.png
Line 129: unifiedbitmap_Bitmap, String, 1\mats\brick_non_uniform_running_bump.png
// 长度 1350.00mm 即 4.429ft
texture_RealWorldScaleX, Distance, 4.42913389205933
// 高度 1200.00mm 即 3.937ft
texture_RealWorldScaleY, Distance, 3.93700790405273
所有 Asset
信息:
AdvancedUIDefinition, String, Mats/MasonryCMU/MasonryCMUAdvancedUI.xml
AssetLibID, String, AD121259-C03E-4A1D-92D8-59A22B4807AD
BaseSchema, String, MasonryCMUSchema
ExchangeGUID, String,
Hidden, Boolean, False
ImplementationGeneric, String, Mats/MasonryCMU/Generic.xml
ImplementationMentalRay, String, Mats/MasonryCMU/MentalImage.xml
ImplementationOGS, String, Mats/MasonryCMU/OGS.xml
ImplementationPreview, String, Mats/MasonryCMU/PreviewColor.xml
SchemaVersion, Integer, 4
UIDefinition, String, Mats/MasonryCMU/MasonryCMUUI.xml
UIName, String, Non-Uniform Running - Burgundy
VersionGUID, String, Masonry-002
assettype, String, materialappearance
category, String, :Masonry/Brick:Default:Brick
common_Shared_Asset, Integer, 1
common_Tint_color, Double4,
common_Tint_toggle, Boolean, False
description, String, Masonry and CMU material.
keyword, String,
localname, String, Masonry
localtype, String, Appearance
masonrycmu_ao_details, Boolean, False
masonrycmu_ao_distance, Double1, 4
masonrycmu_ao_on, Boolean, False
masonrycmu_ao_samples, Integer, 16
masonrycmu_application, Integer, 2
masonrycmu_color, Double4,
UnifiedBitmapSchema, Asset
AdvancedUIDefinition, String, Maps/UnifiedBitmap/UnifiedBitmapAdvancedUI.xml
AssetLibID, String, AD121259-C03E-4A1D-92D8-59A22B4807AD
BaseSchema, String, UnifiedBitmapSchema
ExchangeGUID, String,
Hidden, Boolean, False
ImplementationGeneric, String,
ImplementationMentalRay, String, Maps/UnifiedBitmap/MentalImage.xml
ImplementationOGS, String, Maps/UnifiedBitmap/OGS.xml
ImplementationPreview, String,
SchemaVersion, Integer, 5
UIDefinition, String, Maps/UnifiedBitmap/UnifiedBitmapUI.xml
UIName, String, Masonry-002_masonrycmu_color
VersionGUID, String, Masonry-002_masonrycmu_color
assettype, String, texture
category, String,
common_Shared_Asset, Integer, 0
common_Tint_color, Double4,
common_Tint_toggle, Boolean, False
description, String, Unified Bitmap.
keyword, String, :masonry:brick:burgundy:non-uniform:materials
localname, String, Bitmap Texture
localtype, String, Texture
revision, Integer, 1
swatch, String,
texture_LinkTextureTransforms, Boolean, False
texture_MapChannel, Integer, 1
texture_MapChannel_ID_Advanced, Integer, 1
texture_MapChannel_UVWSource_Advanced, Integer, 0
texture_OffsetLock, Boolean, False
texture_RealWorldOffsetX, Distance, 0
texture_RealWorldOffsetY, Distance, 0
texture_RealWorldScaleX, Distance, 3.33333333333333
texture_RealWorldScaleY, Distance, 3.89649923896667
texture_ScaleLock, Boolean, True
texture_UOffset, Double1, 0
texture_URepeat, Boolean, True
texture_UScale, Double1, 1
texture_UVScale, Double1, 1
texture_VOffset, Double1, 0
texture_VRepeat, Boolean, True
texture_VScale, Double1, 1
texture_WAngle, Double1, 0
thumbnail, String, Maps\UnifiedBitmap\UnifiedBitmap.png
unifiedbitmap_Bitmap, String, 1\mats\brick_non_uniform_running_burgundy.png
unifiedbitmap_Bitmap_urn, String,
unifiedbitmap_Blur, Double1, 0.01
unifiedbitmap_Blur_Offset, Double1, 0
unifiedbitmap_Filtering, Integer, 0
unifiedbitmap_Invert, Boolean, False
unifiedbitmap_RGBAmount, Double1, 0.865
version, Integer, 2
masonrycmu_color_by_object, Boolean, False
masonrycmu_pattern, Integer, 1
masonrycmu_pattern_height, Double1, 0.15
masonrycmu_pattern_map, Reference,
UnifiedBitmapSchema, Asset
AdvancedUIDefinition, String, Maps/UnifiedBitmap/UnifiedBitmapAdvancedUI.xml
AssetLibID, String, AD121259-C03E-4A1D-92D8-59A22B4807AD
BaseSchema, String, UnifiedBitmapSchema
ExchangeGUID, String,
Hidden, Boolean, False
ImplementationGeneric, String,
ImplementationMentalRay, String, Maps/UnifiedBitmap/MentalImage.xml
ImplementationOGS, String, Maps/UnifiedBitmap/OGS.xml
ImplementationPreview, String,
SchemaVersion, Integer, 5
UIDefinition, String, Maps/UnifiedBitmap/UnifiedBitmapUI.xml
UIName, String, Masonry-002_masonrycmu_pattern_map
VersionGUID, String, Masonry-002_masonrycmu_pattern_map
assettype, String, texture
category, String,
common_Shared_Asset, Integer, 0
common_Tint_color, Double4,
common_Tint_toggle, Boolean, False
description, String, Unified Bitmap.
keyword, String, :maps:misc
localname, String, Bitmap Texture
localtype, String, Texture
revision, Integer, 1
swatch, String,
texture_LinkTextureTransforms, Boolean, False
texture_MapChannel, Integer, 1
texture_MapChannel_ID_Advanced, Integer, 1
texture_MapChannel_UVWSource_Advanced, Integer, 0
texture_OffsetLock, Boolean, False
texture_RealWorldOffsetX, Distance, 0
texture_RealWorldOffsetY, Distance, 0
texture_RealWorldScaleX, Distance, 3.33333333333333
texture_RealWorldScaleY, Distance, 3.89649923896667
texture_ScaleLock, Boolean, True
texture_UOffset, Double1, 0
texture_URepeat, Boolean, True
texture_UScale, Double1, 1
texture_UVScale, Double1, 1
texture_VOffset, Double1, 0
texture_VRepeat, Boolean, True
texture_VScale, Double1, 1
texture_WAngle, Double1, 0
thumbnail, String, Maps\UnifiedBitmap\UnifiedBitmap.png
unifiedbitmap_Bitmap, String, 1\mats\brick_non_uniform_running_bump.png
unifiedbitmap_Bitmap_urn, String,
unifiedbitmap_Blur, Double1, 0.01
unifiedbitmap_Blur_Offset, Double1, 0
unifiedbitmap_Filtering, Integer, 0
unifiedbitmap_Invert, Boolean, False
unifiedbitmap_RGBAmount, Double1, 0.865
version, Integer, 2
masonrycmu_refl_depth, Integer, 0
masonrycmu_roundcorners_allow_different_materials, Boolean, False
masonrycmu_roundcorners_on, Boolean, False
masonrycmu_roundcorners_radius, Double1, 0.25
masonrycmu_type, Integer, 1
mode, Integer, 4
reflection_glossy_samples, Integer, 32
revision, Integer, 1
swatch, String, Swatch-Wall
thumbnail, String, C:/Users/shenj/AppData/Local/Temp/MaterialThumbnails_PID_1d38/583c74c0.png
version, Integer, 2
PatternOffset, Double2, Autodesk.Revit.DB.DoubleArray
https://thebuildingcoder.typepad.com/blog/2017/10/material-texture-path.html