Search in sources :

Example 16 with ModelBatch

use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.

the class CullTest method create.

@Override
public void create() {
    ModelBuilder builder = new ModelBuilder();
    sphere = builder.createSphere(2f, 2f, 2f, 16, 16, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)), Usage.Position | Usage.Normal);
    // cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam = new OrthographicCamera(45, 45 * (Gdx.graphics.getWidth() / (float) Gdx.graphics.getHeight()));
    cam.near = 1;
    cam.far = 200;
    Random rand = new Random();
    for (int i = 0; i < instances.length; i++) {
        pos.set(rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * -100 - 3);
        instances[i] = new ModelInstance(sphere, pos);
    }
    modelBatch = new ModelBatch();
    batch = new SpriteBatch();
    font = new BitmapFont();
// Gdx.graphics.setVSync(true);
// Gdx.app.log("CullTest", "" + Gdx.graphics.getBufferFormat().toString());
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) Random(java.util.Random) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Material(com.badlogic.gdx.graphics.g3d.Material) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 17 with ModelBatch

use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.

the class VoxelTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch();
    font = new BitmapFont();
    modelBatch = new ModelBatch();
    DefaultShader.defaultCullFace = GL20.GL_FRONT;
    camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.near = 0.5f;
    camera.far = 1000;
    controller = new FirstPersonCameraController(camera);
    Gdx.input.setInputProcessor(controller);
    lights = new Environment();
    lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
    lights.add(new DirectionalLight().set(1, 1, 1, 0, -1, 0));
    Texture texture = new Texture(Gdx.files.internal("data/g3d/tiles.png"));
    TextureRegion[][] tiles = TextureRegion.split(texture, 32, 32);
    MathUtils.random.setSeed(0);
    voxelWorld = new VoxelWorld(tiles[0], 20, 4, 20);
    PerlinNoiseGenerator.generateVoxels(voxelWorld, 0, 63, 10);
    float camX = voxelWorld.voxelsX / 2f;
    float camZ = voxelWorld.voxelsZ / 2f;
    float camY = voxelWorld.getHighest(camX, camZ) + 1.5f;
    camera.position.set(camX, camY, camZ);
}
Also used : DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) FirstPersonCameraController(com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 18 with ModelBatch

use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.

the class ShaderCollectionTest method create.

@Override
public void create() {
    super.create();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.1f, 0.1f, 0.1f, 1.f));
    environment.add(dirLight = new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
    shaderProvider = new TestShaderProvider();
    shaderBatch = new ModelBatch(shaderProvider);
    cam.position.set(1, 1, 1);
    cam.lookAt(0, 0, 0);
    cam.update();
    showAxes = true;
    onModelClicked("g3d/shapes/teapot.g3dj");
    shaderRoot = (hotLoadFolder != null && Gdx.app.getType() == ApplicationType.Desktop) ? Gdx.files.absolute(hotLoadFolder) : Gdx.files.internal("data/g3d/shaders");
}
Also used : DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 19 with ModelBatch

use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.

the class ShaderTest method create.

@Override
public void create() {
    modelBatch = new ModelBatch(new DefaultShaderProvider() {

        @Override
        protected Shader createShader(Renderable renderable) {
            if (renderable.material.has(TestAttribute.ID))
                return new TestShader(renderable);
            return super.createShader(renderable);
        }
    });
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0f, 0f, 20f);
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();
    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);
    Material testMaterial1 = new Material("TestMaterial1", new TestAttribute(1f));
    Material redMaterial = new Material("RedMaterial", ColorAttribute.createDiffuse(Color.RED));
    Material testMaterial2 = new Material("TestMaterial2", new TestAttribute(1f), ColorAttribute.createDiffuse(Color.BLUE));
    ModelBuilder builder = new ModelBuilder();
    Node node;
    builder.begin();
    node = builder.node();
    node.id = "testCone1";
    node.translation.set(-10, 0f, 0f);
    builder.part("testCone", GL20.GL_TRIANGLES, Usage.Position, testMaterial1).cone(5, 5, 5, 20);
    node = builder.node();
    node.id = "redSphere";
    builder.part("redSphere", GL20.GL_TRIANGLES, Usage.Position, redMaterial).sphere(5, 5, 5, 20, 20);
    node = builder.node();
    node.id = "testCone1";
    node.translation.set(10, 0f, 0f);
    builder.part("testCone", GL20.GL_TRIANGLES, Usage.Position, testMaterial2).cone(5, 5, 5, 20);
    model = builder.end();
    ModelInstance modelInstance;
    modelInstance = new ModelInstance(model);
    testAttribute1 = (TestAttribute) modelInstance.getMaterial("TestMaterial1").get(TestAttribute.ID);
    testAttribute2 = (TestAttribute) modelInstance.getMaterial("TestMaterial2").get(TestAttribute.ID);
    instances.add(modelInstance);
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) Renderable(com.badlogic.gdx.graphics.g3d.Renderable) Node(com.badlogic.gdx.graphics.g3d.model.Node) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera)

Example 20 with ModelBatch

use of com.badlogic.gdx.graphics.g3d.ModelBatch in project libgdx by libgdx.

the class ShadowMappingTest method create.

@Override
public void create() {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
    environment.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -1f, -.8f, -.2f));
    environment.shadowMap = shadowLight;
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0f, 7f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 50f;
    cam.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.ColorUnpacked, new Material(ColorAttribute.createDiffuse(Color.WHITE)));
    mpb.setColor(1f, 1f, 1f, 1f);
    mpb.box(0, -1.5f, 0, 10, 1, 10);
    mpb.setColor(1f, 0f, 1f, 1f);
    mpb.sphere(2f, 2f, 2f, 10, 10);
    model = modelBuilder.end();
    instance = new ModelInstance(model);
    shadowBatch = new ModelBatch(new DepthShaderProvider());
    Gdx.input.setInputProcessor(camController = new CameraInputController(cam));
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) DirectionalShadowLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) DepthShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DepthShaderProvider)

Aggregations

ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)24 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)18 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)16 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)14 Environment (com.badlogic.gdx.graphics.g3d.Environment)13 Material (com.badlogic.gdx.graphics.g3d.Material)12 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)11 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)10 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)8 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)7 Texture (com.badlogic.gdx.graphics.Texture)5 DefaultShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider)5 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4 ObjLoader (com.badlogic.gdx.graphics.g3d.loader.ObjLoader)4 AssetManager (com.badlogic.gdx.assets.AssetManager)3 Model (com.badlogic.gdx.graphics.g3d.Model)3 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)3 DirectionalShadowLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight)3 DepthShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DepthShaderProvider)3