Is it possible to scale a mesh?

Hi!



I am trying to scale a mesh.

Well I created it with scalarfield, but it requires big values to look good…

I put the mesh on a geometry and scaled the geometry.

But after I scale it, if I use mesh.createCollisionData() that will use the real (not scaled) mesh info and cast rays will get mad on this…



Why this? if I dont scale the terrain back, I think I will be forced to scale up everything, even forces, what will be a big trouble…



I am thinking on going on each float of Position buffer and scale it, will try tomorrow. I wonder if there is an easier/faster way?



EDIT: mmm ok, I found that change scalarfield cubesize from 1.0 to 0.5 works great! tho, I am still interested in the mesh stuff above xD

You can scale the geometry (via Geometry.setLocalScale() or scale()) and it should work fine. createCollisionData() is supposed to use the actual mesh values and not transformed ones and work with the rays.

Make sure you’re using the latest jME3 version (from SVN/nightly) as a bug related to ray picking was fixed recently.

cool, I am always updated (each 3 days ±)



haha fun!

it worked great, most usefull for cast picking ray!!

if someone wanna have fun with this:

private void scaleMesh(Geometry geom, float scale) {

Mesh mesh = geom.getMesh();

VertexBuffer vtbuf = mesh.getBuffer(Type.Position);

FloatBuffer fbuff = (FloatBuffer)vtbuf.getData();

for(int i=0; i<fbuff.limit(); i++){

fbuff.put(fbuff.get(i)*scale);

}

vtbuf.updateData(fbuff);

mesh.createCollisionData();

//((PhysicsNode)geom.getParent()).setCollisionShape(collisionShape); //TODO instanceof for each, box, sphere, mesh…

geom.updateGeometricState();

}