Example usage for com.badlogic.gdx.graphics.g3d ModelBatch ModelBatch

List of usage examples for com.badlogic.gdx.graphics.g3d ModelBatch ModelBatch

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g3d ModelBatch ModelBatch.

Prototype

public ModelBatch() 

Source Link

Document

Construct a ModelBatch with the default implementation

Usage

From source file:br.com.raphaelbruno.game.zombieinvaders.vr.GameBase.java

License:Apache License

@Override
public void create() {
    modelBatch = new ModelBatch();
    spriteBatch = new SpriteBatch();
    soundBg = Gdx.audio.newMusic(Gdx.files.internal("sounds/bg.mp3"));

    playBg();/*  w  w w.ja va2 s .com*/
    setScreen(new SplashScreen(this));
}

From source file:com.andgate.ikou.view.GameScreen.java

License:Open Source License

public GameScreen(Ikou game, Level level, int currentFloorNumber) {
    this.game = game;
    this.level = level;
    batch = new SpriteBatch();

    TilePalette palette = level.getFloor(currentFloorNumber).getPalette();
    Color bg = palette.background;

    game.bloom.setClearColor(bg.r, bg.g, bg.b, bg.a);

    Gdx.graphics.setVSync(false);/*from ww w.java2  s .  c o  m*/

    camera = new PerspectiveCamera(Constants.DEFAULT_FIELD_OF_VIEW, Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());

    modelBatch = new ModelBatch();
    levelRender = new LevelRender(level);
    levelRender.setCamera(camera);
    levelRender.resetTransform();
    levelRender.offsetFloors();
    levelRender.spaceFloors(Constants.FLOOR_SPACING);

    player = new Player(game, level, currentFloorNumber);
    createEnvironment();

    setupCamera();
    InputProcessor moveController = new PlayerDirectionGestureDetector(player, camController);

    im = new InputMultiplexer();
    im.addProcessor(moveController);
    Gdx.input.setInputProcessor(im);
    controlsMenu = new GameControlsMenu(game, im, moveController, camController);
}

From source file:com.badlogic.gdx.tests.ViewportTest3.java

License:Apache License

public void create() {
    modelBatch = new ModelBatch();
    modelBuilder = new ModelBuilder();

    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
    shadowLight = new DirectionalLight();
    shadowLight.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
    environment.add(shadowLight);/*www .java 2 s .  c  o  m*/

    modelBatch = new ModelBatch();

    camera = new PerspectiveCamera();
    camera.fieldOfView = 67;
    camera.near = 0.1f;
    camera.far = 300f;
    camera.position.set(0, 0, 100);
    camera.lookAt(0, 0, 0);

    viewports = ViewportTest1.getViewports(camera);
    viewport = viewports.first();

    names = ViewportTest1.getViewportNames();
    name = names.first();

    ModelBuilder modelBuilder = new ModelBuilder();
    Model boxModel = modelBuilder.createBox(50f, 50f, 50f,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    boxInstance = new ModelInstance(boxModel);
    boxInstance.transform.rotate(1, 0, 0, 30);
    boxInstance.transform.rotate(0, 1, 0, 30);

    Gdx.input.setInputProcessor(new InputAdapter() {
        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(viewport, true) + 1) % viewports.size;
                name = names.get(index);
                viewport = viewports.get(index);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    });
}

From source file:com.badlogic.invaders.Renderer.java

License:Apache License

public Renderer() {
    try {// www.j  ava2  s .  c  o m
        lights = new Environment();
        lights.add(new DirectionalLight().set(Color.WHITE, new Vector3(-1, -0.5f, 0).nor()));

        spriteBatch = new SpriteBatch();
        modelBatch = new ModelBatch();

        backgroundTexture = new Texture(Gdx.files.internal("data/planet.jpg"), Format.RGB565, true);
        backgroundTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);

        font = new BitmapFont(Gdx.files.internal("data/font10.fnt"), Gdx.files.internal("data/font10.png"),
                false);

        camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.barconr.games.marblegame.Maze3Drenderer.java

License:Apache License

public Maze3Drenderer() {
    modelBatch = new ModelBatch();
    instances = new ArrayList<ModelInstance>();
    modelBuilder = new ModelBuilder();

    createModels(Assets.mazemap);/*w  ww.  j  a v a2 s. c o  m*/

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    float mapPixelWidth = layerWidth * CUBE_SIZE;
    float mapPixelHeight = layerHeight * CUBE_SIZE;

    cam.position.set((float) Gdx.graphics.getWidth() / 2, (float) Gdx.graphics.getHeight() / 2, 100f);
    cam.lookAt((float) Gdx.graphics.getWidth() / 2, (float) Gdx.graphics.getHeight() / 2, 0);

    cam.near = 0.1f;
    cam.far = 150f;

    cam.update();
    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, -1f, -0.8f, -0.2f));

}

From source file:com.cyphercove.doublehelix.MainRenderer.java

License:Apache License

