Memory Archives

Thrakbad

27-03-2010 21:42:10

Can someone please give me a short snippet on how to use memory archives? All the tutorials I found regarding the archive system were about file archives and something doesn't seem to work right with them. Basically I have a MeshData and want to create a Mesh from it. I'm using Detrius fresh from the Git today.

betajaen

27-03-2010 22:44:15

It's just "memory://", you don't have to create an archive (it doesn't use them) or resource names (again doesn't use them). You can literally throw anything at it, and it will cope (resize when necessary), it will clean up once the resource is destroyed - but unless your me, you'll never need to use the memory resource system.

Basically have a look at NxOgre::ManualMesh for creating Meshes; it's very like the Ogre::ManualMesh.

Thrakbad

27-03-2010 23:33:21

Thanks, I'm currently trying that. But on my call to ManualMesh::end I get this exception:
Resource 'memory:// is not a PhysX NXS mesh file.
That is the same exception I got, when I tried to cook the MeshData to a memory archive and then load it from there. This is the way I set up the ManualMesh:
NxOgre::ManualMesh manMesh = NxOgre::ManualMesh();
manMesh.begin(type, vertex_count, index_count);
// add vertices
for(unsigned int i = 0; i < vertex_count; i++)
{
manMesh.vertex(vertices[i].x, vertices[i].y, vertices[i].z);
}

// add indices
for(unsigned int i = 0; i < index_count; i++)
{
manMesh.index(indices[i]);
}
delete[] vertices;
delete[] indices;
return manMesh.end();

Do I have to set the normals and texture coordinates also?

betajaen

27-03-2010 23:56:09

Not usually for TriangleMeshes or Convexes, they are automatically calculated by PhysX.

What type of mesh are you trying to cook?

Thrakbad

28-03-2010 08:41:32

I'm testing with a convex mesh, but later it should also work for triangle meshes

EDIT: I think itt has to do with my index buffer. Maybe it is in a different format than the one, you use. In which way do I have to specify the indices? As a Trianglestrip or something else?

EDIT2: If I leave out the passing of the index data it seems to work, but sometimes I also get the above error. I'm investigating further to find out what exactly is causing this

XpLoDWilD

07-04-2010 15:00:13

Did you manage to solve this problem ? I can't use ManualMeshes, it gives me this error on man_mesh->end(); . Btw I'm using the same code as Flour 3.2 to create the manual mesh from OGRE mesh, and using git master branch.

Thrakbad

07-04-2010 15:25:33

No. Strangely sometimes I get an error, but most of the time with the same mesh it works

XpLoDWilD

07-04-2010 15:39:52

Could you please share your code ? Mine always fail. Thanks

Thrakbad

07-04-2010 15:54:54

The code is still the same as above, except the indices are commented out. The buffers and counts are set by the optimized version of this function (simple copy and paste). You can ignore the parts of the position, scale and orientation data for purposes of building the PhysX Mesh.

XpLoDWilD

07-04-2010 18:39:06

Okay, I tried it, and got the same result : "Resource 'memory:' is not a PhysX NXS mesh file.". Did you have to do something else special ? Declaring memory: archive or so? (What version of PhysX SDK are you using ? I'm using 2.8.1)

betajaen

07-04-2010 19:45:50

It's referring to the mesh that was cooked, wasn't actually cooked. There is an error in your vertices or indices.

Thrakbad

07-04-2010 20:20:15

Yep, I'm using the same version 2.8.1

XpLoDWilD

07-04-2010 21:01:03

I tried with other meshes, all give the same result.

Here's the code I'm using :

Ogre::MeshPtr mesh = sm->createEntity(meshName)->getMesh();

if (mesh.isNull()) {
printf("Mesh could not be loaded.\n");
return 0;
}

size_t vertex_count,index_count;
Ogre::Vector3* vertices;
unsigned long* indices;
getMeshInformation(mesh.getPointer(), vertex_count, vertices, index_count, indices, Ogre::Vector3::ZERO, Ogre::Quaternion::IDENTITY, Ogre::Vector3::UNIT_SCALE);

NxOgre::ManualMesh manMesh = NxOgre::ManualMesh();
manMesh.begin(NxOgre::Enums::MeshType_Convex, vertex_count, index_count);

// add vertices
for(unsigned int i = 0; i < vertex_count; i++)
{
manMesh.vertex(vertices[i].x, vertices[i].y, vertices[i].z);
}

// add indices
for(unsigned int i = 0; i < index_count; i++)
{
manMesh.index(indices[i]);
}



delete[] vertices;
delete[] indices;
return manMesh.end();


I tried with both indices and not; Convex and Triangle type, different meshes (exported by blender exporter or meshes provided with ogre samples), it complains everytime about the same error. It's really driving me nuts and I don't know where to start to try to debug it. Any ideas?

betajaen

07-04-2010 21:19:17

Even something simple?

NxOgre::ManualMesh mm = NxOgre::ManualMesh();
mm.begin(NxOgre::Enums::MeshType_Convex);
mm.vertex(-1,0,-1)
mm.vertex(1,0,-1)
mm.vertex(1,0,1)
mm.vertex(-1,0,1)
mm.vertex(0,1,0)
mm.end();

XpLoDWilD

07-04-2010 21:23:18

Yes, even something simple. Same error happening on mm.end(); .

betajaen

07-04-2010 21:58:32

Hmm, I'll put it on my todo list then.

XpLoDWilD

09-04-2010 13:52:02

No need to hurry, but it would be nice if you could fix it before April 16th, as my game's deadline is April 18th. Feel free to ask me if you need something.

betajaen

09-04-2010 14:20:41

I don't know what to say. This works:

int main(int argc, char **argv)
{

NxOgre::World* world = NxOgre::World::createWorld();
NxOgre::ManualMesh mm = NxOgre::ManualMesh();

mm.begin(NxOgre::Enums::MeshType_Convex);
mm.vertex(-1,0,-1);
mm.vertex(1,0,-1);
mm.vertex(1,0,1);
mm.vertex(-1,0,1);
mm.vertex(0,1,0);
Mesh* mesh = mm.end();

std::cout << mesh << std::endl;
std::cout << (mesh->getType() == Enums::MeshType_Convex) << std::endl;

NxOgre::World::destroyWorld();

}


N:\projects\nxogre.org\Flour\application>FlourDebug.exe
[+] Opening Memory Archive
[+] Opening Memory resource
[-] Closing Memory resource. -> End Size is 1087 bytes
00C2E8F0
1
[-] Closing Memory Archive


And I know Convex shapes works because I was playing with them yesterday. I'm going to be doing some heavy commits this weekend, you can try to see if that makes a difference for you.

Thrakbad

09-04-2010 15:20:44

The error occured for me only when I was trying to add indices, too. Simple vertex-only polyhedra also worked

betajaen

09-04-2010 17:03:55

I'm working on Flour right now (adding the flower load/save code into detritus), if I'm bound to find any bugs with Mesh cooking it'll be that.

XpLoDWilD

10-04-2010 09:59:51

I put the same code as you, in the beginning of my main(), and I got the same error. "'memory:' is not a NXS ....". I'm really lost, I checked all my DLLs and everything, I can't see what's going wrong...

betajaen

10-04-2010 10:10:02

Do you mean a completely fresh application with just that code?

XpLoDWilD

10-04-2010 10:20:37

I put the code before the initialisation of my game, I'm going to try with a fresh app

EDIT : Same goes with fresh app
EDIT2 : Same code but with detritus works... I'll try to convert my game's physics code (not very complex) to Detritus
EDIT3 : Everything's okay with detritus :)