Model

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
marceloguto
Posts: 7
Joined: Wed Apr 23, 2008 4:23 pm

Model

Post by marceloguto »

Hi,

This is my first post here.
First of all, congratulation for this Engine :)

I´m begginer with engines, so be patience with my questions heeheh

I need to do a project for my final test, the idea is do a Cave where the character will walk and kill some creatures or something like that. First time I´m tried to show the model on the screen and collid with the Cave (another model).

I´ve a model with 12 meshes, I´m using DisplayModel class to show it, but only the first mesh of the model displayed on the screen. Do you know what is happened ?

Second time, I think in move the character on the Cave with collision detected, to move the character, Is there some function for it ? or I need to use the tradional way, multiplyng matrix ?

If you have another tips to help me with my project I´ll be gratefull.

Thanks,
Marcelo
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Model

Post by Norbo »

I bet if you find the 'center' of your model you'll see the other 11 meshes stuck in one spot. This is a little something I seem to have forgotten to address- the fix isn't too hard, but I am a bit low on time now. I'll repost later with details.

The DynamicCharacterController has a move and a moveTo method in it which can be used to reposition it, if that's what you're needing.

I'll be back later with a slightly more thorough post.
User avatar
cosmixy
Posts: 225
Joined: Fri Jul 07, 2006 6:51 am

Re: Model

Post by cosmixy »

Currently the pivot of every mesh must be at World 0,0,0 for them to be oriented correctly. It makes bones quite useless =O
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Model

Post by Norbo »

cosmixy wrote:Currently the pivot of every mesh must be at World 0,0,0 for them to be oriented correctly. It makes bones quite useless =O
Yes indeed!

Here's the updated code for the DisplayModel draw method, the only changed line is the effect.World within the inner foreach:

Code: Select all

        public void draw(Matrix viewMatrix, Matrix projectionMatrix)
        {
            if (entity != null)//Update the world matrix if the model is following an entity.
                worldMatrix = entity.rotationMatrix * Matrix.CreateTranslation(entity.centerPosition);
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = mesh.ParentBone.Transform * worldMatrix;
                    effect.View = viewMatrix;
                    effect.Projection = projectionMatrix;
                }
                mesh.Draw();
            }
        }
I should also mention that the StaticTriangleGroup method that takes in a ModelMesh doesn't automatically set its worldMatrix to match the ModelMesh's. After building it, you'll just have to set the worldMatrix of the StaticTriangleGroup appropriately. In v0.5.1, I'll probably have a method that takes in a Model as well, not just a single ModelMesh.

As for the character movement, if you just want to scoot him around like he's walking, then you can just use the applyMovementImpulse method. You can see it being used in the Character's update method. I would like to mention that the character in the demos isn't quite perfect; its not as solid as I'd like. v0.5.1 might include some improvements, but I might need to wait on those- at some point I will be adding in an example for a purely kinematic character, closer to what you might find in most games in terms of functionality.

EDIT: The above code does not take into account all possible transforms and won't work in some cases. Using the absolute transforms will work.
marceloguto
Posts: 7
Joined: Wed Apr 23, 2008 4:23 pm

Re: Model

Post by marceloguto »

Thanks for help, I´ll keep on your suggestion, if I´ve new questions, I´ll be back ehehehe !!!

Thanks again.
Marcelo Lopes
marceloguto
Posts: 7
Joined: Wed Apr 23, 2008 4:23 pm

Re: Model

Post by marceloguto »

Folks,

I tried to do that you told me, but I dont know if I understood or not.

My code:

DisplayModel myModelDisplayModel = new DisplayModel(myModelTest);
entityRenderer.displayModels.Add(myModelDisplayModel);

I put this after:

foreach (ModelMesh mesh in myModelTest.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = mesh.ParentBone.Transform * Matrix.CreateScale(0.03f);
effect.View = viewMatrix;
effect.Projection = projectionMatrix;
}
mesh.Draw();
}

Unfortunatelly didnt work.

Norbo, it´s possible I get the source code and update the draw method ofDisplayModel ? Or do you have another idea?

Thanks guys,
Marcelo
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Model

Post by Norbo »

I'm not sure I understand; the source I gave you was the fixed draw method in DisplayModel. You can take the method I posted and totally overwrite the current draw method to incorporate the bone transformations, or you can just rewrite the

effect.World = worldMatrix;
as
effect.World = mesh.ParentBone.Transform * worldMatrix;

If you want to adjust the world matrix of the DisplayModel itself (such as scaling it) you just have to modify the DisplayModel.worldMatrix.


EDIT: The above code does not take into account all possible transforms and won't work in some cases. Using the absolute transforms will work.
marceloguto
Posts: 7
Joined: Wed Apr 23, 2008 4:23 pm

Re: Model

Post by marceloguto »

Hi Norbo,

I found and fix the problem. It was missing multiply the mesh boneTransforms.

Code: Select all

public void draw(Matrix viewMatrix, Matrix projectionMatrix)
        {
            //Update the world matrix if the model is following an entity.
            if (entity != null) 
                worldMatrix = entity.rotationMatrix * Matrix.CreateTranslation(entity.centerPosition);

            Matrix[] boneTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(boneTransforms);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = boneTransforms[mesh.ParentBone.Index] * this.worldMatrix;
                    effect.View = viewMatrix;
                    effect.Projection = projectionMatrix;
                }
                mesh.Draw();
            }
        }
Post Reply