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.
Oh, plus the patch to the actor header.
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;