Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Texture on a 3d Object
  Posted by: ToastbrotX
  When: 10/09/2010 at 10:23:08

 Unable to Build
  Posted by: Rich_Zap
  When: 09/09/2010 at 15:39:33

 HLSL calculating normals
  Posted by: Rich_Zap
  When: 09/09/2010 at 15:34:56

 Texture on a 3d Object
  Posted by: ToastbrotX
  When: 09/09/2010 at 11:14:19

 DRIVER ERROR XBOX 360
  Posted by: Anonymous
  When: 09/09/2010 at 01:12:47

 Reflection problem in corners ...
  Posted by: Anonymous
  When: 08/09/2010 at 21:03:35

 Texture on a 3d Object
  Posted by: radulph
  When: 08/09/2010 at 17:34:01

 InvalidDataException???
  Posted by: Anonymous
  When: 08/09/2010 at 09:10:36

 Unable to Build
  Posted by: Anonymous
  When: 08/09/2010 at 07:49:36

 Suggestion to change a few lines
  Posted by: Insomnica
  When: 06/09/2010 at 14:37:05

 Collision with series 1
  Posted by: radulph
  When: 05/09/2010 at 13:33:14

 HLSL calculating normals
  Posted by: miroslavign
  When: 04/09/2010 at 17:26:26

 Collision with series 1
  Posted by: ToastbrotX
  When: 04/09/2010 at 16:52:02

 HLSL calculating normals
  Posted by: Rich_Zap
  When: 04/09/2010 at 15:00:20

 Collision with series 1
  Posted by: ToastbrotX
  When: 04/09/2010 at 12:28:41

 HLSL calculating normals
  Posted by: miroslavign
  When: 04/09/2010 at 08:46:31

 Walk along a wall
  Posted by: Anonymous
  When: 03/09/2010 at 10:28:02

 model problems
  Posted by: muffinman
  When: 03/09/2010 at 06:47:32

 Vertices problem
  Posted by: Anonymous
  When: 03/09/2010 at 05:48:35

 OcTree Question
  Posted by: Zorzomezz
  When: 03/09/2010 at 04:07:03




Topic: Loading two different models?



  
Goto parent category
  
Create a new user account


   Loading two different models?
 Poster : soarer
 Posts: 15
 Country : Australia
 City:

  
Posted by soarer on 27/06/2008 at 20:07:24
Hey

Just wondering if you wanted to load two different 3D models; would you need a new function for each of them .. eg. DrawTank() , DrawXwing() etc

and as a result have a matrix calculation in each of them?

Thanks
 Poster : soarer
 Posts: 15
 Country : Australia
 City:

  
Posted by soarer on 27/06/2008 at 22:49:26
Can anyone spot the problem with this function?


        private void DrawModelTaxi()
        {
            Matrix worldMatrix = Matrix.CreateScale(0.05f, 0.05f, 0.05f) * Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateTranslation(new Vector3(7, 0.5f, speedX));

            Matrix[] taxiTransforms = new Matrix[taxiModel.Bones.Count];
            taxiModel.CopyAbsoluteBoneTransformsTo(taxiTransforms);
            int i = 0;
            foreach (ModelMesh mesh in taxiModel.Meshes)
            {
                foreach (Effect currentEffect in mesh.Effects)
                {
                    currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
                    currentEffect.Parameters["xWorld"].SetValue(taxiTransforms[mesh.ParentBone.Index] * worldMatrix);
                    currentEffect.Parameters["xView"].SetValue(viewMatrix);
                    currentEffect.Parameters["xProjection"].SetValue(projectionMatrix);
                    currentEffect.Parameters["xTexture"].SetValue(taxiTextures[i]);
                    ++i;
                }
                mesh.Draw();
            }
        }
 Poster : soarer
 Posts: 15
 Country : Australia
 City:

  
Posted by soarer on 27/06/2008 at 22:50:19
Forgot to add, that its loading the model and only what seems about 1/3rd of the textures, its mostly white.
 Poster : soarer
 Posts: 15
 Country : Australia
 City:

  
Posted by soarer on 27/06/2008 at 22:50:24
Forgot to add, that its loading the model and only what seems about 1/3rd of the textures, its mostly white.
 Poster : soarer
 Posts: 15
 Country : Australia
 City:

  
Posted by soarer on 29/06/2008 at 18:17:04
Interesting development; any model with only 1 texture it loads in perfectly.  Soon as there is about 5 or 6+ textures for one model; it seems to only attach like a couple and make the rest white.
 Poster : soarer
 Posts: 15
 Country : Australia
 City:

  
Posted by soarer on 30/06/2008 at 19:58:51
Trying a whole range of different 3D models + multiple textures.

A bunch of them give me an error at this line:

textures[i++] = currentEffect.Texture;

Index was outside the bounds of the array
 Poster : soarer
 Posts: 15
 Country : Australia
 City:

  
Posted by soarer on 30/06/2008 at 22:56:12
Thats the LoadModel() I am using aswell.


private Model LoadModel(string assetName, out Texture2D[] textures)
{

Model newModel = Content.Load<Model>(assetName);

textures = new Texture2D[newModel.Meshes.Count];
int i = 0;
foreach (ModelMesh mesh in newModel.Meshes)
foreach (BasicEffect currentEffect in mesh.Effects)
textures[i++] = currentEffect.Texture;
              
foreach (ModelMesh mesh in newModel.Meshes)
foreach (ModelMeshPart meshPart in mesh.MeshParts)
meshPart.Effect = effect.Clone(device);

return newModel;
}
 Poster : riemer
 Posts: 1388
 Country : Belgium
 City: Antwerp

  
Posted by riemer on 01/07/2008 at 16:36:53
Hi there

Yes, for each model you want to render you need to make a World matrix and render the model. Otherwise, you should search around for "hardware instancing".

Your code seems to be fine at first glance .. I would say there are textures present, if not their color would be black, not white. As a first check, you can save them to file to check if the textures are loaded correctly:


textures[0].Save(...);
textures[1].Save(....);
...
 Poster : soarer
 Posts: 15
 Country : Australia
 City:

  
Posted by soarer on 01/07/2008 at 18:31:22
I had a play around with this other tutorial (wont paste link) to see if my 3D models were actually working.  and it loads any 3D model I had fine, but doesnt even load any textures (they seem to attach by themselves) or any effect but BasicEffect.

I could be wrong but I think using the effect.fx file could be causing a problem.
 Poster : riemer
 Posts: 1388
 Country : Belgium
 City: Antwerp

  
Posted by riemer on 03/07/2008 at 13:20:55
If the capabilities of the BasicEffect are enough for you, than you should use it. When you start using your own effects, you'll need to override them in a way similar to Series 2. The best way is to override them in a Custom Model Processor, as explained exactly in Recipe 4-12.

  
Post a new reply
 





Google
 
Web www.riemers.net
If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !
- Website design & DirectX code : Riemer Grootjans -
©2006 Riemer Grootjans


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 3.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)