MeshShape scale with NxOgre0.9

daedar

11-05-2007 23:48:46

Hi again,

one more question... I'm using MeshShape to auto-detect a static shape from a mesh:

PhysicEngine::getSingleton()->getNxScene()->createBody("Bulding.mesh", new NxOgre::MeshShape("Bulding.mesh"), Vector3(0,10,0), "static: yes");

but I need scaled meshes (not only visually scaled but also physically scaled). With this line : body->getNode()->setScale(...) I can scale the visual mesh but the physic shape isn't scaled.

Any idea?

Thx

daedar

12-05-2007 09:15:43

I tried this:

NxOgre::Body *body = PhysicEngine::getSingleton()->getNxScene()->createBody("Bulding.mesh", new NxOgre::MeshShape("Bulding.mesh"), Vector3(0,10,0), "mesh-scale:"+StringConverter::toString(scaleVector->getScale())+", static: yes");

doesn't seems to work. :(

betajaen

12-05-2007 09:20:46

At the moment it doesn't seem it's possible with the current code.

I'll add it in though, because other shapes could use the parameter as well, but the code would go:

NxOgre::Body *body = PhysicEngine::getSingleton()->getNxScene()->createBody("Bulding.mesh", new NxOgre::MeshShape("Bulding.mesh","scale:" + StringConverter::toString(scaleVector->getScale() ), Vector3(0,10,0), "static: yes");

Because it's a parameter for the shape and not the body.

[Edit]

The ShapeParams class accepts mesh-scale, and the cooking function has a scale argument, but it seems I haven't tied them together. It seems half of the work was already written for me, by me ;)

daedar

12-05-2007 09:33:16

Ok thx a lot betajaen, I'll have to wait the next commit :wink:
Not a problem for the moment as I'm porting from OgreNewt so I have a lot of other work to do.

daedar

20-05-2007 11:22:52

I know this is really easy to do but here's the patch to have scaled MeshShapes:

Index: include/NxOgreCooking.h
===================================================================
--- include/NxOgreCooking.h (revision 23)
+++ include/NxOgreCooking.h (working copy)
@@ -26,7 +26,7 @@

NxConvexMesh* NxGenerateConvexMeshFromOgreMesh(const NxString& meshname, NxScene *scene, NxVec3 scale = NxVec3(1,1,1));
NxConvexMesh* NxGenerateConvexMeshFromVertices(NxVec3 *verts, unsigned int nbVerts, NxScene *scene);
- NxTriangleMesh* NxGenerateTriangleMeshFromOgreMesh(const NxString&, NxScene *scene);
+ NxTriangleMesh* NxGenerateTriangleMeshFromOgreMesh(const NxString&, NxScene *scene, NxVec3 scale = NxVec3(1,1,1));
NxHeightField* NxGenerateHeightFieldFromImage(const NxString& imageFilename, unsigned int nbRows, NxScene *scene);

};
Index: source/NxOgreCooking.cpp
===================================================================
--- source/NxOgreCooking.cpp (revision 23)
+++ source/NxOgreCooking.cpp (working copy)
@@ -175,7 +175,7 @@

////////////////////////////////////////////////////////////////////////////////////////////////////

- NxTriangleMesh* NxGenerateTriangleMeshFromOgreMesh(const NxString& meshName, NxScene *scene) {
+ NxTriangleMesh* NxGenerateTriangleMeshFromOgreMesh(const NxString& meshName, NxScene *scene, NxVec3 scale) {


unsigned int mVertexCount = 0, mIndexCount = 0;
@@ -247,7 +247,7 @@

for( size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize()) {
posElem->baseVertexPointerToElement(vertex, &pReal);
- mMeshVertices[current_offset + j] = NxVec3(pReal[0], pReal[1], pReal[2]);
+ mMeshVertices[current_offset + j] = NxVec3(pReal[0]*scale.x, pReal[1]*scale.y, pReal[2]*scale.z);
}

vbuf->unlock();
Index: source/NxOgreShapeDescriptionMesh.cpp
===================================================================
--- source/NxOgreShapeDescriptionMesh.cpp (revision 23)
+++ source/NxOgreShapeDescriptionMesh.cpp (working copy)
@@ -57,7 +57,7 @@

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

- mShapeDescription.meshData = NxGenerateTriangleMeshFromOgreMesh(meshname, actor->getNxScene());
+ mShapeDescription.meshData = NxGenerateTriangleMeshFromOgreMesh(meshname, actor->getNxScene(), mParams.mMeshScale);

#if 0
if (mParams.mMaterial != "")


Maybe you'll find it usefull...

betajaen

20-05-2007 11:53:58

I did. It's now added, and will be in the next SVN commit.