0
votes

I'm trying to make the game, using LibGDX. I create a Model from *g3db file like this:

public AssetManager assets;
assets = new AssetManager();
assets.load("data/road.g3db", Model.class);
Model road = assets.get("data/road.g3db", Model.class);
ModelInstance roadInstance = new ModelInstance(road);

data/road.g3db is a а long ribbon like road. I make its in blender 3d. Somthing like this:

      ****
     *    *****         ****
    *          *       *
 ***            *******

My question is: how can i create body from this Model? I try this:

ChainShape shape = new ChainShape();
Mesh roadMesh = roadInstance.model.meshes.get(0);

float ar[] = new float[roadMesh.getVerticesBuffer().capacity()];
roadMesh.getVerticesBuffer().get(ar);

shape.createChain(ar);

But there are error:

 AL lib: (EE) alc_cleanup: 1 device not closed
 Assertion failed!

 Program: C:\Program Files (x86)\Java\jre7\bin\javaw.exe
 File: /var/lib/jenkins/workspace/libgdx/gdx/jni/Box2D/Collision/Shapes/b2ChainShape.cpp,
 Line 63

Expression: b2DistanceSquared(v1, v2) > 0.005f * 0.005f

Is there another way to create body for long road ?

1
Do you mean a box2d body? That won't be a good idea, as Box2D is a 2D physics engine. If you need your physics only in 2d then you have to create a body somehow but not with the Model, cause Model is 3D. - Robert P
Maybe you're right, but this guy use libgdx and box2d body for ship. And this is 3d game. github.com/bompo/BackyardPirates - andr
I think that then the physics are in 2D only... But i am not sure. I only know, that for 3D physics there is "PhysicsBullet" - Robert P
Yes! Yes! PhysicsBullet is just what I need. Thanks, Springrbua. - andr

1 Answers

0
votes

Box2D is, as the name says, for 2D physics. If you have a 3D game, with 2D physics only, you can easily use it under the hood and change the view to 3D. But if you need 3D physics i would suggest to use PhysicsBullet. It is a 3D Collision Detection and Rigid Body Dynamics Library. To give you something to read: Bullet physics on GitHub