C# WPF HELIX 3D How to get a model's material and make it a usable material

2.2k views Asked by At

I have a model of a human head with hair...don't worry about the bleeding, I'm only trying to get a rudimentary program going for altering meshes and things.

enter image description here

It's an .OBJ model and I am loading it using the Helix 3D toolkit. I tried various ways of getting the material used for the hair (once the model is loaded). The hair is a child mesh and is child 0. I am calling the imported model 'start' and it is loaded like this :

 ObjReader CurrentHelixObjReader = new ObjReader();
 start = CurrentHelixObjReader.Read("C:/Users/Roger/Desktop/head/base_med_.obj");

The model can be loaded successfully but things break when I attempt this :

 Material matty = (MaterialGroup)((GeometryModel3D)start.Children[0]).Material;

What I am trying to do is get the material from the original model. Is this the correct way to create a new material from an existing one ?

Once I have the material I would want to use it at a later stage.

I would welcome any advice and thank you for taking a look.

EDIT: Error Message is :

"An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll Additional information: 'The invocation of the constructor on type 'HelixTrial.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '9'. If there is a handler for this exception, the program may be safely continued."

1

There are 1 answers

0
Rog On

OK I think I found the solution, I simplified my code to just this and it's working now.

 Material matty = (MaterialGroup)((GeometryModel3D)start.Children[0]).Material;

Changed to :

 Material matty = ((GeometryModel3D)start.Children[0]).Material;