Java 类com.badlogic.gdx.graphics.g3d.attributes.IntAttribute 实例源码

项目:GdxDemo3D    文件:ModelFactory.java   
public static void createOutlineModel(Model model, Color outlineColor, float fattenAmount) {
    fatten(model, fattenAmount);
    for (Material m : model.materials) {
        m.clear();
        m.set(new IntAttribute(IntAttribute.CullFace, Gdx.gl.GL_FRONT));
        m.set(ColorAttribute.createDiffuse(outlineColor));
    }
}
项目:libgdxcn    文件:DefaultShader.java   
protected void bindMaterial (final Renderable renderable) {
    if (currentMaterial == renderable.material) return;

    int cullFace = config.defaultCullFace == -1 ? defaultCullFace : config.defaultCullFace;
    int depthFunc = config.defaultDepthFunc == -1 ? defaultDepthFunc : config.defaultDepthFunc;
    float depthRangeNear = 0f;
    float depthRangeFar = 1f;
    boolean depthMask = true;

    currentMaterial = renderable.material;
    for (final Attribute attr : currentMaterial) {
        final long t = attr.type;
        if (BlendingAttribute.is(t)) {
            context.setBlending(true, ((BlendingAttribute)attr).sourceFunction, ((BlendingAttribute)attr).destFunction);
            set(u_opacity, ((BlendingAttribute)attr).opacity);
        } else if ((t & IntAttribute.CullFace) == IntAttribute.CullFace)
            cullFace = ((IntAttribute)attr).value;
        else if ((t & FloatAttribute.AlphaTest) == FloatAttribute.AlphaTest)
            set(u_alphaTest, ((FloatAttribute)attr).value);
        else if ((t & DepthTestAttribute.Type) == DepthTestAttribute.Type) {
            DepthTestAttribute dta = (DepthTestAttribute)attr;
            depthFunc = dta.depthFunc;
            depthRangeNear = dta.depthRangeNear;
            depthRangeFar = dta.depthRangeFar;
            depthMask = dta.depthMask;
        } else if (!config.ignoreUnimplemented) throw new GdxRuntimeException("Unknown material attribute: " + attr.toString());
    }

    context.setCullFace(cullFace);
    context.setDepthTest(depthFunc, depthRangeNear, depthRangeFar);
    context.setDepthMask(depthMask);
}
项目:gaiasky    文件:AtmosphereShader.java   
protected void bindMaterial(final Renderable renderable) {
    if (currentMaterial == renderable.material)
        return;

    int cullFace = config.defaultCullFace == -1 ? defaultCullFace : config.defaultCullFace;
    int depthFunc = config.defaultDepthFunc == -1 ? defaultDepthFunc : config.defaultDepthFunc;
    float depthRangeNear = 0f;
    float depthRangeFar = 1f;
    boolean depthMask = true;

    currentMaterial = renderable.material;
    for (final Attribute attr : currentMaterial) {
        final long t = attr.type;
        if (BlendingAttribute.is(t)) {
            context.setBlending(true, ((BlendingAttribute) attr).sourceFunction, ((BlendingAttribute) attr).destFunction);
        } else if ((t & IntAttribute.CullFace) == IntAttribute.CullFace)
            cullFace = ((IntAttribute) attr).value;
        else if ((t & DepthTestAttribute.Type) == DepthTestAttribute.Type) {
            DepthTestAttribute dta = (DepthTestAttribute) attr;
            depthFunc = dta.depthFunc;
            depthRangeNear = dta.depthRangeNear;
            depthRangeFar = dta.depthRangeFar;
            depthMask = dta.depthMask;
        } else if (!config.ignoreUnimplemented)
            throw new GdxRuntimeException("Unknown material attribute: " + attr.toString());
    }

    context.setCullFace(cullFace);
    context.setDepthTest(depthFunc, depthRangeNear, depthRangeFar);
    context.setDepthMask(depthMask);
}
项目:eamaster    文件:SoftBodyTest.java   
@Override
    public void create () {
        super.create();

        world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
            0.25f + 0.5f * (float)Math.random(), 1f);

        float x0 = -2f, y0 = 6f, z0 = -2f;
        float x1 = 8f, y1 = 6f, z1 = 8f;
        Vector3 patch00 = new Vector3(x0, y0, z0);
        Vector3 patch10 = new Vector3(x1, y1, z0);
        Vector3 patch01 = new Vector3(x0, y0, z1);
        Vector3 patch11 = new Vector3(x1, y1, z1);
        softBody = btSoftBodyHelpers.CreatePatch(worldInfo, patch00, patch10, patch01, patch11, 15, 15, 15, false);
        softBody.takeOwnership();
        softBody.setTotalMass(100f);
