Search in sources :

Example 46 with ModelInstance

use of com.badlogic.gdx.graphics.g3d.ModelInstance in project bladecoder-adventure-engine by bladecoder.

the class Sprite3DRenderer method retrieveSource.

private void retrieveSource(String source) {
    ModelCacheEntry entry = (ModelCacheEntry) sourceCache.get(source);
    if (entry == null || entry.refCounter < 1) {
        loadSource(source);
        EngineAssetManager.getInstance().finishLoading();
        entry = (ModelCacheEntry) sourceCache.get(source);
    }
    if (entry.modelInstance == null) {
        Model model3d = EngineAssetManager.getInstance().getModel3D(source);
        entry.modelInstance = new ModelInstance(model3d);
        entry.controller = new AnimationController(entry.modelInstance);
        entry.camera3d = getCamera(entry.modelInstance);
    }
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) Model(com.badlogic.gdx.graphics.g3d.Model)

Example 47 with ModelInstance

use of com.badlogic.gdx.graphics.g3d.ModelInstance in project bladecoder-adventure-engine by bladecoder.

the class Utils3D method createFloor.

public static void createFloor() {
    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.ColorUnpacked, new Material(ColorAttribute.createDiffuse(Color.WHITE)));
    mpb.setColor(1f, 1f, 1f, 1f);
    // mpb.box(0, -0.1f, 0, 10, .2f, 10);
    mpb.rect(-10, 0, -10, -10, 0, 10, 10, 0, 10, 10, 0, -10, 0, 1, 0);
    floorModel = modelBuilder.end();
    floorInstance = new ModelInstance(floorModel);
    // TODO Set only when FBO is active
    floorInstance.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) Material(com.badlogic.gdx.graphics.g3d.Material) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)

Example 48 with ModelInstance

use of com.badlogic.gdx.graphics.g3d.ModelInstance in project bladecoder-adventure-engine by bladecoder.

the class Utils3D method createAxes.

private static void createAxes() {
    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder builder = modelBuilder.part("grid", GL20.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);
    }
    builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material());
    builder.setColor(Color.RED);
    builder.line(0, 0, 0, 10, 0, 0);
    builder.setColor(Color.GREEN);
    builder.line(0, 0, 0, 0, 10, 0);
    builder.setColor(Color.BLUE);
    builder.line(0, 0, 0, 0, 0, 10);
    axesModel = modelBuilder.end();
    axesInstance = new ModelInstance(axesModel);
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) Material(com.badlogic.gdx.graphics.g3d.Material) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)

Example 49 with ModelInstance

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

