class MeshObject {
LPD3DXMESH mesh;
}
MeshObject meshes[10];
void loadMesh() {
LPD3DXMESH mesh;
LoadMeshFromFile(&mesh, "test.x");
for(int i=0; i<10; i++)
meshes->mesh = mesh;
}
class MeshObject {
LPD3DXMESH mesh;
}
MeshObject meshes[10];
void loadMesh() {
LPD3DXMESH mesh;
LoadMeshFromFile(&mesh, "test.x");
for(int i=0; i<10; i++)
meshes->mesh = mesh;
}
std::map<std::string, boost::shared_ptr<Mesh> > meshes;std::vector<boost::shared_ptr<Mesh> > meshInstances;boost::shared_ptr<Mesh> LoadMesh(const std::string &path){ std::map<std::string, boost::shared_ptr<Mesh> >::iterator it; it = meshes.find(path); if (it == meshes.end() { //mesh not loaded yet it = meshes.insert(std::pair<std::string, boost::shared_ptr<Mesh> >(path, boost::shared_ptr<Mesh>(new Mesh()))); D3dXLoadMesh(it->second.get()); } return it->second;}void PopualteMeshInstances(){ for (int i = 0; i < 10; ++i) { meshInstances.push_back(LoadMesh("yo.mesh")); }}
struct MeshInstance{ Matrix ModelTransform; boost::shared_ptr<MeshObject> Mesh;};std::vector<MeshInstance> meshInstances;
Quote:Original post by bzroom
LPD3DXMESH is already a pointer LP is the give away. So you're already store it as a pointer. So assinging it to each mesh object as you did is only making a reference to the mesh. It is only loaded and stored 1 time. Since you called Load 1 time, and are only copying references, not the mesh data.
This means though, that if you call meshes[0]->mesh->doSomething(), that it will effect all the other meshes, since they are the same mesh.
int i=0;for(i=0; i<10; i++) loadMesh("test.x");i=0;void loadMesh(char* filename) { LPD3DXMESH mesh; LoadMeshFromFile(&mesh, filename); meshes[i++]->mesh = mesh;}
LPD3DXMESH* mesh;void ObjectManager::addObject(char *file, MeshObject* object) std::map<std::string, LPD3DXMESH>::iterator it; it = MeshList.find(file); if (it == MeshList.end()) { mesh = new LPD3DXMESH; LoadMeshFromFile(mesh, file); MeshList.insert(std::pair<std::string, LPD3DXMESH>(file, (*mesh))); object->mesh = treemesh; } else { object->mesh = &(it->second); } scene->AttachChild(object);}