XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Loading a custom model in Racing template?

Last post 03-28-2008 10:02 PM by Coppen. 3 replies.
  • 03-28-2008 5:44 PM

    Loading a custom model in Racing template?

    Ok, I have the model and want to replace the original one with my own. When I try to load my model instead of the one already there, I get a bunch of errors concerning the effect variable("Object reference is not set to an instance of an object"), for example on lines like this:

    effect.Parameters["UseAlpha"].SetValue(false);

     

    Are there any tutorials out there on implementing custom models in the xna racing template?

  • 03-28-2008 5:55 PM In reply to

    Re: Loading a custom model in Racing template?

    I'm sure the loading is fine, the problem is that your model might not have the same effect. So when you make that particular call, you won't get anything back from the Parameters collection which will cause an exception when you try to call SetValue on it. You will need to make sure that you are either applying the effect to your models before exporting to FBX or X or you will want to set the proper effect on the model after you load it in. I believe switching the effect is as easy as:

    foreach (ModelMesh mesh in myModel.Meshes)
    {
    foreach (ModelMeshPart part in mesh.MeshParts)
    part.Effect = myDesiredEffect;
    }

    Then you can assign the proper effect to your models and you'll be all set.

    Hopefully that helps. Let us know if that doesn't solve things for you.

    Nick Gravelyn -- Microsoft XNA MVP
    Blog | XNA Wiki | FX-izer | EasyZip | Current Adventures | Next-Gen
  • 03-28-2008 6:41 PM In reply to

    Re: Loading a custom model in Racing template?

    Ok, I can get my car to render, but the parts are all misplaced, and Im sure it has to do with the matrices. For instance:

    cachedEffectParameters[effectParameterIndex++].SetValue(BaseGame.WorldMatrix);

    I am not sure why it is done like this, but here I get the same error. I thought the effect had something to do with shaders, why are they used for the matrices?

  • 03-28-2008 10:02 PM In reply to

    Re: Loading a custom model in Racing template?

    Ok, I got it working the way you said.. I just had to apply an existing shader from the template as "myDesiredEffect". But I will have to create new custom shaders as the ones in there now creates awkward effects =)
Page 1 of 1 (4 items) Previous Next