load models

Feb 5, 2013 at 8:06 AM
Edited Feb 5, 2013 at 9:26 AM
hello,
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();
where
                           <GeometryModel3D.Material>
                               <MaterialGroup x:Name="theMaterial">
                                   <DiffuseMaterial>
                                       <DiffuseMaterial.Brush>
                                           <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                                               <LinearGradientBrush.GradientStops>
                                                   <GradientStop Color="LightBlue" Offset="0" />
                                                   <GradientStop Color="LightBlue" Offset="1" />
                                               </LinearGradientBrush.GradientStops>
                                           </LinearGradientBrush>
                                       </DiffuseMaterial.Brush>
                                   </DiffuseMaterial>
                               </MaterialGroup>
                           </GeometryModel3D.Material>
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'.
thanks
Coordinator
Feb 10, 2013 at 3:43 PM
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());