| 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. | |
|
|