the class DungeonScreen 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;
    }
    // if exiting dungeon rooms, move out of the room with orientation to next coordinate
    if (combatMap.getType() == MapType.dungeon) {
        Direction exitDirection = context.getParty().getActivePartyMember().combatMapExitDirection;
        if (exitDirection != null) {
            currentDir = exitDirection;
            int x = (Math.round(currentPos.x) - 1);
            int y = (Math.round(currentPos.z) - 1);
            // check for portal to another dungeon
            for (Portal p : combatMap.getPortals()) {
                if (p.getX() == x && p.getY() == y && p.getExitDirection() == exitDirection) {
                    Maps m = Maps.get(p.getDestmapid());
                    if (m == dngMap) {
                        break;
                    }
                    log("Entering " + m.getLabel() + "!");
                    DungeonScreen sc = new DungeonScreen(this.gameScreen, this.context, m);
                    sc.restoreSaveGameLocation(p.getStartx(), p.getStarty(), p.getStartlevel(), currentDir);
                    mainGame.setScreen(sc);
                    this.gameScreen.newMapPixelCoords = this.gameScreen.getMapPixelCoords(p.getRetroActiveDest().getX(), p.getRetroActiveDest().getY());
                    return;
                }
            }
            if (exitDirection == Direction.EAST) {
                x = x + 1;
                if (x > 7) {
                    x = 0;
                }
            } else if (exitDirection == Direction.WEST) {
                x = x - 1;
                if (x < 0) {
                    x = 7;
                }
            } else if (exitDirection == Direction.NORTH) {
                y = y - 1;
                if (y < 0) {
                    y = 7;
                }
            } else if (exitDirection == Direction.SOUTH) {
                y = y + 1;
                if (y > 7) {
                    y = 0;
                }
            }
            DungeonTile tile = dungeonTiles[currentLevel][x][y];
            try {
                if (tile != DungeonTile.WALL) {
                    currentPos = new Vector3(x + .5f, .5f, y + .5f);
                    camera.position.set(currentPos);
                    if (currentDir == Direction.EAST) {
                        camera.lookAt(currentPos.x + 1, currentPos.y, currentPos.z);
                    } else if (currentDir == Direction.WEST) {
                        camera.lookAt(currentPos.x - 1, currentPos.y, currentPos.z);
                    } else if (currentDir == Direction.NORTH) {
                        camera.lookAt(currentPos.x, currentPos.y, currentPos.z - 1);
                    } else if (currentDir == Direction.SOUTH) {
                        camera.lookAt(currentPos.x, currentPos.y, currentPos.z + 1);
                    }
                    checkTileAffects(tile, x, y);
                    moveMiniMapIcon();
                }
            } catch (PartyDeathException e) {
                partyDeath();
            }
            if (tile.getValue() >= 208 && tile.getValue() <= 223) {
                RoomLocater loc = null;
                for (RoomLocater r : locaters) {
                    if (r.z == currentLevel && r.x == x && r.y == y) {
                        loc = r;
                        break;
                    }
                }
                enterRoom(loc, Direction.reverse(currentDir));
            }
        }
    }
}
Also used : DungeonTileModelInstance(util.DungeonTileModelInstance) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) DungeonTileModelInstance(util.DungeonTileModelInstance) Portal(objects.Portal) Vector3(com.badlogic.gdx.math.Vector3) PartyDeathException(util.PartyDeathException)

Example 50 with ModelInstance

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

the class DungeonScreen 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, new Material(TextureAttribute.createDiffuse(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.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, new Material(ColorAttribute.createDiffuse(Color.DARK_GRAY)), 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.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.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, new Material(ColorAttribute.createDiffuse(c), ColorAttribute.createSpecular(c), new BlendingAttribute(0.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() >= 208 && tile.getValue() <= 223) {
        // room indicator
        Model model = builder.createBox(1, 1, 1, new Material(ColorAttribute.createDiffuse(Color.DARK_GRAY), ColorAttribute.createSpecular(Color.DARK_GRAY), new BlendingAttribute(0.6f)), Usage.Position | Usage.Normal);
        ModelInstance instance = new ModelInstance(model, tx, .5f, tz);
        DungeonTileModelInstance in = new DungeonTileModelInstance(instance, tile, level);
        modelInstances.add(in);
    } else if (tile == DungeonTile.DOOR || tile == DungeonTile.SECRET_DOOR) {
        Model model = builder.createBox(1, 1, 1, new Material(TextureAttribute.createDiffuse(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) {
            matDoor = new Material(TextureAttribute.createDiffuse(assets.get("assets/graphics/door.png", Texture.class)));
        } else {
            matDoor = new Material(new Material(ColorAttribute.createDiffuse(Color.DARK_GRAY), ColorAttribute.createSpecular(Color.DARK_GRAY), new BlendingAttribute(0.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);
    }
}
Also used : DungeonTileModelInstance(util.DungeonTileModelInstance) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) DungeonTileModelInstance(util.DungeonTileModelInstance) Color(com.badlogic.gdx.graphics.Color) Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)56 Material (com.badlogic.gdx.graphics.g3d.Material)30 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)26 Model (com.badlogic.gdx.graphics.g3d.Model)23 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