use of com.badlogic.gdx.graphics.g3d.ModelInstance in project ultimate-java by pantinor.
the class StaticGeneratedDungeonScreen method addBlock.
public void addBlock(int level, DungeonTile tile, float tx, float ty, float tz) {
ModelBuilder builder = new ModelBuilder();
if (tile == DungeonTile.WALL) {
Model model = builder.createBox(1, 1, 1, getMaterial(assets.get("assets/graphics/mortar.png", Texture.class)), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
ModelInstance instance = new ModelInstance(model, tx, ty, tz);
// rotate so the texture is aligned right
instance.transform.setFromEulerAngles(0, 0, 90).trn(tx, ty, tz);
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
modelInstances.add(in);
} else if (tile.getValue() >= 144 && tile.getValue() <= 148) {
ModelInstance instance = new ModelInstance(fountainModel, tx - .15f, 0, tz + .2f);
instance.nodes.get(0).scale.set(.010f, .010f, .010f);
instance.calculateTransforms();
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
modelInstances.add(in);
} else if (tile == DungeonTile.ROCKS) {
ModelInstance instance = new ModelInstance(rocksModel, tx, 0, tz);
instance.nodes.get(0).scale.set(.010f, .010f, .010f);
instance.calculateTransforms();
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
modelInstances.add(in);
} else if (tile == DungeonTile.MOONGATE) {
Color c = Color.CYAN;
Model model = builder.createBox(1, 1, 1, getMaterial(c, .7f), Usage.Position | Usage.Normal);
ModelInstance instance = new ModelInstance(model, tx, .5f, tz);
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
modelInstances.add(in);
in.x = (int) tx;
in.y = (int) tz;
} else if (tile.getValue() >= 10 && tile.getValue() <= 48) {
ModelInstance instance = new ModelInstance(ladderModel, tx, 0, tz);
instance.nodes.get(0).scale.set(.060f, .060f, .060f);
instance.calculateTransforms();
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
modelInstances.add(in);
Model manhole = builder.createCylinder(.75f, .02f, .75f, 32, getMaterial(Color.DARK_GRAY, 1), Usage.Position | Usage.Normal);
if (tile == DungeonTile.LADDER_DOWN) {
instance = new ModelInstance(manhole, tx, 0, tz);
modelInstances.add(new DungeonTileModelInstance(instance, tile, level));
} else if (tile == DungeonTile.LADDER_UP) {
instance = new ModelInstance(manhole, tx, 1, tz);
modelInstances.add(new DungeonTileModelInstance(instance, tile, level));
} else if (tile == DungeonTile.LADDER_UP_DOWN) {
instance = new ModelInstance(manhole, tx, 0, tz);
modelInstances.add(new DungeonTileModelInstance(instance, tile, level));
instance = new ModelInstance(manhole, tx, 1, tz);
modelInstances.add(new DungeonTileModelInstance(instance, tile, level));
}
} else if (tile == DungeonTile.CHEST) {
ModelInstance instance = new ModelInstance(chestModel, tx, 0, tz);
instance.nodes.get(0).scale.set(.010f, .010f, .010f);
instance.calculateTransforms();
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
modelInstances.add(in);
in.x = (int) tx;
in.y = (int) tz;
} else if (tile == DungeonTile.COLUMN) {
Model sf = builder.createCylinder(.35f, 2.5f, .35f, 32, getMaterial(assets.get("assets/graphics/Stone_Masonry.jpg", Texture.class)), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
ModelInstance instance = new ModelInstance(sf);
instance.transform.setToTranslation(tx, 0, tz);
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
in.x = (int) tx;
in.y = (int) tz;
modelInstances.add(in);
} else if (tile == DungeonTile.ORB) {
ModelInstance instance = new ModelInstance(orbModel, tx, .5f, tz);
instance.nodes.get(0).scale.set(.0025f, .0025f, .0025f);
instance.calculateTransforms();
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
in.x = (int) tx;
in.y = (int) tz;
modelInstances.add(in);
} else if (tile == DungeonTile.ALTAR) {
ModelInstance instance = new ModelInstance(altarModel, tx, 0, tz);
instance.nodes.get(0).scale.set(.0040f, .0040f, .0040f);
instance.calculateTransforms();
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
in.x = (int) tx;
in.y = (int) tz;
modelInstances.add(in);
} else if (tile == DungeonTile.LIGHT) {
// PointLight pl = new PointLight().set(nll2.x, nll2.y, nll2.z, tx, .8f, tz, 2f);
// DirectionalLight pl = new DirectionalLight().set(nll2.x, nll2.y, nll2.z, tx, .8f, tz);
// environment[level].add(pl);
// Model lm = builder.createSphere(.02f, .02f, .02f, 10, 10, getMaterial(new Color(nll2.x, nll2.y, nll2.z, 1), .7f), Usage.Position);
// ModelInstance instance = new ModelInstance(lm);
// instance.transform.setToTranslation(tx, .8f, tz);
// DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
// in.x=(int)tx; in.y=(int)tz;
// modelInstances.add(in);
} else if (tile == DungeonTile.FIRE) {
ModelInstance instance = new ModelInstance(campfireModel, tx, 0, tz);
instance.nodes.get(0).scale.set(.510f, .510f, .510f);
instance.calculateTransforms();
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
modelInstances.add(in);
} else if (tile.getValue() >= 160 && tile.getValue() <= 163) {
Color c = Color.GREEN;
if (tile == DungeonTile.FIELD_ENERGY) {
c = Color.BLUE;
}
if (tile == DungeonTile.FIELD_FIRE) {
c = Color.RED;
}
if (tile == DungeonTile.FIELD_SLEEP) {
c = Color.PURPLE;
}
Model model = builder.createBox(1, 1, 1, getMaterial(c, .7f), Usage.Position | Usage.Normal);
ModelInstance instance = new ModelInstance(model, tx, .5f, tz);
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
modelInstances.add(in);
in.x = (int) tx;
in.y = (int) tz;
} else if (tile == DungeonTile.DOOR || tile == DungeonTile.SECRET_DOOR || tile == DungeonTile.LOCKED_DOOR) {
Model model = builder.createBox(1, 1, 1, getMaterial(assets.get("assets/graphics/mortar.png", Texture.class)), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
ModelInstance instance = new ModelInstance(model, tx, ty, tz);
instance.transform.setFromEulerAngles(0, 0, 90).trn(tx, ty, tz);
DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
modelInstances.add(in);
Material matDoor = null;
if (tile == DungeonTile.DOOR || tile == DungeonTile.LOCKED_DOOR) {
matDoor = getMaterial(assets.get("assets/graphics/door.png", Texture.class));
} else {
matDoor = getMaterial(Color.DARK_GRAY, .3f);
}
model = builder.createBox(1.04f, .85f, .6f, matDoor, Usage.Position | Usage.TextureCoordinates | Usage.Normal);
instance = new ModelInstance(model, tx, .4f, tz);
in = new DungeonTileModelInstance(instance, tile, level);
modelInstances.add(in);
model = builder.createBox(.6f, .85f, 1.04f, matDoor, Usage.Position | Usage.TextureCoordinates | Usage.Normal);
instance = new ModelInstance(model, tx, .4f, tz);
in = new DungeonTileModelInstance(instance, tile, level);
modelInstances.add(in);
}
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance 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();
}
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project ultimate-java by pantinor.
the class CodexScreen method nextPiece.
private void nextPiece() {
switch(codexQuestionCount) {
case 1:
// modelInstances.add(createLine(3.75f, 6.5f, 5.5f, 3.5f, 0.204f, Color.WHITE));
modelInstances.add(createPolygonBox(Virtue.HONESTY.getColor(), .02f, .02f, 3.5f, -30f, 4.65f, 0.204f, 5.0f));
break;
case 2:
// modelInstances.add(createLine(5.5f, 3.5f, 7.25f, 6.5f, 0.204f, Color.WHITE));
modelInstances.add(createPolygonBox(Virtue.COMPASSION.getColor(), .02f, .02f, 3.5f, 30f, 6.35f, 0.204f, 5.0f));
break;
case 3:
// modelInstances.add(createLine(7.25f, 6.5f, 3.75f, 6.5f, 0.204f, Color.WHITE));
modelInstances.add(createPolygonBox(Virtue.VALOR.getColor(), .02f, .02f, 3.5f, 90f, 5.5f, 0.204f, 6.5f));
break;
case 4:
// modelInstances.add(createLine(3.5f, 4.75f, 7.5f, 4.75f, 0.204f, Color.WHITE));
modelInstances.add(createPolygonBox(Virtue.JUSTICE.getColor(), .02f, .02f, 3.7f, 90f, 5.5f, 0.204f, 4.75f));
break;
case 5:
// modelInstances.add(createLine(7.25f, 4.25f, 5.25f, 7.5f, 0.204f, Color.WHITE));
modelInstances.add(createPolygonBox(Virtue.SACRIFICE.getColor(), .02f, .02f, 3.7f, -30f, 6.2f, 0.204f, 5.9f));
break;
case 6:
// modelInstances.add(createLine(5.75f, 7.5f, 3.75f, 4.25f, 0.204f, Color.WHITE));
modelInstances.add(createPolygonBox(Virtue.HONOR.getColor(), .02f, .02f, 3.7f, 30f, 4.8f, 0.204f, 5.9f));
break;
case 7:
ModelBuilder builder = new ModelBuilder();
Model sp = builder.createSphere(.08f, .08f, .08f, 32, 32, new Material(ColorAttribute.createDiffuse(Virtue.SPIRITUALITY.getColor())), Usage.Position | Usage.Normal);
ModelInstance modelInstance = new ModelInstance(sp);
modelInstance.transform.setTranslation(5.5f, 0.204f, 5.5f);
modelInstances.add(modelInstance);
// modelInstances.add(fillCircle(.05f, center, 0.204f, Virtue.SPIRITUALITY.getColor()));
break;
case 8:
// modelInstances.add(fillCircle(2.5f,center, 0.202f, Virtue.HUMILITY.getColor()));
modelInstances.add(createCylinder(4.0f, .1f, 5.5f, 0.1f, 5.5f, Virtue.HUMILITY.getColor()));
break;
case 9:
// modelInstances.add(createCircle(.9f, .03f, new Vector3(5.05f, 0, 5.25f), 0.204f, Color.BLUE));
modelInstances.add(createCylinder(.9f, .1f, 5.05f, 0.204f, 5.25f, Color.BLUE));
break;
case 10:
// modelInstances.add(createCircle(.9f, .03f,new Vector3(5.95f, 0, 5.25f), 0.204f, Color.YELLOW));
modelInstances.add(createCylinder(.9f, .1f, 5.95f, 0.204f, 5.25f, Color.YELLOW));
break;
case 11:
// modelInstances.add(createCircle(.9f, .03f,new Vector3(5.5f, 0, 6.025f), 0.204f, Color.RED));
modelInstances.add(createCylinder(.9f, .1f, 5.5f, 0.204f, 6.025f, Color.RED));
break;
default:
break;
}
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project ultimate-java by pantinor.
the class CodexScreen method createAxes.
private void createAxes() {
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
// grid
MeshPartBuilder builder = modelBuilder.part("grid", GL30.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material());
builder.setColor(Color.LIGHT_GRAY);
for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) {
builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
}
// axes
builder = modelBuilder.part("axes", GL30.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material());
builder.setColor(Color.RED);
builder.line(0, 0, 0, 500, 0, 0);
builder.setColor(Color.GREEN);
builder.line(0, 0, 0, 0, 500, 0);
builder.setColor(Color.BLUE);
builder.line(0, 0, 0, 0, 0, 500);
axesModel = modelBuilder.end();
axesInstance = new ModelInstance(axesModel);
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project ultimate-java by pantinor.
the class CodexScreen method createLine.
private ModelInstance createLine(float sx, float sy, float ex, float ey, float z, Color color) {
Model model = null;
ModelBuilder mb = new ModelBuilder();
mb.begin();
MeshPartBuilder builder = mb.part("line", GL30.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material());
builder.setColor(color);
builder.line(sx, 0, sy, ex, 0, ey);
model = mb.end();
ModelInstance modelInstance = new ModelInstance(model);
modelInstance.transform.setToTranslation(0, z, 0);
return modelInstance;
}
Aggregations