BepuPhysic Draw Model Error

Discuss topics related to BEPUphysics or physics engine development.
Post Reply
-=Magic=-
Posts: 41
Joined: Thu Jun 30, 2011 11:32 am

BepuPhysic Draw Model Error

Post by -=Magic=- »

Inside the demos, the ModelDrawer has an error.

If you use the same Model, but with different textures, the drawer display the last texture that has been set.

This because the texture of the effect applied to the model is set inside the Texture properties of DisplayModel class.

This should be moved inside the Draw code.

Before:

Code: Select all

        public override void Draw(Matrix viewMatrix, Matrix projectionMatrix)
        {
            //This is not a particularly fast method of drawing.
            //It's used very rarely in the demos.
            myModel.CopyAbsoluteBoneTransformsTo(transforms);
            for (int i = 0; i < Model.Meshes.Count; i++)
            {
                for (int j = 0; j < Model.Meshes[i].Effects.Count; j++)
                {
                    var effect = Model.Meshes[i].Effects[j] as BasicEffect;
                    if (effect != null)
                    {
                        effect.World = transforms[Model.Meshes[i].ParentBone.Index] * WorldTransform;
                        effect.View = viewMatrix;
                        effect.Projection = projectionMatrix;
                    }
                }
                Model.Meshes[i].Draw();
            }
        }
After:

Code: Select all

        public override void Draw(Matrix viewMatrix, Matrix projectionMatrix)
        {
            //This is not a particularly fast method of drawing.
            //It's used very rarely in the demos.
            myModel.CopyAbsoluteBoneTransformsTo(transforms);
            for (int i = 0; i < Model.Meshes.Count; i++)
            {
                for (int j = 0; j < Model.Meshes[i].Effects.Count; j++)
                {
                    var effect = Model.Meshes[i].Effects[j] as BasicEffect;
                    if (effect != null)
                    {
                        effect.World = transforms[Model.Meshes[i].ParentBone.Index] * WorldTransform;
                        effect.View = viewMatrix;
                        effect.Projection = projectionMatrix;

                        if (myTexture != null)
                        {
                            effect.TextureEnabled = true;
                            effect.Texture = myTexture;
                        }
                        else
                            effect.TextureEnabled = false;
                    }
                }
                Model.Meshes[i].Draw();
            }
        }

BTW, great physic engine :)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: BepuPhysic Draw Model Error

Post by Norbo »

Thanks; it's been fixed for the next version.

By the way, you may already be aware, but I usually warn people to avoid the BEPUphysicsDrawer for anything but debug drawing/testing purposes. It's not suitable for a game's actual renderer.
Post Reply