Patch to OgreShapeDescriptionMesh

Backov

02-06-2007 00:38:49

I modified this a little bit to make my life easier. It's a good change, I'm sure someone else will like it too.

Basically when you create a mesh shape, you can tell it to load from a cooked file rather than a mesh in memory.


Index: NxOgreShapeDescriptionMesh.h
===================================================================
--- NxOgreShapeDescriptionMesh.h (revision 24)
+++ NxOgreShapeDescriptionMesh.h (working copy)
@@ -30,7 +30,7 @@

public:

- MeshShape(const NxString& meshName, const ShapeParams& = "");
+ MeshShape(const NxString& meshName, const ShapeParams& = "",bool load = false);
~MeshShape();

NxTriangleMeshShapeDesc mShapeDescription;
@@ -39,6 +39,8 @@

NxString meshname;

+ bool loadFromFile;
+
virtual bool isDynamic() {return false;}
virtual bool isStaticOnly(){return true;}
virtual Shape* _bindToActorDescription(Actor*, NxArray<NxShapeDesc*>&);
@@ -48,4 +50,4 @@

};

-#endif
+#endif

Index: NxOgreShapeDescriptionMesh.cpp
===================================================================
--- NxOgreShapeDescriptionMesh.cpp (revision 24)
+++ NxOgreShapeDescriptionMesh.cpp (working copy)
@@ -23,6 +23,7 @@
#include "NxOgreShapeMesh.h" // For: Convex
#include "NxOgreHelpers.h" // For: Conversions
#include "NxOgreCooking.h" // For: Cooking the convex shapes
+#include "NxOgreUserStream.h"

namespace NxOgre {

@@ -37,8 +38,9 @@



-MeshShape::MeshShape(const NxString& meshName, const ShapeParams& p) : ShapeDescription(p) {
+MeshShape::MeshShape(const NxString& meshName, const ShapeParams& p, bool load) : ShapeDescription(p) {

+ loadFromFile = load;

mShapeDescription.setToDefault();
mShapeDescription.skinWidth = mParams.mSkinWidth;
@@ -57,8 +59,17 @@

Shape* MeshShape::_bindToActorDescription(Actor* actor, NxArray<NxShapeDesc*>& shapes) {

- mShapeDescription.meshData = NxGenerateTriangleMeshFromOgreMesh(meshname, actor->getNxScene(), mParams.mMeshScale);
+ if (loadFromFile)
+ {
+ UserStream rbuf(meshname.c_str(), true);
+
+ mShapeDescription.meshData = actor->getNxScene()->getPhysicsSDK().createTriangleMesh(rbuf);

+ fclose(rbuf.fp);
+
+ } else
+ mShapeDescription.meshData = NxGenerateTriangleMeshFromOgreMesh(meshname, actor->getNxScene());
+
#if 0
if (mParams.mMaterial != "")
mShapeDescriptionm.aterialIndex = b->owner->findMaterialIndex(mParams.mMaterial);
@@ -82,4 +93,4 @@
return 0;
}

-}; //End of NxOgre namespace.
+}; //End of NxOgre namespace.


Oh, plus the patch to the actor header.


Index: NxOgreActor.h
===================================================================
--- NxOgreActor.h (revision 24)
+++ NxOgreActor.h (working copy)
@@ -34,9 +34,9 @@
public:


- ActorParams() {}
- ActorParams(const char* p) {process(p);}
- ActorParams(NxString p) {process(p);}
+ ActorParams() { setToDefault(); }
+ ActorParams(const char* p) { setToDefault(); process(p);}
+ ActorParams(NxString p) { setToDefault(); process(p);}

void setToDefault();
void parse(Parameters);
@@ -249,8 +249,6 @@

virtual Summary getSummary();

- void* getNxUserData();
-
protected:

Scene *mOwner;

betajaen

02-06-2007 00:55:55

Thankyou. I had this idea yesterday, but I was going to expand it to all shapes. Seems you beat me to it!

Backov

02-06-2007 01:04:29

Thankyou. I had this idea yesterday, but I was going to expand it to all shapes. Seems you beat me to it!

I was thinking of that, but only my big-ass triangle mesh shapes seem to take any time at all to generate. The other stuff is nearly instant.

I had another routine I added which is just a modified version of the cooker routine that simply cooks it to a specified filename, but you seem to have chopped quite a bit out of that file, so I couldn't make a diff easily.

betajaen

03-06-2007 14:39:42

Right. I've modified the Convex and Mesh shapes to accept nxs files instead of Ogre meshes, bypassing the cooking process and just reading them in, like so:

Body* cow = mScene->createBody("cow.mesh", new MeshShape("cow.MeshShape.nxs"), Vector3(0,2.5,0),"static:yes, node-scale: 8 8 8");


Cloth is a little more tricky because there is the visual aspect to take care of; normals and texture coordinates which aren't needed with NxCloth but required with Ogre. I may be able to use the userdata in NxCloth to sneak them in but we shall see.


But for now on anything that is cooked in Debug mode, is saved in the same folder as your program as "meshName.<ShapeName>.nxs" which can be read in with code like the snippet above.