How to add Meshes "on the fly"?

All about the core api and animation, input, sound, effect, collision and physics engines.
You can also post here your feature requests.

Moderator: Brume Dev Team

How to add Meshes "on the fly"?

Postby Bostich on Sat Dec 08, 2007 9:25 pm

Hi Silmaryls, its me again :P.

as the topic say, how is it possible?

ATM i got one simple method in my main Brume class.

Code say more then 1000 words :D

Code: Select all
private void loadTiny(float x, float y, float z, String name)
        {
            //setup Tiny
            XMesh = new BrumeXMesh(this, "tiny_4anim.x", "tiny_4anim.x", false);
            tiny = new BrumeLightedObject(this, name);
            tiny.Mesh = XMesh;
            tiny.Size = 0.005f;
            tiny.Orient(new BrumeVector(0f, 1F, 0.0f), new BrumeVector(1f, 0F, 0f));
            tiny.Pos = new BrumeVector(x, y, z);
            tiny.UseParentRenderStates = true;
            BrumeAnimationManager.AddAnimationsFromMesh(XMesh);
            tiny.Animation = BrumeAnimationManager.GetAnimation("Jog");
            BrumeAnimationManager.AddAnimationsFromMesh(XMesh);
            tiny.Animation = BrumeAnimationManager.GetAnimation("Jog");
            tiny.HasCollisions = true;
        }


on line

Code: Select all
//setup Tiny
            XMesh = new BrumeXMesh(this, "tiny_4anim.x", "tiny_4anim.x", false);



it throws a direct3dexeption.

the same method works in "gameInit", so my simple question is, how can i load a second tiny just "one the fly". hope u understand what i mean :P

then my second question is (if this problem solved):

this method is only usefuel to create a holy new object. if i want to update just the position of this created mesh, i think it isnt good to create it everytime again. so my first idea was to create a second method, that only validates the position of this object.

to understand what i want:

in the first method i create a new object with name "name".

so my second method would look somethink like this

Code: Select all
public void validatePosition(float x, float y, float z, String name)
{
  //Here is what i need to know and i need something like this
tiny.getName(name).Pos.X = x;
...
}


ty
Bostich ;)


//Edit:

Need information :D
Bostich
Brume Rookie
 
Posts: 10
Joined: Mon Nov 26, 2007 9:31 pm

Re: How to add Meshes "on the fly"?

Postby Silmaryls on Wed Dec 12, 2007 8:37 pm

Hi Bostich,

Well the best way to do what you want to do is to load the mesh only once (you can leave it in the GameInit if you wants) and then create BrumeObjects on the fly.
Each object can point to the same mesh (you can use brume.Meshes["myMeshName"])
Each object must be initialized with brume.InitObject(myObj) and the added to the scene with brume.AddObject (or as a child of another object).

This should work.

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

Re: How to add Meshes "on the fly"?

Postby Bostich on Thu Dec 13, 2007 11:50 am

Ty for reply,

but i got another problem.

i have rewritten the method as u said.

but i got a null pointer exeption while creating the new object.

i do this as follow:

Code: Select all
BrumeLightedObject model = new BrumeLightedObject(this,"myName");
...


The NullPointer Exception hapends in BrumeRenderStates.

on line 230
Code: Select all
/// <summary>
        /// constructor from init states
        /// </summary>
        public void Init(Brume3DCardCaps caps)
        {
            this.RenderOnTexture = true;

            Texture = new BrumeTexture[caps.MaxNbrOfTextures];
            TextureStates = new BrumeTextureStates[caps.MaxNbrOfTextures];
            ClipPlanes = new BrumeClipPlane[caps.MaxUserClipPlanes];
            ...


and the exception hapends on line
Code: Select all
Texture = new BrumeTexture[caps.MaxNbrOfTextures];


because caps is null.

So what can i do to solve this?

Ty and Greetings

Bostich :)
Bostich
Brume Rookie
 
Posts: 10
Joined: Mon Nov 26, 2007 9:31 pm

Re: How to add Meshes "on the fly"?

Postby Silmaryls on Thu Dec 13, 2007 10:39 pm

Can you post a more complete source code ?

I don't understand how you arrived in BrumeRenderStates.Init with null caps.
Caps are used on brume startup to init the engine so it's really strange. Are you sure that Brume main form is in a normal state ?
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Re: How to add Meshes "on the fly"?

Postby Bostich on Fri Dec 14, 2007 11:53 am

Hi :)

this is the method to create new player on the fly:

Code: Select all
        public void loadNewPlayer(float x, float y, float z, String nick)
        {
            BrumeLightedObject player = new BrumeLightedObject(this, nick);
            this.InitObject(player);
            this.AddObject(player);
            player.Mesh = this.Meshes["Tiny.x"];
            player.Size = 0.005f;
            player.Orient(new BrumeVector(0f, 1F, 0.0f), new BrumeVector(1f, 0F, 0f));
            player.Pos = new BrumeVector(x, y, z);
            player.UseParentRenderStates = true;
            BrumeAnimationManager.AddAnimationsFromMesh(XMesh);
            player.Animation = BrumeAnimationManager.GetAnimation("Jog");
            player.HasCollisions = true;
        }


This is written from my mind, cause atm i dont sit at my computer^^

what did u mean with "Are you sure that Brume main form is in a normal state ?" ?

Ty, Bostich :)

//Edit:
Ah i think i know the problem. if this is what i think, i will post it here later^^
Bostich
Brume Rookie
 
Posts: 10
Joined: Mon Nov 26, 2007 9:31 pm

Re: How to add Meshes "on the fly"?

Postby Silmaryls on Sat Dec 15, 2007 5:29 pm

Hi Bostich,

I tested your source code and found some problems. First avoid the HasCollisions flag with tiny cause it won't work well with ODE (in fact it seems to slow down the game). It's better to use a capsule or cylinder for collision testing (search the forum there are some samples for that).

Here is a simplified version that works for me

Code: Select all

override protected void GameInit()
{
    ...
    XMesh = new BrumeXMesh(this, "Tiny.x", "Tiny.x", true);
    BrumeAnimationManager.AddAnimationsFromMesh(XMesh);
    ...
}

public void loadNewPlayer(float x, float y, float z, String nick)
{
    BrumeLightedObject player = new BrumeLightedObject(this, nick);
    player.Mesh = this.Meshes["Tiny.x"];
    player.Size = 0.005f;
    player.Orient(new BrumeVector(0f, 1F, 0.0f), new BrumeVector(1f, 0F, 0f));
    player.Pos = new BrumeVector(x, y, z);
    player.Animation = BrumeAnimationManager.GetAnimation("Jog");
    this.InitObject(player);
    //this.MoveObject(player);
}



Note : due to a bug I fixed for next release, it's possible that you see Tiny untransformed during one frame and then correctly transformed for next frames.
To fix that just try to uncomment the line I leaved in the source code.

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


Return to Technical discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron