<commit_before>package de.longri.cachebox3.gui.widgets;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.BoundingBox;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import de.longri.cachebox3.CB;
import org.slf4j.LoggerFactory;

/**
 * Draw a 3D Model at Position of an Actor
 * <p>
 * Created by Longri on 06.11.16.
 */
public class Actor3D extends Actor {

    final static org.slf4j.Logger log = LoggerFactory.getLogger(Actor3D.class);

    /**
     * myLocationModel batch must set from initialisation
     */
    public static ModelBatch modelBatch;

    private Model model;
    private ModelInstance modelInstance;
    private PerspectiveCamera cam;
    private Environment environment;
    private final String name;

    private float worldX, worldY, modelScale = 1;

    private Drawable background;

    public Actor3D(String name, Model model) {
        this(name, model, null);
    }

    public Actor3D(String name, Model model, Environment environment) {
        this.model = model;
        this.name = name;

        if (environment == null) {
            this.environment = new Environment();
            this.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.5f, 0.5f, 0.5f, 1f));
            this.environment.add(new DirectionalLight().set(0.5f, 0.5f, 0.5f, -1f, -0.8f, -0.2f));
            this.environment.add(new DirectionalLight().set(0.5f, 0.5f, 0.5f, 1f, -0.8f, -0.2f));
        } else {
            this.environment = environment;
        }

        if (modelBatch == null) modelBatch = new ModelBatch();

        this.createModelInstance();
    }


    @Override
    public void draw(Batch batch, float parentColor) {

        //draw background
        if (background != null) {
            background.draw(batch, getX(), getY(), getWidth(), getHeight());
        }

        if (modelInstance != null) {
            //we must finish the 2D Batch for rendering 3D
            batch.flush();
            batch.end();

            // move viewport
            Gdx.gl.glViewport((int) worldX, (int) worldY, (int) getWidth(), (int) getHeight());


            //render 3d model
            modelBatch.begin(cam);
            modelBatch.render(modelInstance, environment);
            modelBatch.end();

            // return viewport
            Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

            // restart 2D Batch
            batch.begin();
        }
    }

    private void createModelInstance() {
        modelInstance = new ModelInstance(model);<commit_msg>fix ordering for Actor3D<commit_after>package de.longri.cachebox3.gui.widgets;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.BoundingBox;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import de.longri.cachebox3.CB;
import org.slf4j.LoggerFactory;

/**
 * Draw a 3D Model at Position of an Actor
 * <p>
 * Created by Longri on 06.11.16.
 */
public class Actor3D extends Actor {

    final static org.slf4j.Logger log = LoggerFactory.getLogger(Actor3D.class);

    /**
     * myLocationModel batch must set from initialisation
     */
    public static ModelBatch modelBatch;

    private Model model;
    private ModelInstance modelInstance;
    private PerspectiveCamera cam;
    private Environment environment;
    private final String name;

    private float worldX, worldY, modelScale = 1;

    private Drawable background;

    public Actor3D(String name, Model model) {
        this(name, model, null);
    }

    public Actor3D(String name, Model model, Environment environment) {
        this.model = model;
        this.name = name;

        if (environment == null) {
            this.environment = new Environment();
            this.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.5f, 0.5f, 0.5f, 1f));
            this.environment.add(new DirectionalLight().set(0.5f, 0.5f, 0.5f, -1f, -0.8f, -0.2f));
            this.environment.add(new DirectionalLight().set(0.5f, 0.5f, 0.5f, 1f, -0.8f, -0.2f));
        } else {
            this.environment = environment;
        }

        if (modelBatch == null) modelBatch = new ModelBatch();

        this.createModelInstance();
    }


    @Override
    public void draw(Batch batch, float parentColor) {

        //draw background
        if (background != null) {
            background.draw(batch, getX(), getY(), getWidth(), getHeight());
        }

        if (modelInstance != null) {
            //we must finish the 2D Batch for rendering 3D
            batch.flush();
            batch.end();

            // move viewport
            Gdx.gl.glViewport((int) worldX, (int) worldY, (int) getWidth(), (int) getHeight());

            // finish depth test for previews 3D rendering like Map
            Gdx.gl.glClear( GL20.GL_DEPTH_BUFFER_BIT );


            //render 3d model
            modelBatch.begin(cam);
            modelBatch.render(modelInstance, environment);
            modelBatch.end();

            // return viewport
            Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

            // restart 2D Batch
            batch.begin();
        }
    }

    private void createModelInstance() {
        modelInstance = new ModelInstance(model);
{'fraction_non_alphanumeric': 0.1146781910788702, 'fraction_numerical': 0.020064824818644852, 'mean_word_length': 2.6881047239612976, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6435131', 'n_tokens_mistral': 2120, 'n_tokens_neox': 1986, 'n_words': 445}