Search in sources :

Example 21 with ModelInstance

use of com.badlogic.gdx.graphics.g3d.ModelInstance in project ultimate-java by pantinor.

the class CodexScreen method createPolygonBox.

public ModelInstance createPolygonBox(Color color, float width, float height, float length, float rotation, float x, float y, float z) {
    Vector3 corner000 = new Vector3(-width / 2, -height / 2, -length / 2);
    Vector3 corner010 = new Vector3(width / 2, -height / 2, -length / 2);
    Vector3 corner100 = new Vector3(-width / 2, -height / 2, length / 2);
    Vector3 corner110 = new Vector3(width / 2, -height / 2, length / 2);
    Vector3 corner001 = new Vector3(-width / 2, height / 2, -length / 2);
    Vector3 corner011 = new Vector3(width / 2, height / 2, -length / 2);
    Vector3 corner101 = new Vector3(-width / 2, height / 2, length / 2);
    Vector3 corner111 = new Vector3(width / 2, height / 2, length / 2);
    Material material = new Material(ColorAttribute.createDiffuse(color));
    ModelBuilder mb = new ModelBuilder();
    mb.begin();
    mb.part("box", GL30.GL_TRIANGLES, Usage.Position | Usage.Normal, material).box(corner000, corner010, corner100, corner110, corner001, corner011, corner101, corner111);
    Model model = mb.end();
    ModelInstance modelInstance = new ModelInstance(model);
    modelInstance.transform.rotate(new Vector3(0, 1, 0), rotation);
    modelInstance.transform.setTranslation(x, y, z);
    return modelInstance;
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) Model(com.badlogic.gdx.graphics.g3d.Model) Vector3(com.badlogic.gdx.math.Vector3) Material(com.badlogic.gdx.graphics.g3d.Material)

Example 22 with ModelInstance

use of com.badlogic.gdx.graphics.g3d.ModelInstance in project ultimate-java by pantinor.

the class DungeonScreen method init.

