load models

Anonymous 9 years ago 0
This discussion was imported from CodePlex

it_test wrote at 2013-02-05 09:06:

Can anyone provide a working code for loading one\group of models from .obj .mtl and some .jpg files and rendering them on screen? I was trying to load models, but I cannot load or apply textures, and it gets messy.
I looked at example folder, but it only loads model with no texture.
I'm probably not applying them correctly, but there might be other errors.

I think there is a problem with materials; first I load the model
        model = ModelImporter.Load("filename.obj");
        material = (MaterialGroup)((GeometryModel3D)model.Children[0]).Material;

then return that material:
        this.theMaterial = (MaterialGroup)faceNeutral.getMaterial();
                               <MaterialGroup x:Name="theMaterial">
                                           <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                                                   <GradientStop Color="LightBlue" Offset="0" />
                                                   <GradientStop Color="LightBlue" Offset="1" />
but object still renders as LightBlue.

also number of times I got
//Unable to cast object of type 'System.Windows.Media.Media3D.MaterialGroup' to type 'System.Windows.Media.Media3D.DiffuseMaterial'.

objo wrote at 2013-02-10 16:43:

The casting error is in your code, right? If you want to replace the MaterialGroup with the material from faceNeutral, I think you should change the Material property of the GeometryModel3D instead. If you need to keep the MaterialGroup, try Children.Clear() and Children.Add(faceNeutral.GetMaterial());