AB4D Forum
Another Texture Problem - Printable Version

+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: Viewer3ds and Ab3d.Reader3ds (https://forum.ab4d.com/forumdisplay.php?fid=5)
+--- Thread: Another Texture Problem (/showthread.php?tid=56)

Another Texture Problem - Bryan Gabric - 08-26-2010

Ok, first off, I think I’m really beginning to like your product. I’m just learning C# so I may be making things more difficult then they need to be. Also, I’m using the evaluation software until I can get enough built to convince my supervisor to buy me the software.

My goal is to be able to load 3ds models at run time. In the end I need to be able to grab a path from an xml file and load the model it points to.

Right now I can load a model and its textures loaded into the project as a resource. The problem comes when I change the path to a hard coded path on the hard drive. I can get the model to load but, the textures do not show up at all. Am I doing something wrong?

on a side note I have no idea how to work "ThrowMissingTextureException" The help file was less then helpful.

namespace Battleship
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        private Ab3d.Reader3ds _battleship;

        PerspectiveCamera myPCamera = new PerspectiveCamera();

        // Directional light values.
        private DirectionalLight myDirectionalLight = new DirectionalLight();
        Model3DGroup modelGroup = new Model3DGroup();
        public MainWindow()

        private void myPageLoaded(object sender, EventArgs e)

            _battleship = new Ab3d.Reader3ds();
            _battleship.ThrowMissingTextureException = true;

            //Uri uri = new Uri("pack://application:,,,/WpfApplication1;component/models/battleship.3DS", UriKind.Absolute);

            //_battleship.TexturesPath = "pack://application:,,,/WpfApplication1;component/models";

            _battleship.TexturesPath = "C:/Documents and Settings/p00009656/Desktop/3d Models";
            _battleship.ReadFile("C:/Documents and Settings/p00009656/Desktop/3d Models/battleship.3DS", Viewport1);

            //using (Stream stream = Application.GetResourceStream(uri).Stream)

            //    modelGroup = _battleship.ReadFile(stream, Viewport1, 0);

            myDirectionalLight.Color = Colors.White;
            myDirectionalLight.Direction = new Vector3D(0, -1, 0);

            myPCamera = (Viewport1.Camera as PerspectiveCamera);

            //Set camera viewpoint and properties.
            myPCamera.FieldOfView = 60;
            myPCamera.Position = new Point3D(8000, 2000, 5000);
            myPCamera.LookDirection = new Vector3D(-1, -.2, -.5);
            myPCamera.UpDirection = new Vector3D(0, 1, 0);




RE: Another Texture Problem - abenedik - 08-27-2010

I find this very strange.

Are you sure that the texture file is in the same folder as the 3ds file (C:/Documents and Settings/p00009656/Desktop/3d Models).

The Reader3ds automatically searches for the texture files in the same folder (if TexturesPath is not set). So it should be enough to put the texture files in the same folder as 3ds file and call ReadFile method.

Sometimes the cause of such problems is that the texture file names in 3ds file are stored only with 8 characters. So if your texture file name is longer than 8 characters, the file would not be found by Reader3ds because in 3ds file the file names is truncated.

Such problems can be found by setting ThrowMissingTextureException to true. In this case the Reader3ds would throw an Reader3ds.MissingTextureException exception with missing file name. This way you can get the file name that is causing problems and display it.

The following code displays the missing file name and than reads the 3ds file again with ThrowMissingTextureException set to false (the code sample is from the help file for the ThrowMissingTextureException property):

Ab3d.Reader3ds newReader3ds;
Model3DGroup buttonModel3DGroup;

newReader3ds = new Ab3d.Reader3ds();
newReader3ds.ThrowMissingTextureException = true;

    buttonModel3DGroup = newReader3ds.ReadFile("c:\\models\\button.3ds");
catch (Reader3ds.MissingTextureException e)
    MessageBox.Show("Missing texture: " + e.MissingTextureFileName);
    newReader3ds.ThrowMissingTextureException = false;
    buttonModel3DGroup = newReader3ds.ReadFile("c:\\models\\button.3ds");

I would advice you to use the code and check if the file is really present.

RE: Another Texture Problem - Bryan Gabric - 08-27-2010

Thanks that worked great! I did some digging and found that if i use:
modelGroup = _battleship.ReadFile("C:/Documents and Settings/p00009656/Desktop/3d Models/battleship.3DS", Viewport1);
it works great. however if i skip the model3dgroup and just use:
_battleship.ReadFile("C:/Documents and Settings/p00009656/Desktop/3d Models/battleship.3DS", Viewport1);
it no longer displays the textures.

Thanks again,

RE: Another Texture Problem - abenedik - 08-28-2010

Obviously you are calling the ReadFile method with the same parameters in both cases - so from Reader3ds perspective the same code is executed.

Maybe the problem is that in the first case you also add the light to the modelGroup (as seen from the code in your first post). Maybe you have forgotten to add the light to the Viewport1 in the second case (this can be also done in xaml where you have defined the Viewport1).

RE: Another Texture Problem - Bryan Gabric - 08-28-2010

Yea that's it. Without adding the "modelGroup" the lights I added have no reference to the model at all. In effect I've added lights to a model3Dgroup that is never added to the Viewport and only exist in the code behind. A stupid mistake but, at least I understand whats going on now. The textures were always there but, my lights where missing.