具有可见背面的libgdx半透明3D对象

时间:2018-03-28 21:36:18

标签: opengl libgdx

我尝试在libgdx中渲染带孔的半透明3D立方体?对于渲染背面,我将剔除面设置为无,深度测试设置为假。

public void init() {
    batch = new ModelBatch();

    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.2f, -0.8f, -1f));

    modelInstance = new ModelInstance(assets.get("cube.g3dj", Model.class));

    Material material = modelInstance.getMaterial("Main");
    material.clear();
    material.set(ColorAttribute.createDiffuse(new Color(0x0075f4ff)));
    material.set(new BlendingAttribute(0.6f));
    material.set(IntAttribute.createCullFace(GL20.GL_NONE));
    material.set(new DepthTestAttribute(false));
}

public void render(float delta) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    batch.begin(camera);
    batch.render(modelInstance, environment);
    batch.end();
}

cube.g3dj:

{
    "version": [  0,   1], 
    "id": "", 
    "meshes": [
        {
            "attributes": ["POSITION", "NORMAL"], 
            "vertices": [
                -1.000000, -1.000000,  1.000000, -1.000000,  0.000000,  0.000000, 
                -1.000000,  1.000000,  1.000000, -1.000000,  0.000000,  0.000000, 
                -1.000000,  1.000000, -1.000000, -1.000000,  0.000000,  0.000000, 
                -1.000000, -1.000000, -1.000000, -1.000000,  0.000000,  0.000000, 
                 1.000000,  1.000000,  1.000000,  0.000000, -0.000000,  1.000000, 
                -1.000000,  1.000000,  1.000000,  0.000000, -0.000000,  1.000000, 
                 1.000000, -1.000000,  1.000000,  0.000000, -0.000000,  1.000000, 
                -1.000000, -1.000000,  1.000000,  0.000000, -0.000000,  1.000000, 
                 1.000000, -1.000000, -1.000000,  1.000000, -0.000000,  0.000000, 
                 1.000000,  1.000000,  1.000000,  1.000000, -0.000000,  0.000000, 
                 1.000000, -1.000000,  1.000000,  1.000000, -0.000000,  0.000000, 
                 1.000000,  1.000000, -1.000000,  1.000000, -0.000000,  0.000000, 
                -1.000000, -1.000000, -1.000000,  0.000000,  0.000000, -1.000000, 
                 1.000000,  1.000000, -1.000000,  0.000000,  0.000000, -1.000000, 
                 1.000000, -1.000000, -1.000000,  0.000000,  0.000000, -1.000000, 
                -1.000000,  1.000000, -1.000000,  0.000000,  0.000000, -1.000000, 
                 1.000000, -1.000000, -1.000000,  0.000000, -1.000000, -0.000000, 
                -0.500000, -1.000000, -0.500000,  0.000000, -1.000000, -0.000000, 
                -1.000000, -1.000000, -1.000000,  0.000000, -1.000000, -0.000000, 
                 0.500000, -1.000000, -0.500000,  0.000000, -1.000000, -0.000000, 
                -1.000000,  1.000000, -1.000000, -0.000000,  1.000000,  0.000000, 
                -0.500000,  1.000000,  0.500000, -0.000000,  1.000000,  0.000000, 
                -0.500000,  1.000000, -0.500000, -0.000000,  1.000000,  0.000000, 
                -1.000000,  1.000000,  1.000000, -0.000000,  1.000000,  0.000000, 
                -1.000000,  1.000000,  1.000000,  0.000000,  1.000000,  0.000000, 
                 1.000000,  1.000000,  1.000000,  0.000000,  1.000000,  0.000000, 
                -0.500000,  1.000000,  0.500000,  0.000000,  1.000000,  0.000000, 
                 0.500000,  1.000000,  0.500000,  0.000000,  1.000000,  0.000000, 
                 1.000000,  1.000000,  1.000000,  0.000000,  1.000000,  0.000000, 
                 1.000000,  1.000000, -1.000000,  0.000000,  1.000000,  0.000000, 
                 0.500000,  1.000000,  0.500000,  0.000000,  1.000000,  0.000000, 
                 0.500000,  1.000000, -0.500000,  0.000000,  1.000000,  0.000000, 
                -1.000000,  1.000000, -1.000000,  0.000000,  1.000000, -0.000000, 
                 0.500000,  1.000000, -0.500000,  0.000000,  1.000000, -0.000000, 
                 1.000000,  1.000000, -1.000000,  0.000000,  1.000000, -0.000000, 
                -0.500000,  1.000000, -0.500000,  0.000000,  1.000000, -0.000000, 
                -1.000000, -1.000000,  1.000000, -0.000000, -1.000000,  0.000000, 
                -0.500000, -1.000000, -0.500000, -0.000000, -1.000000,  0.000000, 
                -0.500000, -1.000000,  0.500000, -0.000000, -1.000000,  0.000000, 
                -1.000000, -1.000000, -1.000000, -0.000000, -1.000000,  0.000000, 
                 1.000000, -1.000000,  1.000000,  0.000000, -1.000000, -0.000000, 
                -1.000000, -1.000000,  1.000000,  0.000000, -1.000000, -0.000000, 
                 0.500000, -1.000000,  0.500000,  0.000000, -1.000000, -0.000000, 
                -0.500000, -1.000000,  0.500000,  0.000000, -1.000000, -0.000000, 
                 1.000000, -1.000000,  1.000000,  0.000000, -1.000000,  0.000000, 
                 0.500000, -1.000000, -0.500000,  0.000000, -1.000000,  0.000000, 
                 1.000000, -1.000000, -1.000000,  0.000000, -1.000000,  0.000000, 
                 0.500000, -1.000000,  0.500000,  0.000000, -1.000000,  0.000000, 
                -0.500000, -1.000000,  0.500000,  1.000000,  0.000000,  0.000000, 
                -0.500000,  1.000000, -0.500000,  1.000000,  0.000000,  0.000000, 
                -0.500000,  1.000000,  0.500000,  1.000000,  0.000000,  0.000000, 
                -0.500000, -1.000000, -0.500000,  1.000000,  0.000000,  0.000000, 
                 0.500000, -1.000000,  0.500000, -1.000000,  0.000000,  0.000000, 
                 0.500000,  1.000000,  0.500000, -1.000000,  0.000000,  0.000000, 
                 0.500000,  1.000000, -0.500000, -1.000000,  0.000000,  0.000000, 
                 0.500000, -1.000000, -0.500000, -1.000000,  0.000000,  0.000000, 
                -0.500000, -1.000000,  0.500000,  0.000000,  0.000000, -1.000000, 
                 0.500000,  1.000000,  0.500000,  0.000000,  0.000000, -1.000000, 
                 0.500000, -1.000000,  0.500000,  0.000000,  0.000000, -1.000000, 
                -0.500000,  1.000000,  0.500000,  0.000000,  0.000000, -1.000000, 
                -0.500000,  1.000000, -0.500000,  0.000000,  0.000000,  1.000000, 
                -0.500000, -1.000000, -0.500000,  0.000000,  0.000000,  1.000000, 
                 0.500000,  1.000000, -0.500000,  0.000000,  0.000000,  1.000000, 
                 0.500000, -1.000000, -0.500000,  0.000000,  0.000000,  1.000000
            ], 
            "parts": [
                {
                    "id": "Cube_part1", 
                    "type": "TRIANGLES", 
                    "indices": [
                          0,   1,   2,   0,   2,   3,   4,   5,   6,   5,   7,   6, 
                          8,   9,  10,   9,   8,  11,  12,  13,  14,  13,  12,  15, 
                         16,  17,  18,  17,  16,  19,  20,  21,  22,  21,  20,  23, 
                         24,  25,  26,  26,  25,  27,  28,  29,  30,  30,  29,  31, 
                         32,  33,  34,  33,  32,  35,  36,  37,  38,  37,  36,  39, 
                         40,  41,  42,  42,  41,  43,  44,  45,  46,  45,  44,  47, 
                         48,  49,  50,  49,  48,  51,  52,  53,  54,  52,  54,  55, 
                         56,  57,  58,  57,  56,  59,  60,  61,  62,  62,  61,  63
                    ]
                }
            ]
        }
    ], 
    "materials": [
        {
            "id": "Main", 
            "ambient": [ 0.000000,  0.000000,  0.000000], 
            "diffuse": [ 0.422876,  0.619359,  0.800000], 
            "emissive": [ 0.422876,  0.619359,  0.800000], 
            "opacity":  0.614078, 
            "specular": [ 1.000000,  1.000000,  1.000000], 
            "shininess":  9.607843
        }
    ], 
    "nodes": [
        {
            "id": "Cube", 
            "rotation": [-0.707107,  0.000000,  0.000000,  0.707107], 
            "scale": [ 0.500000,  0.500000,  0.500000], 
            "parts": [
                {
                    "meshpartid": "Cube_part1", 
                    "materialid": "Main"
                }
            ]
        }
    ], 
    "animations": []
}

但我有两个问题:

  1. 仅显示孔的两个面而不是四个。
  2. 旋转时不同的立方体显示。
  3. The cube image rotated by 0, 90, 180 and 270 degrees

0 个答案:

没有答案