public void init() {
    assets = new AssetManager();
    assets.load("assets/graphics/dirt.png", Texture.class);
    assets.load("assets/graphics/map.png", Texture.class);
    assets.load("assets/graphics/Stone_Masonry.jpg", Texture.class);
    assets.load("assets/graphics/door.png", Texture.class);
    assets.load("assets/graphics/mortar.png", Texture.class);
    assets.load("assets/graphics/rock.png", Texture.class);
    assets.update(2000);
    // convert the collada dae format to the g3db format (do not use the obj format)
    // C:\Users\Paul\Desktop\blender>fbx-conv-win32.exe -o G3DB ./Chess/pawn.dae ./pawn.g3db
    ModelLoader<?> gloader = new G3dModelLoader(new UBJsonReader());
    fountainModel = gloader.loadModel(Gdx.files.internal("assets/graphics/fountain2.g3db"));
    ladderModel = gloader.loadModel(Gdx.files.internal("assets/graphics/ladder.g3db"));
    chestModel = gloader.loadModel(Gdx.files.internal("assets/graphics/chest.g3db"));
    orbModel = gloader.loadModel(Gdx.files.internal("assets/graphics/orb.g3db"));
    altarModel = gloader.loadModel(Gdx.files.internal("assets/graphics/altar.g3db"));
    // blocksModel = gloader.loadModel(Gdx.files.internal("assets/graphics/box.g3db"));
    Pixmap pixmap = new Pixmap(MM_BKGRND_DIM, MM_BKGRND_DIM, Format.RGBA8888);
    pixmap.setColor(0.8f, 0.7f, 0.5f, .8f);
    pixmap.fillRectangle(0, 0, MM_BKGRND_DIM, MM_BKGRND_DIM);
    MINI_MAP_TEXTURE = new Texture(pixmap);
    pixmap.dispose();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.05f, 0.05f, 0.05f, 1f));
    // environment.set(new ColorAttribute(ColorAttribute.Fog, 0.13f, 0.13f, 0.13f, 1f));
    fixedLight = new PointLight().set(1f, 0.8f, 0.6f, 4f, 4f, 4f, 5f);
    environment.add(fixedLight);
    modelBatch = new ModelBatch();
    batch = new SpriteBatch();
    camera = new PerspectiveCamera(67, Ultima4.MAP_WIDTH, Ultima4.MAP_HEIGHT);
    camera.near = 0.1f;
    camera.far = 1000f;
    decalBatch = new DecalBatch(new CameraGroupStrategy(camera));
    // inputController = new CameraInputController(camera);
    // inputController.rotateLeftKey = inputController.rotateRightKey = inputController.forwardKey = inputController.backwardKey = 0;
    // inputController.translateUnits = 30f;
    ModelBuilder builder = new ModelBuilder();
    lightModel = builder.createSphere(.1f, .1f, .1f, 10, 10, new Material(ColorAttribute.createDiffuse(1, 1, 1, 1)), Usage.Position);
    lightModel.nodes.get(0).parts.get(0).setRenderable(pLight = new Renderable());
    for (int x = 0; x < 12; x++) {
        for (int y = 0; y < 12; y++) {
            Model sf = builder.createBox(1, 1, 1, new Material(TextureAttribute.createDiffuse(assets.get("assets/graphics/rock.png", Texture.class))), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
            floor.add(new ModelInstance(sf, new Vector3(x - 1.5f, -.5f, y - 1.5f)));
        }
    }
    for (int x = 0; x < 12; x++) {
        for (int y = 0; y < 12; y++) {
            Model sf = builder.createBox(1, 1, 1, new Material(TextureAttribute.createDiffuse(assets.get("assets/graphics/dirt.png", Texture.class))), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
            ceiling.add(new ModelInstance(sf, new Vector3(x - 1.5f, 1.5f, y - 1.5f)));
        }
    }
    try {
        InputStream is = new FileInputStream("assets/data/" + dungeonFileName.toLowerCase());
        byte[] bytes = IOUtils.toByteArray(is);
        int pos = 0;
        for (int i = 0; i < DUNGEON_MAP; i++) {
            for (int y = 0; y < DUNGEON_MAP; y++) {
                for (int x = 0; x < DUNGEON_MAP; x++) {
                    int index = bytes[pos] & 0xff;
                    pos++;
                    DungeonTile tile = DungeonTile.getTileByValue(index);
                    dungeonTiles[i][x][y] = tile;
                    addBlock(i, tile, x + .5f, .5f, y + .5f);
                }
            }
        }
        // rooms
        pos = 0x200;
        for (int i = 0; i < rooms.length; i++) {
            if (pos >= bytes.length) {
                continue;
            }
            rooms[i] = new DungeonRoom(bytes, pos);
            pos = pos + 256;
        }
        for (int i = 0; i < DUNGEON_MAP; i++) {
            for (int y = 0; y < DUNGEON_MAP; y++) {
                for (int x = 0; x < DUNGEON_MAP; x++) {
                    DungeonTile tile = dungeonTiles[i][x][y];
                    if (tile.getValue() >= 208 && tile.getValue() <= 223) {
                        DungeonRoom room = rooms[tile.getValue() - 207 - 1];
                        if (dngMap == Maps.ABYSS) {
                            if (i == 0 || i == 1) {
                            // nothing
                            } else if (i == 2 || i == 3) {
                                room = rooms[tile.getValue() - 207 + 16 - 1];
                            } else if (i == 4 || i == 5) {
                                room = rooms[tile.getValue() - 207 + 32 - 1];
                            } else if (i == 6 || i == 7) {
                                room = rooms[tile.getValue() - 207 + 48 - 1];
                            }
                        }
                        // for (int j=0;j<4;j++) if (room.triggers[j].tile.getIndex() != 0) System.out.println(room.triggers[j].toString());
                        if (room.hasAltar) {
                            if (x == 1) {
                                room.altarRoomVirtue = BaseVirtue.TRUTH;
                            } else if (x == 7) {
                                room.altarRoomVirtue = BaseVirtue.COURAGE;
                            } else {
                                room.altarRoomVirtue = BaseVirtue.LOVE;
                            }
                        }
                        RoomLocater loc = new RoomLocater(x, y, i, room);
                        locaters.add(loc);
                    }
                }
            }
        }
        miniMapIcon = new MiniMapIcon();
        miniMapIcon.setOrigin(5, 5);
        stage.addActor(miniMapIcon);
        setStartPosition();
        camera.position.set(currentPos);
        camera.lookAt(currentPos.x + 1, currentPos.y, currentPos.z);
        // i went 2 layers duplicated on each edges + the corners
        for (int i = 0; i < DUNGEON_MAP; i++) {
            {
                int y = 0;
                for (int x = 0; x < DUNGEON_MAP; x++) {
                    // bottom across the top
                    DungeonTile tile = dungeonTiles[i][x][y + DUNGEON_MAP - 1];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f, .5f, y - .5f);
                    tile = dungeonTiles[i][x][y + DUNGEON_MAP - 2];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f, .5f, y - 1.5f);
                }
                for (int x = 0; x < DUNGEON_MAP; x++) {
                    // top across the bottom
                    DungeonTile tile = dungeonTiles[i][x][y];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f, .5f, y + .5f + DUNGEON_MAP);
                    tile = dungeonTiles[i][x][y + 1];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f, .5f, y + .5f + DUNGEON_MAP + 1);
                }
            }
            {
                int x = 0;
                for (int y = 0; y < DUNGEON_MAP; y++) {
                    DungeonTile tile = dungeonTiles[i][x][y];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f + DUNGEON_MAP, .5f, y + .5f);
                    tile = dungeonTiles[i][x + 1][y];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f + DUNGEON_MAP + 1, .5f, y + .5f);
                }
                for (int y = 0; y < DUNGEON_MAP; y++) {
                    DungeonTile tile = dungeonTiles[i][x + DUNGEON_MAP - 1][y];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x - .5f, .5f, y + .5f);
                    tile = dungeonTiles[i][x + DUNGEON_MAP - 2][y];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x - 1.5f, .5f, y + .5f);
                }
            }
            {
                // copy bottom right corner to the top left corner
                DungeonTile tile = dungeonTiles[i][DUNGEON_MAP - 1][DUNGEON_MAP - 1];
                addBlock(i, tile, -.5f, .5f, -.5f);
            }
            {
                // copy bottom left corner to the top right corner
                DungeonTile tile = dungeonTiles[i][0][DUNGEON_MAP - 1];
                addBlock(i, tile, DUNGEON_MAP + .5f, .5f, -.5f);
            }
            {
                // copy top right corner to the bottom left corner
                DungeonTile tile = dungeonTiles[i][DUNGEON_MAP - 1][0];
                addBlock(i, tile, -.5f, .5f, DUNGEON_MAP + .5f);
            }
            {
                // copy top left corner to the bottom right corner
                DungeonTile tile = dungeonTiles[i][0][0];
                addBlock(i, tile, DUNGEON_MAP + .5f, .5f, DUNGEON_MAP + .5f);
            }
        }
        createMiniMap();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DecalBatch(com.badlogic.gdx.graphics.g3d.decals.DecalBatch) CameraGroupStrategy(com.badlogic.gdx.graphics.g3d.decals.CameraGroupStrategy) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) Renderable(com.badlogic.gdx.graphics.g3d.Renderable) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) UBJsonReader(com.badlogic.gdx.utils.UBJsonReader) AssetManager(com.badlogic.gdx.assets.AssetManager) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Material(com.badlogic.gdx.graphics.g3d.Material) Vector3(com.badlogic.gdx.math.Vector3) FileInputStream(java.io.FileInputStream) PartyDeathException(util.PartyDeathException) DungeonTileModelInstance(util.DungeonTileModelInstance) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) G3dModelLoader(com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader) Model(com.badlogic.gdx.graphics.g3d.Model) Environment(com.badlogic.gdx.graphics.g3d.Environment) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) PointLight(com.badlogic.gdx.graphics.g3d.environment.PointLight) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 23 with ModelInstance