private void finishCreate() {
    needFinishCreate = false;//from   w  ww.  j ava  2  s .c  om

    modelBatch = new ModelBatch();
    disposables.add(modelBatch);

    environment = new Environment();

    assets = new AssetManager();
    disposables.add(assets);

    TextureLoader.TextureParameter trilinearRepeatTextureParams = new TextureLoader.TextureParameter();
    trilinearRepeatTextureParams.format = Pixmap.Format.RGBA8888;
    trilinearRepeatTextureParams.magFilter = Texture.TextureFilter.Linear;
    trilinearRepeatTextureParams.minFilter = Texture.TextureFilter.MipMapLinearLinear;
    trilinearRepeatTextureParams.wrapU = Texture.TextureWrap.Repeat;
    trilinearRepeatTextureParams.wrapV = Texture.TextureWrap.Repeat;
    trilinearRepeatTextureParams.genMipMaps = true;
    assets.load(HELIX_NORMAL_AO_TEXTURE, Texture.class, trilinearRepeatTextureParams);
    assets.load(PARTICLE_A_TEXTURE, Texture.class, trilinearRepeatTextureParams);

    TextureLoader.TextureParameter bilinearClampedTextureParams = new TextureLoader.TextureParameter();
    bilinearClampedTextureParams.format = Pixmap.Format.RGBA8888;
    bilinearClampedTextureParams.magFilter = Texture.TextureFilter.Linear;
    bilinearClampedTextureParams.minFilter = Texture.TextureFilter.MipMapLinearNearest;
    bilinearClampedTextureParams.wrapU = Texture.TextureWrap.ClampToEdge;
    bilinearClampedTextureParams.wrapV = Texture.TextureWrap.ClampToEdge;
    bilinearClampedTextureParams.genMipMaps = true;
    assets.load(BG_GLOW_TEXTURE, Texture.class, bilinearClampedTextureParams);
    assets.load(BG_BLOOM_TEXTURE, Texture.class, bilinearClampedTextureParams);
    assets.load(POINT_PARTICLE_TEXTURE, Texture.class, bilinearClampedTextureParams);

    TextureLoader.TextureParameter borderTexParams = new TextureLoader.TextureParameter();
    borderTexParams.format = Pixmap.Format.Alpha;
    borderTexParams.magFilter = Texture.TextureFilter.Linear;
    borderTexParams.minFilter = Texture.TextureFilter.Linear;
    assets.load(FILM_BORDER_TEXTURE, Texture.class, borderTexParams);

    TextureLoader.TextureParameter noiseTexParams = new TextureLoader.TextureParameter();
    noiseTexParams.format = Pixmap.Format.Alpha;
    noiseTexParams.magFilter = Texture.TextureFilter.Nearest;
    noiseTexParams.minFilter = Texture.TextureFilter.Nearest;
    noiseTexParams.wrapU = Texture.TextureWrap.Repeat;
    noiseTexParams.wrapV = Texture.TextureWrap.Repeat;
    assets.load(FILM_NOISE_TEXTURE, Texture.class, noiseTexParams);

    TextureLoader.TextureParameter scanlineTexParams = new TextureLoader.TextureParameter();
    scanlineTexParams.format = Pixmap.Format.Alpha;
    scanlineTexParams.magFilter = Texture.TextureFilter.Linear;
    scanlineTexParams.minFilter = Texture.TextureFilter.Linear;
    scanlineTexParams.wrapU = Texture.TextureWrap.Repeat;
    scanlineTexParams.wrapV = Texture.TextureWrap.Repeat;
    assets.load(SCANLINE_TEXTURE, Texture.class, scanlineTexParams);

    assets.load(HELIX_MODEL, Model.class);
    assets.load(BG_MODEL, Model.class);
    assets.load(BG_BLOOM_MODEL, Model.class);

    assets.finishLoading();

    helixNormalAOTexture = assets.get(HELIX_NORMAL_AO_TEXTURE, Texture.class);
    backgroundTexture = assets.get(BG_GLOW_TEXTURE, Texture.class);
    backgroundBloomTexture = assets.get(BG_BLOOM_TEXTURE, Texture.class);
    Texture filmNoiseTexture = assets.get(FILM_NOISE_TEXTURE, Texture.class);
    Texture filmBorderTexture = assets.get(FILM_BORDER_TEXTURE, Texture.class);
    Texture scanlineTexture = assets.get(SCANLINE_TEXTURE, Texture.class);

    Model helixModel = assets.get(HELIX_MODEL, Model.class);
    mainHelixModelInstance = new ModelInstance(helixModel);
    mainHelixModelInstance.userData = Settings.frontHelixColor;
    mainHelixTransformManager = new TransformManager(mainHelixModelInstance);
    rearHelixModelInstance = new ModelInstance(helixModel);
    rearHelixModelInstance.userData = Settings.rearHelixColor;
    rearHelixTransformManager = new TransformManager(rearHelixModelInstance);
    rearHelixTransformManager.eulers.set(12.477f, -96.843f, -7.902f);
    rearHelixTransformManager.position.set(7.95135f, -5.46558f, 9.82413f);

    Model bgModel = assets.get(BG_MODEL, Model.class);
    backgroundModelInstance = new ModelInstance(bgModel);

    Model bgBloomModel = assets.get(BG_BLOOM_MODEL, Model.class);
    backgroundBloomModelInstance = new ModelInstance(bgBloomModel);

    sssShader = new SubsurfaceScatteringShader(helixNormalAOTexture, (new Vector3(-0.6f, 1f, 1f)).nor());
    sssShader.init();
    disposables.add(sssShader);

    backgroundShader = new BackgroundShader(backgroundTexture);
    backgroundShader.init();
    disposables.add(backgroundShader);

    unlitShader = new UnlitShader(backgroundBloomTexture);
    unlitShader.init();
    disposables.add(unlitShader);

    blackShader = new BlackShader();
    blackShader.init();
    disposables.add(blackShader);

    bloomShaderProgram = loadShaderProgram("bloom");
    disposables.add(bloomShaderProgram);

    particleATexture = assets.get(PARTICLE_A_TEXTURE, Texture.class);
    particleATextureRegion = new TextureRegion(particleATexture);

    particlePointTexture = assets.get(POINT_PARTICLE_TEXTURE, Texture.class);

    particles = new Particles(particlePointTexture, particleATextureRegion, cam);
    InputMultiplexer inputMultiplexer = new InputMultiplexer(inputAdapter, particles.inputAdapter);
    Gdx.input.setInputProcessor(inputMultiplexer);

    particleGroupStrategy = new ParticleGroupStrategy(cam);
    disposables.add(particleGroupStrategy);

    decalBatch = new DecalBatch(Particles.MAX_PARTICLES, particleGroupStrategy);
    disposables.add(decalBatch);

    billboardDecalBatch = new BillboardDecalBatch(Particles.MAX_PARTICLES, particleGroupStrategy);
    disposables.add(billboardDecalBatch);

    filmGrain = new FilmGrain(filmNoiseTexture, filmBorderTexture, scanlineTexture, false);
    disposables.add(filmGrain);
    filmGrainForBloom = new FilmGrain(filmNoiseTexture, filmBorderTexture, scanlineTexture, true);
    disposables.add(filmGrainForBloom);
}

