n00b
n00b

Reputation: 2768

Create hollow cylinder with LibGDX

I'm trying to create a hollow cylinder on android application with LibGDX. Looks like there isn't any method that would create it. I tought of drawing two cylinders. One bigger and a smaller one with which I could "remove" the inside of the bigger one therefor creating a hollow cylinder. Now what I'm asking, is there any better way to do this?

Thanks!

Upvotes: 3

Views: 1549

Answers (2)

Mr. Developerdude
Mr. Developerdude

Reputation: 9678

Answer #1

There are two ways to do this. The first is using createCylinder() convenience method of ModelBuilder to create a model with a single cylinder mesh in it.

Answer #2

Using the createCylinder() method of the MeshBuilder class to create a Mesh and then wrap that in a model later.

Example (way #2)

The following example code was adapted from this:

    MeshBuilder meb = new MeshBuilder();
    final long atr = Usage.Position | Usage.Color; //Add  Usage.TextureCoordinates or similar here if you need it

    //Create mesh #1
    meb.begin(atr);
    meb.cylinder(4f, 6f, 4f, 16);
    Mesh cyl1 = meb.end();

    //Create mesh #2
    meb.begin(atr);
    meb.cylinder(4f, 6f, 4f, 16);
    Mesh cyl2 = meb.end();

    //Combine the two meshes into one model using ModelBuilder
    ModelBuilder mob = new ModelBuilder();
    mob.begin();
    mob.part("cylinder1", cyl1, Usage.Position | Usage.Normal | Usage.TextureCoordinates, new Material(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(1, 1, 1, 1), FloatAttribute.createShininess(8f)));
    mob.part("cylinder2", cyl2, Usage.Position | Usage.Normal | Usage.TextureCoordinates, new Material(ColorAttribute.createDiffuse(Color.GREEN), ColorAttribute.createSpecular(1, 1, 1, 1), FloatAttribute.createShininess(8f))).mesh.transform(new Matrix4().translate(0, 0, -2f));
    Model cyl = mob.end();

Upvotes: 2

jpm
jpm

Reputation: 1083

You can make a obj using blender http://www.youtube.com/watch?v=JFdVRdD9VSM

Don't forget to triangulate it.

and load using

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/assets/loaders/ModelLoader.html [included only in nightlies]

you can find a pretty good example in gdx-test repository https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests

Upvotes: 2

Related Questions