Search in sources :

Example 1 with ModelCache

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

the class GraphicsSystem method begin.

@Override
protected void begin() {
    super.begin();
    if (physicsSystem == null) {
        physicsSystem = entities.getEntitySystem(PhysicsSystem.class);
    }
    if (cameraSystem == null) {
        cameraSystem = entities.getEntitySystem(CameraSystem.class);
    }
    if (physicsSystem.isPhysicsInitialized()) {
        if (debugDrawer == null) {
            debugDrawer = new DebugDrawer();
            debugDrawer.setDebugMode(btIDebugDraw.DebugDrawModes.DBG_MAX_DEBUG_DRAW_MODE);
        }
        physicsSystem.setDebugDrawer(debugDrawer);
    }
    cameras = cameraSystem.cameras;
    for (int i = 0; i < cameras.size - modelBatches.size; i++) {
        modelBatches.add(new ModelBatch(shaderProvider));
        dynamicCaches.add(new ModelCache());
        staticCaches.add(new ModelCache());
    }
    for (int i = 0; i < cameras.size; i++) {
        Camera camera = cameras.get(i);
        ModelCache dynamicCache = dynamicCaches.get(i);
        dynamicCache.begin(camera);
    }
}
Also used : DebugDrawer(com.badlogic.gdx.physics.bullet.DebugDrawer) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Camera(com.badlogic.gdx.graphics.Camera) ModelCache(com.badlogic.gdx.graphics.g3d.ModelCache)

Example 2 with ModelCache

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

the class MultipleRenderTargetTest method create.

@Override
public void create() {
    //use default prepend shader code for batch, some gpu drivers are less forgiving
    batch = new SpriteBatch();
    //depth texture not currently sampled
    ShaderProgram.pedantic = false;
    modelCache = new ModelCache();
    ShaderProgram.prependVertexCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_ARB_explicit_attrib_location : enable\n" : "#version 300 es\n";
    ShaderProgram.prependFragmentCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_ARB_explicit_attrib_location : enable\n" : "#version 300 es\n";
    renderContext = new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.ROUNDROBIN));
    shaderProvider = new BaseShaderProvider() {

        @Override
        protected Shader createShader(Renderable renderable) {
            return new MRTShader(renderable);
        }
    };
    renderableSorter = new DefaultRenderableSorter() {

        @Override
        public int compare(Renderable o1, Renderable o2) {
            return o1.shader.compareTo(o2.shader);
        }
    };
    mrtSceneShader = new ShaderProgram(Gdx.files.internal("data/g3d/shaders/mrtscene.vert"), Gdx.files.internal("data/g3d/shaders/mrtscene.frag"));
    if (!mrtSceneShader.isCompiled()) {
        System.out.println(mrtSceneShader.getLog());
    }
    quad = createFullScreenQuad();
    camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.near = 1f;
    camera.far = 100f;
    camera.position.set(3, 5, 10);
    camera.lookAt(0, 2, 0);
    camera.up.set(0, 1, 0);
    camera.update();
    cameraController = new FirstPersonCameraController(camera);
    cameraController.setVelocity(50);
    Gdx.input.setInputProcessor(cameraController);
    frameBuffer = new MRTFrameBuffer(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 3);
    AssetManager assetManager = new AssetManager();
    assetManager.load("data/g3d/materials/cannon.g3db", Model.class);
    assetManager.finishLoading();
    Model scene = assetManager.get("data/g3d/materials/cannon.g3db");
    cannon = new ModelInstance(scene, "Cannon_LP");
    cannon.transform.setToTranslationAndScaling(0, 0, 0, 0.001f, 0.001f, 0.001f);
    ModelBuilder modelBuilder = new ModelBuilder();
    for (int i = 0; i < NUM_LIGHTS; i++) {
        modelBuilder.begin();
        Light light = new Light();
        light.color.set(MathUtils.random(1f), MathUtils.random(1f), MathUtils.random(1f));
        light.position.set(MathUtils.random(-10f, 10f), MathUtils.random(10f, 15f), MathUtils.random(-10f, 10f));
        light.vy = MathUtils.random(10f, 20f);
        light.vx = MathUtils.random(-10f, 10f);
        light.vz = MathUtils.random(-10f, 10f);
        MeshPartBuilder meshPartBuilder = modelBuilder.part("light", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorPacked | VertexAttributes.Usage.Normal, new Material());
        meshPartBuilder.setColor(light.color.x, light.color.y, light.color.z, 1f);
        meshPartBuilder.sphere(0.2f, 0.2f, 0.2f, 10, 10);
        light.lightInstance = new ModelInstance(modelBuilder.end());
        lights.add(light);
    }
    modelBuilder.begin();
    MeshPartBuilder meshPartBuilder = modelBuilder.part("floor", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorPacked | VertexAttributes.Usage.Normal, new Material());
    meshPartBuilder.setColor(0.2f, 0.2f, 0.2f, 1f);
    meshPartBuilder.box(0, -0.1f, 0f, 20f, 0.1f, 20f);
    floorInstance = new ModelInstance(modelBuilder.end());
    Gdx.input.setInputProcessor(new InputMultiplexer(this, cameraController));
}
Also used : RenderContext(com.badlogic.gdx.graphics.g3d.utils.RenderContext) AssetManager(com.badlogic.gdx.assets.AssetManager) Material(com.badlogic.gdx.graphics.g3d.Material) DefaultRenderableSorter(com.badlogic.gdx.graphics.g3d.utils.DefaultRenderableSorter) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder) Shader(com.badlogic.gdx.graphics.g3d.Shader) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BaseShaderProvider(com.badlogic.gdx.graphics.g3d.utils.BaseShaderProvider) ModelCache(com.badlogic.gdx.graphics.g3d.ModelCache) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) Renderable(com.badlogic.gdx.graphics.g3d.Renderable) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) Model(com.badlogic.gdx.graphics.g3d.Model) FirstPersonCameraController(com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController) DefaultTextureBinder(com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder)

