Search in sources :

Example 41 with ModelInstance

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

the class FogTest method create.

@Override
public void create() {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
    environment.set(new ColorAttribute(ColorAttribute.Fog, 0.13f, 0.13f, 0.13f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(30f, 10f, 30f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 45f;
    cam.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    instance = new ModelInstance(model);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 42 with ModelInstance

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

the class FrameBufferCubemapTest method renderScene.

public void renderScene() {
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
    Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
    // Render scene to screen
    super.render();
    // Render scene to cubemap
    camFb.position.set(cam.position);
    camFb.near = cam.near;
    camFb.far = cam.far;
    fb.begin();
    while (fb.nextSide()) {
        fb.getSide().getUp(camFb.up);
        fb.getSide().getDirection(camFb.direction);
        camFb.update();
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
        modelBatch.begin(camFb);
        for (ModelInstance instance : instances) modelBatch.render(instance, lights);
        if (space != null)
            modelBatch.render(space);
        modelBatch.end();
    }
    fb.end();
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance)

Example 43 with ModelInstance

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

the class MaterialTest method create.

@Override
public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), true);
    // Create material attributes. Each material can contain x-number of attributes.
    textureAttribute = new TextureAttribute(TextureAttribute.Diffuse, texture);
    colorAttribute = new ColorAttribute(ColorAttribute.Diffuse, Color.ORANGE);
    blendingAttribute = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    ModelBuilder builder = new ModelBuilder();
    model = builder.createBox(1, 1, 1, new Material(), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    model.manageDisposable(texture);
    modelInstance = new ModelInstance(model);
    modelInstance.transform.rotate(Vector3.X, 45);
    material = modelInstance.materials.get(0);
    builder.begin();
    MeshPartBuilder mpb = builder.part("back", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates, new Material(textureAttribute));
    mpb.rect(-2, -2, -2, 2, -2, -2, 2, 2, -2, -2, 2, -2, 0, 0, 1);
    backModel = builder.end();
    background = new ModelInstance(backModel);
    modelBatch = new ModelBatch();
    camera = new PerspectiveCamera(45, 4, 4);
    camera.position.set(0, 0, 3);
    camera.direction.set(0, 0, -1);
    camera.update();
    Gdx.input.setInputProcessor(this);
}
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) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Material(com.badlogic.gdx.graphics.g3d.Material) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) Texture(com.badlogic.gdx.graphics.Texture) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Example 44 with ModelInstance

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

the class ViewportTest3 method create.

public void create() {
    modelBatch = new ModelBatch();
    modelBuilder = new ModelBuilder();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
    shadowLight = new DirectionalLight();
    shadowLight.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
    environment.add(shadowLight);
    modelBatch = new ModelBatch();
    camera = new PerspectiveCamera();
    camera.fieldOfView = 67;
    camera.near = 0.1f;
    camera.far = 300f;
    camera.position.set(0, 0, 100);
    camera.lookAt(0, 0, 0);
    viewports = ViewportTest1.getViewports(camera);
    viewport = viewports.first();
    names = ViewportTest1.getViewportNames();
    name = names.first();
    ModelBuilder modelBuilder = new ModelBuilder();
    Model boxModel = modelBuilder.createBox(50f, 50f, 50f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    boxInstance = new ModelInstance(boxModel);
    boxInstance.transform.rotate(1, 0, 0, 30);
    boxInstance.transform.rotate(0, 1, 0, 30);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(viewport, true) + 1) % viewports.size;
                name = names.get(index);
                viewport = viewports.get(index);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    });
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) InputAdapter(com.badlogic.gdx.InputAdapter) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Model(com.badlogic.gdx.graphics.g3d.Model) Environment(com.badlogic.gdx.graphics.g3d.Environment) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 45 with ModelInstance

use of com.badlogic.gdx.graphics.g3d.ModelInstance in project nhglib by VoidZombie.

the class SceneManager method loadAssets.

private void loadAssets(Integer entity) {
    final ModelComponent modelComponent = modelMapper.get(entity);
    // Group all assets
    final Array<Asset> allAssets = new Array<>();
    final Asset modelAsset = modelComponent.asset;
    for (PbrMaterial mat : modelComponent.pbrMaterials) {
        if (mat.albedoAsset != null) {
            allAssets.add(mat.albedoAsset);
        }
        if (mat.metalnessAsset != null) {
            allAssets.add(mat.metalnessAsset);
        }
        if (mat.roughnessAsset != null) {
            allAssets.add(mat.roughnessAsset);
        }
        if (mat.normalAsset != null) {
            allAssets.add(mat.normalAsset);
        }
        if (mat.ambientOcclusionAsset != null) {
            allAssets.add(mat.ambientOcclusionAsset);
        }
    }
    // Start loading them
    assets.queueAsset(modelAsset);
    // Wait for them
    messaging.get(Strings.Events.assetLoaded).subscribe(new Consumer<Message>() {

        @Override
        public void accept(Message message) throws Exception {
            Asset asset = (Asset) message.data.get(Strings.Defaults.assetKey);
            if (asset != null) {
                if (asset.is(modelAsset.alias)) {
                    Model model = assets.get(asset);
                    modelComponent.model = new ModelInstance(model);
                    if (modelComponent.model.animations.size > 0) {
                        modelComponent.animationController = new AnimationController(modelComponent.model);
                    }
                    assets.queueAssets(allAssets);
                } else {
                    if (allAssets.contains(asset, false)) {
                        temporaryLoadedAssets.add(asset);
                        allAssets.removeValue(asset, false);
                        Bundle bundle = new Bundle();
                        bundle.put("size", allAssets.size);
                        bundle.put("modelComponent", modelComponent);
                        sizeSubject.onNext(bundle);
                    }
                }
            }
        }
    });
}
Also used : Message(io.github.voidzombie.nhglib.runtime.messaging.Message) Bundle(io.github.voidzombie.nhglib.utils.data.Bundle) Array(com.badlogic.gdx.utils.Array) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) Model(com.badlogic.gdx.graphics.g3d.Model) Asset(io.github.voidzombie.nhglib.assets.Asset) PbrMaterial(io.github.voidzombie.nhglib.graphics.utils.PbrMaterial)

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