use of com.badlogic.gdx.graphics.g3d.ModelInstance in project ultimate-java by pantinor.

the class DungeonScreen method render.

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT);
    lightFactor += Gdx.graphics.getDeltaTime();
    float lightSize = 4.75f + 0.25f * (float) Math.sin(lightFactor) + .2f * MathUtils.random();
    Vector3 ll = isTorchOn ? nll : vdll;
    ll = isTorchOn ? nll2 : vdll;
    fixedLight.set(ll.x, ll.y, ll.z, currentPos.x, currentPos.y + .35f, currentPos.z, lightSize);
    ((ColorAttribute) pLight.material.get(ColorAttribute.Diffuse)).color.set(fixedLight.color);
    pLight.worldTransform.setTranslation(fixedLight.position);
    Gdx.gl.glViewport(32, 64, Ultima4.MAP_WIDTH, Ultima4.MAP_HEIGHT);
    camera.update();
    modelBatch.begin(camera);
    modelBatch.render(pLight);
    for (ModelInstance i : floor) {
        modelBatch.render(i, environment);
    }
    for (ModelInstance i : ceiling) {
        modelBatch.render(i, environment);
    }
    for (DungeonTileModelInstance i : modelInstances) {
        if (i.getLevel() == currentLevel) {
            modelBatch.render(i.getInstance(), environment);
        }
    }
    modelBatch.end();
    for (Creature cr : dngMap.getMap().getCreatures()) {
        decalBatch.add(cr.getDecal());
    }
    decalBatch.flush();
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.begin();
    batch.draw(Ultima4.backGround, 0, 0);
    if (showMiniMap) {
        batch.draw(MINI_MAP_TEXTURE, xalignMM, yalignMM);
        batch.draw(miniMap, xalignMM, yalignMM);
    }
    Ultima4.hud.render(batch, context.getParty());
    Ultima4.font.draw(batch, this.dngMap.getLabel(), 315, Ultima4.SCREEN_HEIGHT - 7);
    Ultima4.font.draw(batch, "Level " + (currentLevel + 1), 515, Ultima4.SCREEN_HEIGHT - 7);
    if (showZstats > 0) {
        context.getParty().getSaveGame().renderZstats(showZstats, Ultima4.font, batch, Ultima4.SCREEN_HEIGHT);
    }
    batch.end();
    stage.act();
    stage.draw();
}
Also used : DungeonTileModelInstance(util.DungeonTileModelInstance) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) Creature(objects.Creature) DungeonTileModelInstance(util.DungeonTileModelInstance) Vector3(com.badlogic.gdx.math.Vector3)

