Search in sources :

Example 31 with Mesh

use of com.badlogic.gdx.graphics.Mesh in project libgdx by libgdx.

the class TextureArrayTest method create.

@Override
public void create() {
    GL30Profiler.enable();
    ShaderProgram.prependVertexCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_EXT_texture_array : enable\n" : "#version 300 es\n";
    ShaderProgram.prependFragmentCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_EXT_texture_array : enable\n" : "#version 300 es\n";
    String[] texPaths = new String[] { "data/g3d/materials/Searing Gorge.jpg", "data/g3d/materials/Lava Cracks.jpg", "data/g3d/materials/Deep Fire.jpg" };
    camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.position.set(8, 10f, 20f);
    camera.lookAt(10, 0, 10);
    camera.up.set(0, 1, 0);
    camera.update();
    cameraController = new FirstPersonCameraController(camera);
    Gdx.input.setInputProcessor(cameraController);
    textureArray = new TextureArray(texPaths);
    textureArray.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
    shaderProgram = new ShaderProgram(Gdx.files.internal("data/shaders/texturearray.vert"), Gdx.files.internal("data/shaders/texturearray.frag"));
    System.out.println(shaderProgram.getLog());
    int vertexStride = 6;
    int vertexCount = 100 * 100;
    terrain = new Mesh(false, vertexCount * 6, 0, new VertexAttributes(VertexAttribute.Position(), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 3, ShaderProgram.TEXCOORD_ATTRIBUTE + 0)));
    Pixmap data = new Pixmap(Gdx.files.internal("data/g3d/heightmap.png"));
    float[] vertices = new float[vertexCount * vertexStride * 6];
    int idx = 0;
    for (int i = 0; i < 100 - 1; i++) {
        for (int j = 0; j < 100 - 1; j++) {
            idx = addVertex(i, j, vertices, data, idx);
            idx = addVertex(i, j + 1, vertices, data, idx);
            idx = addVertex(i + 1, j, vertices, data, idx);
            idx = addVertex(i, j + 1, vertices, data, idx);
            idx = addVertex(i + 1, j + 1, vertices, data, idx);
            idx = addVertex(i + 1, j, vertices, data, idx);
        }
    }
    terrain.setVertices(vertices);
    data.dispose();
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) VertexAttributes(com.badlogic.gdx.graphics.VertexAttributes) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) TextureArray(com.badlogic.gdx.graphics.TextureArray) Mesh(com.badlogic.gdx.graphics.Mesh) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) FirstPersonCameraController(com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 32 with Mesh

use of com.badlogic.gdx.graphics.Mesh in project libgdx by libgdx.

the class SpawnInfluencerPanel method onTemplateChecked.

@Override
public void onTemplateChecked(Model model, boolean isChecked) {
    //Update the shapes
    SpawnShapeValue shapeValue = null;
    Mesh mesh = model.meshes.get(0);
    weightMeshSpawnShapeValue.setMesh(mesh, model);
    meshSpawnShapeValue.setMesh(mesh, model);
    if (shapeCombo.getSelectedItem() == SPAWN_SHAPE_WEIGHT_MESH) {
        SpawnInfluencer influencer = (SpawnInfluencer) editor.getEmitter().findInfluencer(SpawnInfluencer.class);
        influencer.spawnShapeValue = weightMeshSpawnShapeValue;
    } else if (shapeCombo.getSelectedItem() == SPAWN_SHAPE_MESH) {
        SpawnInfluencer influencer = (SpawnInfluencer) editor.getEmitter().findInfluencer(SpawnInfluencer.class);
        influencer.spawnShapeValue = meshSpawnShapeValue;
    }
    editor.restart();
}
Also used : Mesh(com.badlogic.gdx.graphics.Mesh) SpawnInfluencer(com.badlogic.gdx.graphics.g3d.particles.influencers.SpawnInfluencer) LineSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.LineSpawnShapeValue) EllipseSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.EllipseSpawnShapeValue) UnweightedMeshSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.UnweightedMeshSpawnShapeValue) WeightMeshSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.WeightMeshSpawnShapeValue) RectangleSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.RectangleSpawnShapeValue) PointSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.PointSpawnShapeValue) SpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.SpawnShapeValue) PrimitiveSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.PrimitiveSpawnShapeValue) CylinderSpawnShapeValue(com.badlogic.gdx.graphics.g3d.particles.values.CylinderSpawnShapeValue)

Aggregations

Mesh (com.badlogic.gdx.graphics.Mesh)32 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)15 Texture (com.badlogic.gdx.graphics.Texture)8 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)8 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)4 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 VertexAttributes (com.badlogic.gdx.graphics.VertexAttributes)3 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)3 Material (com.badlogic.gdx.graphics.g3d.Material)3 MeshPart (com.badlogic.gdx.graphics.g3d.model.MeshPart)3 Pixmap (com.badlogic.gdx.graphics.Pixmap)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 Renderable (com.badlogic.gdx.graphics.g3d.Renderable)2 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)2 Vector3 (com.badlogic.gdx.math.Vector3)2 com.badlogic.gdx.physics.bullet.collision.btConvexHullShape (com.badlogic.gdx.physics.bullet.collision.btConvexHullShape)2 com.badlogic.gdx.physics.bullet.collision.btShapeHull (com.badlogic.gdx.physics.bullet.collision.btShapeHull)2 PerspectiveCamController (com.badlogic.gdx.tests.utils.PerspectiveCamController)2 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)1