Search in sources :

Example 1 with G3dModelLoader

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

the class ImportTest method create.

@Override
public void create() {
    super.create();
    ModelLoader g3djLoader = new G3dModelLoader(new JsonReader());
    model = g3djLoader.loadModel(Gdx.files.internal("data/g3d/btscene1.g3dj"));
    disposables.add(model);
    importer = new MyImporter((btDynamicsWorld) world.collisionWorld);
    importer.loadFile(Gdx.files.internal("data/g3d/btscene1.bullet"));
    camera.position.set(10f, 15f, 20f);
    camera.up.set(0, 1, 0);
    camera.lookAt(-10, 8, 0);
    camera.update();
}
Also used : ModelLoader(com.badlogic.gdx.assets.loaders.ModelLoader) G3dModelLoader(com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader) com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld(com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld) G3dModelLoader(com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader) JsonReader(com.badlogic.gdx.utils.JsonReader)

Example 2 with G3dModelLoader

use of com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader 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 3 with G3dModelLoader

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

the class StaticGeneratedDungeonScreen 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);
    assets.get("assets/graphics/rock.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    assets.get("assets/graphics/door.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    assets.get("assets/graphics/mortar.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    assets.get("assets/graphics/dirt.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    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"));
    rocksModel = gloader.loadModel(Gdx.files.internal("assets/graphics/rocks.g3db"));
    campfireModel = gloader.loadModel(Gdx.files.internal("assets/graphics/campfire.g3db"));
    font = new BitmapFont();
    font.setColor(Color.WHITE);
    fixedLight = new PointLight().set(1f, 0.8f, 0.6f, 4f, 4f, 4f, 5f);
    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();
    Model fm = builder.createBox(1, 1, 1, new Material(TextureAttribute.createDiffuse(assets.get("assets/graphics/rock.png", Texture.class))), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
    Model cm = builder.createBox(1, 1, 1, new Material(TextureAttribute.createDiffuse(assets.get("assets/graphics/dirt.png", Texture.class))), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
    try {
        int TILE_SIZE = 16;
        FileHandle f = new FileHandle("assets/tilemaps/tiles-vga-atlas.txt");
        TextureAtlasData a = new TextureAtlasData(f, f.parent(), false);
        mapTileIds = new String[a.getRegions().size + 1];
        for (Region r : a.getRegions()) {
            int x = r.left / r.width;
            int y = r.top / r.height;
            int i = y * TILE_SIZE + x + 1;
            mapTileIds[i] = r.name;
        }
        TiledMap map = new TmxMapLoader().load("assets/tilemaps/delveOfSorrows.tmx");
        Iterator<MapLayer> iter = map.getLayers().iterator();
        int level = 0;
        while (iter.hasNext()) {
            environment[level] = new Environment();
            environment[level].set(new ColorAttribute(ColorAttribute.Ambient, 0.5f, 0.5f, 0.5f, 1f));
            environment[level].add(fixedLight);
            layers[level] = (TiledMapTileLayer) iter.next();
            for (int y = 0; y < DUNGEON_MAP; y++) {
                for (int x = 0; x < DUNGEON_MAP; x++) {
                    String val = mapTileIds[layers[level].getCell(x, DUNGEON_MAP - y - 1).getTile().getId()];
                    DungeonTile tile = DungeonTile.getTileByName(val);
                    if (tile == null) {
                        CreatureType ct = CreatureType.get(val);
                        if (ct != null) {
                            Creature creature = Ultima4.creatures.getInstance(ct, Ultima4.standardAtlas);
                            creature.currentX = x;
                            creature.currentY = y;
                            creature.currentLevel = level;
                            creature.getDecal().setPosition(creature.currentX + .5f, .3f, creature.currentY + .5f);
                            dngMap.getMap().addCreature(creature);
                        } else {
                            System.err.println(val);
                        }
                        dungeonTiles[level][x][y] = DungeonTile.NOTHING;
                    } else if (tile == DungeonTile.WATER) {
                        Model w = builder.createBox(1, 1, 1, getMaterial(Color.BLUE, .9f), Usage.Position | Usage.Normal);
                        ModelInstance wi = new ModelInstance(w, x + .5f, -.5f, y + .5f);
                        DungeonTileModelInstance fin = new DungeonTileModelInstance(wi, DungeonTile.WATER, level);
                        modelInstances.add(fin);
                        dungeonTiles[level][x][y] = DungeonTile.NOTHING;
                    } else {
                        dungeonTiles[level][x][y] = tile;
                        addBlock(level, tile, x + .5f, .5f, y + .5f);
                    }
                    if (tile == null || tile != DungeonTile.WATER) {
                        DungeonTileModelInstance fin = new DungeonTileModelInstance(new ModelInstance(fm, new Vector3(x + .5f, -.5f, y + .5f)), DungeonTile.FLOOR, level);
                        modelInstances.add(fin);
                    }
                    DungeonTileModelInstance cin = new DungeonTileModelInstance(new ModelInstance(cm, new Vector3(x + .5f, 1.5f, y + .5f)), DungeonTile.FLOOR, level);
                    modelInstances.add(cin);
                }
            }
            level++;
        }
        setStartPosition();
        camera.position.set(currentPos);
        camera.lookAt(currentPos.x + 1, currentPos.y, currentPos.z);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DecalBatch(com.badlogic.gdx.graphics.g3d.decals.DecalBatch) Creature(objects.Creature) FileHandle(com.badlogic.gdx.files.FileHandle) MapLayer(com.badlogic.gdx.maps.MapLayer) 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) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) UBJsonReader(com.badlogic.gdx.utils.UBJsonReader) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) AssetManager(com.badlogic.gdx.assets.AssetManager) DungeonTileModelInstance(util.DungeonTileModelInstance) Material(com.badlogic.gdx.graphics.g3d.Material) Vector3(com.badlogic.gdx.math.Vector3) 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) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) Environment(com.badlogic.gdx.graphics.g3d.Environment) PointLight(com.badlogic.gdx.graphics.g3d.environment.PointLight) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Aggregations

G3dModelLoader (com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader)3 AssetManager (com.badlogic.gdx.assets.AssetManager)2 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)2 Texture (com.badlogic.gdx.graphics.Texture)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 Environment (com.badlogic.gdx.graphics.g3d.Environment)2 Material (com.badlogic.gdx.graphics.g3d.Material)2 Model (com.badlogic.gdx.graphics.g3d.Model)2 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)2 CameraGroupStrategy (com.badlogic.gdx.graphics.g3d.decals.CameraGroupStrategy)2 DecalBatch (com.badlogic.gdx.graphics.g3d.decals.DecalBatch)2 PointLight (com.badlogic.gdx.graphics.g3d.environment.PointLight)2 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)2 Vector3 (com.badlogic.gdx.math.Vector3)2 UBJsonReader (com.badlogic.gdx.utils.UBJsonReader)2 DungeonTileModelInstance (util.DungeonTileModelInstance)2 PartyDeathException (util.PartyDeathException)2 ModelLoader (com.badlogic.gdx.assets.loaders.ModelLoader)1