//        softBody.setConfig_kDP(0.2f);
//        softBody.setConfig_kCHR(0.99f);
//        softBody.setConfig_kKHR(0.99f);
//        softBody.setConfig_kSHR(0.99f);
        ((btSoftRigidDynamicsWorld)(world.collisionWorld)).addSoftBody(softBody);

        final int vertCount = softBody.getNodeCount();
        final int faceCount = softBody.getFaceCount();
        mesh = new Mesh(false, vertCount, faceCount * 3, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
            new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2,
                ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
        final int vertSize = mesh.getVertexSize() / 4;
        mesh.getVerticesBuffer().position(0);
        mesh.getVerticesBuffer().limit(vertCount * vertSize);
        mesh.getIndicesBuffer().position(0);
        mesh.getIndicesBuffer().limit(faceCount * 3);
        softBody.getVertices(mesh.getVerticesBuffer(), vertCount, mesh.getVertexSize(), 0);
        softBody.getIndices(mesh.getIndicesBuffer(), faceCount);

        final float[] verts = new float[vertCount * vertSize];
        final int uvOffset = mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4;
        final int normalOffset = mesh.getVertexAttribute(Usage.Normal).offset / 4;
        mesh.getVertices(verts);
        for (int i = 0; i < vertCount; i++) {
            verts[i * vertSize + normalOffset] = 0f;
            verts[i * vertSize + normalOffset + 1] = 1f;
            verts[i * vertSize + normalOffset + 2] = 0f;
            verts[i * vertSize + uvOffset] = (verts[i * vertSize] - x0) / (x1 - x0);
            verts[i * vertSize + uvOffset + 1] = (verts[i * vertSize + 2] - z0) / (z1 - z0);
        }
        mesh.setVertices(verts);
        texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));

        model = ModelBuilder.createFromMesh(mesh, GL20.GL_TRIANGLES, new Material(TextureAttribute.createDiffuse(texture),
            ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f), IntAttribute.createCullFace(0)));
        instance = new ModelInstance(model);
        world.add(new BulletEntity(instance, null));

        shoot(320f, 240f, 20f);
    }
项目:libgdxcn    文件:SoftBodyTest.java   
@Override
public void create () {
    super.create();

    world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
        0.25f + 0.5f * (float)Math.random(), 1f);

    float x0 = -2f, y0 = 6f, z0 = -2f;
    float x1 = 8f, y1 = 6f, z1 = 8f;
    Vector3 patch00 = new Vector3(x0, y0, z0);
    Vector3 patch10 = new Vector3(x1, y1, z0);
    Vector3 patch01 = new Vector3(x0, y0, z1);
    Vector3 patch11 = new Vector3(x1, y1, z1);
    softBody = btSoftBodyHelpers.CreatePatch(worldInfo, patch00, patch10, patch01, patch11, 15, 15, 15, false);
    softBody.takeOwnership();
    softBody.setTotalMass(100f);
    ((btSoftRigidDynamicsWorld)(world.collisionWorld)).addSoftBody(softBody);

    final int vertCount = softBody.getNodeCount();
    final int faceCount = softBody.getFaceCount();
    mesh = new Mesh(false, vertCount, faceCount * 3, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
        new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2,
            ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
    final int vertSize = mesh.getVertexSize() / 4;
    mesh.getVerticesBuffer().position(0);
    mesh.getVerticesBuffer().limit(vertCount * vertSize);
    mesh.getIndicesBuffer().position(0);
    mesh.getIndicesBuffer().limit(faceCount * 3);
    softBody.getVertices(mesh.getVerticesBuffer(), vertCount, mesh.getVertexSize(), 0);
    softBody.getIndices(mesh.getIndicesBuffer(), faceCount);

    final float[] verts = new float[vertCount * vertSize];
    final int uvOffset = mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4;
    final int normalOffset = mesh.getVertexAttribute(Usage.Normal).offset / 4;
    mesh.getVertices(verts);
    for (int i = 0; i < vertCount; i++) {
        verts[i * vertSize + normalOffset] = 0f;
        verts[i * vertSize + normalOffset + 1] = 1f;
        verts[i * vertSize + normalOffset + 2] = 0f;
        verts[i * vertSize + uvOffset] = (verts[i * vertSize] - x0) / (x1 - x0);
        verts[i * vertSize + uvOffset + 1] = (verts[i * vertSize + 2] - z0) / (z1 - z0);
    }
    mesh.setVertices(verts);
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));

    model = ModelBuilder.createFromMesh(mesh, GL20.GL_TRIANGLES, new Material(TextureAttribute.createDiffuse(texture),
        ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f), IntAttribute.createCullFace(0)));
    instance = new ModelInstance(model);
    world.add(new BulletEntity(instance, null));
}
项目:gaiasky    文件:ModelComponent.java   
/**
 * Initialises the texture if it is not initialised yet
 */
public void touch() {
    if (GlobalConf.scene.LAZY_TEXTURE_INIT && !initialised) {

        if (tc != null) {
            if (!loading) {
                Logger.info(I18n.bundle.format("notif.loading", tc.base));
                tc.initialize(manager);
                // Set to loading
                loading = true;
            } else if (tc.isFinishedLoading(manager)) {
                Gdx.app.postRunnable(() -> {
                    tc.initMaterial(manager, instance, cc, culling);
                });

                // Set to initialised
                initialised = true;
                loading = false;
            }
        } else {
            // Use color if necessary
            if (cc != null && useColor) {
                // Regular mesh, we use the color
                int n = instance.materials.size;
                for (int i = 0; i < n; i++) {
                    Material material = instance.materials.get(i);
                    if (material.get(TextureAttribute.Ambient) == null && material.get(TextureAttribute.Diffuse) == null) {
                        material.set(new ColorAttribute(ColorAttribute.Diffuse, cc[0], cc[1], cc[2], cc[3]));
                        material.set(new ColorAttribute(ColorAttribute.Ambient, cc[0], cc[1], cc[2], cc[3]));
                        if (!culling)
                            material.set(new IntAttribute(IntAttribute.CullFace, GL20.GL_NONE));
                    }
                }
            }
            // Set to initialised
            initialised = true;
            loading = false;
        }

    }

}