Example 24 with ModelInstance

use of com.badlogic.gdx.graphics.g3d.ModelInstance in project ultimate-java by pantinor.

the class DungeonScreen method dispose.

@Override
public void dispose() {
    modelBatch.dispose();
    batch.dispose();
    decalBatch.dispose();
    MINI_MAP_TEXTURE.dispose();
    miniMapIcon.dispose();
    stage.dispose();
    for (ModelInstance mi : floor) {
        mi.model.dispose();
    }
    for (ModelInstance mi : ceiling) {
        mi.model.dispose();
    }
}
Also used : DungeonTileModelInstance(util.DungeonTileModelInstance) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance)

Example 25 with ModelInstance

use of com.badlogic.gdx.graphics.g3d.ModelInstance in project ultimate-java by pantinor.

the class StaticGeneratedDungeonScreen method endCombat.

@Override
public void endCombat(boolean isWon, BaseMap combatMap, boolean wounded) {
    mainGame.setScreen(this);
    if (isWon) {
        if (currentEncounter != null) {
            log("Victory!");
            context.getParty().adjustKarma(KarmaAction.KILLED_EVIL);
            int x = (Math.round(currentPos.x) - 1);
            int y = (Math.round(currentPos.z) - 1);
            /* add a chest, if the creature leaves one */
            if (!currentEncounter.getNochest() && dungeonTiles[currentLevel][x][y] == DungeonTile.NOTHING) {
                ModelInstance instance = new ModelInstance(chestModel, x + .5f, 0, y + .5f);
                instance.nodes.get(0).scale.set(.010f, .010f, .010f);
                instance.calculateTransforms();
                DungeonTileModelInstance in = new DungeonTileModelInstance(instance, DungeonTile.CHEST, currentLevel);
                in.x = x;
                in.y = y;
                modelInstances.add(in);
                dungeonTiles[currentLevel][x][y] = DungeonTile.CHEST;
            }
        }
    } else {
        if (combatMap.getType() == MapType.combat && context.getParty().didAnyoneFlee()) {
            log("Battle is lost!");
        // no flee penalty in dungeons
        } else if (!context.getParty().isAnyoneAlive()) {
            partyDeath();
        }
    }
    if (currentEncounter != null) {
        dngMap.getMap().removeCreature(currentEncounter);
        currentEncounter = null;
    }
}
Also used : DungeonTileModelInstance(util.DungeonTileModelInstance) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) DungeonTileModelInstance(util.DungeonTileModelInstance)

Aggregations

ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)55 Material (com.badlogic.gdx.graphics.g3d.Material)29 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)26 Model (com.badlogic.gdx.graphics.g3d.Model)22 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)17 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)16 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)15 MeshPartBuilder (com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)11 Texture (com.badlogic.gdx.graphics.Texture)10 Environment (com.badlogic.gdx.graphics.g3d.Environment)10 Vector3 (com.badlogic.gdx.math.Vector3)10 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)9 AnimationController (com.badlogic.gdx.graphics.g3d.utils.AnimationController)9 DungeonTileModelInstance (util.DungeonTileModelInstance)8 BlendingAttribute (com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute)7 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)7 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)6 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)5 AssetManager (com.badlogic.gdx.assets.AssetManager)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4