From source file:com.LibGdxUtils.java

License:Open Source License

@Override
public void create() {
    try {//from www  . j  a v  a  2s . c  o  m
        logger.setLevel(Logger.DEBUG);
        Gdx.app.setLogLevel(Application.LOG_DEBUG);

        Texture.setAssetManager(Assets.manager);

        spriteBatch = new SpriteBatch();
        modelBatch = new ModelBatch();

        game.create();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Gdx.app.exit();
    }
}

From source file:com.mbrlabs.demo.MundusDemo.java

License:Apache License

@Override
public void create() {
    batch = new ModelBatch();
    fpsLogger = new FPSLogger();

    // setup mundus & load our scene
    mundus = new Mundus(Gdx.files.internal("mundus"));
    mundus.init();// ww w .  j  a  v  a  2s . c o  m
    scene = mundus.loadScene("Main Scene.mundus");
    scene.sceneGraph.batch = batch;

    // position cam
    scene.cam.position.set(230, 150, 190);
    scene.cam.direction.rotate(Vector3.Y, 70);
    scene.cam.direction.rotate(Vector3.Z, -20);

    // setup input
    controller = new FirstPersonCameraController(scene.cam);
    controller.setVelocity(200f);
    Gdx.input.setInputProcessor(controller);
}

From source file:com.mbrlabs.mundus.core.Mundus.java

License:Apache License

/**
 * Loads & initializes everything.//from   w w  w  .j  av a2 s  .  co m
 *
 * This includes editor specific resources but also project specific
 * resources (see ProjectContext).
 *
 */
public static void init() {
    File homeDir = new File(Registry.HOME_DIR);
    if (!homeDir.exists()) {
        homeDir.mkdir();
    }

    initStyle();
    initFontAwesome();

    shapeRenderer = new ShapeRenderer();
    modelBatch = new ModelBatch();
    shaders = new Shaders();
    input = new InputManager();
    goPicker = new GameObjectPicker();
    handlePicker = new ToolHandlePicker();
    eventBus = new EventBus();
    kryoManager = new KryoManager();
    registry = kryoManager.loadRegistry();
    freeCamController = new FreeCamController();
    commandHistory = new CommandHistory(CommandHistory.DEFAULT_LIMIT);

    modelImporter = new ModelImporter(registry);
    projectManager = new ProjectManager(kryoManager, registry, shaders);
    toolManager = new ToolManager(input, projectManager, goPicker, handlePicker, modelBatch, shaders,
            shapeRenderer, commandHistory);
    shortcutController = new ShortcutController(registry, projectManager, commandHistory);
}

From source file:com.nsoft.boxuniverse.world.BaseWorld.java

License:Open Source License

public BaseWorld(WorldDefinition def, boolean needGeneration) {

    this.def = def;
    layers = new Layer[def.NumLayers];

    batch = new SpriteBatch();
    background = new Texture(def.BackGroundPath);

    b = new ModelBatch();
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0, 0, 10);/* ww w.  j a  v a 2 s.  com*/
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();

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

    for (int i = 0; i < layers.length; i++) {

        layers[i] = new Layer(i, needGeneration);
    }

    // debug();
}