Example 3 with ModelCache

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

the class ModelCacheTest method create.

@Override
public void create() {
    super.create();
    modelCache = new ModelCache();
    cacheCheckBox = new CheckBox("Cache", skin);
    cacheCheckBox.setChecked(false);
    cacheCheckBox.setPosition(hudWidth - cacheCheckBox.getWidth(), moveCheckBox.getTop());
    hud.addActor(cacheCheckBox);
}
Also used : CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ModelCache(com.badlogic.gdx.graphics.g3d.ModelCache)

Example 4 with ModelCache

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

the class GraphicsSystem method rebuildCache.

private void rebuildCache(RenderableProvider... renderableProviders) {
    Array<ModelCache> previousModelCaches = new Array<>(staticCaches);
    for (int i = 0; i < cameras.size; i++) {
        ModelCache previousModelCache = previousModelCaches.get(i);
        ModelCache staticCache = staticCaches.get(i);
        Camera camera = cameras.get(i);
        previousModelCache.begin(camera);
        previousModelCache.add(staticCache);
        previousModelCache.end();
        staticCache.begin(camera);
        staticCache.add(previousModelCache);
        for (RenderableProvider provider : renderableProviders) {
            staticCache.add(provider);
        }
        staticCache.end();
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) RenderableProvider(com.badlogic.gdx.graphics.g3d.RenderableProvider) Camera(com.badlogic.gdx.graphics.Camera) ModelCache(com.badlogic.gdx.graphics.g3d.ModelCache)

Example 5 with ModelCache

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

the class GraphicsSystem method process.

@Override
protected void process(int entityId) {
    ModelComponent modelComponent = modelMapper.get(entityId);
    NodeComponent nodeComponent = nodeMapper.get(entityId);
    if (modelComponent.enabled) {
        if (modelComponent.animationController != null) {
            modelComponent.animationController.update(Gdx.graphics.getDeltaTime());
        }
        if (modelComponent.type == ModelComponent.Type.DYNAMIC && modelComponent.model != null) {
            modelComponent.model.transform.set(nodeComponent.getTransform());
            for (ModelCache modelCache : dynamicCaches) {
                modelCache.add(modelComponent.model);
            }
        }
    }
}
Also used : ModelComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent) ModelCache(com.badlogic.gdx.graphics.g3d.ModelCache)

Aggregations

ModelCache (com.badlogic.gdx.graphics.g3d.ModelCache)6 Camera (com.badlogic.gdx.graphics.Camera)3 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)2 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)1 AssetManager (com.badlogic.gdx.assets.AssetManager)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 Material (com.badlogic.gdx.graphics.g3d.Material)1 Model (com.badlogic.gdx.graphics.g3d.Model)1 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)1 Renderable (com.badlogic.gdx.graphics.g3d.Renderable)1 RenderableProvider (com.badlogic.gdx.graphics.g3d.RenderableProvider)1 Shader (com.badlogic.gdx.graphics.g3d.Shader)1 BaseShaderProvider (com.badlogic.gdx.graphics.g3d.utils.BaseShaderProvider)1 DefaultRenderableSorter (com.badlogic.gdx.graphics.g3d.utils.DefaultRenderableSorter)1 DefaultTextureBinder (com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder)1 FirstPersonCameraController (com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController)1 MeshPartBuilder (com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)1 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)1 RenderContext (com.badlogic.gdx.graphics.g3d.utils.RenderContext)1