Smart Man
Smart Man

Reputation: 325

trouble about working with material of model visual 3d?

I made a 3d box in code behind.

I want to get color of material (for example, DiffuseMaterial) in a string format by using RayMeshGeometry3DHitTestResult result1 in mouse left button down:

GeometryModel3D result2 = result1.ModelHit as GeometryModel3D;

I used:

MessageBox.Show(result2.Material.ToString());

This does not work!

Thanks alot.

Upvotes: 0

Views: 536

Answers (1)

dkozl
dkozl

Reputation: 33364

If you want to get color of the Brush used to create DiffuseMaterial as a string then you need to first check if it is DiffuseMaterial, as not all materials need to work of Brush, and then you have to check if Brush is SolidColorBrush as only that will support single color. Something like below should work:

DiffuseMaterial material = result2.Material as DiffuseMaterial;
if (material != null)
{
    string brushColor = null;
    var brush = material.Brush as SolidColorBrush;
    if (brush != null)
        brushColor = brush.Color.ToString();
}

Upvotes: 2

Related Questions