【问题标题】:Create hollow cylinder with LibGDX使用 LibGDX 创建空心圆柱体
【发布时间】:2014-03-24 04:59:27
【问题描述】:

我正在尝试使用 LibGDX 在 android 应用程序上创建一个空心圆柱体。看起来没有任何方法可以创建它。我很难画出两个圆柱体。一个更大一个更小的一个,我可以用它“移除”较大的内部,从而创建一个空心圆柱体。现在我要问的是,有没有更好的方法来做到这一点?

谢谢!

【问题讨论】:

    标签: java android 3d libgdx


    【解决方案1】:

    答案 #1

    有两种方法可以做到这一点。第一种是使用createCylinder() convenience method of ModelBuilder 创建一个模型,其中包含一个圆柱体网格。

    答案 #2

    使用 MeshBuilder 类的 createCylinder() 方法创建一个 Mesh,然后将其包装在模型中。

    示例(方式 #2)

    以下示例代码改编自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();
    

    【讨论】:

      【解决方案2】:

      您可以使用搅拌机制作 obj http://www.youtube.com/watch?v=JFdVRdD9VSM

      不要忘记对其进行三角测量。

      并使用加载

      http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/assets/loaders/ModelLoader.html [仅包含在睡梦中]

      您可以在 gdx-test 存储库中找到一个非常好的示例 https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-03
        相关资源
        最近更新 更多