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();
}
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();
}
}
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();
}
}
Aggregations