Bug when Overriding the Render function of a brumeObject

Think you found a bug ? This is where to go...

Moderator: Brume Dev Team

Bug when Overriding the Render function of a brumeObject

Postby MoDDiB on Fri Jun 08, 2007 5:06 pm

If I override the Render function of a brumeObject
to draw a lot of object(like for a particles emitter), I can't use a different texture or color for each object drawn : the first texture and color set will be used.

Is it a feature ? :)
MoDDiB
Brume user
 
Posts: 83
Joined: Mon Nov 20, 2006 5:05 pm

Postby MoDDiB on Sat Jun 09, 2007 11:17 am

Other problem : I can't draw the same BrumeXMesh a lot of times :/
MoDDiB
Brume user
 
Posts: 83
Joined: Mon Nov 20, 2006 5:05 pm

Postby Silmaryls on Sat Jun 09, 2007 7:34 pm

Well,

For the first problem : how are you rendering ?
In fact if you want to render with different textures/properties, you should use different BrumeObject instances. But in certain cases it may be too heavy as this class is really big.

In such situations you can still access the API wrapper in the Render method in order to influence the drawing.
Here is a sample from the snow particle system :

Code: Select all

public override void Render()
{
    BrumeMatrix world = this.WorldTransformation;

    ...
    ...
    ...


    for (int i = 0; i < this.Particles.Length; i++)
    {
        local.M41 = this.Particles[i].Position.X;
        local.M42 = this.Particles[i].Position.Y;
        local.M43 = this.Particles[i].Position.Z;

        brume.GraphicApi.SetWorld(local * newWorld);
        this.Mesh.Render();
    }
   
}



Here I used only brume.GraphicApi.SetWorld but you can also change textures or materials or whatever you want.


I think it also solves your second problem.
But to be certain, here is the (simplified) code I use for the physic stack : the sphere mesh is shared between all objects. In this case you have N BrumeObject instances.

Code: Select all

private void TestPhysicsStack()
{
    // reuse sphere meshes
    BrumeMesh reuseMesh = null;
    BrumeBoundingSphere reuseBounding = null;
    float stackX = -15.0f;
    float stackY = 5.5f;
    float stackZ = 10.0f;

    // cubes & spheres
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 25; j++)
        {
            if (reuseMesh == null)
            {
                // first sphere is generated as always
                BrumeSphereTextured sph = new BrumeSphereTextured(this, "sphere");
                sph.RenderStates.Texture[0] = this.GetTexture("multitex1.tga");
                sph.Pos = new BrumeVector(stackX + i, stackY + j, stackZ);

                sph.HasPhysicsAndCollisions = true;

                // we save the mesh and bounding info
                reuseMesh = sph.Mesh;
                reuseBounding = sph.BoundingSphere;

            }
            else
            {
                // optimisation : reuse of mesh and bounding info
                BrumeLightedObject sph = new BrumeLightedObject(this, "sphere");
                sph.Mesh = reuseMesh;
                sph.RenderStates.Texture[0] = this.GetTexture("multitex1.tga");
                sph.Pos = new BrumeVector(stackX + i, stackY + j, stackZ);
                sph.AddBoundingSphere(new BrumeBoundingSphere(reuseBounding.Center, reuseBounding.Radius));

                sph.HasPhysicsAndCollisions = true;

            }

        }
    }
}




This gives you another method...but if you still have the problem with BrumeXMesh, please post me a simple test case and I will look at it.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby MoDDiB on Sat Jun 09, 2007 7:53 pm

I did like for the snowparticle system : Try to use different texture or color it won't work.
For the mesh to reuse I did the same too but with a complex mesh : I will try with a sphere.
MoDDiB
Brume user
 
Posts: 83
Joined: Mon Nov 20, 2006 5:05 pm

Postby Silmaryls on Sat Jun 09, 2007 8:14 pm

Whooops....you're right !
That won't work with complex meshes as they are....complex :lol:

Can you try to access the GetGeometries() property on your mesh (You will have to cast to BrumeComplexMesh) : it' a list of BrumeMeshGeometry objects.

Each of them has two arrays : meshMaterials and meshTextures which are used during rendering (the array index is the mesh subset).
Try to alter them with your own material and texture.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby MoDDiB on Sat Jun 09, 2007 8:17 pm

Ok I will try it.
Do you tried with color and textures ?
MoDDiB
Brume user
 
Posts: 83
Joined: Mon Nov 20, 2006 5:05 pm

Postby Silmaryls on Sat Jun 09, 2007 10:27 pm

No but I am sure it won't work : complex mesh are setting Material and Textures inside the Render call.

So I trust you :wink:
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby MoDDiB on Sun Jun 10, 2007 7:37 am

In fact my problem with color and texture is not with a complex mesh but with a quad like for the snow particle :/
MoDDiB
Brume user
 
Posts: 83
Joined: Mon Nov 20, 2006 5:05 pm

Postby Silmaryls on Mon Jun 11, 2007 12:35 am

Ok !

I tried to change the texture in the snow system and it worked. Just added this line :

Code: Select all
brume.GraphicApi.SetTexture(0,brume.GetTexture("multitex2.tga"));


For color it doesn't work but the material is set (I checked with pix) so I think that it is just a render states problem. Tell me if you cannot find the correct states for color.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby MoDDiB on Mon Jun 11, 2007 9:24 pm

Thanks it was a renderstate problem : when I use you function I don't have any problem.

For the color it works too using brume.GraphicApi.SetAmbientLight.

:)
MoDDiB
Brume user
 
Posts: 83
Joined: Mon Nov 20, 2006 5:05 pm

Postby Silmaryls on Tue Jun 12, 2007 8:07 am

Nice to hear that !

We are waiting for new samples :wink:
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby MoDDiB on Wed Jun 13, 2007 8:19 am

Don't worry I'll post soon new videos but for the moment the game need a lot of optimizations ( 30 fps sometimes in the game isn't good at all :p )

I succeed to draw the mesh like it :
Code: Select all
for (int i = 0; i < ((BrumeComplexMesh)mesh).GetGeometries()[0].meshTextures.Length; i++)
                    {
                        RTSEngineForm.Engine.GraphicApi.SetTexture(0, ((BrumeComplexMesh)mesh).GetGeometries()[0].meshTextures[i]);

                        foreach (BrumeMeshGeometry geometry in ((BrumeComplexMesh)mesh).GetGeometries())
                        {
                            geometry.DrawSubSet(i);

                        }

                    }




I've created a method DrawSubSet in the brume engine to avoid a reference to DirectX :)

But When I override the render method the original object is still drawn and if I set the visibility to false nothing is drawn : what should I do ?

EDIT : I write :
brume.GraphicApi.SetAmbientLight( Color.LightSteelBlue);
to set the light but it doesn't work :/
MoDDiB
Brume user
 
Posts: 83
Joined: Mon Nov 20, 2006 5:05 pm

Postby Silmaryls on Thu Jun 14, 2007 12:55 pm

Can you PM me the class ? I don't exactly understand what you are trying to do.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby MoDDiB on Thu Jun 14, 2007 6:40 pm

For optimizations reasons I need to draw my trees in the same function to avoid changing textures , and other renderstate options toO often.
I'll pack you a version to show you why I really need to optimize and how I optimize because I think I will need your help for that

EDIT : PM SENT
MoDDiB
Brume user
 
Posts: 83
Joined: Mon Nov 20, 2006 5:05 pm


Return to Bugs In English

Who is online

Users browsing this forum: No registered users and 0 guests

cron