AB4D Forum

Full Version: Convert OpenGL materials to WPF
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am finding a number of sites on the Internet that define material properties for various real world items.  For example: http://www.it.hiof.no/~borres/j3d/explai...rials.html

Is there some easy want to map the OpenGL definitions to WPF?

Thanks,
Arthur
Good find Arthur!

You can use the following code to convert the samples from the web site you found to WPF:

Code:
//Brass
//float[] mat_ambient  = { 0.329412f, 0.223529f, 0.027451f, 1.0f };
//float[] mat_diffuse  = { 0.780392f, 0.568627f, 0.113725f, 1.0f };
//float[] mat_specular = { 0.992157f, 0.941176f, 0.807843f, 1.0f };
//float shine = 27.8974f;

var diffuseMaterial = new DiffuseMaterial(new SolidColorBrush(Color.FromScRgb(1, 0.329412f, 0.223529f, 0.027451f)));
diffuseMaterial.AmbientColor = Color.FromScRgb(1, 0.329412f, 0.223529f, 0.027451f);

var specularMaterial = new SpecularMaterial(new SolidColorBrush(Color.FromScRgb(1, 0.992157f, 0.941176f, 0.807843f)), 27.8974);

var materialGroup = new MaterialGroup();
materialGroup.Children.Add(diffuseMaterial);
materialGroup.Children.Add(specularMaterial);

After that you can assign materialGroup to a Material property.

You get better results when you also add some AmbientLight to the scene - for example the following xaml does that:

Code:
<ModelVisual3D>
   <ModelVisual3D.Content>
       <Model3DGroup>
           <AmbientLight Color="#333333"/>
       </Model3DGroup>
   </ModelVisual3D.Content>
</ModelVisual3D>
Excellent!  Thank you.