Copies of meshes
Copies of meshes
okay, i have been able to load .obj files! Now, in trying to wrap my head around how IRR does things i have a basic question (that doesnt seem to be answered in the tutorials or doc) - say i have a cube.obj mesh - now i want to make a hundred of them - so i call getMesh each time? does this load a brand new mesh or is it keeping one copy of my cube mesh and giving me a new node each time?
-
Robomaniac
- Posts: 602
- Joined: Sat Aug 23, 2003 2:03 am
- Location: Pottstown, PA
- Contact:
ug. but is that really keeping 100 extraneous copies of the vertex data? i hope not!
if so, im going to have some major beef with Niko
as this is something the engine's resource management should take care of-- the difference between sharable and not shareable data. EG: a texture is shareable (multiple models can use the same texture) but a "sprite" (something that keeps track of animation and the current position/frame of a series of textures) is not. similarly, vertex data and animation matrices are shareable, but the current position/animationframe of an individual model is not.
I really hope the engine keeps this in mind, and does not waste memory using multiple copies of shareable data.
if so, im going to have some major beef with Niko
I really hope the engine keeps this in mind, and does not waste memory using multiple copies of shareable data.
a screen cap is worth 0x100000 DWORDS
keless - exactly! - i am going to have tons of copies of objects - many will have different textures but the core mesh will be the same - i imagine this is how irrlicht has to work since making copies of meshes is not workable - ogre has mesh->entity->node - IRR just has mesh->node which i think is better - raises a couple questions though
- can i make a node and not attach is to the scene? (until later? - so then i can set the position and textures but not pop it into the scene yet to be rendered)
- and on managing textures as well as meshes - what is the preferred way to decide that a texture is no longer needed - same with a mesh?
- can i make a node and not attach is to the scene? (until later? - so then i can set the position and textures but not pop it into the scene yet to be rendered)
- and on managing textures as well as meshes - what is the preferred way to decide that a texture is no longer needed - same with a mesh?
I'm quite sure the 'get' methods (getMesh, getTexture, etc) do impliment resource management. ie they keep track of paths and do not reload previously loaded files.
However, powerpop are you looking to load 100 copies of the mesh, or load 100 scene nodes using that mesh? If the latter, you'll want something closer to
However, powerpop are you looking to load 100 copies of the mesh, or load 100 scene nodes using that mesh? If the latter, you'll want something closer to
Code: Select all
IAnimatedMesh *mesh = smgr->getMesh("cube.obj");
for(int i=0;i<100;i++)
{
node[i] = smgr->addMeshSceneNode(mesh->getMesh(0),...);
}and how does it tell when you are not using that mesh anymore? or is that up to us?
same with textures?
and there is my original question - when i load a static mesh (a .3ds for instance) niko told me to use getMesh(0) to get the first frame and made my SceneNode out of that - but then there is the awkward thing that there was an animated mesh created somewhere - who handles getting rid of that at the end?
same with textures?
and there is my original question - when i load a static mesh (a .3ds for instance) niko told me to use getMesh(0) to get the first frame and made my SceneNode out of that - but then there is the awkward thing that there was an animated mesh created somewhere - who handles getting rid of that at the end?
-
knightoflight
- Posts: 199
- Joined: Sun Aug 24, 2003 5:47 pm
- Location: Germany
it seems we do need some way to drop a mesh (or better said to drop a reference to the shared copy of the mesh) when we get rid of a node that references it - and then when the count reaches zero IRR can get rid of that mesh - waiting until an exit is a bad idea - especially for an app that loads many levels
i guess its okay if niko doesnt keep a reference count as long as its obvious when a mesh is being referenced - we could keep our own reference list if need be (its awkward but we could do it) - to this end it might be nice to allow a userdata pointer on a mesh object (and texture objects) - this way we could attach our reference number to it and increment/decrement it as needed - in fact, this is probably better since i can see each game needing to do different kinds of management of resources
or you could just add a short to every resource object for this purpose!
i guess its okay if niko doesnt keep a reference count as long as its obvious when a mesh is being referenced - we could keep our own reference list if need be (its awkward but we could do it) - to this end it might be nice to allow a userdata pointer on a mesh object (and texture objects) - this way we could attach our reference number to it and increment/decrement it as needed - in fact, this is probably better since i can see each game needing to do different kinds of management of resources
or you could just add a short to every resource object for this purpose!
I already have a Managed Memory Objects system, though its obviously not built into IrrLicht's scene/mesh/etc classes. basically for a resource that you want to be managed, you inherit from B_MMObject. the constructor for B_MMObj requires a B_MMO_Provider pointer-- this is a class that keeps a list of each MMO. it has functions such as 'cleanGarbage' which will remove all objects with less than one reference to them. It is required to use SmartPointers to reference MMObjs (because smart pointers will automatically increment and decrement an MMO's reference counter).
because each MMO is linked to a specific MMO_Provider, you can have multiple providers with their own group of MMOs-- for instance, I plan on giving each state its own MMO_P-- when a state is destroyed, MMO_P is also destroyed, which makes it call 'DestroyLiveObjects' to empty its MMO list. This will delete ALL MMOs no matter if you forgot to stop referencing them in your state or not. this means each state will definately keep good track of its MMOs.
Objects which should stay intact across states will use the game_Engine's MMO_P instead of just the state's.
Not sure if you want to use this code as a part of the IrrLicht engine or not, but if individual developers want it-- just post/IM/PM/email me.
because each MMO is linked to a specific MMO_Provider, you can have multiple providers with their own group of MMOs-- for instance, I plan on giving each state its own MMO_P-- when a state is destroyed, MMO_P is also destroyed, which makes it call 'DestroyLiveObjects' to empty its MMO list. This will delete ALL MMOs no matter if you forgot to stop referencing them in your state or not. this means each state will definately keep good track of its MMOs.
Objects which should stay intact across states will use the game_Engine's MMO_P instead of just the state's.
Not sure if you want to use this code as a part of the IrrLicht engine or not, but if individual developers want it-- just post/IM/PM/email me.
a screen cap is worth 0x100000 DWORDS
Cleves - do you really want 25 copies of the same mesh - or do you want 25 copies of the same 3D object - copies of the mesh means you have separate data for all the vertices and polys in the model (can be very expensive) - copies of the mesh (which means having a node for each object that points to the same mesh object) allows you to change the textures individual (or let them all have the same texture) - but you wont use the MeshCopy call at all but the following, after you load in a Mesh
node = smgr->addMeshSceneNode(mesh);
once you do this you can make calls on node to change the materials and orient the block however you wish - the node holds this data
------
in another area i ran into a mesh copy oddity - so if i want to make a copy of a mesh i have to make a meshmanipulator - kind of seems like a backwards way to get a new mesh - wouldnt it be better to have a clone method on the base Mesh type? so then each kind of mesh can duplicate itself??
node = smgr->addMeshSceneNode(mesh);
once you do this you can make calls on node to change the materials and orient the block however you wish - the node holds this data
------
in another area i ran into a mesh copy oddity - so if i want to make a copy of a mesh i have to make a meshmanipulator - kind of seems like a backwards way to get a new mesh - wouldnt it be better to have a clone method on the base Mesh type? so then each kind of mesh can duplicate itself??